You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm using pyModbusTCP to read 19 devices on Modbus with mbusd (on same host).
Everything seems to work fine but if set auto_open=True the TCP socket after mbusd timeout (60s) is
closed and it is not re-opened at first access on Modbus but it is working since second access...
A call to close() and open() don't help and the behaviour is always the same: the socket is reopened starting
from second access on the bus.
To test this I'm using following Python script:
#!/usr/bin/env python3
import time
from pyModbusTCP.client import ModbusClient
def on_tx_rx(frame: bytes, is_tx: bool):
if is_tx:
print(f'[tx] {frame}')
else:
print(f'[rx] {frame}')
c = ModbusClient(host="localhost", auto_open=True, auto_close=False, timeout=120)
c.on_tx_rx = on_tx_rx
value = 25
for ch in range(1,20):
c.unit_id = ch
c.write_single_register(36, value)
print(f'W {ch} {value}')
while True:
for ch in range(1,20):
c.unit_id = ch
if(c.is_open == False):
c.close()
c.open()
rup = c.read_holding_registers(36, 1)
print(f'R {ch} {rup} is_open: {c.is_open}')
time.sleep(60)
The text was updated successfully, but these errors were encountered:
However, here are some notes/tips that I hope will help you:
avoid using a large timeout unless you are dealing with a very slow network or server (120s seems really huge to me).
socket I/O is only triggered when a request like "read_holding_registers" is issued. So if you try to read from a recently closed TCP socket (from the server's point of view, from the client's point of view, or both), that read will fail (return None). Only the next request will try to reopen the TCP link (when auto_open is set to True, otherwise you have to call open()).
if you want to manage TCP link yourself (with is_open, open() or close() method) just set auto_open and auto_close to False.
Hi,
I'm using pyModbusTCP to read 19 devices on Modbus with mbusd (on same host).
Everything seems to work fine but if set
auto_open=True
the TCP socket after mbusd timeout (60s) isclosed and it is not re-opened at first access on Modbus but it is working since second access...
A call to close() and open() don't help and the behaviour is always the same: the socket is reopened starting
from second access on the bus.
To test this I'm using following Python script:
The text was updated successfully, but these errors were encountered: