Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter TwelveInternet Functions (continued)

12.5 Serial Interface

12.5.1 General

Legato provides low-level access to any specified serial asynchronous communications port that exists on a system. Serial ports need not be plain RS-232 and can be USB or virtual depending on the hardware and drivers employed. This section discusses basic communications.

There are three basic operations for serial communications: channel control, receiving data, and sending data. Channel control basically involves opening a serial port and performing the necessary setup such as speed and data characteristics. Receiving involves essentially examining the input (receive) queue and collecting characters until some specified event or series of characters passes through. Sending information (transmit) involves sending characters.

Since characters can be received at any time, and when the script is not waiting for characters, the script has a built in receive queue. If the buffer nears overflow, a handshake protocol is employed to indicate to the external system to stop sending. If a handshake is not enabled or incorrectly configured, data may be lost.

The Serial functions operate in asynchronous mode, that is, data is sent character by character at any time. Each character send has a start bit, data bits, a possible parity bit and one or more stop bits. Data can be 7 or 8 bits, parity is not required but if present can be odd or even parity and finally stop bits can be 1, 1.5 or 2. The parity bit is a check bit to verify the data word which can operate in a number of modes such as odd or even counting. However, parity is a crude ‘old school’ method of data checking that has been long since superseded by better checking using various data protocols.

At its best, for every 8 bit character sent, 2 additional bits of overhead are required. It is critical that both the send and receive devices have the same settings.

Serial channels operate at a specified speed known as a baud rate also known as bits per second (bps). The rate supported depends on both the hardware employed on the script side and interfacing parties side. Baud rate settings must match between devices or errors will occur or possibly no communications at all. There are a series of standard rates supported by most devices ranging from 110 to 256000: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 58600, 115200, 128000 and 256000. Non-standard rates may not be supported by a specific device. Some devices may also “auto baud” mean that they will detect a series of characters and measure their timing and then set a baud rate to match.

To further complicate matters, the eventual speed being employed may not match the baud rate. A good example would be the use of a modem with a maximum speed of 56K. The serial port may be configured as 56K but when the modem connects to another device, the speed can be significantly slower and may actually change depending on conditions.

12.5.2 Serial Functions

SerialEnumeratePorts — Enumerates all available serial ports.

SerialOpen — Opens a serial communications port with specified parameters.

SerialGetLinkStatus — Returns the link status of the communications port.

SerialGetProperties — Gets the current channel properties such as baud rate.

SerialGetRxQueueCount — Returns the number of characters in the receive buffer to be retrieved.

SerialRxCharacter — Checks the input queue for a character.

SerialRxLine — Receive characters until end of line, escape character or time-out.

SerialRxPurge — Purges the input queue and buffer.

SerialSetProperties — Sets (resets) the parameters for an open serial port.

SerialTxBlock — Transmits a series of bytes from the specified variable.

SerialTxPurge — Purges any remaining characters from the transmit queue.

SerialTxString — Transmits a string of characters.

SerialTxWithDelay — Transmits a string of characters with optional delay escape characters and provisions for escaped control characters.