有API函数,WaitCommEvent; BOOL WaitCommEvent( HANDLE hFile, // handle to comm device LPDWORD lpEvtMask, // event type LPOVERLAPPED lpOverlapped, // overlapped structure ); Parameters hFile [in] Handle to the communications device. The CreateFile function returns this handle. lpEvtMask [out] Pointer to a variable that receives a mask indicating the type of event that occurred. If an error occurs, the value is zero; otherwise, it is one of the following values. Value Meaning EV_BREAK A break was detected on input. EV_CTS The CTS (clear-to-send) signal changed state. EV_DSR The DSR (data-set-ready) signal changed state. EV_ERR A line-status error occurred. Line-status errors are CE_FRAME, CE_OVERRUN, and CE_RXPARITY. EV_RING A ring indicator was detected. EV_RLSD The RLSD (receive-line-signal-detect) signal changed state. EV_RXCHAR A character was received and placed in the input buffer. EV_RXFLAG The event character was received and placed in the input buffer. The event character is specified in the device's DCB structure, which is applied to a serial port by using the SetCommState function. EV_TXEMPTY The last character in the output buffer was sent. 不过通常串口是只接三根线,很难判断!
BOOL WaitCommEvent(
HANDLE hFile, // handle to comm device
LPDWORD lpEvtMask, // event type
LPOVERLAPPED lpOverlapped, // overlapped structure
);
Parameters
hFile
[in] Handle to the communications device. The CreateFile function returns this handle.
lpEvtMask
[out] Pointer to a variable that receives a mask indicating the type of event that occurred. If an error occurs, the value is zero; otherwise, it is one of the following values. Value Meaning
EV_BREAK A break was detected on input.
EV_CTS The CTS (clear-to-send) signal changed state.
EV_DSR The DSR (data-set-ready) signal changed state.
EV_ERR A line-status error occurred. Line-status errors are CE_FRAME, CE_OVERRUN, and CE_RXPARITY.
EV_RING A ring indicator was detected.
EV_RLSD The RLSD (receive-line-signal-detect) signal changed state.
EV_RXCHAR A character was received and placed in the input buffer.
EV_RXFLAG The event character was received and placed in the input buffer. The event character is specified in the device's DCB structure, which is applied to a serial port by using the SetCommState function.
EV_TXEMPTY The last character in the output buffer was sent.
不过通常串口是只接三根线,很难判断!