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. 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 SetCommTimeouts API can be used to specify COMM timeouts. 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. The Number symbol (#) prefix is optional, but recommended for the purposes of clarity. |
See also |
Serial Communications, COMM CLOSE, COMM function, COMM OPEN, COMM PRINT, COMM RECV, COMM RESET, COMM SEND, COMM SET, 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$) |