System tag read issue

When using system.tag.read and trying to get the value and evaluating it, I can't seem to get this to evaluate the way i'd expect. How do you detect if there is a Null value?

This is the result of the tag read.

If the first value is the only one with a value currently in it, why are they all reading as 'Full' with this line of code?

u'' is the repr string-formatted output of an empty string, which is falsey in Python, but distinctly different from the None singleton - so you can either:

  1. Change your loop condition to check against 'truth' of a value, so empty strings, empty collections, None, 0, and boolean False will all fail the condition:
	read = system.tag.read("path").value
	if read:
		# it was truthy
	else:
		# it was falsey
  1. Check for the empty string explicitly in your loop condition:
	read = system.tag.read("path").value
	if read == "":
		# it was truthy
	else:
		# it was falsey
1 Like

As an aside, system.tag.browse is already a "heavy" operation. Pairing it with a bunch of individual system.tag.read calls is going to kill your gateway if you're not careful.

In every case, prefer to aggregate tag reading and writing operations into the largest batches possible in your unit of scripting. In this case, something like this will run literally orders of magnitude faster:

tagset = system.tag.browseTags(parentPath = "AGTC_FPA3_13/Door")
pileNumberPaths = ["%s/PileNumber" % tag.path for tag in tagset]
qualifiedValues = system.tag.readBlocking(pileNumberPaths)

for qv in qualifiedValues:
	read = qv.value
	if read:
		# it was truthy
	else:
		# it was falsey
1 Like

@PGriffith Preformatted text
The end goal of this script is to sync pile and serial data to a database. Each rollerbed has an array of serials 1-50, I want to be able to look to see how many serials exist and then make an entry into the database for each individual serial. Is this something that can be done using a transaction group rather than looping in a script to get the information?
I'm using a stored procedure and this is the code for that in Microsoft SQL

[dbo].[UpdatePileLocation](

@serial varchar(50), @Sequence int, @pile int, @location varchar(20))

1-50 entries per rollerbed, the sequence will auto increment until there is no more serial data, pile will remain the same, and location will remain the same.