Tag Script Not Executing While Loop Statement

Hello,

I'm having trouble with a while loop tied to some tag scripts for a new type of asset we're logging info on at our site. On other assets using this same script, the while loop is checking for an empty or null value to execute but on this new type of asset the default value of the tag I'm reading is a populated string value. When I test this script on a PB event in designer and monitor with the console it works as expected so I'm not sure what may be missing for it to run as a gateway event. I placed some gateway loggers in to see if something in the while loop isn't running, but the logs are showing that the while loop just never executes.

Overall when the script is triggered it reads some tag values to store into a DB table. Sometimes the reason tag updates slower from assets so the while loop does a check every .5s for a valid reason tag value until a timeout then proceeds to log the event with a default N/A descriptor.

I appreciate any help looking over this!

if not initialChange and previousValue.value != currentValue.value:

	assetID = system.tag.readBlocking(["[.]AssetID"])[0].value
	reason = system.tag.readBlocking(["[.]FaultDescription"])[0].value
	Detail1 = system.tag.readBlocking("[.]InMotion")[0].value
	Detail2 = system.tag.readBlocking(["[.]TranspCurrent"])[0].value
	Detail3 = system.tag.readBlocking(["[.]TranspNext"])[0].value
	
	if currentValue.value > 0: 
		logger = system.util.getLogger("myLogger")
		logger.info("D570 Strothmann Cart 01 fault string: %s"% (reason))
		state = 1
		#Give timeout for description tag to update before moving on.
		import time
		from time import sleep
		timeout = 4
		start = time.time()
		while reason == "NO FAULTS PRESENT":
			time.sleep(.5)
			reason = system.tag.readBlocking(["[.]FaultDescription"])[0].value
			delta = time.time() - start
			logger.info("D570 Strothmann Cart 01 Delta loop time: %s"% (delta))
			logger.info("D570 Strothmann Cart 01 Delta loop fault string: %s"% (reason))
			if delta >= timeout:
				logger.info("D570 Strothmann Cart 01 Delta loop timeout: %s"% (delta))
				reason = "Fault Description N/A"
				break			
	else:
		state = 0
	
	shared.OEE_HX.logDowntime_HX(assetID, reason, state, detail1 = Detail1, detail2 = Detail2, detail3 = Detail3)

A couple of comments:

  1. All your tag reads should be done in one call.
tagPaths = [
    "[.]AssetID",
    "[.]FaultDescription",
    "[.]InMotion",
    "[.]TranspCurrent",
    "[.]TranspNext"
]
res = system.tag.readBlocking(tagPaths)
assetID, reason, Detail1, Detail2, Detail3 = [i.value for i in res]
  1. You're going to get a lot of stick for using timers and sleep in a script. It's generally a bad idea.

Ideally whatever triggers this script shouldn't change state until all the data is ready.

Thanks for the feedback! Yea this original script layout goes back a decent way to like Ignition 7.8 kinda days so some of that new readblocking syntax might be a nice update to go apply to all of these! Similar with the time sleep, like you mentioned having that thread stop on gateway probably not awesome in high volume. I'm pretty rusty these days so not sure how clean I can make an invokeLater callout for this :sweat_smile:, but since the usage of this script has been copied so much it's probably a good time to figure out how to make that the pause function instead.

I'll also note here that when I did button testing I did a character length check to make sure that default reason tag value doesn't have some extra spaces compared to what's in the while statement. Hopefully that helps expedite this to the next diagnostic step here.