이온빔 시리얼 통신 checksum 방법 rs232C 또는 rs485 비코 이온빔

2020. 12. 9. 09:15엔지니어링

728x90
반응형

#Checksum:
The first character is the low order byte and the second character is the high order byte of the 16 bit value.  

This pattern repeats until there are no more characters.  

If there is not a character for the high order byte set it to 0.  

Once all of the values have been added up, add the carry back in if there is any.  

If this generates a new carry add it back in too.  Once there are no more carries, invert the result and convert it to a 4 byte ASCII value.

Example:
For the checksum for a command “BV123”<cr>

In the following x represents hexadecimal, it is not part of the checksum.

ASCII                     Hex value
B                             x42
V                             x56
1                              x31
2                              x32
3                              x33

The first char is the low order byte and the second char is the high order byte.  

If there is not a char to be the high order byte it is set to 0.  This will generate the following 2 byte values

   V  B
x5642

   2  1                      
x3231

        3
x0033

These values are then added
X5642 + x3231 + x0033 = x88A6

Invert the bits = x7759 and then convert this to its 4 byte ASCII value:
Hex                        ASCII code
X7 =                       ‘7’ = x37
X7 =                       ‘7’ = x37
X5 =                       ‘5’ = x35
X9 =                       ‘9’ = x39

So the 4 byte ASCII checksum would be “7759”

When you get to larger sums the carry must be added back to the original number.

If the summation above would have been x588A6 then you would do the following

X88A6 + X0005 = x88AB => Invert => x7754 => ASCII “7754”.

728x90
반응형