sgr_commhandler.driver.modbus.shared_client

Provides shared Modbus RTU clients.

Attributes

logger

_global_shared_lock

global singleton for locking.

_global_shared_rtu_clients

global singleton containing registered clients.

Classes

ModbusClientWrapper

Implements a Modbus client wrapper for shared use.

Functions

register_shared_client(serial_port, parity, baudrate, ...)

Registers a device at a shared transport.

unregister_shared_client(serial_port, device_id)

Unregisters a device from a shared transport.

Module Contents

sgr_commhandler.driver.modbus.shared_client.logger
class sgr_commhandler.driver.modbus.shared_client.ModbusClientWrapper(identifier, client, shared=False)

Implements a Modbus client wrapper for shared use.

Parameters:
identifier
client
shared = False
registered_devices
connected_devices
async connect_async(device_id)

Connects the device to the underlying transport.

Parameters:

device_id (str) – the unique device identifier

async disconnect_async(device_id)

Disconnects the device from the underlying transport.

Parameters:

device_id (str) – the unique device identifier

is_connected(device_id)

Tells if the device is connected to the transport.

Parameters:

device_id (str) – the unique device identifier

Returns:

the connection state

Return type:

bool

sgr_commhandler.driver.modbus.shared_client._global_shared_lock

global singleton for locking.

sgr_commhandler.driver.modbus.shared_client._global_shared_rtu_clients: dict[str, ModbusClientWrapper]

global singleton containing registered clients.

sgr_commhandler.driver.modbus.shared_client.register_shared_client(serial_port, parity, baudrate, device_id)

Registers a device at a shared transport. Creates the transport if it does not exist.

Parameters:
  • serial_port (str) – the serial port device name

  • parity (str) – the serial port parity

  • baudrate (int) – the serial port baudrate

  • device_id (str) – the unique device identifier

Returns:

a wrapper for the transport

Return type:

ModbusClientWrapper

sgr_commhandler.driver.modbus.shared_client.unregister_shared_client(serial_port, device_id)

Unregisters a device from a shared transport. Removes the transport if no other device uses it.

Parameters:
  • serial_port (str) – the serial port device name

  • device_id (str) – the unique device identifier