Data Sheet
dScript
dScript User Manual v2.15
Reading data from a serial port
The "Read" command is used to read serial data, the syntax is:
mySerialPortName.Read( <string name>, <start position>, <number of bytes to read>)
Data read from the serial port is placed in a string - think of it as a byte array holding your
incoming data. The following program will read and display the firmware version number of the
LCD05.
S1[0] = 15 ; LCD05 command to read firmware version
LCD05.Write(s1,0,1) ; send it
threadsleep 5 ; wait for data to arrive
LCD05.Read(s1,0,1) ; get it.
C = s1[0]
s1 = " LCD05 V" + C ; format for display – note the two leading spaces
s1[0] = 2 ; for the set cursor command
s1[1] = 41
LCD05.Write(s1,0,s1.Length) ; display the version number
The number of data bytes available in the receive buffer can be read with
serialport.BytesToRead. Instead of sleeping for 5mS we could have written:
do
C = LCD05.BytesToRead ; get number of bytes in receive buffer
while C < 1
There are two serial port transmit buffer parameters:
BytesToWrite will return the number of data bytes in the transmit buffer that are still to be
transmitted.
serialport.BytesAvailable will return the number of free bytes in the transmit buffer that you
can write to.
Copyright © 2016, Devantech Ltd.
All rights reserved.
www.robot-electronics.co.uk
31