|Top Previous Next|
Receives data from the serial port.
A string of length count or less, or a negative number if failure.
If the requested number of bytes has already been received and is waiting in the port's input buffer, this function will return immediately with a string of length count. Otherwise, this function will pause execution waiting for received data up to the amount of time specified by the readTimeout property. If the read times out before receiving all of the requested data, the return string will contain the data that had been received to that point. If no data was received, the return value is the empty string. The bytesCanRead property can be used to determine the largest of value for count that can be passed without causing execution to pause.
If the received data is binary, individual bytes can be accessed from the returned string using the element reference operator .
This function can fail if the serial port has not been enabled by setting its bitRate property to a positive value.
// reconstruct 16-bit word sent low byte first
if (Cell.Serial.bytesCanRead >= 2)
val = val + (val << 8);