118150-001 REV. B
Page 10 of 66
ProcessOutputString = Chr(2) & outputString & CSb$ & Chr(3)
End Function
Here is an example of an actual Checksum calculation for command 10
(Program kV set point)
The original message with a placeholder for the checksum is
<STX>10,4095,<CS><ETX>
First, you add up all the characters starting with the ‘1’ in the command number,
to the comma before the checksum with their ASCII values (in hexadecimal):
0x31 + 0x30 + 0x2C + 0x34 + 0x30 + 0x39 + 0x35 + 0x2C = 0x18B
Next, you then take the two’s complement of that number by negating it, by
subtracting it from 0x100 (decimal 256), and only retain the lowest 7 bits by
bitwise ANDing the results with 0x7F. :
This combines the steps of getting the twos complement, truncating the result to
8 bits and clearing the 8
th
bit.
(0x100
– 0x18B) & 0x7F = 0x75
Finally, bitwise OR the result with 0x40:
0x75 | 0x40 = 0x75
The checksum byte is 0x75 (Decimal 117, ASCII: u)