Trying to scale an OPC integer down to a float

So I am trying to scale an integer that is coming from an OPC source down to a float. For example, if the source gives me 578, I want the tag to have the value 5.78.

The issue I am running into here is that if I pull the integer from the OPC source as an integer, it will round the scaled-down value to the nearest integer value. Because of this, the tag scaling will return 6.0 instead of 5.78. If I change the tag type to a float, it will not properly poll the Modbus address.

Is there any workaround to this issue? Another stipulation that makes this a little more difficult is that I want to read and write to this value as well.

Thanks for any help you guys can give.

Hmm i'm not sure if there's going to be a way of doing this that's as elegant as you might hope. For a "read only" context you can just create an expression tag that's of datatype float, and is equal to your integer opc tag / 100.0

To be able to write a value of 5.78 to that tag and then have it push 578 to the OPC tag is more complicated. If it were me I would keep the tag as the integer OPC and have whatever graphics in your perspective/vision app handle the conversion.

So you might have a label's text binding be to your tag, with a transform that divides by 100.0. And a numeric entry field with a property change script that writes "toInt(value* 100)" to the target tag.

You need to change the Ignition tag datatype to float while leaving the underlying Modbus address as an integer type, then set up tag scaling.

4 Likes

I had assumed that I would have had to change the modbus command from HRI to HRF if the tag type was changed, but I guess ignition is pretty flexible and type casts to whatever the tag type is.

Thanks