LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting Modbus U16 Registers to Float32

Solved!
Go to solution

I am trying to read the Mains frequency from a Power meter. ( Schneider EM6436H) 

The Modbus register for that is 3110 and the data is formatted for FLOAT 32. And the ModbusRead Holding register returns the data as a 1-D array of 16U Integers. How to convert this to Float 32 ? 

 

Thanks !

 

EM6436H_Modbus_Read.png

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 7
(5,159 Views)

Use a Type Cast to convert the array into a SGL (Single Precision Floating Point).  You may have to swap your two words depending on the specification of the data.


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 2 of 7
(5,148 Views)

Hi Moga,

 

a Float32 is called SGL in LabVIEW:

(See the other message comment on byte swapping…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 7
(5,146 Views)

Typecast to a SGL. This was the first method I tried and also tried various methods of swapping the bytes with data manipulation functions like Swap Words and Swap Bytes with no success. Its possible i made a mistake somewhere ?  Tried to read up how LV handles the float and see that it conforms to the IEEE754. So now the problem is to convert the U16 array with two elements to a pattern that can be converted to a SGL number ? 

 

And did some reverse casting to find out the U16 array that results from a SGL with value of 50.11 and now fed this Array into the Cast to SGL. It works ... the snippet is as below.  So now I need to manipulate  the existing U16 array to get what i want !

 

U16ArrayCastToSGL.png

 

And this is the array that results in 50.11

 

U16Array.JPG

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 4 of 7
(5,073 Views)
Solution
Accepted by topic author MogaRaghu

Hi Moga,

 

it would be so much easier when you would provide the manual of your Modbus device, atleast the part explaining the expected data format of this special parameter! Such manuals usually explain how to convert from/to U16 arrays…

 


@MogaRaghu wrote:

Typecast to a SGL. This was the first method I tried and also tried various methods of swapping the bytes with And did some reverse casting to find out the U16 array that results from a SGL with value of 50.11 and now fed this Array into the Cast to SGL. It works ... the snippet is as below.  So now I need to manipulate  the existing U16 array to get what i want !

And this is the array that results in 50.11


Your snippets DON'T converts to SGL, it converts to EXT: this is a huge difference!

And what is the data you really want to convert when you only show your "reverse casting" result?

 

When converting the SGL value "50.11" back to an U16 array you should get the U16 values as shown in the constant:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 7
(5,068 Views)

Sorry ... missed the data type and ended up in a totally different U16 array.

 

I am enclosing the XLS of the full Modbus data info for the power meter that i am using. 

 

Edit : Just checked . Its the mistake of the EXT data type in place of SGL. Its OK now.

 

Thanks for your persistent support. 👍

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 6 of 7
(5,047 Views)

I am a little late to the party...

I am also working on modbus data conversion (my first time dealing with modbus) so I created a vim. I am relatively new to vims too so I am sure there could be some improvements 🙂

 

Frozen_0-1589988265519.png

 

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
0 Kudos
Message 7 of 7
(5,036 Views)