Before we start listing Command ID bytes, lets look at the “this long” portion of our
sentence. For this, count the two command ID bytes (count the bytes, don’t add the
values!), add the count of the two NUL bytes (again, don’t add the values), add the count
of the value bytes (this really should sink in now - don’t add the values themselves). This
equals the “byte-count” for the command sentence (string) – we are always counting
bytes. Below is an example of the bytes we want to count:
Byte 1 Byte 2 Byte 3 Byte 4 Byte 5
Command ID 1 Command ID 2 NUL Value Byte n NUL
HELPER-RULE: There will always be two command ID bytes and two
NUL bytes – and there should always be at least one value byte for a
command. This means that you should never have a byte count below “5”
for a command. You must also always use two bytes to convey the byte-
count value; so an example would be “05” or 0x30 0x35.
For now let’s look at the most simple control of the iScan product – turning its power
“on”. The Command ID for the power control (“controls this function”) is “A” and “1”
– hey, if you were reading this from the beginning you’ll recognize capital “A” as HEX
0x41. The people who wrote the ASCII Look-Up-Tables were nice enough to realize that
humans would occasionally use the table – so they lined up decimal numbers to the 0x30
HEX range (i.e. 0=0x30, 1=0x31, 2=0x32, etc.). This means that the “1” we need is
0x31.
So the command ID bytes for the power control are (in HEX) 0x41 0x31.
Let’s look at the sentence again, replacing what we know now:
“0x02 0x33 0x30 which is this long 0x41 0x31 0x00 this is the value I want to set
0x00 [checksum – optional] 0x03”
Now let’s look at the value we want to set this to – in the table in Section 3 you will
see the commands and the values that are possible. Looking up Power, we see that the
values for OFF and ON are “0” and “1” respectively. We already know how to convert
the “1” to HEX notation and since we do want to turn the unit “on”, this is the value
we’re going to use. “The value” = 0x31.
Let’s look at the sentence again, replacing what we know:
“0x02 0x33 0x30 which is this long 0x41 0x31 0x00 0x31 0x00 [checksum –
optional] 0x03”
If you’ve read this far and understand what’s happening - Great! Now the only things
we are missing are the Checksum and the length-count bytes. Since the checksum must
be the last thing we calculate, we’ll do the length first: Two bytes for command ID + one
byte for NUL + one byte for value + one byte for NUL = 5 bytes or “05”. Converting the
count to HEX notation we get 0x30 and 0x35.
17