ClearCommError

  BOOL ClearCommError(hCommDev, lpdwErrors, lpcmst)    
  HANDLE hCommDev; /* device to clear */
  LPDWORD lpdwErrors; /* address of buffer for error codes */
  LPCOMSTAT lpcmst; /* address of buffer for comm status */

The ClearCommError function re-enables a communications device after a communications error.

Parameters

hCommDev

Specifies the communication device to be cleared. The CreateFile function returns this value.

lpdwErrors

Points to a DWORD to be filled with a mask containing the error, as shown in the following list:

Value Meaning

CE_BREAK The hardware detected a break condition.
CE_CTSTO Clear-to-send timeout. CTS is low for the duration specified by CtsTimeout while trying to transmit a character.
CE_DSRTO Data-set-ready timeout. DSR is low for the duration specified by DsrTimeout while trying to transmit a character.
CE_FRAME The hardware detected a framing error.
CE_IOE An I/O error occurred while trying to communicate with a device.
CE_MODE Requested mode is not supported, or the hCommDev parameter is invalid. If set, this is the only valid error.
CE_OOP The parallel device signalled that it is out of paper.
CE_OVERRUN Character-buffer overrun. The next character is lost.
CE_RLSDTO Receive-line-signal-detect timeout. RLSD is low for the duration specified by RlsdTimeout while trying to transmit a character.
CE_RXOVER Receive queue overflow. There is either no room in the input queue or a character is received after the EOF character is received.
CE_RXPARITY The hardware detected a parity error.
CE_TXFULL The transmit queue was full while trying to queue a character.
CE_DNS The parallel device is not selected.
CE_PTO Timeout on a parallel device.

lpcmst

Points to the COMSTAT structure that is to receive the device status. The structure contains information about a communication device. If lpcmst is NULL, no status is returned.

The COMSTAT structure has the following format:

typedef struct _COMSTAT { /* cst */

DWORD fCtsHold : 1;

DWORD fDsrHold : 1;

DWORD fRlsdHold : 1;

DWORD fXoffHold : 1;

DWORD fXoffSent : 1;

DWORD fEof : 1;

DWORD fTxim : 1;

DWORD fReserved : 17;

DWORD cbInQue;

DWORD cbOutQue;

} COMSTAT, *LPCOMSTAT;

Return Value

The return value is TRUE if the function was successful, or FALSE if an error occurred. Use the GetLastError function to obtain extended error information.

Comments

In case of a communications error, such as a buffer overrun or framing error, the communications software will abort all read and write operations on the communications port. No further read or write operations will be accepted until this function is called. This function will enable the communications ports for further reads and writes.

This function fills the status buffer pointed to by the lpcmst parameter with the current status of the communication device specified by the hCommDev parameter.

See Also

ClearCommBreak, EscapeCommFunction