data$, count = ReadSerialData(id, len[, timeout])
lenbytes 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
timeoutargument to set a timeout for the read operation. If the
timeoutparameter 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
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()
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
To poll the number of bytes currently in the read buffer, use the PollSerialQueue() function. See PollSerialQueue for details.
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.