COMM function  


Retrieve the value or status of a communications parameter.


lResult& = COMM([#] hComm, Comfunc)


hComm is the PowerBASIC file number as was used by the COMM OPEN statement to open the communications port.  Select a Comfunc keyword from the following table to retrieve the associated setting.


value  (TRUE <> 0, FALSE = 0)


Port Baud Rate (9600, 14400, 19200, etc).


TRUE/FALSE Break is asserted.  Break is generally used to "get the attention" of the connected modem, terminal or system.


Number of bits per byte (4, 5, 6, 7, or 8).


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.


TRUE/FALSE  Clear-To-Send state is returned (READ-ONLY).


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.


TRUE/FALSE  Data-Set-Ready state is returned (READ-ONLY).


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.


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.


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.


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.


TRUE/FALSE Null ($NUL) bytes are discarded when read.


TRUE/FALSE Enable parity checking. This mode must be enabled for the other Parity options to be selected.


Character to use for parity error replacement.  PARITY must be enabled.


TRUE/FALSE Enable character replacement on parity error.  PARITY must be enabled.


0 = None, 1 = Odd, 2 = Even, 3 = Mark, 4 = Space.  PARITY must be enabled.  Default = 0.


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.


Receive-line-signal-detect (READ-ONLY).  See CD/Carrier Detect above.


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


Size of the receive buffer in bytes.


Characters currently in the receive buffer (READ-ONLY).


0 = 1 stop bits, 1 = 1.5 stop bits, 2 = 2 stop bits.


Size of the transmit buffer in bytes.  In some cases, Windows may not be able to report the transmit size.


Characters currently in the transmit buffer (READ-ONLY).


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.


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.

PowerBASIC sets the ERR system variable if an error occurs when using the COMM function.

The Number symbol (#) prefix is optional, but recommended for the purposes of clarity.


Due to differences between Win32 operating systems, parameters (such as the TXBUFFER and TXQUE) may not be queried successfully in all circumstances.

See also



Qty& = COMM(#hComm, RXQUE)

x$ = "The receive buffer contains " + _

        FORMAT$(Qty&) + " bytes of data."


Qty& = COMM(#hComm, TXBUFFER) - COMM(#hComm, TXQUE)

x$ = "There is room for " + FORMAT$(Qty&) + _

  " bytes in the transmit buffer."