I encountered a problem: I created a TCP server with a port of 60000, which broadcasts the data sent to it and can interact with a modbus RTU
slave. When I use libmodbus
When API creates a modbus RTU over TCP
master station A to connect to port 60000, modbus communication is normal. However, when I use modbus pull
software to connect to port 60000 using modbus RTU over TCP
, there will be a situation where both master station A and modbus pull
data are scrambled. Ultimately, it is determined that this is because either master station A or modbus pull
received data in their input cache that does not belong to them, If a modbus_flush()
is added before modbus_write(read)_xxx()
, this problem can be solved. Then the problem arises.
for example:
modbus_flush(ctx);
if (-1 == modbus_write_registers(ctx, addr, count, buf)) {
}
Why can't this modbus_flush() be directly encapsulated into modbus_write(read)_xxx()? So, every time we go to write or read, the data is always clean?