07-23-2010 02:37 PM
Seems that there is some confusion between "checksum" and "checksum byte". I thought underlining the "byte" word in my rephrased sentence would be clear enough. 😞
Kudos to Darin who gave a correct interpretation of my post. 😄
07-23-2010 02:44 PM
To me, the confusion in your second sentence was
"The checksum shall be computed on the entire message including command, data length, dat and checksum byte itself." making it sound like the checksum was computed on everything including the checksum byte.
07-23-2010 02:58 PM
Ravens Fan a écrit :
To me, the confusion in your second sentence was
"The checksum shall be computed on the entire message including command, data length, dat and checksum byte itself." making it sound like the checksum was computed on everything including the checksum byte.
Yes, and the checksum -the sum to be checked- is FF or 00 or whatever has been decided in the protocol.
The confusion is still between checksum and checksum byte. Operation versus operand. But this is probably a problem of language. Remember I'm just a frog... 😉
07-23-2010 03:15 PM
07-23-2010 03:16 PM
I see what you are saying. Yes, I think it is just semantics.
To me, the checksum is the byte that is the result of the calculations. And when generating that byte, you use only the command and data bytes, while the OP's original statement and your rephrasing of his statement made it sound like you use the checksum byte in the calculation which is of course impossible to do when you first generate it because it doesn't exist.
I'd say for a normal process of verifying a checksum, you do the same thing, process the command and data, NOT the checksum byte, then compare that result to the last byte that came through which is the checksum byte. It just so happens in this case by the nature of the algorithm (which probably doesn't hold true for other methods like CRC or LRC) is that if you do the sum on command, data, and the checksum byte, the result is always going to be FF. (or if you go FF - the sum of FF, you get 00).
07-23-2010 03:44 PM
Ravens Fan a écrit :
[...] It just so happens in this case by the nature of the algorithm (which probably doesn't hold true for other methods like CRC or LRC) is that if you do the sum on command, data, and the checksum byte, the result is always going to be FF. (or if you go FF - the sum of FF, you get 00).
As a matter of fact, it's true, even for CRC methods :
Quotation from Wikipedia :
[...] To check the CRC, instead of calculating the CRC on the message and comparing it to the CRC, a CRC calculation may be run on the entire codeword. If the result is zero, the check passes. [...] This simplifies many implementations by avoiding the need to treat the last few bytes of the message specially when checking CRCs. [...]
Well... I'am not sure that the actual sentence, when read by a non-specialist, makes much sense. There is still a confusion between the CRC calculation and the CRC value. And I really enjoy the CRC check idea ! 😄 😄 😄
07-23-2010 03:52 PM
Thanks,
You're right. I know the CRC calculation is a pretty complicated algorhithm, so I figured the math wouldn't work out that way. But looking at the modbus library examples, I see it does.
07-26-2010 07:29 AM
@Ravens Fan wrote:
To me, the confusion in your second sentence was
"The checksum shall be computed on the entire message including command, data length, dat and checksum byte itself." making it sound like the checksum was computed on everything including the checksum byte.
I fell into the same trap. But in hindsight, the sentence kinda makes sense... kinda.. Knowing what to expect makes a lot of difference in interpreting it. 😉
I can't come up with a better sentence on the spur of the moment.