Jump to content

Recommended Posts

Posted
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). 

Posted
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
  • MVP 2023
Posted

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.

Posted
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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.