High load on Modbus TCP. Packet sticking.

Hello. We have encountered the following problem. Our software sends data using the modbus protocol over TCP/IP with a frequency of about 20 ms (production necessity). However, using TCP/IP, which is a stream, we encounter the fact that the packets stick together, and our controller (Innovance Easy320) understands only the first modbus packet of the two stuck together that got into the frame.
Tell me, maybe there is some special delimiter character that can be sent between packets so that the PLC splits them?

If there is no answer, I will be glad if you direct me to literature/documentation where I can read about working with the modbus protocol in high-load conditions? But, please, if you send me to the documentation, at least indicate the page, otherwise I'm already going crazy...

Thank you!

(sorry for google translate)
 
You need to change your software implementation such that only a single Modbus message is contained in each TCP frame.

The Modbus/TCP specification (https://modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf) states the following on the bottom of page 10:

A TCP frame must transport only one MODBUS ADU. It is advised against sending multiple MODBUS requests or responses on the same TCP PDU
I, unfortunately, come to the same conclusion. Can I do this from the software side, sending data to the controller? Or do I need to implement this somehow on the PLC?

If this can be solved from the software, then should I do it? I can't make TCP work differently, can I?
 
Can I do this from the software side, sending data to the controller? Or do I need to implement this somehow on the PLC?
If your software is packing multiple Modbus messages into a single TCP frame, then your software must be corrected so that it sends only one Modbus message per TCP frame.

If this can be solved from the software, then should I do it? I can't make TCP work differently, can I?
You don't need to (and as you stated, nor can you) make TCP work differently. You need only modify the payload of the TCP frame to ensure only one Modbus message is contained within each single TCP frame.

In order to offer any additional advice or recommendations, we would need to have further details and context. What is the software and what device does it run on? Is it custom software you wrote? Does it run on a computer? If so, what programming language is used? Are you using a Modbus library or did you write your own Modbus protocol stack?

Any additional relevant details would be helpful. Remember, we're not in front of your equipment, so we need to rely on your accurate description and details in order to provide assistance.
 
You don't need to (and as you stated, nor can you) make TCP work differently. You need only modify the payload of the TCP frame to ensure only one Modbus message is contained within each single TCP frame.
IF the machine generating the modbus TCP frames is a computer running a full OS (rather than something embedded) one thing you can do is to disable Nagle's algorithm. This will stop the OS from buffering the data you send down for a time interval before generating a datagram on the wire. Now, the flip side of that is your library code MUST send the entire modbus pdu as a single send() call.

In C on any OS with a unix-like sockets library, this would typically look like:

int flag = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int));

At a minimum, you'd need to include <netinet/tcp.h> and <sys/socket.h> to pick up the needed macros and prototypes.

Or, if you're working in a higher-level language like python, the syntax will be a bit different, but you should be able to find examples of disabling Nagle with a little bit of googling.

-Tom
 
Top