Shorter and longer frames than expected in Modbus over serial line

  • Thread starter Francesco Peduto
  • Start date
F

Thread Starter

Francesco Peduto

I have the following doubt:

if I have not communication error, but I have a frame shorter or longer than expected, what should the slave do?

Example:

I would like to read an input register from the slave at address 0x4000, the right frame is:

010440000001+CRC

and the right answer is like:

010402AAAA+CRC

if the request is shorter (one byte less ):

a) 0104400000+CRC

or longer (an extra byte ):

b) 01044000000105+crc

what should the slave answer in both case?

I didn't find a clear answer in "Modbus application protocol specification V1.1b"

Thank you
Best regards
 
Hello,

If the frame is shorter or longer, the frame is wrong so, the slave shouldn't send any response.
And if the frame has an extra byte or lost any byte I don't think the CRC is correct...

Regards,
Andrzej
www.modbus.pl
 
L

Lynn August Linse

As mentioned, the wrong size or unexpected formatting makes it an error. The Modbus spec probably just assumes you'd understand that.

Your slave needs to check for this & you should just discard the message. Assuming the CRC is correct, then the master is wrong to send that message ... but that's not your slave device's fault or responsibility to handle.

I have seen slaves which - in your 1 byte short scenario - assume the first byte of the CRC is the 2nd byte of the length - clearly a bad idea. And in the 1 byte longer case they still answer, but I cannot see how one considers either situation 'correct behavior'.
 
F

Francesco Peduto

Ok, thank you.

The crc is right because it is built on the shorter or longer frame, the master is sending a wrong frame.

Regards,
Francesco
 
F

Francesco Peduto

Ok, assuming that unexpected formatting frames should be discarded, to say that these frames are wrong, the slave should be recognize them. This means that the slave should know the format of all the modbus frame, is it right?

My device supports just two function code 0x02 and 0x04 and I thought to recognize just these two formats. In this case, for example, if the frame received is:

010340000001+CRC ( correct )

or

0103400000+CRC ( one byte less )

my device responses in both case:

018301+CRC

I agree with you that in 1 byte scenario the device shouldn't response, but as showed in the example above could be it a compromise? Or is it necessary to recognize all the modbus frame?

thank you,

Regards
Francesco
 
L

Lynn August Linse

>> This means that the slave should know the
>> format of all the modbus frame, is it right?

You don't need to know ALL the frames, but certainly your slave should know the 2 which it supports.

If you receive an unknown function and the CRC is correct, return the 0x01 "Illegal Function"

If you receive one of your 2 known functions, the length with CRC should be exactly 8 bytes.

If the CRC is correct, but the length is wrong, you could consider returning the 0x02 "Illegal data Address". As you say the standard doesn't directly address that situation, but that would help point out to the user that the request was flawed.
 
F

Francesco Peduto

> If the CRC is correct, but the length is wrong, you could consider returning
> the 0x02 "Illegal data Address". As you say the standard doesn't directly
> address that situation, but that would help point out to the user that the request was flawed.

I think I will adopt this solution.

thanks,
regards

Francesco
 
Top