|
1 | 1 | import logging |
2 | 2 | from classes.protocol_settings import Registry_Type, protocol_settings |
3 | 3 |
|
| 4 | +import inspect |
| 5 | + |
| 6 | + |
4 | 7 | try: |
5 | 8 | from pymodbus.client.sync import ModbusSerialClient |
6 | 9 | except ImportError: |
@@ -38,10 +41,19 @@ def __init__(self, settings : SectionProxy, protocolSettings : protocol_settings |
38 | 41 | address : int = settings.getint("address", 0) |
39 | 42 | self.addresses = [address] |
40 | 43 |
|
41 | | - self.client = ModbusSerialClient(method='rtu', port=self.port, |
42 | | - baudrate=int(self.baudrate), |
43 | | - stopbits=1, parity='N', bytesize=8, timeout=2 |
44 | | - ) |
| 44 | + # Get the signature of the __init__ method |
| 45 | + init_signature = inspect.signature(ModbusSerialClient.__init__) |
| 46 | + |
| 47 | + if 'method' in init_signature.parameters: |
| 48 | + self.client = ModbusSerialClient(method='rtu', port=self.port, |
| 49 | + baudrate=int(self.baudrate), |
| 50 | + stopbits=1, parity='N', bytesize=8, timeout=2 |
| 51 | + ) |
| 52 | + else: |
| 53 | + self.client = ModbusSerialClient(port=self.port, |
| 54 | + baudrate=int(self.baudrate), |
| 55 | + stopbits=1, parity='N', bytesize=8, timeout=2 |
| 56 | + ) |
45 | 57 |
|
46 | 58 | def read_registers(self, start, count=1, registry_type : Registry_Type = Registry_Type.INPUT, **kwargs): |
47 | 59 |
|
|
0 commit comments