alpr_94

Display a HEX value as floating

9 posts in this topic

Hello, From modbus, Im reading a HEX variable in the data register D0, as it is a 32 bit variable, the second part is saved in D1, then I get:

D0: BE62

D1: 31D7

The value that I should obtain in float is -0.2208932 as I obtained setting  BE6231D7 in online Hex to float converter and this agree with what I'm reading on the flowmeter. 

The problem is that when I try to change the data type from channel to Real on CX programmer I obtain a different value, also the registers are not sort in the proper way, instead they are sort inversely 31D7BE62, and obviusly the obtained value is completely different.

Also instead of Hex, I want to display the decimal, or floating value, is there a way to do this?

I'll attach some captures.

 

 

D0 and D1 real.png

D0 and D1.png

Share this post


Link to post
Share on other sites

If it sorts inversely, then move the data words to change their order of the 16 bit data words and convert to float

D0: BE62   move to D2

D1: 31D7   stays in D1

D1: 31D7
D2: BE62

new inverse of the sequential data D1 D2 is BE6231D7; convert D1 D2 to the correct float

Share this post


Link to post
Share on other sites

Oh, I aprecciate your answer. I already do that and its working perfectly, thanks. Is this the best way? this wouldn't affect the speed in which the data is showed?

Share this post


Link to post
Share on other sites

Is it the best way?  I don't know.   Does it matter how fast the conversion is?

I do know that there four different word/byte (IEE754) formats for 32 bit floating point values, two of which are commonly used in Modbus.

Many Modbus master/clients provide the ability to pick one of the two to use to interpret the raw data.

If your master/client has a choice for floating point formats, you could try the alternative one and see if it does the conversion properly with the raw data, before moving the data.

Share this post


Link to post
Share on other sites

Ok ok, I understand, Thanks for your fast answers! It was really helpful!

Share this post


Link to post
Share on other sites

@alpr_94Deselect the "16" button.  It forces the display to hex.

16button.jpg.3ad27e7e037c3f453a713b46fbb

If you specify Real as the display in the watch window and none of the format buttons are selected in the toolbar as shown above, the format selected in the watch window will be the format that is displayed.

 

Share this post


Link to post
Share on other sites
On ‎1‎/‎14‎/‎2020 at 2:12 PM, alpr_94 said:

Is this the best way?

There are may ways to exchange data. DanW shows you the basic method that would work with any PLC. Omron has a Data Exchange instruction that would accomplish this without using another memory location.

XCHG(073), D0, D1

On ‎1‎/‎14‎/‎2020 at 2:12 PM, alpr_94 said:

this wouldn't affect the speed in which the data is showed?

The conversion, no matter how you do it, can happen within one PLC scan. You'll never notice the micro seconds that it take to execute the instructions.

If you can, I would do as DanW suggests and change the setting at your Modbus source.

Edited by IO_Rack

Share this post


Link to post
Share on other sites

I missed the fact that the words were swapped.  I did not look at the values close enough.  My point was that there is not a conversion function from HEX to Float per se, you just need to interpret it the right way.  

Share this post


Link to post
Share on other sites
18 hours ago, Michael Walsh said:

you just need to interpret it the right way.  

That's always worth mentioning. I believe this has got to be the most common issue that people have with Omron PLCs. Especially if they have come from AB or any IEC 61131-3 compliant system.

Share this post


Link to post
Share on other sites

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