网址:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa363180
获取 通信错误的信息,汇报当前的通信设备的状态。
当一个通信错误发生的时候,调用这个函数,将会清除设备的错误标志,来使能其他的输入输出操作
BOOL WINAPI ClearCommError(
_In_ HANDLE hFile,
_Out_opt_ LPDWORD lpErrors,
_Out_opt_ LPCOMSTAT lpStat
);
参数:
句柄
A handle to the communications device. The CreateFile function returns this handle.
发生的错误的类型
A pointer to a variable that receives a mask indicating the type of error. This parameter can be one or more of the following values.
Value | Meaning | |
---|---|---|
CE_BREAK | 0x0010 | The hardware detected a break condition. |
CE_FRAME | 0x0008 | The hardware detected a framing error. |
CE_OVERRUN | 0x0002 | A character-buffer overrun has occurred. The next character is lost. |
CE_RXOVER | 0x0001 | An input buffer overflow has occurred. There is either no room in the input buffer, or a character was received after the end-of-file (EOF) character. |
CE_RXPARITY | 0x0004 | The hardware detected a parity error. |
The following values are not supported:
CE_DNS
CE_IOE
CE_MODE
CE_OOP
CE_PTO
CE_TXFULL
A pointer to a COMSTAT structure in which the device’s status information is returned. If this parameter is NULL, no status information is returned.
成功,返回非0
失败,返回0
获取更多的信息,使用 GetLastError.
如果通信接口设置DCB结构体的fAbortOnError成员变量为TRUE,
当发生一个通信错误的时候,通信驱动会终止所有在通信接口上的读和写操作。
直到应用软件使用ClearCommError函数来处理通信错误,没有新的读或者写操作会被接受。
ClearCommError 将会填充用hFile参数指向的通信设备的当前状态,填充lpStat参数执行的状态缓冲
包含通信设备的信息,这个结构体是被ClearCommError函数填充的
typedef struct _COMSTAT {
DWORD fCtsHold :1;
DWORD fDsrHold :1;
DWORD fRlsdHold :1;
DWORD fXoffHold :1;
DWORD fXoffSent :1;
DWORD fEof :1;
DWORD fTxim :1;
DWORD fReserved :25;
DWORD cbInQue;
DWORD cbOutQue;
} COMSTAT, *LPCOMSTAT;
If this member is TRUE, transmission is waiting for the CTS (clear-to-send) signal to be sent.
If this member is TRUE, transmission is waiting for the DSR (data-set-ready) signal to be sent.
If this member is TRUE, transmission is waiting for the RLSD (receive-line-signal-detect) signal to be sent.
If this member is TRUE, transmission is waiting because the XOFF character was received.
If this member is TRUE, transmission is waiting because the XOFF character was transmitted. (Transmission halts when the XOFF character is transmitted to a system that takes the next character as XON, regardless of the actual character.)
If this member is TRUE, the end-of-file (EOF) character has been received.
If this member is TRUE, there is a character queued for transmission that has come to the communications device by way of the TransmitCommChar function. The communications device transmits such a character ahead of other characters in the device’s output buffer.
Reserved; do not use.
cbInQue
串口接收缓冲区的字节数,它们还没有来得及被ReadFile操作读走
The number of bytes of user data remaining to be transmitted for all write operations. This value will be zero for a nonoverlapped write.