资源简介

串口操作封装类: 包括: BOOL WriteComm(char* lpBuffer, int nLen); // 写串口 BOOL ReadComm(char* lpBuff, int nLen); // 读串口函数 BOOL SetTimeOuts(COMMTIMEOUTS stTimeOuts); // 设置超时时间 BOOL SetComm(int nBaudRate/*波特率*/,int nParity/*奇偶校验*/,int nByteSize, int nStopBits); // 设置串口 void CloseComm

资源截图

代码片段和文件信息

// Comm.cpp: implementation of the CComm class.
//
//////////////////////////////////////////////////////////////////////

#include “stdafx.h“
#include “Comm.h“

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
const int MAXBLOCK =2048;
CComm::CComm()
{
m_hComm = INVALID_HANDLE_VALUE;
}

CComm::~CComm()
{
CloseComm();//关闭串口
}
// 
BOOL CComm::OpenComm(int nComm)
{
CString strCommName =_T(““);
CString strErrInfo =_T(““);
strCommName.Format(_T(“COM%d“) nComm);
m_hComm =::CreateFile(strCommName /*要打开串口名称*/
GENERIC_READ | GENERIC_WRITE /*允

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2753  2009-06-18 20:39  Comm.cpp

     文件        770  2009-07-07 09:55  Comm.h

----------- ---------  ---------- -----  ----

                 3523                    2


评论

共有 条评论