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)