Skip to main content
Version: 8.1

system.serial.configureSerialPort

This function is used in Python Scripting.

Description​

Configure a serial port for use in a later call. This only needs to be done once unless the configuration has changed after the initial call. All access to constants must be prefixed by " system.serial. ".

Client Permission Restrictions​

This scripting function has no Client Permission restrictions.

Syntax​

tip

This function accepts keyword arguments.

system.serial. configureSerialPort(port, [bitRate], [dataBits], [hardwareFlowControl], [parity], [stopBits])

Parameters​

TypeParameterDescription
StringportThe name of the serial port, e.g., "COM1" or "/dev/ttyS0". This parameter is required.
IntegerbitRateConfigure the bit rate. Valid values are defined by the following constants [optional]:

system.serial.BIT_RATE_110, system.serial.BIT_RATE_150, system.serial.BIT_RATE_300, system.serial.BIT_RATE_600, system.serial.BIT_RATE_1200, system.serial.BIT_RATE_2400, system.serial.BIT_RATE_4800, system.serial.BIT_RATE_9600, system.serial.BIT_RATE_19200, system.serial.BIT_RATE_38400, system.serial.BIT_RATE_57600, system.serial.BIT_RATE_115200, system.serial.BIT_RATE_230400, system.serial.BIT_RATE_460800, system.serial.BIT_RATE_921600
IntegerdataBitsConfigure the data bits. Valid values are defined by the following constants [optional]:

system.serial.DATA_BITS_5, system.serial.DATA_BITS_6, system.serial.DATA_BITS_7, system.serial.DATA_BITS_8
BooleanhardwareFlowControlConfigure hardware flow control. On or off. [optional]
IntegerparityConfigure parity. Valid values are defined by the following constants [optional]:

system.serial.PARITY_EVEN, system.serial.PARITY_ODD, system.serial.PARITY_MARK, system.serial.PARITY_SPACE, system.serial.PARITY_NONE
IntegerstopBitsConfigure stop bits.Valid values are defined by the following constants [optional]:

system.serial.STOP_BITS_1, system.serial.STOP_BITS_2
note

The serial library was updated in 8.0. Any constants, like HANDSHAKE, that do not have an equivalent value will result in a value of 0.

Returns​

SerialConfigurator - A SerialConfigurator object with exposed functions that can be used to configure the serial port instead of, or in addition to, the arguments passed to configureSerialPort.

Scope​

Gateway, Vision Client, Perspective Session

SerialConfigurator Methods​

Below is a listing of methods on the SerialConfigurator object. All methods return the original SerialConfigurator object, but with a modified parameter value. For a list of possible values, see the appropriate parameter on the function description above.

MethodDescription
setBitRateSets the bit rate on the SerialConfigurator.
setDataBitsSets the data bits on the SerialConfigurator.
setParitySets the parity on the SerialConfigurator.
setStopBitsSets the stop bits on the SerialConfigurator.
setFlowControlSets the flow control on the SerialConfigurator.
setHandshakeSets the handshake on the SerialConfigurator.
setHardwareFlowControlSets the hardware flow control on the SerialConfigurator.

Code Examples​

Example #1 Configuring Serial Port
# Configure a serial port using keyword args.
# The "port" keyword is mandatory.

system.serial.configureSerialPort(\
port="COM1",\
bitRate=system.serial.BIT_RATE_9600,\
dataBits=system.serial.DATA_BITS_8,\
handshake=system.serial.HANDSHAKE_NONE,\
hardwareFlowControl=False,\
parity=system.serial.PARITY_NONE,\
stopBits=system.serial.STOP_BITS_1)
Example #2 Configuring Serial Port
# Configure a serial port using a SerialConfigurator (returned by configureSerialPort()):

system.serial.configureSerialPort("COM1")\
.setBitRate(system.serial.BIT_RATE_9600)\
.setDataBits(system.serial.DATA_BITS_8)\
.setHandshake(system.serial.HANDSHAKE_NONE)\
.setHardwareFlowControl(False)\
.setParity(system.serial.PARITY_NONE)\
.setStopBits(system.serial.STOP_BITS_1)