Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.5b

Application v 5.24b

  

 

Chapter TwelveInternet Functions (continued)

SerialOpen Function

Overview

The SerialOpen function opens a specified serial port using the default or provided configuration.

Syntax/Parameters

Syntax

handle = SerialOpen ( handle hSerial, int port, [int baud], [int bits], [int stop],
                                            [int parity], [int handshake] );

Parameters

hSerial

A handle to a Serial Port Object.

port

An int specifying the port number. For example, 1 becomes “COM1”. The com port must exist and must not be in use by another process or part of the program.

baud

An optional int specifying the baud rate for bits per second. The supported rates depend on the physical hardware and also must match the corresponding communication device. Standard rates are: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 12800, and 256000. If baud is not specified, the default from the device system configuration value is used. Optional settings for the remaining parameters are then applied from the default function values, not Windows.

bits

An optional int specifying the number of bits that make a character (byte) to transmit and receive. The maximum (and normally the default) is 8. Some older systems may employ 7-bit (pure ASCII). The baud parameter must be specified to use this parameter. If bits is not specified, the default value is 8-bits.

stop

An optional int specifying the number of stop bits. The values can be:

SP_STOP_BIT_ONE      — 1 stop bit (de facto standard)

SP_STOP_BIT_ONE_FIVE — 1.5 stop bits (old systems)

SP_STOP_BIT_TWO      — 2 stop bits (old systems)

The bits parameter must be specified to use this parameter. If stop is not specified, the default value is SP_STOP_BIT_ONE.

parity

An optional int specifying the type of parity checking to employ. The values can be:

SP_PARITY_NONE — No parity checking is employed

SP_PARITY_EVEN — Even parity is used

SP_PARITY_ODD  — Odd parity is used

The stop parameter must be specified to use this parameter. If parity is not specified, the default value is SP_PARITY_NONE.

handshake

An optional int specifying the handshake mode to use.

SP_HANDSHAKE_NONE     — No Handshaking (software or other)

SP_HANDSHAKE_SOFTWARE — Handshaking Via Ctrl+Q Ctrl+S

SP_HANDSHAKE_HARDWARE — Handshaking Via CTS/RTS, DSR

The parity parameter must be specified to use this parameter. If handshake is not specified, the default value is SP_HANDSHAKE_NONE.

Return Value

Returns a handle to the communications device or NULL_HANDLE on failure. Use the GetLastError to retrieve a formatted error code.

Remarks

SerialOpen connects to a specific hardware port (virtual or physical), sets the channel parameters and readies the channel for communications.

If the baud parameter is not provided, the settings will be picked up from the Windows driver and configuration associated with the device. The baud will result in all remaining optional values to be set from the script defaults as specified above. Programmers should be aware of the pitfalls of mismatching bits, parity and stop bits. When combined with using the wrong rate, initial channel testing can be difficult. A good example is interfacing to an external device expecting 7-bits with even parity using 8-bits with no parity setting. The external equipment will randomly have parity errors and the receiving script will randomly have the top bit of every byte set. This is the result of the parity being confused with the 8th bit.

The function will automatically delay 250ms after the open to allow a device channel to settle. For example, a modem may need time for the hardware to reset.

Related Functions

Platform Support

Go13, Go16, GoFiler Complete, GoFiler Corporate, GoFiler, GoFiler Lite, GoXBRL

Legato IDE, Legato Basic