LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I can't read my exact float value in modbus communication

Solved!
Go to solution

thanks for the reply,

 

Is their any possibility to give any example.

0 Kudos
Message 11 of 19
(1,289 Views)

What?

 

YOU need to give the example.  What are the values of the bytes you actually read?  What is the value you are expecting when you read those registers?

 

 

0 Kudos
Message 12 of 19
(1,281 Views)
Solution
Accepted by Balaji_dm

wiebe@CARYA wrote:

If you wire a U16 to a double or single, the value simply gets converted. That's might not be what you need. You get bytes that represent a float, but they are communicated as 16 bit numbers (2 bytes).

 

You probably need to combine two U16s, with a Join Number for instance, and then Type Cast it to a single (4 bytes). Bytes might need swapping, the words might need swapping. you might even need to combine 4 U16s to make a double (8 bytes).

 

Changing the type to float does not magically turn a I16\U16 into a float. You need to make that happen.


Here's an example of what wiebe is saying

 

In one of my programs I am reading 12 watt meters connected through MODBUS.

m1.PNG

 

Here is whats inside my Get_Primary_Measurements VI. (I use the NI-MODBUS library)

 m2.PNG

 

Here's the part I want you to see. Each measurement is returned as TWO U16 integers.

I have to combine and convert these to a float. That is what the "Bytes 2 DBL" vi does.

m3.PNG

  1. Merge the two integers
  2. Typecast to a SINGLE precision
  3. Convert to a double precision

 

 

 

========================
=== Engineer Ambiguously ===
========================
Message 13 of 19
(1,278 Views)

@RTSLVU wrote:

I have to combine and convert these to a float. That is what the "Bytes 2 DBL" vi does.

m3.PNG

  1. Merge the two integers
  2. Typecast to a SINGLE precision
  3. Convert to a double precision

But do note that the High Byte and Low Byte might need to be swapped. This depend on the Modbus dialect that is used... Of course you can also swap the read order of the registers.

 

If that doesn't work (either way), send some data that you read, and the expected value.

0 Kudos
Message 14 of 19
(1,268 Views)

wiebe@CARYA wrote:

But do note that the High Byte and Low Byte might need to be swapped. 

Of course you can also swap the read order of the registers.


But can you really do that? 

 

Using the NI-MODBUS library when reading multiple registers you tell it what register to start at and how many to read.

 

So it always returns the register contents in sequential order starting at the first register.

 

I guess you could do multiple single register reads to get a different order, but that seems redundant. 

========================
=== Engineer Ambiguously ===
========================
Message 15 of 19
(1,251 Views)

Thanks for the reply,

 

What i am getting data is  this below pic

M1.PNG

 

 

 

 

 

 

 

 

What i really need is below pic. This value collected from Modbus toolkit. (value 81.7 is my need)

M2.PNG

But, In labview what i getting is 81

Download All
0 Kudos
Message 16 of 19
(1,233 Views)

Thanks for the reply,

 

Is their any possibility to convert data type has 32 bit float(little- endian byte swap).

0 Kudos
Message 17 of 19
(1,226 Views)

Sorry, but your data doesn't make any sense.  Your two pictures seem to have nothing to do with each other.

 

There is no way you can get from a simple 0 and 64 or 0 and 27 to values like 81.7 and 46.8.

81.7 as a single precision float would show up as 17059 and 26214.

 

Have your read the manual thoroughly?

 

0 Kudos
Message 18 of 19
(1,195 Views)
Thanks for the reply, I got the solution🙂. I able to read my register.
0 Kudos
Message 19 of 19
(1,191 Views)