不多说先来段代码(重叠方式)
if(hCom != NULL)
{
CloseHandle(hCom);
}
hCom=CreateFile(_T("COM1:"), GENERIC_READ|GENERIC_WRITE, 0,NULL , OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
if (hCom==INVALID_HANDLE_VALUE)
{
AfxMessageBox(_T("打开COM失败!"));
return false;
}
else{
SetupComm(hCom,100,100);
COMMTIMEOUTS TimeOuts;
TimeOuts.ReadIntervalTimeout=MAXDWORD;
TimeOuts.ReadTotalTimeoutMultiplier=0;
TimeOuts.ReadTotalTimeoutConstant=0;
TimeOuts.WriteTotalTimeoutMultiplier=100;
TimeOuts.WriteTotalTimeoutConstant=500;
SetCommTimeouts(hCom,&TimeOuts);
DCB dcb;
dcb.BaudRate=1200;
dcb.ByteSize=8;
dcb.Parity=NOPARITY;
dcb.StopBits=TWOSTOPBITS;
SetCommState(hCom,&dcb);
PurgeComm(hCom,PURGE_TXCLEAR|PURGE_RXCLEAR);
CreateFile(_T("COM1:")...) 因为少了一个“:” 浪费一下午,哎。。。。。。