LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

checksum calculation

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. 😄

Chilly Charly    (aka CC)
0 Kudos
Message 11 of 18
(1,809 Views)

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.

Message 12 of 18
(1,807 Views)

 


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... 😉

 

Chilly Charly    (aka CC)
0 Kudos
Message 13 of 18
(1,793 Views)
The parity analogy is perhaps helpful here. Substitute parity for checksum and bit for byte. The parity is calculated for all bits including the parity bit. How you choose to set the parity bit depends on the protocol. Now we say the checksum is calculated for all bytes including the checksum byte. How you choose to set the checksum byte depends on the protocol. I have adopted CC's convention of calling the extra byte the checksum byte. Don't think for a second that this was always clear to me either. What is funny is that the other uses for checksum is what causes the confusion. What is a more natural checksum than checking the sum?
0 Kudos
Message 14 of 18
(1,783 Views)

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).

0 Kudos
Message 15 of 18
(1,782 Views)

 


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 ! 😄 😄 😄

 

Chilly Charly    (aka CC)
Message 16 of 18
(1,770 Views)

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. 

0 Kudos
Message 17 of 18
(1,766 Views)

 


@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.

0 Kudos
Message 18 of 18
(1,723 Views)