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​
This function accepts keyword arguments.
system.serial. configureSerialPort(port, [bitRate], [dataBits], [hardwareFlowControl], [parity], [stopBits])
Parameters​
Type | Parameter | Description |
---|---|---|
String | port | The name of the serial port, e.g., "COM1" or "/dev/ttyS0". This parameter is required. |
Integer | bitRate | Configure 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 |
Integer | dataBits | Configure 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 |
Boolean | hardwareFlowControl | Configure hardware flow control. On or off. [optional] |
Integer | parity | Configure 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 |
Integer | stopBits | Configure stop bits.Valid values are defined by the following constants [optional]:system.serial.STOP_BITS_1, system.serial.STOP_BITS_2 |
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.
Method | Description |
---|---|
setBitRate | Sets the bit rate on the SerialConfigurator. |
setDataBits | Sets the data bits on the SerialConfigurator. |
setParity | Sets the parity on the SerialConfigurator. |
setStopBits | Sets the stop bits on the SerialConfigurator. |
setFlowControl | Sets the flow control on the SerialConfigurator. |
setHandshake | Sets the handshake on the SerialConfigurator. |
setHardwareFlowControl | Sets the hardware flow control on the SerialConfigurator. |
Code Examples​
# 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)
# 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)