Evaluating tag write quality codes in scripts

What are the options for evaluating the quality code returned from system.tag.writeBlocking? I would rather have a comparison to a meaningful value like “Good” than a number like 192. Do we have access to built-in constants, or would I need to write my own?

Also, I see that in the expression language, there’s an isGood() function which returns True for any of the good tag quality values. Is there an equivalent available in scripting?

You can compare to the enum if you really want to:

from com.inductiveautomation.ignition.common.sqltags.model.types import DataQuality
if tag.quality == DataQuality.GOOD_DATA:
   ...

The values are available in the javadocs. Search for Quality, and then open DataQuality from the known implementing classes.

E.g.
DISABLED
GOOD_DATA
OPC_BAD_DATA
NOT_FOUND
… etc.

Otherwise, you can also use str() to convert the DataQuality to a string and simply compare to “Good”, “Disabled”, “Not Found”, etc.

Also yes, you can use isGood() on the quality as well (also visible from the javadocs):

val.quality.isGood()
1 Like

Thanks, Nick. The isGood method is exactly what I need.

Psst! Nick!

val.quality.good

Haha, i thought there might have been a Javabeans method, but the ‘is’ tripped me up. Cheers! And happy new year

1 Like

Hi, apologies if I'm resurecting a dead topic, out of curiousity I tried your method

from com.inductiveautomation.ignition.common.sqltags.model.types import DataQuality

res = system.tag.readBlocking(["[default]Testing/test_events/Ref_to_Trigger"])
print(res[0].quality)
print(DataQuality.GOOD_DATA)
if res[0].quality == DataQuality.GOOD_DATA:
print("I confirm that the quality is good")

Somehow, the IF statement is never true, although the 2 prints shows the exact same "Good" string.

I obviously opted for the isGood() method and it works, but I'm just curious why the the statement is false :smile:

Cheers

im pretty sure the sqltags library is an outdated, so the enum probably is no good anymore or moved to a different location,
what version are you running?

Edit:
yup seems this should work instead now on newer version:

from com.inductiveautomation.ignition.common.model.values import QualityCode	
res = system.tag.readBlocking(["[default]Components/oneShot"])
return QualityCode.Good == res[0].quality

image

try printing the type of the tag quality e.g.:

print type(res[0].quality)

AH you guys are so right, the sqltags library is outdated and the new library works. I missed the lack of sqltags in the path

Now I can sleep easy, it was bothering me for a while now :rofl:

Cheers!!

1 Like