ReadSerialData -- read data from serial port connection (V8.0)
data$, count = ReadSerialData(id, len[, timeout])
This command can be used to read len bytes of data from the serial port connection specified in id. The serial port connection must have been opened using OpenSerialPort() before. Additionally, you can pass a duration in milliseconds in the timeout argument to set a timeout for the read operation. If the timeout parameter is specified, ReadSerialData() will never block for longer than the specified duration. Otherwise it will wait forever for data to arrive.

ReadSerialData() will return the data it has read from the serial port and the length of the data in bytes. Note that this can be less than the length specified in len. If ReadSerialData() returns less bytes than you requested in len, you have to call ReadSerialData() again and again until you have received all the data you need.

Note that the value returned in count will always be the same as the ByteLen() for data$. The only reason for the count return value is a performance gain because in that way you don't have to call ByteLen() to calculate the length of data$.

To poll the number of bytes currently in the read buffer, use the PollSerialQueue() function. See PollSerialQueue for details.

identifier of the serial port connection to use
number of bytes to read from the serial port
optional: number of milliseconds after which to abort the operation (defaults to 0 which means to block forever until data arrives)
the data read from the serial port
number of bytes read from the serial port
OpenSerialPort(1, "COM1")
Print(ReadSerialData(1, 256))
The code above will wait forever for data to arrive from the serial port. As soon as something arrives, it will return and print it. This can be less than 256 bytes. The only thing that is guaranteed is that it will never be more than 256 bytes.

Show TOC