标签:串口 重叠i/o | 分类:Windows |
HANDLE hComm; hComm = CreateFile( gszPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0); if (hComm == INVALID_HANDLE_VALUE) // error opening port; abort |
标签:串口 重叠i/o it | 分类:Windows |
DWORD dwStoredFlags; dwStoredFlags = EV_BREAK | EV_CTS | EV_DSR | EV_ERR | EV_RING | EV_RLSD | EV_RXCHAR | EV_RXFLAG | EV_TXEMPTY ; if (!SetCommMask(hComm, dwStoredFlags)) // error tting communications mask |
事件标志 | 描述 |
EV_BREAK | 检测到输入中的break |
EV_CTS | CTS(Clear To Send)信号状态改变。要取得CTS线路状态,应使用GetCommModemStatus函数。 |
EV_DSR | DSR(Data Set Ready)信号状态改变。要取得DSR线路状态,应使用GetCommModemStatus函数。 |
EV_ERR | 某线路状态错误发生。线路状态错误包括CE_FRAME、CE_OVERRUN和CE_RXPARITY。要取得具体错误种类,需调用ClearCommError函数。 |
EV_RING | 检测到振铃指示 |
EV_RLSD | RLSD(Receive Line Signal Detect)信号状态改变。要取得RLSD线路状态,需调用GetCommModemStatus函数。注意,RLSD通常被称作CD(carrier detect)。 |
EV_RXCHAR | 接收到一个字符并且已放入输入缓冲区。请参考下面的“警告”节对此标志的详细讨论。 |
EV_RXFLAG | 接收到一个事件字符并且已放入输入缓冲区。事件字符由下文讨论的DCB结构EvtChar字段指定。下面的“警告”节也讨论了这个标志。 |
EV_TXEMPTY | 输出缓冲区中最后一个字符被发送到串口设备了。如果使用硬件缓冲区,此标志仅表示所有数据已经发送到硬件了。如果不与设备驱动交互,是无法确定硬件缓冲区空的。 |
DWORD dwCommEvent; 工程管理学报 if (!SetCommMask(hComm, EV_RING)) // Error tting communications mask return FALSE; if (!WaitCommEvent(hComm, &dwCommEvent, NULL)) // An error occurred waiting for the event. return FALSE; el // Event has occurred. return TRUE; |
#define STATUS_CHECK_TIMEOUT 500 // Milliconds DWORD dwRes; DWORD dwCommEvent; DWORD dwStoredFlags; BOOL fWaitingOnStat = FALSE; OVERLAPPED osStatus = {0}; dwStoredFlags = EV_BREAK | EV_CTS | EV_DSR | EV_ERR | EV_RING |\ EV_RLSD | EV_RXCHAR | EV_RXFLAG | EV_TXEMPTY ; if (!SetCommMask(comHandle, dwStoredFlags)) // error tting communications mask; abort return 0; osStatus.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (osStatus.hEvent == NULL) 于敏的事迹 // error creating event; abort return 0; for ( ; ; ) { // Issue a status event check if one hasn't been issued already. if (!fWaitingOnStat) { if (!WaitCommEvent(hComm, &dwCommEvent, &osStatus)) { if (GetLastError() == ERROR_IO_PENDING) bWaitingOnStatusHandle = TRUE; el // error in WaitCommEvent; abort break; }月子饭 el // WaitCommEvent returned immediately. // Deal with status event as appropriate. ReportStatusEvent(dwCommEvent); } // Check on overlapped operation. if (fWaitingOnStat) { // Wait a little while for an event to occur. dwRes = WaitForSingleObject(osStatus.hEvent, STATUS_CHECK_TIMEOUT); switch(dwRes) { 真情满天下 // Event occurred. ca WAIT_OBJECT_0: 五行属土的行业 if (!GetOverlappedResult(hComm, &osStatus, &dwOvRes, FALSE)) // An error occurred in the overlapped operation; // call GetLastError to find out what it was // and abort if it is fatal. el // Status event is stored in the event flag // specified in the original WaitCommEvent call. // Deal with the status event as appropriate. ReportStatusEvent(dwCommEvent); // Set fWaitingOnStat flag to indicate that a new // WaitCommEvent is to be issued. fWaitingOnStat = FALSE; break; ca WAIT_TIMEOUT: // Operation isn't complete yet. fWaitingOnStatusHandle flag // isn't changed since I'll loop back around and I don't want // to issue another WaitCommEvent until the first one finishes. //那的组词 // This is a good time to do some background work. DoBackgroundWork(); break; default: // Error in the WaitForSingleObject; abort // This indicates a problem with the OVERLAPPED structure's // event handle. CloHandle(osStatus.hEvent); return 0; } } } CloHandle(osStatus.hEvent); |
本文发布于:2023-05-17 12:25:03,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/fan/89/908085.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |