How to readout bit by bit

A

Thread Starter

Alex

Hello,

I need some help...

I want to readout from a hex number as e.g. "0x0037" the bits as bit by bit. I have a modbus frame like this: "79030037". Behind the "0x0037" are 16 bits to which I want an access on every single bit to read them out.

How can I realise that?

Thank you and best regards...Alex
 
> Behind the "0x0037" are 16 bits to which I want an access on every
> single bit to read them out.<pre>
Hex 0037
Dec 55
Bin 0000 0000 0011 0111</pre>
Windows calculator in scientific view can convert it for you.
 
L

Lynn August Linse

> Behind the "0x0037" are 16 bits to which I want an access on every
> single bit to read them out.

Check out the formal Modbus Application Protocol Specification V1.1b.

If you treat the 2 bytes 0x0037 as big-endian word, then 0xFF00 (upper word) are the lower 8 bits and 0x00FF (lower word) are the next higher 8 bits. This is because Modbus coil operations packs bits byte-by-byte, not word-by-word. This means the bit masked by 0x0100 would be 1st bit, 0x8000 is 8th bit, 0x0001 is 9th, 0x0080 is 16th and so on.

HOWEVER - if you obtain that 0x0037 by using the holding register commands, how the product packs coils into registers can vary by Vendor. It's either as above, or the bytes will be swapped. You may need to read the documentation and/or even do experimentation to discover the truth.
 
Top