資源簡介
串口操作封裝類:
包括:
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
評論
共有 條評論