SetCommState

  BOOL SetCommState(hFile, lpdcb)    
  HANDLE hFile;    
  LPDCB lpdcb;    

The SetCommState function sets a communication device to the state specified by the device control block pointed to by the lpDCB parameter. The device is identified by the hFile parameter. This function reinitializes all hardware and controls as defined by lpDCB, but does not empty transmit or receive queues.

Parameters

hFile

Specifies the communication device to receive the settings. The CreateFile function returns this value.

lpdcb

Points to a DCB structure that contains the desired communications setting for the device.

The DCB structure has the following form:

typedef struct _DCB { /* dcb */

DWORD DCBlength; /* sizeof(DCB) */

DWORD BaudRate; /* Baudrate at which running */

DWORD fBinary: 1; /* Binary Mode (skip EOF check) */

DWORD fParity: 1; /* Enable parity checking */

DWORD fOutxCtsFlow:1; /* CTS handshaking on output */

DWORD fOutxDsrFlow:1; /* DSR handshaking on output */

DWORD fDtrControl:2; /* DTR Flow control */

DWORD fDsrSensitivity:1; /* DSR Sensitivity */

DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */

DWORD fOutX: 1; /* Enable output X-ON/X-OFF */

DWORD fInX: 1; /* Enable input X-ON/X-OFF */

DWORD fErrorChar: 1; /* Enable Err Replacement */

DWORD fNull: 1; /* Enable Null stripping */

DWORD fRtsControl:2; /* Rts Flow control */

DWORD fAbortOnError:1; /* Abort all reads and writes on Error */

DWORD fDummy2:1; /* Reserved */

WORD wReserved; /* Not currently used */

WORD XonLim; /* Transmit X-ON threshold */

WORD XoffLim; /* Transmit X-OFF threshold */

BYTE ByteSize; /* Number of bits/byte, 4-8 */

BYTE Parity; /* 0-4=None,Odd,Even,Mark,Space */

BYTE StopBits; /* 0,1,2 = 1, 1.5, 2 */

char XonChar; /* Tx and Rx X-ON character */

char XoffChar; /* Tx and Rx X-OFF character */

char ErrorChar; /* Error replacement char */

char EofChar; /* End of Input character */

char EvtChar; /* Received Event character */

} DCB;

Return Value

The return value is TRUE if the function is successful or FALSE if an error occurs.

Comments

SetCommState will fail if DCB.XonChar is equal to DCB.XoffChar.

For 8250 restrictions that might cause failure, see the DCB definition.

See Also

GetCommState,