msl.equipment.connection_serial module

Base class for equipment that is connected through a serial port.

class msl.equipment.connection_serial.ConnectionSerial(record)[source]

Bases: ConnectionMessageBased

Base class for equipment that is connected through a serial port.

The properties for a serial connection supports the following key-value pairs in the Connections Database (see also serial.Serial for more details about each parameter):

'baud_rate': int, the baud rate [default: 9600]
'data_bits': int, the number of data bits, e.g. 5, 6, 7, 8 [default: 8]
'dsr_dtr': bool, enable hardware (DSR/DTR) flow control [default: False]
'encoding': str, the encoding to use [default: 'utf-8']
'encoding_errors': str, encoding error handling scheme, e.g. 'strict', 'ignore' [default: 'strict']
'inter_byte_timeout': float or None, the inter-character timeout [default: None]
'max_read_size': int, the maximum number of bytes that can be read [default: 1 MB]
'parity': str or None, parity checking, e.g. 'even', 'odd' [default: None]
'read_termination': str or None, read until this termination sequence is found [default: '\n']
'rstrip': bool, whether to remove trailing whitespace from "read" messages [default: False]
'rts_cts': bool, enable hardware (RTS/CTS) flow control [default: False]
'stop_bits': int or float, the number of stop bits, e.g. 1, 1.5, 2 [default: 1]
'termination': shortcut for setting both 'read_termination' and 'write_termination' to this value
'timeout': float or None, the timeout (in seconds) for read and write operations [default: None]
'write_termination': str or None, termination sequence appended to write messages [default: '\r\n']
'xon_xoff': bool, enable software flow control [default: False]

The backend value must be equal to MSL to use this class for the communication system. This is achieved by setting the value in the Backend field for a connection record in the Connections Database to be MSL.

Do not instantiate this class directly. Use the connect() method to connect to the equipment.

Parameters

record (EquipmentRecord) – A record from an Equipment-Register Database.

Raises

MSLConnectionError – If the serial port cannot be opened.

property serial

The reference to the serial object.

Type

serial.Serial

property baud_rate

The baud rate setting.

Type

int

property data_bits

The number of data bits.

Type

DataBits

property stop_bits

The stop bit setting.

Type

StopBits

property parity

The parity setting.

Type

Parity

disconnect()[source]

Close the serial port.

static parse_address(address)[source]

Get the serial port from an address.

Parameters

address (str) – The address of a ConnectionRecord

Returns

dict or None – The serial port in a format that is valid for PySerial (i.e., ASRL3 becomes COM3) or None if the port cannot be determined from address.