win32 ClearCommError 和 COMSTAT 结构体

网址:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa363180

获取 通信错误的信息,汇报当前的通信设备的状态。
当一个通信错误发生的时候,调用这个函数,将会清除设备的错误标志,来使能其他的输入输出操作

BOOL WINAPI ClearCommError(
  _In_      HANDLE    hFile,
  _Out_opt_ LPDWORD   lpErrors,
  _Out_opt_ LPCOMSTAT lpStat
);

参数:

hFile [in]

句柄
A handle to the communications device. The CreateFile function returns this handle.

lpErrors [out, optional]

发生的错误的类型
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.

ValueMeaning
CE_BREAK0x0010The hardware detected a break condition.
CE_FRAME0x0008The hardware detected a framing error.
CE_OVERRUN0x0002A character-buffer overrun has occurred. The next character is lost.
CE_RXOVER0x0001An 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_RXPARITY0x0004The hardware detected a parity error.

The following values are not supported:
CE_DNS
CE_IOE
CE_MODE
CE_OOP
CE_PTO
CE_TXFULL

lpStat [out, optional]

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.

Remarks

如果通信接口设置DCB结构体的fAbortOnError成员变量为TRUE,
当发生一个通信错误的时候,通信驱动会终止所有在通信接口上的读和写操作。
直到应用软件使用ClearCommError函数来处理通信错误,没有新的读或者写操作会被接受。
ClearCommError 将会填充用hFile参数指向的通信设备的当前状态,填充lpStat参数执行的状态缓冲

COMSTAT 结构体

包含通信设备的信息,这个结构体是被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;

成员变量

fCtsHold

If this member is TRUE, transmission is waiting for the CTS (clear-to-send) signal to be sent.

fDsrHold

If this member is TRUE, transmission is waiting for the DSR (data-set-ready) signal to be sent.

fRlsdHold

If this member is TRUE, transmission is waiting for the RLSD (receive-line-signal-detect) signal to be sent.

fXoffHold

If this member is TRUE, transmission is waiting because the XOFF character was received.

fXoffSent

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.)

fEof

If this member is TRUE, the end-of-file (EOF) character has been received.

fTxim

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.

fReserved

Reserved; do not use.

cbInQue

串口接收缓冲区的字节数,它们还没有来得及被ReadFile操作读走

cbOutQue

The number of bytes of user data remaining to be transmitted for all write operations. This value will be zero for a nonoverlapped write.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值