DWORD WINAPI ReadPortThread(LPVOID lpvoid)
{
BYTE Byte;
DWORD dwCommModemStatus,
dwBytesTransferred;
CString tempStr;
// Specify a set of events to be monitored for the port.
SetCommMask (hPort, EV_RXCHAR);
WaitCommEvent (hPort, &dwCommModemStatus, 0);
if (dwCommModemStatus & EV_RXCHAR)
{
DWORD length=0;
COMSTAT ComStat;
DWORD dwErrorFlags;
char *buf=NULL;
ClearCommError(hPort,&dwErrorFlags,&ComStat);
length=ComStat.cbInQue;
ReadFile(hPort,buf,length,&length,NULL);
CString temp=buf;
MessageBox(NULL,temp,TEXT( "Result "),MB_OK);
}
// Retrieve modem control-register values.
GetCommModemStatus (hPort, &dwCommModemStatus);
}
则消息框里为空。
在下查到些方案,如
if(dwLength> 0)
{
//从串口读取数据
TCHAR* buf=new TCHAR[256];
fReadState=ReadFile(hPort,buf,dwLength,&dwLength,NULL);
if(!fReadState)
{
//不能从串口读取数据
MessageBox(NULL,TEXT( "Error in read from serial port "),TEXT( "Read Error "),MB_OK);
}