ClearCommError(hComm, ref dwErrorFlags, ref ComStat);
if (dwErrorFlags != 0)
PurgeComm(hComm, PURGE_RXCLEAR | PURGE_RXABORT);
if (ComStat.cbInQue >= 5)
ReadFile(hComm, rectmp, 5, ref BytesRead, ref ovlCommPort);
现在问题是,ComStat.cbInQue 有时候是0,但可以确认对方已经发出数据了。有时候是正确的.但
ComStat.cbInQue >0时,使用ReadFile去读取数据时,也不能读到数据.
ReadFile(hComm, rectmp, 5, ref BytesRead, ref ovlCommPort);
uint err = GetLastError();
ComStat.cbInQue 有数据来,但是使用readfile就是读不到数据.这是为什么?
err值为0x80000005
ClearCommError(hComm, ref dwErrorFlags, ref ComStat);
if (dwErrorFlags != 0)
PurgeComm(hComm, PURGE_RXCLEAR | PURGE_RXABORT);
现在是dwErrorFlags =8,清掉读的数据了,现在不知道为什么会是8
BOOL WINAPI ClearCommError(
__in HANDLE hFile,
__out_opt LPDWORD lpErrors,
__out_opt LPCOMSTAT lpStat
);
Value Meaning
CE_BREAK
0x0010
The hardware detected a break condition.
CE_FRAME
0x0008
The hardware detected a framing error.
CE_OVERRUN
0x0002
A character-buffer overrun has occurred. The next character is lost.
CE_RXOVER
0x0001
An input buffer overflow has occurred. There is either no room in the input buffer, or a character was received after the end-of-file (EOF) character.
CE_RXPARITY
0x0004
The hardware detected a parity error.