I have a gateway script that is looking for the triggering tag to be true. Once the script fires it does some database stuff, logs a message to the log about what it did, and turns the bit off. The problem I am having is that it seems the script in firing mulitple times. Here is the script:
if newValue.getValue()==1:
#Save the tag values to varibles
Hanger = system.tag.read("SMS/SMS_HangerLoadedHangerNum").value
#get the tag directly from the OPC server to guarantee the value is fresh
server = 'Ignition OPC-UA Server'
tagPath = '[PLC]db_Hangers[' + str(Hanger)
tags = [tagPath + x for x in ['].PartNumber', '].WorkOrder']]
values = [x.value for x in system.opc.readValues(server, tags)]
PartNumber = values[0]
WorkOrder = values[1]
#Get the recipe ID of the part number loaded into SMS_HangerDataBuffer so we know which coats to copy
query = '''SELECT recipes_id FROM parts WHERE PartNumber = ?'''
Recipe = system.db.runPrepQuery(query, [PartNumber], "foxall")
RecipeID = Recipe.getValueAt(0,0)
#Delete any existing data for the hanger
query ='''DELETE FROM production
WHERE HangerNumber=?'''
system.db.runPrepUpdate(query, [Hanger], "foxall")
query ='''DELETE FROM hangers
WHERE HangerNumber=?'''
system.db.runPrepUpdate(query, [Hanger], "foxall")
#Copy the part number's coats from the coats table and into the production table. Adding the hanger number that was scanned.
query = '''INSERT INTO production(HangerNumber, CoatNumber, RobotNumber, DryingRoom, MinDryTime, MaxDryTime, ManualPick)
SELECT ? AS HangerNumber, CoatNumber, RobotNumber, DryingRoom, MinDryTime, MaxDryTime, ManualPick
FROM coats WHERE recipes_id = ?'''
system.db.runPrepUpdate(query, [Hanger,RecipeID], "foxall")
#insert a new hanger into the hanger table
query = '''INSERT INTO hangers (HangerNumber, recipes_id, PartNumber, CoatsCompleted, WorkOrder)
VALUES (?,?,?,?,?)'''
system.db.runPrepUpdate(query, [Hanger, RecipeID, PartNumber, 1, WorkOrder], "foxall")
#Save to the system log what was saved
Logger = "GatewayTagChange"
logMessage = "Added hanger number %s using part number %s" %(Hanger, PartNumber)
shared.Global.StoreLog(Logger, logMessage)
#Set the tag back to 0 to indicate we have finished
system.tag.write("SMS/SMS_NewWaxLoaded",0)
Here is what I get in the log after turning the bit on:
Any ideas about what is going on would be appericative.