hvl_ccb.comm.modbus
Communication protocol for Modbus communications. Makes use of the pymodbus library.
- class ModbusBaseCommunication(configuration)[source]
Bases:
CommunicationProtocol,ABCImplements the Communication Protocol for modbus.
- open() None[source]
Open the Modbus connection.
- Raises:
ModbusConnectionFailedError – 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
- class ModbusBaseCommunicationConfig(unit: int = 1)[source]
Bases:
objectBase modbus communication config
- 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
- 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.
- 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 = 1
- exception ModbusConnectionError(string='')[source]
Bases:
ConnectionException,CommunicationErrorError raised when the connection failed.
- class ModbusSerialCommunication(configuration)[source]
Bases:
ModbusBaseCommunicationModbus with the Serial-Version, can be RTU or ASCII
- static config_cls() type[ModbusSerialCommunicationConfig][source]
Return the default configdataclass class.
- Returns:
a reference to the default configdataclass class
- class ModbusSerialCommunicationConfig(terminator: bytes = b'\r\n', encoding: str = 'utf-8', encoding_error_handling: str = 'strict', wait_sec_read_text_nonempty: int | float = 0.5, default_n_attempts_read_text_nonempty: int = 10, port: str | None = None, baudrate: int = 9600, parity: str | ~hvl_ccb.comm.serial.SerialCommunicationParity = <SerialCommunicationParity.NONE: 'N'>, stopbits: int | float | ~hvl_ccb.comm.serial.SerialCommunicationStopbits = <SerialCommunicationStopbits.ONE: 1>, bytesize: int | ~hvl_ccb.comm.serial.SerialCommunicationBytesize = <SerialCommunicationBytesize.EIGHTBITS: 8>, timeout: int | float = 2, unit: int = 1, framer: str | ~pymodbus.framer.base.FramerType = FramerType.RTU)[source]
Bases:
ModbusBaseCommunicationConfig,SerialCommunicationConfigConfiguration dataclass for
ModbusRtuCommunication.- 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
- framer: str | FramerType = 'rtu'
- 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.
- 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.
- class ModbusTcpCommunication(configuration)[source]
Bases:
ModbusBaseCommunicationModbus with the TCP-Version
- static config_cls() type[ModbusTcpCommunicationConfig][source]
Return the default configdataclass class.
- Returns:
a reference to the default configdataclass class
- class ModbusTcpCommunicationConfig(unit: int = 1, host: str | IPv4Address | IPv6Address | None = None, port: int = 502)[source]
Bases:
ModbusBaseCommunicationConfigConfiguration 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
- 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.