Combining Modbus Registers Indirectly

I have a plc that is mirroring values from a Modbus device (Not connected directly) and it is giving me Hi and Lo values to combine into 1 tag.

What is the appropriate math to do in an expression tag? I have 2 values, 1 is an integer combine, the other is a float.

See screenshots below:
Integers

Float

Online, I keep people saying that I need to do (hi << 16) + (Lo 0xFFFF) but this doesn't really work for me using the expression language.

For the integer one, I have been using this int(hi * 10000) + int(Lo). It gets me the correct value that matches the one on the device.

I don't believe either of these are correct, but I am not really sure if this is bullet proof or not. Ignition doesn't really have tools to see what is happening on the bit level in the opc browser, so I can't easily diagnose what the math needs to be.

Also, for the float one, I am simply getting wild numbers.

What is the exact expression you were using? Do you have the high and low words brought in as OPC tags already, and you're now just creating a 3rd expression tag to combine them?

P.S. the float case is tricky and can't be done with the expression language alone: 64-Bit Double Little Endian Input Register - #25 by Kevin.Herron (there's also a corresponding Float.intBitsToFloat in the Java standard library)

1 Like

Personally, I would combine these in the PLC and then pass them onto the HMI as the proper DINT/Integer or REAL/Float. For the float you're going to have to do some BITD commands to put the bits in the proper order into a DINT, then do a COP of that DINT to a REAL.

So yes, they are already in as OPC points. Unfortunately I have no control over the PLC.

So here is the expression that cave me the correct value. IMO weird way to store a number as you are separating out digits at this point. However, I cannot figure out how the float one works.

image

I will try the library you suggested.

As @Kevin.Herron pointed out, floating point values are represented completely different. Try whatever he's suggested, but here's the basics of how it works.

https://en.wikibooks.org/wiki/A-level_Computing/AQA/Paper_2/Fundamentals_of_data_representation/Floating_point_numbers