sgr_commhandler.driver.modbus

Provides the Modbus RTU/TCP interface driver.

Submodules

Classes

ModbusDataPoint

Implements a data point of a Modbus interface.

ModbusFunctionalProfile

Implements a functional profile of a Modbus interface.

SGrModbusInterface

Implements a Modbus device interface.

Package Contents

class sgr_commhandler.driver.modbus.ModbusDataPoint(dp_spec, fp_spec, interface)

Bases: sgr_commhandler.api.data_point_api.DataPointProtocol[sgr_specification.v0.product.ModbusFunctionalProfile, sgr_specification.v0.product.ModbusDataPoint]

Implements a data point of a Modbus interface.

Parameters:
  • dp_spec (sgr_specification.v0.product.ModbusDataPoint)

  • fp_spec (sgr_specification.v0.product.ModbusFunctionalProfile)

  • interface (SGrModbusInterface)

_interface
_address: int = -1
_data_type: sgr_specification.v0.product.modbus_types.ModbusDataType
_size = 0
_register_type: sgr_specification.v0.product.modbus_types.RegisterType
async set_val(value)
Parameters:

value (Any)

async get_val(parameters=None, skip_cache=False)
Parameters:
  • parameters (Optional[dict[str, str]])

  • skip_cache (bool)

Return type:

Any

class sgr_commhandler.driver.modbus.ModbusFunctionalProfile(fp_spec, interface)

Bases: sgr_commhandler.api.functional_profile_api.FunctionalProfile[sgr_specification.v0.product.ModbusFunctionalProfile]

Implements a functional profile of a Modbus interface.

Parameters:
  • fp_spec (sgr_specification.v0.product.ModbusFunctionalProfile)

  • interface (SGrModbusInterface)

_interface
_data_points
get_data_points()
Return type:

dict[tuple[str, str], sgr_commhandler.api.data_point_api.DataPoint]

class sgr_commhandler.driver.modbus.SGrModbusInterface(frame, sharedRTU=False)

Bases: sgr_commhandler.api.device_api.SGrBaseInterface

Implements a Modbus device interface.

Parameters:
  • frame (sgr_specification.v0.product.DeviceFrame)

  • sharedRTU (bool)

_client_wrapper: sgr_commhandler.driver.modbus.shared_client.ModbusClientWrapper = None
byte_order
address_offset = -1
functional_profiles
_device_id = ''
__del__()
is_connected()
Return type:

bool

async connect_async()
async disconnect_async()
async read_data(reg_type, address, size, data_type)

Reads data from the given Modbus address(es).

Parameters:
  • reg_type (sgr_specification.v0.product.modbus_types.RegisterType)

  • address (int)

  • size (int)

  • data_type (sgr_specification.v0.product.modbus_types.ModbusDataType)

Return type:

Any

async write_data(reg_type, address, data_type, value)

Writes data to the given Modbus address(es).

Parameters:
  • reg_type (sgr_specification.v0.product.modbus_types.RegisterType)

  • address (int)

  • data_type (sgr_specification.v0.product.modbus_types.ModbusDataType)

  • value (Any)

set_slave_id(slave_id)
Parameters:

slave_id (int)