Skip to content

Commit 038398c

Browse files
committed
Update modbus_tcp.py
confirmed working; need to implement address tho
1 parent 0e96b34 commit 038398c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

classes/transports/modbus_tcp.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class modbus_tcp(modbus_base):
1010
port : str = 502
1111
host : str = ""
1212
client : ModbusTcpClient
13+
pymodbus_slave_arg = 'unit'
1314

1415
def __init__(self, settings : SectionProxy, protocolSettings : protocol_settings = None):
1516
#logger = logging.getLogger(__name__)
@@ -25,8 +26,16 @@ def __init__(self, settings : SectionProxy, protocolSettings : protocol_settings
2526
super().__init__(settings, protocolSettings=protocolSettings)
2627

2728
def read_registers(self, start, count=1, registry_type : Registry_Type = Registry_Type.INPUT, **kwargs):
29+
30+
if 'unit' not in kwargs:
31+
kwargs = {'unit': 1, **kwargs}
32+
33+
#compatability
34+
if self.pymodbus_slave_arg != 'unit':
35+
kwargs['slave'] = kwargs.pop('unit')
36+
2837
if registry_type == Registry_Type.INPUT:
29-
return self.client.read_input_registers(start, count, **kwargs)
38+
return self.client.read_input_registers(start, count, **kwargs )
3039
elif registry_type == Registry_Type.HOLDING:
3140
return self.client.read_holding_registers(start, count, **kwargs)
3241

0 commit comments

Comments
 (0)