Menu

#17 LRC Checksum calculated wrong

v1.2rc1
closed-fixed
Transport (27)
7
2015-03-12
2005-02-03
No

Reported by Llewellyn Kruger:

>We corrected a bug of MODBUS-ASCII
>A 2's complement was meant to be applied to the result of
>LRC according to the specification.

In the discussion we realized that the specification probably
contains a misleading C code example (same as it has been the
case with the CRC).

Discussion

  • Dieter Wimberger

    • status: open --> closed-fixed
     
  • Nobody/Anonymous

    Are you saying the specification is wrong? Regardless of any C implementation, the spec (V1.02, Dec. 20, 2006) clearly states:

    "The LRC is calculated by adding together successive 8–bit bytes in the message, discarding any carries, and then two’s
    complementing the result. The LRC is an 8–bit field, therefore each new addition of a character that would result in a value higher than
    255 decimal simply ‘rolls over’ the field’s value through zero. Because there is no ninth bit, the carry is discarded automatically."

    This seems to be borne out by other sites (e.g. http://www.modbustools.com/modbus.asp\).

     
  • Nobody/Anonymous

    Nevermind. I see this has been fixed in HEAD. Sorry. (Linked from duplicate bug, id #1508936.)

     

Log in to post a comment.