08-17-2021 03:50 PM
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.
Solved! Go to Solution.
08-17-2021 04:52 PM - edited 08-17-2021 04:52 PM
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. 😉
08-17-2021 05:12 PM - edited 08-17-2021 05:14 PM
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).
08-17-2021 05:20 PM
Sorry I was reading the wrong thing. I was reading the register map, not the message!
08-17-2021 05:30 PM
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".
08-17-2021 05:41 PM
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.
08-17-2021 05:44 PM
Where did 9540 come from?
08-17-2021 05:52 PM
Something's not adding up. This should be trivial.
08-17-2021 09:22 PM
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).
(I cannot really tell if you are reading the right registers.)
08-17-2021 09:44 PM - edited 08-17-2021 09:45 PM
@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).
(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.