COMM SET statement

Purpose | Set communication options for a serial port.
Syntax | COMM SET [#] hComm, Comfunc = value
Remarks | Set the parameters needed to communicate with a serial port. This must always be done before you can send and receive data through the port. To configure the communication parameters, use keywords from the following table to specify the Comfunc as well as a suitable value chosen from the range applicable to the Comfunc parameter you want to set. If an error occurs when attempting to set a parameter, PowerBASIC sets the ERR system variable to indicate the error number. While each parameter must be set individually, it is also possible to change certain parameters without the need to close and re-establish communications. COMM SET keywords table
Comfunc | value (TRUE <> 0, FALSE = 0)
BAUD | Port Baud Rate (9600, 14400, 19200, etc). See notes below.
BREAK | TRUE/FALSE Break is asserted. Break is generally used to "get the attention" of the connected modem, terminal or system.
BYTE | Number of bits per byte (4, 5, 6, 7, or 8).
CD | TRUE/FALSE Carrier Detect state; synonym for RLSD (READ-ONLY). When CD is TRUE, the DCE (modem) has a suitable connection on the communications channel present. When CD is FALSE, there is no suitable connection.
CTSFLOW | TRUE/FALSE Enable CTS output flow control (Input signal). When CTSFLOW is enabled, it causes the DTE (computer) to stop sending data whenever the CTS signal is set to logic low by the DCE (modem). Transmission continues when the DCE (modem) sets the CTS signal back to logic high. The CTS signal is usually used in response to an RTS signal.
DSRFLOW | TRUE/FALSE Enable DSR output flow control (Input signal). When DSRFLOW is enabled, it causes the DTE (computer) to stop sending data whenever the DSR signal is set to logic low by the DCE (modem). Transmission is enabled when the DSR signal returns to logic high. The DSR signal is often used in conjunction with CTS in response to a RTS signal.
DSRSENS | TRUE/FALSE Enable DSR sensitivity. When DSRSENS is enabled, data received by the DTE (computer) is placed into the receive buffer only if DSR is set to logic high. If DSR is set low, received data is discarded. Enabling DSRSENS allows DSR to enable or disable the DTE (the computer) to receive data from the DTE (the modem). DSRSENS is rarely used in practical communications situations.
DTRFLOW | TRUE/FALSE Enable DTR handshaking flow control (Output signal). When DTRFLOW is enabled, it signals that the DCE (modem) should prepare to connect to the communications channel. DTR is usually used for modem on-hook/off-hook control, but can also be used in conjunction with DSR for handshaking.
DTRLINE | TRUE/FALSE Enable DTR line. When enabled, DTRLINE leaves the DTR line active when the port is closed by the DTE (computer). This ensures that the DCE (modem) does not close the communications channel when the port is closed.
NULL | TRUE/FALSE Null ($NUL) bytes are discarded when read.
PARITY | TRUE/FALSE Enable parity checking. This mode must be enabled for the other Parity options to be selected.
PARITYCHAR | Character to use for parity error replacement. PARITY must be enabled.
PARITYREPL | TRUE/FALSE Enable character replacement on parity error. PARITY must be enabled.
PARITYTYPE | 0 = None, 1 = Odd, 2 = Even, 3 = Mark, 4 = Space. PARITY must be enabled. Default = 0.
RING | TRUE/FALSE Ring indicator is on (READ-ONLY). When RING returns TRUE, a ringing signal is being received on the communications channel (by the modem). RING approximates the state of the ringing signal; however, it may not be reported accurately on all Windows platforms.
RLSD | Receive-line-signal-detect (READ-ONLY). See CD/Carrier Detect above.
RTSFLOW | Ready To Send (Output signal). 0 = Disable, 1 = Enable, 2 = Handshake, 3 = Toggle. Toggle is used for half-duplex (2-wire) operations to "reverse" the line. While the DTE (computer) is busy sending data, it raises the RTS signal and the DCE (modem) blocks its data receive channel. When RTS signal reverts to logic low, the DCE (modem) reverts to transmit mode and the DTE (computer) switches to receive mode. Handshake mode causes the DTE (computer) to check the receive buffer (RXQUE) after each character is placed into the buffer. When the buffer is 5/6th full, the RTS signal is dropped. When the receive buffer drops to below 1/6th full, RTS is raised again.
RXBUFFER | Size of the receive buffer in bytes.
RXQUE | Characters currently in the receive buffer (READ-ONLY).
STOP | 0 = 1 stop bits, 1 = 1.5 stop bits, 2 = 2 stop bits.
TXBUFFER | Size of the transmit buffer in bytes. In some cases, Windows may not be able to report the transmit size.
TXQUE | Characters currently in the transmit buffer (READ-ONLY).
XINPFLOW | TRUE/FALSE Enable XON/XOFF input flow control. When the DTE (computer) receive buffer is full, an XOFF character is sent to the DCE (modem) to instruct it to halt transmission. When the DCE is ready to resume transmission, an XON character is sent to the DCE. Typically, XOFF is sent when the receive buffer has less than 1/16th remaining, and XON is sent when the receive buffer drops to less than 1/16th of its maximum size. Default = FALSE.
XOUTFLOW | TRUE/FALSE Enable XON/XOFF out flow control. When enabled, the DCE (modem) sends an XOFF to the DTE (computer) to halt data transmission to the DCE. When the DCE is ready to receive more data, an XON character is sent. XOUTFLOW typically uses the same 1/16th rules as XINPFLOW. Default = FALSE.
Common baud rates range from 110 to 256000. There are equates defined in the WIN32API.INC file, prefixed with %CBR_ to assist you with specifying a common baud rate, but you are not restricted to a limited set of rates. Attempting to set a READ-ONLY attribute will result in a compile-time Error 542 ("May not be altered"). The Number symbol (#) prefix is optional, but recommended for the purposes of clarity.
See also | Serial Communications, COMM CLOSE, COMM function, COMM LINE, COMM OPEN, COMM PRINT, COMM RECV, COMM RESET, COMM SEND, COMM TIMEOUT
Example | To open a communication port and initialize it for use, you will need to set the following parameters (the selection is typical, but is mainly for demonstration purposes - you may choose your own settings as necessary) ' Minimum settings COMM SET #hComm, BAUD = 9600 ' 9600 baud COMM SET #hComm, BYTE = 8 ' 8 bits COMM SET #hComm, PARITY = %FALSE ' No parity COMM SET #hComm, STOP = 0 ' 1 stop bit COMM SET #hComm, TXBUFFER = 2048 ' transmit buffer COMM SET #hComm, RXBUFFER = 4096 ' receive buffer ' Optional settings for flow control COMM SET #hComm, CTSFLOW = 1 ' Enable CTS COMM SET #hComm, RTSFLOW = 1 ' Enable RTS COMM SET #hComm, XINPFLOW = 0 ' Disable XON/OFF ' Input flow control COMM SET #hComm, XOUTFLOW = 0 ' Disable XON/XOFF ' Output flow control