hvl_ccb.comm.modbus_tcp

digraph inheritance7cbd6b86c1 { bgcolor=transparent; rankdir=TB; size=""; "ABC" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Helper class that provides a standard way to create an ABC using"]; "CCBError" [URL="../hvl_ccb.error.html#hvl_ccb.error.CCBError",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "CommunicationError" [URL="../hvl_ccb.comm.base.html#hvl_ccb.comm.base.CommunicationError",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "CCBError" -> "CommunicationError" [arrowsize=0.5,style="setlinewidth(0.5)"]; "CommunicationProtocol" [URL="../hvl_ccb.comm.base.html#hvl_ccb.comm.base.CommunicationProtocol",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Communication protocol abstract base class."]; "ConfigurationMixin" -> "CommunicationProtocol" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ABC" -> "CommunicationProtocol" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ConfigurationMixin" [URL="../hvl_ccb.configuration.html#hvl_ccb.configuration.ConfigurationMixin",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Mixin providing configuration to a class."]; "ABC" -> "ConfigurationMixin" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ConnectionException" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Error resulting from a bad connection."]; "ModbusException" -> "ConnectionException" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ModbusException" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base modbus exception."]; "ModbusTcpCommunication" [URL="../hvl_ccb.comm.modbus_tcp.html#hvl_ccb.comm.modbus_tcp.ModbusTcpCommunication",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Implements the Communication Protocol for modbus TCP."]; "CommunicationProtocol" -> "ModbusTcpCommunication" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ModbusTcpCommunicationConfig" [URL="../hvl_ccb.comm.modbus_tcp.html#hvl_ccb.comm.modbus_tcp.ModbusTcpCommunicationConfig",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Configuration dataclass for :class:`ModbusTcpCommunication`."]; "ModbusTcpConnectionFailedError" [URL="../hvl_ccb.comm.modbus_tcp.html#hvl_ccb.comm.modbus_tcp.ModbusTcpConnectionFailedError",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Error raised when the connection failed."]; "ConnectionException" -> "ModbusTcpConnectionFailedError" [arrowsize=0.5,style="setlinewidth(0.5)"]; "CommunicationError" -> "ModbusTcpConnectionFailedError" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

Communication protocol for modbus TCP ports. Makes use of the pymodbus library.

class ModbusTcpCommunication(configuration)[source]

Bases: CommunicationProtocol

Implements the Communication Protocol for modbus TCP.

close()[source]

Close the Modbus TCP connection.

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:

ModbusTcpConnectionFailedError – 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

read_input_registers(address: int, count: int) list[int][source]

Read specified number of register starting with given address and return the values from each register in a list.

Parameters:
  • address – address of the first register

  • count – count of registers to read

Returns:

list of int values

write_registers(address: int, values: list[int] | int)[source]

Write values from the specified address forward.

Parameters:
  • address – address of the first register

  • values – list with all values

class ModbusTcpCommunicationConfig(host: str | IPv4Address | IPv6Address, unit: int, port: int = 502)[source]

Bases: object

Configuration dataclass for ModbusTcpCommunication.

clean_values()[source]
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 | IPv4Address | IPv6Address
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
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
exception ModbusTcpConnectionFailedError(string='')[source]

Bases: ConnectionException, CommunicationError

Error raised when the connection failed.