Connections
PyLabware connection adapters.
- class PyLabware.connections.AbstractConnection(connection_parameters)[source]
Bases:
ABC
Base abstract class for all connection adapters.
- Parameters:
connection_parameters (
Dict
) – Dictionary with connection settings relevant for the concrete type of connection.
-
DEFAULT_CONNECTION_PARAMETERS:
Dict
= {'address': None, 'command_delay': 0.5, 'encoding': 'UTF-8', 'port': None, 'receive_buffer_size': 128, 'receive_timeout': 1, 'receiving_interval': 0.05, 'transmit_timeout': 1}
- abstract close_connection()[source]
Closes the connection.
This method has to be redefined in child classes.
- abstract is_connection_open()[source]
Checks whether the connection is open.
This method has to be redefined in child classes.
- Returns:
True if connection is open, False if connection is closed.
- Return type:
(bool)
- abstract open_connection()[source]
Opens the connection. This method should create self._connection object, set up necessary parameters and open connection. Connection object creation shouldn’t be done in __init__(), otherwise the connection object instance might not be reusable after close()-open() sequence.
This method has to be redefined in child classes.
- class PyLabware.connections.HTTPConnection(connection_parameters)[source]
Bases:
AbstractConnection
HTTP REST connection adapter based on Requests library.
- Parameters:
connection_parameters (Dict) – Dictionary with connection settings for HTTP REST connection.
-
HTTP_DEFAULT_CONNECTION_PARAMETERS:
Dict
= {'headers': '', 'password': None, 'schema': 'http', 'user': None, 'verify_ssl': True}
- class PyLabware.connections.SerialConnection(connection_parameters)[source]
Bases:
AbstractConnection
Serial connection adapter.
- Parameters:
connection_parameters (
Dict
) – Dictionary with connection settings relevant for the serial connection.
-
SERIAL_DEFAULT_CONNECTION_PARAMETERS:
Dict
= {'baudrate': 9600, 'bytesize': 8, 'dsrdtr': False, 'inter_byte_timeout': False, 'parity': 'N', 'rtscts': False, 'stopbits': 1, 'write_timeout': 0.5, 'xonxoff': False}
- connection_listener()[source]
Periodically checks for new data on the connection, reads it, puts the data read into receive buffer and raises data ready flag.
- is_connection_open()[source]
Checks whether the serial port is opened.
- Returns:
If the serial port is open.
- Return type:
(bool)
- class PyLabware.connections.TCPIPConnection(connection_parameters)[source]
Bases:
AbstractConnection
Socket-based TCP/IP connection adapter.
Default constructor.
- Parameters:
connection_parameters (
Dict
) – Dictionary with connection settings for socket-based connection.
-
TCPIP_DEFAULT_CONNECTION_PARAMETERS:
Dict
= {'protocol': 'TCP'}
- connection_listener()[source]
Periodically checks for new data on the connection, reads it, puts it into receive buffer and raises data ready flag.
- is_connection_open()[source]
Checks whether the socket is open
- Returns:
If the socket is open.
- Return type:
(bool)
- receive(retries=3)[source]
Gets the data from receive buffer, clears the data ready flag and passes the data back.
- Parameters:
retries (int) – Number of times to retry if receive times out. Introduced due to RCTDigitalHotplate test showing that around 0.02 % of attempted get_temperature calls timeout. These are spaced out and not all happening at once so 1 retry should be sufficient to protect against these anomalies and prevent unnecessary crashes.
- Returns:
Reply from the device packed into LabDeviceReply object.
- Return type: