COMM LINE statement  

Purpose

Receive a CR/LF ($CRLF) terminated "line" of data from a serial port.

Syntax

COMM LINE [INPUT] [#] hComm, string_var

Remarks

Read a delimited line of data from the receive buffer, where a "line" is defined as a stream of data that is terminated by a CR/LF (carriage return and linefeed, $CRLF, or CHR$(13,10)).  COMM LINE INPUT is ideal for retrieving modem response strings in reply to "AT" commands sent to a modem.

hComm is the file number you used with COMM OPEN, an integer in the range of 1 to 32767.  The Number symbol (#) prefix is optional, but recommended for clarity.

COMM LINE reads the receive buffer up to the next $CRLF character pair.  The $CRLF bytes are removed from the buffer but do not form part of the string data returned by COMM LINE.  Note that if there is no $CRLF pair in the receive buffer, the statement will wait indefinitely for a complete $CRLF terminated line of data.  In this sense, COMM LINE is a blocking statement.  The COMM TIMEOUT statement can be used to specify COMM timeouts limits.

The data received is assigned to the string_var.  The character mode of the string_var must match the CHR option in COMM OPEN (ANSI/WIDE). If not, an error 5 (Illegal function call) will be generated, and no data will be received.

The EOF function may also be used with COMM LINE (and TCP LINE) to detect that an incomplete line was received.  Normally, the COMM LINE statement reads data until a $CRLF character pair is found, and in that case, EOF will return false (zero).  However, if a timeout does occur, COMM LINE will return whatever data has been accumulated, and set EOF to logical TRUE (non-zero).

In many cases, it would be prudent to test EOF after every COMM LINE statement to verify that a full line has been received.  In some cases, you may wish to execute the statement one or more additional times, combining the data, in order to obtain a full line of text.

See also

Serial CommunicationsCOMM CLOSE, COMM function, COMM OPEN, COMM PRINT, COMM RECV, COMM RESET, COMM SEND, COMM SET, COMM TIMEOUT, EOF

Example

COMM PRINT #hComm, "AT"

SLEEP 1000 ' delay for modem to respond

DO

  COMM LINE INPUT #hComm, a$

  CALL DisplayResponse(a$) ' display the modem echo

LOOP UNTIL LEN(a$)