Skip to content

Commit 25c3b88

Browse files
committed
use port 5020 for pymodbus 2.x also
1 parent 9a177ca commit 25c3b88

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

clickplc/util.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class AsyncioModbusClient:
2626
def __init__(self, address, timeout=1):
2727
"""Set up communication parameters."""
2828
self.ip = address
29-
port = 5020 if address == '127.0.0.1' else 502 # pymodbus simulator is 127.0.0.1:5020
29+
self.port = 5020 if address == '127.0.0.1' else 502 # pymodbus simulator is 127.0.0.1:5020
3030
self.timeout = timeout
3131
self._detect_pymodbus_version()
3232
if self.pymodbus30plus:
33-
self.client = AsyncModbusTcpClient(address, timeout=timeout, port=port)
33+
self.client = AsyncModbusTcpClient(address, timeout=timeout, port=self.port)
3434
else: # 2.x
3535
self.client = ReconnectingAsyncioModbusTcpClient()
3636
self.lock = asyncio.Lock()
@@ -57,7 +57,7 @@ async def _connect(self) -> None:
5757
if self.pymodbus30plus:
5858
await asyncio.wait_for(self.client.connect(), timeout=self.timeout) # 3.x
5959
else: # 2.4.x - 2.5.x
60-
await self.client.start(self.ip) # type: ignore
60+
await self.client.start(host=self.ip, port=self.port) # type: ignore
6161
except Exception:
6262
raise OSError(f"Could not connect to '{self.ip}'.")
6363

0 commit comments

Comments
 (0)