gpt4 book ai didi

c++ - WaitCommEvent 挂起

转载 作者:行者123 更新时间:2023-11-28 02:47:11 26 4
gpt4 key购买 nike

我正在使用非重叠的 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:

If hFile was not opened with FILE_FLAG_OVERLAPPED, WaitCommEvent does not return until one of the specified events or an error occurs.

关于c++ - WaitCommEvent 挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24015639/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com