先贴代码吧,如下:
if (!ClearCommError(m_hComm, &dwError, &state))
{
PurgeComm(m_hComm, PURGE_RXABORT | PURGE_RXCLEAR);
return -3;
} if (!state.cbInQue)
{
if (dwWait)
{
SetCommMask(m_hComm, EV_RXCHAR | EV_ERR);
if (!WaitCommEvent(m_hComm, &dwMask, &m_ReadOverlapped))
{
if (GetLastError() == ERROR_IO_PENDING)
WaitForSingleObject(m_ReadOverlapped.hEvent, dwWait);
} ClearCommError(m_hComm, &dwError, &state);
} if (!state.cbInQue)
return -4;
} if (!ReadFile(m_hComm, lpBuffer, len, &dwRead, &m_ReadOverlapped))
{
return -9;
}
在执行过程中,cbInQue一直是0,但是监控串口已经读到了正确的数据,每次都是返回-4,请问大侠们,到底是什么原因啊?
if (!ClearCommError(m_hComm, &dwError, &state))
{
PurgeComm(m_hComm, PURGE_RXABORT | PURGE_RXCLEAR);
return -3;
} if (!state.cbInQue)
{
if (dwWait)
{
SetCommMask(m_hComm, EV_RXCHAR | EV_ERR);
if (!WaitCommEvent(m_hComm, &dwMask, &m_ReadOverlapped))
{
if (GetLastError() == ERROR_IO_PENDING)
WaitForSingleObject(m_ReadOverlapped.hEvent, dwWait);
} ClearCommError(m_hComm, &dwError, &state);
} if (!state.cbInQue)
return -4;
} if (!ReadFile(m_hComm, lpBuffer, len, &dwRead, &m_ReadOverlapped))
{
return -9;
}
在执行过程中,cbInQue一直是0,但是监控串口已经读到了正确的数据,每次都是返回-4,请问大侠们,到底是什么原因啊?
state.cbInQue cbInQue bytes have been received, but not read
仔细看看MSDN的帮助文档
http://msdn.microsoft.com/en-us/library/ms810467.aspx#serial_topic4