COMM-DRV/Lib: SetPortCharacteristics() Set line control parameters(baudrate, length, parity,etc.)


This function sets the port characteristics. It is used to change baud rate, parity, length, stopbits, and line protocol of the port. The constants used for the arguments are defined in the include files(comm.h,, etc.).


stat = SetPortCharacteristics(port,baud,parity,length,stopbit,protocol);

On Entry-

int port;

Port previously opened with OpenComPort().

unsigned short baud;

BAUD110 – 110 baud
BAUD150 – 150 baud
BAUD300 – 300 baud
BAUD600 – 600 baud
BAUD1200 – 1200 baud
BAUD2400 – 2400 baud
BAUD4800 – 4800 baud
BAUD9600 – 9600 baud
BAUD14400 – 14400 baud
BAUD19200 – 19200 baud
BAUD28800 – 28800 baud
BAUD38400 – 38400 baud
BAUD57600 – 57600 baud
BAUD115200 – 115200 baud

unsigned short parity;

PAR_NONE – None parity
PAR_ODD – Odd parity
PAR_EVEN – Even parity
PAR_SODD – Sticky odd(MARK Parity)
PAR_SEVEN – Sticky even(SPACE Parity)

unsigned short length;

LENGTH_5 – 5 bits
LENGTH_6 – 6 bits
LENGTH_7 – 7 bits
LENGTH_8 – 8 bits

unsigned short Stopbit;

STOPBIT_1 1 stopbit
STOPBIT_2 2 stopbits

unsigned short Protocol;

PROT_RTSRTS Local CTS/RTS handshake-Remote CTS/RTS handshake.
PROT_RTSXON Local CTS/RTS handshake-Remote XON/XOFF handshake.
PROT_RTSDTR Local CTS/RTS handshake-Remote DSR/DTR handshake.
PROT_RTSNON Local CTS/RTS handshake-Remote no handshake.
PROT_NONNON Local no protocol-Remote no protocol.
PROT_NONXON Local no protocol-XON/XOFF handshake.
PROT_XONNON Local XOFF/XON protocol-Remote no protocol.
PROT_XONXON Local XON/XOFF protocol-Remote XON/XOFF protocol.
PROT_DTRNON Local DSR/DTR protocol-Remote no protocol.
PROT_DTRRTS Local DSR/DTR protocol-Remote CTS/RTS protocol.
PROT_DTRDTR Local DSR/DTR protocol-Remote DSR/DTR protocol.
PROT_DTRXON Local DSR/DTR protocol-Remote DSR/DTR protocol.
PROT_NONRTS Local no protocol-Remote CTS/RTS protocol.
PROT_NONDTR Local no protocol-Remote DSR/DTR protocol.
PROT_XONRTS Local XOFF/XON protocol-Remote CTS/RTS protocol.
PROT_XONDTR Local XOFF/XON protocol-Remote DSR/DTR protocol.

The first three bytes specifies the protocol the local computer is using, while the last three bytes specifies the protocol the remote device is expected to be using. PROT_RTS???, PROT_DTR???, and PROT_XON??? means that when the local computer’s input buffer is filling up, the local computer will de-assert RTS, DTR, or send an XOFF respectively to tell the remote device to stop sending. The local machine will re-assert RTS, DTR, or send an XON to make remote device restart transmission. PROT_???RTS, PROT_???DTR, and PROT_???XON means that when the remote device’s input buffer is filling up, the remote device is expected to de-assert RTS, DTR, or send an XOFF respectively to tell the local computer to stop sending. The remote device is expected to re-assert RTS, DTR, or send an XON to make the local computer restart transmission.(Default PROT_RTSRTS).

On Exit-

int stat;

This function returns one of the COMM-DRV/LIB errors. The error codes are defined in Appendix C (Returns RS232ERR_NONE if successful).

See Also-



#include <comm.h>

int port=0;
int stat;
int baud=BAUD9600;
int parity = PAR_NONE;
int length=LENGTH_8;
int stopbit=STOPBIT_1;
int protocol = PROT_RTSRTS;

if ((stat = SetPortCharacteristics(port,baud,parity,length,stopbit,protocol)) != RS232ERR_NONE))
printf(“Error setting port characteristics\n”);

/* Take remedial action */