ljean / modbus-tk

Create Modbus app easily with Python
Other
557 stars 211 forks source link

Transmitting a modbus tcp broadcast message halts other communication for 200-300 ms #167

Open vanDrunen opened 2 years ago

vanDrunen commented 2 years ago

After sending a broadcast message via modbus tcp, I can not send any other messages for 200-300 ms. Non broadcast messages can be sent back-to-back without problems.

I am using a Modbus TCP to RTU converter, with the RS485 bus running at 230400 baud. In my application multiple holding registers are sent to a set of slaves, after which a single broadcast is sent for synchronised execution of a function. Any messages sent directly after the broadcast will not arrive, unless there is a 200-300 ms delay added. This has been tested with Python 3.8.2 and 3.9.12, multiple modbus-tk versions (0.5.0 to 1.1.2) on OSX and OpenWRT Linux.

A simple example that reproduces this problem:

master = modbus_tcp.TcpMaster(host="192.168.2.110")
master.set_timeout(0.5)
master.execute(1, cst.WRITE_MULTIPLE_REGISTERS, 48, output_value=[1, 2, 3, 4, 5, 6, 7, 8)
master.execute(2, cst.WRITE_MULTIPLE_REGISTERS, 48, output_value=[9, 8, 7, 6, 5, 4, 3, 2)
master.execute(0, cst.WRITE_SINGLE_REGISTER, 1, output_value=1)
# Only when we sleep here for 300ms, the next message will send reliably
time.sleep(0.3)
master.execute(3, cst.WRITE_MULTIPLE_REGISTERS, 48, output_value=[1, 2, 3, 4, 5, 6, 7, 8)