Command/Response String and Checksum |
Command/Response Format |
Command Format |
(Leading)(Address)(Command)[CHK](cr) |
Response Format |
(Leading)(Address)(Response)[CHK](cr) |
|
(Leading) |
Leading character, like ~, $, #, @, %, !, ?, >. |
(Address) |
Address of specificed module, from 00 to FF. For some command like #**, the address is ** for all modules. |
(Command/Response) |
Command with parameters or response with data. |
[CHK] |
2-character checksum. If the CheckSum is disabled, no [CHK] here. |
(cr) |
end-of-command character, character return(0Dh) |
|
|
Calculate Checksum
- Calculate ASCII sum of all characters of (Leading), (Address) and (Command)(or (Response)).
- Mask the sum of string with 0ffh, or said only take the last 2 digits of the hex value of the sum.
For example, if the sum is 01BCh, take the "BC" as the [CHK].
|
|
Example
-
Command string : $012
- Sum of string = `$'+`0'+`1'+`2' = 24h+30h+31h+32h = B7h
- The checksum is B7h, and [CHK] = "B7"
- Command string with checksum : $012B7(cr)
-
Response string : !01070600
- Sum of string : `!'+`0'+`1'+`0'+`7'+`0'+`6'+`0'+`0' =
21h + 30h + 31h + 30h + 37h + 30h + 36h + 30h + 30h = 1AFh
- The checksum is AFh, and [CHK] = "AF"
- Response string with checksum : !01070600AF
(cr)
|
|