我正在使用非重叠的WaitCommEvent来读取文件数据。
我想提供如下一段代码...

SetCommMask (io_ptr->comPortHandles->hComPort, EV_RXCHAR|EV_TXEMPTY);
WaitCommEvent (io_ptr->comPortHandles->hComPort, &dwMask, 0);

if (dwMask &= EV_RXCHAR) {
  // Loop getting data.

  // Need to loop because our buffer is only 1024 bytes
  while (TRUE)
  {
    ClearCommError( io_ptr->comPortHandles->hComPort, &dwError, &comstat);

    if (!comstat.cbInQue) continue;
    else
    {
      if(comstat.cbInQue > 0)
        ReceiveInterrupt(io_ptr, comstat);
    }
    // Loop around and check for more data
    // In case additional byte has arrived while reading.
  }
}

最佳答案

如果未使用重叠标志打开文件句柄,则WaitCommEvent将阻塞。在这种情况下,它将等待直到接收到一个字符或发送了最后一个字符。

有关WaitCommEvent的MSDN:

10-07 20:20