hvl_ccb.comm.modbus_tcp¶
Communication protocol for modbus TCP ports. Makes use of the pymodbus library.
-
class
ModbusTcpCommunication
(configuration)[source]¶ Bases:
hvl_ccb.comm.base.CommunicationProtocol
Implements the Communication Protocol for modbus TCP.
-
static
config_cls
()[source]¶ Return the default configdataclass class.
- Returns
a reference to the default configdataclass class
-
open
() → None[source]¶ Open the Modbus TCP connection.
- Raises
ModbusTcpConnectionFailedException – if the connection fails.
-
read_holding_registers
(address: int, count: int) → List[int][source]¶ Read specified number of register starting with given address and return the values from each register.
- Parameters
address – address of the first register
count – count of registers to read
- Returns
list of int values
-
static
-
class
ModbusTcpCommunicationConfig
(host: str, unit: int, port: int = 502)[source]¶ Bases:
object
Configuration dataclass for
ModbusTcpCommunication
.-
force_value
(fieldname, value)¶ Forces a value to a dataclass field despite the class being frozen.
NOTE: you can define post_force_value method with same signature as this method to do extra processing after value has been forced on fieldname.
- Parameters
fieldname – name of the field
value – value to assign
-
host
: str¶ Host is the IP address of the connected device.
-
is_configdataclass
= True¶
-
classmethod
keys
() → Sequence[str]¶ Returns a list of all configdataclass fields key-names.
- Returns
a list of strings containing all keys.
-
classmethod
optional_defaults
() → Dict[str, object]¶ Returns a list of all configdataclass fields, that have a default value assigned and may be optionally specified on instantiation.
- Returns
a list of strings containing all optional keys.
-
port
: int = 502¶ TCP port
-
classmethod
required_keys
() → Sequence[str]¶ Returns a list of all configdataclass fields, that have no default value assigned and need to be specified on instantiation.
- Returns
a list of strings containing all required keys.
-
unit
: int¶ Unit number to be used when connecting with Modbus/TCP. Typically this is used when connecting to a relay having Modbus/RTU-connected devices.
-