LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting modbus data from two registers into float

Solved!
Go to solution

I am reading modbus data from a DUT from two holding registers- 40609 and 40610. The register content I get is an array of two elements (12458, 14019). I want to convert these numbers into a floating point value. Does modbus library has a VI that does it? If not, how do you convert it?

 

Thanks!

0 Kudos
Message 1 of 8
(21,293 Views)

Like this

 

That is join numbers and also typecast.

 

Message 2 of 8
(21,287 Views)

Thanks.

 

But, I am getting a different number than yours.

 

 

0 Kudos
Message 3 of 8
(21,279 Views)

In Ravens Fan's example the array elements are I16. Your array in your example is I32. That's why you have a different answer. What is the bit size of the elements in the array? When you say float are you referring to a 32-bit float (SGL), or 64-bit (DBL)?

 

Also note that you can wire the array directly to Type Cast without having to use Index Array and Join Numbers.

0 Kudos
Message 4 of 8
(21,272 Views)

I am reading modbus holding registers, which I believe are 16-bit, right? I want to convert to a 64-bit double.

0 Kudos
Message 5 of 8
(21,261 Views)

Actually, my elements are U16.  It looks like you made your array elements either U32 or I32.

 

Yes, Modbus registers are 16 bit.  So you if have two registers you can only combine them to become a 32 bit number,  which as a float means a single precision floating point number.

 

You can't combine them to a 64 bit double precision number.

0 Kudos
Message 6 of 8
(21,254 Views)

Ok. So, if I have two hex numbers reading from two holding registers, how do I convert it into a SGL float.

 

For example,

 

FBF1

411F

 

That is equivalent to my DUT output, 9.99.

 

When I follow your suggestion, i am getting a huge number.

 

Thanks

0 Kudos
Message 7 of 8
(21,227 Views)
Solution
Accepted by topic author sbk143

Swap the order of the numbers going into the Join function.

Message 8 of 8
(21,221 Views)