init functions docstrings fixed

This commit is contained in:
Nicolas 2025-04-12 11:27:36 +02:00
parent 05e92d2a20
commit 7c420ae53b
2 changed files with 55 additions and 26 deletions

View File

@ -13,13 +13,6 @@ class BusTerminal():
"""
Base class for all bus terminals.
Args:
bus_coupler: The bus coupler to which this terminal is connected.
output_bit_addresses: List of addresses of the output bits.
input_bit_addresses: List of addresses of input bits.
output_word_addresses: List of addresses of output words.
input_word_addresses: List of addresses of input words.
Attributes:
bus_coupler: The bus coupler to which this terminal is connected.
parameters: The parameters of the terminal.
@ -32,7 +25,16 @@ class BusTerminal():
output_word_addresses: list[int],
input_word_addresses: list[int],
mixed_mapping: bool):
"""
Instantiate a new BusTerminal base class.
Args:
bus_coupler: The bus coupler to which this terminal is connected.
output_bit_addresses: List of addresses of the output bits.
input_bit_addresses: List of addresses of input bits.
output_word_addresses: List of addresses of output words.
input_word_addresses: List of addresses of input words.
"""
self.bus_coupler = bus_coupler
self._output_bit_addresses = output_bit_addresses
self._input_bit_addresses = input_bit_addresses
@ -221,6 +223,21 @@ class BusCoupler():
bus_terminals: A list of bus terminal classes according to the
connected terminals.
modbus: The underlying modbus client used for the connection.
"""
def __init__(self, host: str, port: int = 502, bus_terminals: Iterable[Type[BusTerminal]] = [],
timeout: float = 5, watchdog: float = 0, debug: bool = False):
"""
Instantiate a new bus coupler base class.
Args:
host: ip or hostname of the bus coupler
port: port of the modbus host
debug: outputs modbus debug information
timeout: timeout for waiting for the device response
watchdog: time in seconds after the device sets all outputs to
default state. A value of 0 deactivates the watchdog.
debug: If True, debug information is printed.
Examples:
>>> from pyhoff.devices import *
@ -230,10 +247,6 @@ class BusCoupler():
>>> print(f"Temperature ch1: {t1:.1f} °C, Temperature ch2: {t2:.1f} °C")
Temperature ch1: 23.2 °C, Temperature ch2: 22.1 °C
"""
def __init__(self, host: str, port: int = 502, bus_terminals: Iterable[Type[BusTerminal]] = [],
timeout: float = 5, watchdog: float = 0, debug: bool = False):
self.bus_terminals: list[BusTerminal] = list()
self._next_output_bit_offset = 0
self._next_input_bit_offset = 0

View File

@ -63,6 +63,19 @@ class SimpleModbusClient:
last_error: contains last error message or empty string if no error occurred
debug: if True prints out transmitted and received bytes in hex
"""
def __init__(self, host: str, port: int = 502, unit_id: int = 1, timeout: float = 5, debug: bool = False):
"""
Instantiate a Modbus TCP client
Args:
host: hostname or IP address
port: server port
unit_id: ModBus id
timeout: socket timeout in seconds
debug: if True prints out transmitted and received bytes in hex
Example:
>>> client = SimpleModbusClient('localhost', port = 502, unit_id = 1)
>>> print(client.read_coils(0, 10))
@ -75,7 +88,6 @@ class SimpleModbusClient:
>>> print(client.write_multiple_registers(0, [1234, 5678]))
>>> client.close()
"""
def __init__(self, host: str, port: int = 502, unit_id: int = 1, timeout: float = 5, debug: bool = False):
assert 0 <= unit_id < 256
self.host = host
@ -88,6 +100,10 @@ class SimpleModbusClient:
self.debug = debug
def connect(self) -> bool:
"""
Connect manual to the configured modbus server. Usually there is
no need to call this function since it is handled automatically.
"""
for af, st, pr, _, sa in socket.getaddrinfo(self.host, self.port,
socket.AF_UNSPEC,
socket.SOCK_STREAM):