Also, each of the above “characters” has a related HEX notation number to go with it:
“Attention” = Start Text or STX = 0x02 in HEX notation
>>pause<< = Null or NUL = 0x00 in HEX notation
“I’m Done Talking” = End Text or ETX = 0x03 in HEX notation
It is up to the individual programmer to determine which method is easiest to
understand – but if you haven’t chosen your programming style yet, this writer
recommends sticking with HEX notation. One thing that should be avoided at all costs is
mixing HEX notation with ASCII characters – as you may see in the next set of
examples, mixing numbers and ASCII will get you very confused very fast (You’re not a
computer, so you can’t be expected to keep track of it all). This document will be written
from here to the end slanted to illustrate HEX notation, as it demands the use of “bytes”
and is easiest for new-comers to get used to recognizing characters which need to be
converted from human readable text characters to machine readable numbers.
Let’s take another look at that sentence:
Attention this is a command which is this long and the command controls this
function >>pause<< this is the value I want to set >>pause<< [checksum – optional]
I’m done talking
Now let’s replace the words we know with the HEX notation equivalents:
“0x02 this is a command which is this long and the command controls this
function 0x00 this is the value I want to set 0x00 [checksum – optional] 0x03
We at Anchor Bay have specified the byte value for the “is a command” text’s
replacement as a portion of our protocol specification. We have defined a command as
two ASCII characters of “3” and “0”. In HEX notation this comes out to two bytes: 0x33
and 0x30 (these must be in this order!). Note that the “is a command” is represented by
these two bytes (each 8-bits, or two nybbles).
Let’s look at the sentence again, replacing what we know:
“0x02 0x33 0x30 which is this long and the command controls this function
0x00 this is the value I want to set 0x00 [checksum – optional] 0x03
This gives us enough to have a “wrapper” for all RS-232 control commands:
0x02 0x33 0x30 [length byte 1] [length byte 2] [Command ID byte 1] [Command ID
byte 2] 0x00 [Value x-Bytes] 0x00 [checksum – optional] 0x03
16