Jump to content

Conversion: The value of a IEEE-754 Floating Point


Recommended Posts

18 hours ago, William Rodrigues said:
Hello

I need help to convert a decimal and hexacimal value in visiologic software.

This conversion needs to be in IEEE-754 hex format.

Thank you all!

I think floats on visilogic already are expressed using IEE-754 standard couldn't find anything in the documentation.

However, I need to communicate with a slave device precisely sending IEEE-754 floats over Modbus-TCP IP.

I should be testing that in the following weeks (Need to finish some other stuff first). 

Link to comment
Share on other sites

On 3/21/2023 at 11:49 AM, Fernando Castro said:

I think floats on visilogic already are expressed using IEE-754 standard couldn't find anything in the documentation.

However, I need to communicate with a slave device precisely sending IEEE-754 floats over Modbus-TCP IP.

I should be testing that in the following weeks (Need to finish some other stuff first). 

Seems that my assumption was correct. I just tested using struct function to copy the value stored on a MF to 2 MIs and I got the expected hex values.... you can do it in reverse to build the float number.

image.png.2f61171c6cc4dfe69b84a75c181a1c52.png

image.png.0548074f12913ecadcacc10659a5d596.png

 

image.thumb.png.658faddcaea6be12b207b40988a9a0b4.png

  • Upvote 1
Link to comment
Share on other sites

  • MVP 2023

I dug into the floating point over Modbus topic a few years ago when someone was having trouble reading floats from an energy meter.  Turns out not everyone agrees on the word order of floating point data when it comes to various manufacturers.  The word order of a floating point data type is not in the Modbus specification.

This post was regarding a UniStream, but the concept remains the same.  If you're communicating between two Unitronics devices, you're OK.  If you're getting data from something else via Modbus, you have a 50% chance of getting the data in the wrong order.

 

If you read the floats from your device into an MF register and the value looks OK then you're done.  

As Fernando points out above, the way to tell is to run the floating point value you expect to receive through an online converter that will give you the value of the float in hex.   You can use a STRUCT (collect) block as Fernando does to do a raw bit conversion of an MF to two MIs , which will allow you to examine the MF's value as hex codes.  If the order doesn't match what the online converter gives you, then use STORE blocks to swap their order into a new buffer set of MIs.  Then use a STRUCT (extract) to convert these raw bits into an MF register.

Yes, it's a bit complicated.  Visions don't handle floats well.  If you want to go down that road then you have to get creative.

Joe T.

Link to comment
Share on other sites

12 hours ago, Joe Tauser said:

I dug into the floating point over Modbus topic a few years ago when someone was having trouble reading floats from an energy meter.  Turns out not everyone agrees on the word order of floating point data when it comes to various manufacturers.  The word order of a floating point data type is not in the Modbus specification.

This post was regarding a UniStream, but the concept remains the same.  If you're communicating between two Unitronics devices, you're OK.  If you're getting data from something else via Modbus, you have a 50% chance of getting the data in the wrong order.

 

If you read the floats from your device into an MF register and the value looks OK then you're done.  

As Fernando points out above, the way to tell is to run the floating point value you expect to receive through an online converter that will give you the value of the float in hex.   You can use a STRUCT (collect) block as Fernando does to do a raw bit conversion of an MF to two MIs , which will allow you to examine the MF's value as hex codes.  If the order doesn't match what the online converter gives you, then use STORE blocks to swap their order into a new buffer set of MIs.  Then use a STRUCT (extract) to convert these raw bits into an MF register.

Yes, it's a bit complicated.  Visions don't handle floats well.  If you want to go down that road then you have to get creative.

Joe T.

just to add to Joe's response, there is a SWAP BYTES function on visilogic that also help on rearranging bytes.

the best way to work with this, is using known values so you can see what hexadecimal numbers are and since you know what to expect, you can easily spot the correct order.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...