LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading Holding Registers Float Modbus RTU

Solved!
Go to solution

I'm having an issue with ready any floating point number correctly off of a Shark 100 Power Meter.

I can sucessifully read a block of registers containing the meter name and serial number as 16 bit characters.

 

For example when I read registers 1-16 on the map and flattening them to a string, I get a fully working string returned.

 

ModbusMap.png

 

When I try and read holding registers 1012-1013 (Amps A) I get really funny numbers when I convert to a float.

 

Here is my code so far

Modbus_Back_Panel.png

With my front pannel settings:

Modbus_Front_Panel.png

 

Expected Value I'm looking to have returned: 11.11 Amps

 

but

When I use an indicator to read the registers: 19265, 0

Same value when I do a conversion

When I do a type casting to a float: 1.26484E+7

 

I've tried some different combinations such as reading only one register and joining the numbers, both in big-endian and little-endian order, still no luck.

Please Help!

 

Here is the modbus float definition as defined the owners manual:

RegisterMapFloatDef.png

0 Kudos
Message 1 of 6
(12,256 Views)

The float format you posted is the same as LV uses, so if you put example values (Register 1 = C4E1, Register 2 = 1DB9) in the code below it will give you right result.

Float.png

 

What is the full value of your "Output Registers"? You should have two values in numeric array for this to work.

0 Kudos
Message 2 of 6
(12,223 Views)
Solution
Accepted by topic author ZimZimZalaBim

Also, I've seen that the Modbus toolkit sometimes has a weird off-by-one-register behavior (so you actually have to ask for a different address to get the data you want) and that some devices have an even weirder off-by-one-byte behavior, so that now you're off by half a register and you have to ask for more registers and then rearrange the bytes by taking one byte off the preceding or trailing register.


___________________
Try to take over the world!
Message 3 of 6
(12,212 Views)

Thank you tst!
You were right about the registers being off by one. I ended up subtracting one off the leading register and it fixed things immediately.

 

Solved.png

0 Kudos
Message 4 of 6
(12,170 Views)

This is a long shot this many years later. Could you share the VI. I am new to labview . I have a shark 100 and cant get any data. TY in advance

0 Kudos
Message 5 of 6
(2,209 Views)

There are a bunch of Modbus libraries floating around.  This is the one I personally use.

 

https://www.vipm.io/package/ni_lib_modbus_library/

 

If you look at the documentation for the starting address it talks about the 0 index or 1 index.  This is the one off behavior.  I have been burned by this multiple times.

 

 

ASTDan_0-1688868768468.png

 

Dan Shangraw, P.E.


   

0 Kudos
Message 6 of 6
(2,178 Views)