Data Sheet
dScript
dScript User Manual v2.15
Serial ports
dScript Modules may implement one or more serial ports, these are declared at the start of
your program. Because it takes time to send data out over a serial port we provide each port
with both receive and transmit FIFO (first in first out) buffers. Once declared a serial port will
receive and transmit in the background. Received data will be placed in the Rx Fifo ready for
when your program wants to fetch it. Transmit data can be sent to the Tx Fifo and will then be
sent out in the background. You decide how big these Fifo buffers are, up to the limit of
available RAM. The default format for a newly declared serial port is 9600 baud 2 stop bits.
serialport Name PortNumber RxFifoSize TxFifoSize
serialport LCD05 1 10 90
Name
The first parameter is the port name. This is the name you will use to refer to this serial port in
the rest of your program. In the above example we will connect an LCD05 display module, so
naming the port LCD05 provides a descriptive name to make the program more readable.
PortNumber
Some modules may have three serial ports numbered 1, 2 and 3. This selects which physical
port to use.
RxFifoSize
This is the size of the receive or Rx FIFO. Here the LCD05 will only ever send a few bytes back
in response to a command, so 10 bytes is plenty.
TxFifoSize
This is the size of the transmit or Tx FIFO. In the case of the LCD05 which is a 20x4 character
display, we want to send a complete screen of data plus a few control codes as well, so the size
is set to 90 bytes.
The above example names serial port 1 as "LCD05" with an Rx buffer size of 10 bytes and a
transmit buffer size of 90 bytes.
Writing data to a serial port
The "Write" command is used to send serial data. The syntax is:
mySerialPortName.Write( <string name>, <start position>, <number of bytes to send>)
Data to be written to the serial port should be placed into a string - think of it as a byte array
of the data to send.
Copyright © 2016, Devantech Ltd.
All rights reserved.
www.robot-electronics.co.uk
29