Is it possible to bind a component’s Quality property to another tag using an expression?
I have 2 tags
- Tag1 (Float)
- Tag1_Quality (Float, 0=Good, 1=Bad)
Can the tag Tag1_Quality drive the quality of Tag1 ?
When I use the expression to
ToInt({[default]PLC-1/Tag1_Quality})
I get the error:
ClassCastException: Cannot coerce value '1' into type: class com.inductiveautomation.ignition.common.model.values.QualityCode
I am using Ignition 8.0.1
Thank you,
-Mark
The quality of a tag is automatically determined by its value property - what you would need to do is make Tag1 an expression tag, and use the (new to 8.0) qualifiedValue
expression to do something like this:
qualifiedValue(<expression to retrieve actual value for tag>, <expression to return "Good" or "Bad">)
where the second argument is something like if({Tag1_Quality}, "Good", "Bad")
.
Ok used your suggestion and it kind of works.
The quality state is updating correctly, however the overlay is not reflecting the quality state.
I have the option “Overlay Opt-Out:” turned off. So perhaps this is a bug ?
I observed:
- If “Overlay Opt-Out” is OFF, propertychange event handler is executed when a change to Tag1_Quality occurs
- If “Overlay Opt-Out” is OFF, propertychagne event handler is NOT executed when a change to Tag1_Quality occurs
Here is a workaround using script
if Tag1_Quality changes, update Tag1 quality.
Tag1_Quality propertychange event handler
from com.inductiveautomation.ignition.common.model.values import QualityCode
if (event.propertyName == "state"):
# print event.propertyName, " ", event.newValue
if (event.newValue == 0):
event.source.parent.getComponent('_').quality = QualityCode.Good
else:
event.source.parent.getComponent('_').quality = QualityCode.Bad
I also observed that if Tag1 updates, it replaces its quality with a new one.
So you also need
Tag1 propertychange event handler
from com.inductiveautomation.ignition.common.model.values import QualityCode
print event.propertyName, event.oldValue, event.newValue
if (event.propertyName == "dataQuality"):
BQ_val = event.source.parent.getComponent('BQ').indicatorValue
if (BQ_val == 0):
BQ_quality = QualityCode.Good
else:
BQ_quality = QualityCode.Bad
if (event.source.quality != BQ_quality):
event.source.quality = BQ_quality
Let me know if you can get the expression binding working as it is a lot cleaner solution.
Thank you