05-19-2020 06:13 AM
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 !
Solved! Go to Solution.
05-19-2020 06:30 AM
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.
05-19-2020 06:32 AM - edited 05-19-2020 06:32 AM
05-20-2020 05:51 AM - edited 05-20-2020 06:09 AM
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 !
And this is the array that results in 50.11
05-20-2020 06:36 AM - edited 05-20-2020 06:43 AM
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:
05-20-2020 09:37 AM - edited 05-20-2020 09:53 AM
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. 👍
05-20-2020 10:25 AM
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 🙂