LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

hex conversion + endian

Solved!
Go to solution

I've have a couple instruments that use modbus communication; I've figured out how to format and send commands to the devices, but I can't figure out how to convert the response. It seems like it should be pretty simple: the device sends a response in hex, I've dissected the hex to get the response from two registers; the manual states:

 

"Sensor and process values are stored as big-endian, 32-bit IEEE-754 floating point numbers spanning two registers. Your control system will need to concatenate these into a single value to interpret them correctly."

 

I'm not sure if I'm running into an endian issue or something else. I disabled the main part of the code and have a dummy code to mimic a response I received from the device. I'm pulling a temperature measurement for these values and I'm expecting something around 26 (Celsius). I've also attached the manual but I don't find it very helpful.

Download All
0 Kudos
Message 1 of 11
(2,538 Views)

According to the manual, we are interested in the 5th and 6th registers in the returned messages.  This translates into the 10th thru 12th bytes returned.  I don't think you are working with the correct data, as your example doesn't even go that high.

 

To answer your question/comment in the code, it's not hex, it's a string that wishes it were turned into a byte array that would be interpreted as a double.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 11
(2,523 Views)

Hmm...so the controller returns (in Hex, according to modbus websites, though how Labview is interpreting...?).

01 ---Unit ID

03 ---Read channel

04 ---Number of bytes to be read (there are 2 registers x 2 bytes each)

9540 -- Info in register 1

BF80 -- Info in register 2

DCBA --CRC

 

My simplified example is where I pulled out the two pieces of register info and I'm ignoring the rest, since it doesn't contain the important data.

 

Labview appears to see it as hex? If I leave the string indicators as normal text, it shows nonsense; it's only when I have it put it in hex form that I can read the returned code. I tried going the byte array route, but it didn't seem to work (since I didn't get the expected answer).

0 Kudos
Message 3 of 11
(2,513 Views)

Sorry I was reading the wrong thing.  I was reading the register map, not the message!

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 11
(2,507 Views)

Re: hex question.  Talking about hex and strings and bytes are always confusing.  For Scan From String, "hex" means ASCII characters representing a hex number - e.g., the string "FF".

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 11
(2,502 Views)

So how is this supposed to be interpreted?  There's not enough bytes for a double.  There's enough for u32 or I32 or single.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 11
(2,498 Views)

Where did 9540 come from?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 11
(2,496 Views)

Something's not adding up.  This should be trivial.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 11
(2,493 Views)

OK, you have a SGL, not a DBL and all you need to do is concatenate the two registers in the right order and unflatten the 4byte string to a SGL using the correct byte order (big endian, according to the manual).

 

altenbach_0-1629253281185.png

 

(I cannot really tell if you are reading the right registers.)

 

0 Kudos
Message 9 of 11
(2,458 Views)
Solution
Accepted by topic author plasmageek

@altenbach wrote:

OK, you have a SGL, not a DBL and all you need to do is concatenate the two registers in the right order and unflatten the 4byte string to a SGL using the correct byte order (big endian, according to the manual).

 

altenbach_0-1629253281185.png

 

(I cannot really tell if you are reading the right registers.)

 


Yeah, I was working through the same thing.  I'm fairly convinced we have incorrect data based on the result the OP is looking for.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 11
(2,453 Views)