OpenPLC_v3
OpenPLC_v3 copied to clipboard
Use libmodbus to decode incoming Modbus TCP messages
This allows us to better handle multiple Modbus ADUs in a single TCP frame (fixes #253).
libmodbus
is better at parsing ADUs and we already use it when we are the Modbus client.
I tested this by sending many commands in a short amount of time and verifying via Wireshark that some of them were sent in one TCP frame. I made sure that OpenPLC was sending one response per request, even for those in one TCP packet.
In addition to the receiving problem, I also noticed that the result of write
was ignored, which returns the number of bytes written. If we generate a lot of response messages, we could fill up the kernel buffer and drop some bytes. The new approach calls write in a loop until all bytes have been written or write returns an error.