node-modbus-serial icon indicating copy to clipboard operation
node-modbus-serial copied to clipboard

Reduce the chances of multiple Modbus APUs per TCP frame

Open Abestanis opened this issue 1 year ago • 3 comments

This attempts to reduce the likelihood of the problem described in #540, but unfortunately doesn't completely fix it.

  • For every data we sent via the Modbus TCP socket we now wait for the drain event of the previous data in the hopes that the new data does not get merged into the same TCP frame.
  • We set the NoDelay flag.

Both changes seem to reduce the amount of TCP frames with more than one Modbus APU, but under very high throughput the can still be some of them. There seems to be no way of guaranteeing separate TCP packages short of using a raw socket and implementing the entire TCP stack manually, so I personally think this is a design flaw of the Modbus protocol and in the end I choose to fix the problem on the Modbus server side by accepting TCP packages with multiple APUs. Also, all other Modbus implementation which I found that were not written for bare metal have exactly the same problem.

I'm posting this here in case you still want to have an improvement over the current state. Sorry about all the whitespace changes, that was the auto formatter of my IDE.

Abestanis avatar Sep 02 '24 19:09 Abestanis