Problems getting quality code for bad tags

Ignition 8.1.7

I’m having trouble getting a valid quality code from tags that have bad quality. I made a script to browse through a tag folder/provider and print any tag path that isn’t good, excluding any that are disabled (quality code 515).

When testing this, I realized my code returns 192 for good tags (expected), but a wild negative when quality is bad (e.g. -2147483124). Code below.

I feel like I’m missing something, but if so, why I can read good quality correctly?

def get_bad_tags(path):
	results = system.tag.browse(path, {})
	for result in results.getResults():
		# skip UDT definitions
		if result['name'] == '_Types_':
			continue
		
		# recurse through folders/UDTs
		if result['hasChildren'] == True:
			get_bad_tags(result['fullPath'].toString())
			continue
		
		# print tag paths that aren't good, excluding disabled tags
		if result['tagType'].toString() == 'AtomicTag':
			print(str(result['value'].quality.getCode()))
			if result['value'].quality.isNotGood() and result['value'].quality.getCode() != 515:
				print(result['fullPath'].toString())

image
For reference, Bad 2 is Bad_OutOfRange (524)

Try using only the lower 16 bits of the code you get back, i.e. getCode() & 0xFFFF

1 Like

Thanks, that worked! I see now it’s documented here in the Javadocs, for anyone else that’s curious.

Looks like I also could have done result['value'].quality.getName() == 'Bad_Disabled', which is definitely more readable.

To close the loop, this is my updated script:

def get_bad_tags(path):
	results = system.tag.browse(path, {})
	for result in results.getResults():
		# skip UDT definitions
		if result['name'] == '_Types_':
			continue
		
		# recurse through folders/UDTs
		if result['hasChildren'] == True:
			get_bad_tags(result['fullPath'].toString())
			continue
		
		# print tag paths that aren't good, excluding disabled tags
		if result['tagType'].toString() == 'AtomicTag':
			if (
				result['value'].quality.isNotGood() and
				(result['value'].quality.getCode() & 0xFFFF) != 515 # disabled
			):
				print(result['fullPath'].toString())

Another option would be to compare against one of the static final fields in QualityCode:

from com.inductiveautomation.ignition.common.model.values import QualityCode

		if result['tagType'].toString() == 'AtomicTag':
			if (
				result['value'].quality.isNotGood() and
				result['value'].quality.isNot(QualityCode.Bad_Disabled)
			):
				print(result['fullPath'].toString())
1 Like