用串口发送好几个字符,但只能收到一个,请各位帮忙看看
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)
{
do
{
tempStr=TEXT("");
// Read the data from the serial port.
ReadFile (hPort, &Byte, 1, &dwBytesTransferred, 0);
// Display the data read.
if (dwBytesTransferred == 1)
{
tempStr=(char)Byte;
strInStr+=tempStr;
}
}while (dwBytesTransferred == 0);
MessageBox(NULL,strInStr,TEXT("Result"),MB_OK);
}
// Retrieve modem control-register values.
GetCommModemStatus (hPort, &dwCommModemStatus);
}
则无论我发几个字符都只能收到第一个,要是改为:
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);
}
则消息框里为空。
各位帮帮忙,看看是什么问题啊。