ModBus over TCP - frame delimiting

  • Thread starter Michael Attenborough
  • Start date
M

Thread Starter

Michael Attenborough

I'm getting the impression that "ModBus over TCP" (as opposed to ModBus TCP) is not a a formal standard - all I can find about it is that it is "a ModBus RTU message transmitted with a TCP/IP wrapper and sent over a network".

But ModBus RTU relies on idle gaps on the serial line to delimit frames, and this is not transferable to TCP/IP, where packets may meet variable delays.

And they can't be delimited by the TCP packet either, as these may get split up during transport.
So how are message frames delimited in "ModBus over TCP"?
 
M

Michael Attenborough

> You can determine the length of the message once the first six bytes are received. <

Are you thinking of the Modbus TCP protocol (where the fifth and sixth bytes give the length)? If so, that's not my question, I was asking about "Modbus over TCP", which is apparently a different thing to Modbus TCP.

Or are you saying that once you have received the first 6 bytes of a "Modbus over TCP" frame (which will include the slave ID, the function code and 4 bytes of function-specific data), it is always possible to deduce the length of the frame by knowing the details of the different message types?

Michael A
 
Start evaluating the message as soon as you have enough data to know something worth while. The function code appears early in the message before any variable length portion. Some functions have fixed length messages. Once you know the function code, you know if you are dealing with a fixed length message.

For functions with variable length messages, the quantity word (number of coils or registers) is also near the beginning of the message. Once you have that, you know how long the rest of the message should be.

In addition to all this, standard TCP packets are normally bigger than Modbus messages.
 
Hello,

> Are you thinking of the Modbus TCP protocol (where the fifth and sixth bytes give the length)?

No, I am not referring to MODBUS TCP.

>Or are you saying... different message types?

Yes. That is what I am saying.

Depending on if the code is for a master or slave different logic is used. Using character timing on a PC is almost impossible without writing very low level code. Then add in something like a USB to serial converter and it is impossible.

Good luck,

Mark
http://www.peakhmi.com/
 
M

Michael Attenborough

OK, thanks for your help everyone, this is useful information which I couldn't find anywhere else, including older discussions on this forum.
 
Top