EasyManua.ls Logo

Spellman ST SERIES - Page 67

Spellman ST SERIES
108 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
101501-565 Rev C Page 36 of 58
Dim CSb3 As Integer
Dim CSb$
Dim X
X = 0
For i = 1 To (Len(outputString)) 'Starting with the CMD character
X = X + Asc(Mid(outputString, i, 1)) 'adds ascii values together
Next i
CSb1 = 256 - X
CSb2 = 127 And (CSb1) 'Twos Complement
CSb3 = 64 Or (CSb2) 'OR 0x40
CSb$ = Chr(Val("&H" & (Hex(CSb3))))
ProcessOutputString = Chr(2) & outputString & CSb$ & Chr(3)
End Function
Here is an example of an actual Checksum calculation for command 10
(Program kV setpoint)
The original message with a placeholder for the checksum is
<STX>10,4095,<CSUM><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. :
NOTE: 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)

Table of Contents