Bit and Byte manipulations for the hard of head

Rupp

Senior Member
Ok guys I'm a web developer and rarily get into the bits and bytes of things. I'm playing with my Rain8net device and I need some help (again). So here are my questions. The rain8 takes commands in 3 byte code groups.
The first byte = header (40h). - What does 40 h mean?
 

smee

Senior Member
The "h" means the number is in hex - hexadecimal.

40h -> 01000000 in binary

Or 4 * 16 + 0 in decimal -> 64

So, for example, a chr(64) could be used to send a single byte with a value of 40h or 64 decimal to a serial port.
 

Dean Roddey

Senior Member
The easiest way to look at hex is that every 2 hex 'digits', i.e. the hex value formated out for human reading, is a byte.

So 0x40 is one byte. Each of the digits is a 'nibble', or 4 bits. The second digit (0 here) is the low 4 bits (0 through 3), and the first digit is the high 4 bits (4 through 7).

So if you think of each formatted digit as a value from 0 to 15 (0 to 0xF in hex), it's easier to deal with. Get a little cheat sheet that shows the bits of the 16 possible combinations, and you can translate from the formatted hex digits to the bits that they represent.

0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
6 = 0110
7 = 0111
8 = 1000
9 = 1001
A = 1010
B = 1011
C = 1100
D = 1101
E = 1110
F = 1111

So for 0x40, look up 4 and look up 0 and those are the bits that that value represents.
 

Mike

Senior Member
Another easy way to look at this (as in do translations) is to open the calculator in windows, switch it to scientific mode. Then you can switch between hex and binary and see the values. It is something you can count on finding if you have a computer nearby.

ASCII and Hex tables on the other hand...
 

Rupp

Senior Member
Dang! That was fast. I appreciate the help. Now let me study a bit. Thanks again.
 

Rupp

Senior Member
So could I send the @ (which is the ascii code for dec 64 or 40h using hyperterminal?
 

Dean Roddey

Senior Member
The better thing to do is to get a tool that allows you to send hex bytes. If you google for Hex Comm Tool (from like viddata.com or something), it's a simple and cheap program that allows you to send and recieve hex or ASCII strings. So it's often a lot cleaner for spelunking hex protocol.s
 

Rupp

Senior Member
Thanks Dean. Let me get to the meat of my problem and that is simply I do not know what I'm doing. :)

What I want to do is simply try one command via hyperterminal. So I set it up HT with Bits per second :4800
Data bits:8
Parity:None
Stop bits:1
Flow Control :Hardware. This is the only setting I'm not sure about. The Rain8 doc states Configure port as 4800 bps N-8-1.

It then goes on to say. Add data in and out is formatted in 3 byte code groups. Does this mean the bytes are all sent at once?
The 3 bytes are:
First byte = header (40h)
Second byte = address (1 – 254) 0 & 255 disallowed
Third byte =
Zone number (1 – 8) in lower nibble and
Command (3 = ON & 4 = off) in upper

So I tried (using hyperterminal) entering :
@ then I hit enter
1 then I hit enter
13 then I hit enter.

Now can you guys tell me where I went wrong?

TIA


PS BSR I'm waiting for breaking news ....
 

Dean Roddey

Senior Member
You'll not be able to do it via Hyperterm since it's really a binary protocol. You can bit it'll be seriously tedious. You can't send the ASCII formatted values, you need to send the actual bytes. So you can't send 13 (that's two bytes, the ASCII values for 1 and 3), you'll need to send the literal binary values. That's just way easier in a program that lets you enter hex values. There are various Ctrl-whatever key strokes that will generate the various non-printable ASCII byte values, but that's not a very good way to do it.

If you stick with Hyperterm, you don't want to press enter after each character, since that sends still more bytes.

Also set Hardware flow control to none, unless it explicitly saws to use some kind of hardware flow control.
 

smee

Senior Member
Rupp,

If you're doing this from HomeSeer, it's very easy to send these characters in a script.
 

Rupp

Senior Member
Smee,
Tell me how. I think I know how to send them but I can't for the life of me figure out how to "receive" the echo back.
 

smee

Senior Member
What's it sending back?

{edit}

Never mind. I just looked up the specs.

Do you need to check the ACK message that comes back or check current status?

If not, it's very easy. If you want to, it's a little more difficult. Getting the messages back isn't really a problem in a script, but you need to decide whether you want to tie up the script waiting for it. In HS 1.x, that would tie up HS. In 2.x, I don't think it will but I haven't upgraded yet to check that.
 

Rupp

Senior Member
The immediate response of the Rain8 is to execute any command then send back the same three bytes as an ACK.
 
Top