Gateway Tag Change Script Running Multiple Times per One Change

Good morning,

I've recently created a tool to log production downtime across multiple machines at the end of every shift. I've accomplished this by setting up a "timestamp" expression tag that changes each minute with the clock. A Gateway Tag Change Script is looking at the timestamp tag and when that tag reaches 0700, 1500, and 2300 hours (the end of each shift), some computation is performed using stored machine uptimes and finally every morning during the 0700 event, an email is sent with a report from the day prior. Simplified code copied below...

This tool was working great for about three weeks up until two days ago when I received three emails all at once at 0700 and also noticed the uptime computations were incorrect, likely due to the repeated firing of the script as the arithmetic then gets tripled up. I cannot determine why this would be looping multiple times. I have not edited the script since it was working properly.

Timestamp Tag Expression - getHour24(now())*100+getMinute(now())

if not initialChange:

#Full script declares some variables here...

	if newValue.value == 700:
	
		#Miscellaneous arithmetic is done here on machine uptimes then an email sent as below...
		
		recipients = #my email address
				 
		system.net.sendEmail(#my email server, #my email address, "Daily Production Reporting " + str(d3), body, 0, recipients)	
					
		system.tag.writeBlocking(reportPaths, reportValues)
		system.tag.writeBlocking(uptimePaths, zeroValues)
		logger.info("Machine Uptimes for Previous Shift - Press 1: %f, Press 2: %f, Press 3: %f" % (uptimeValues[0].value, uptimeValues[1].value, uptimeValues[2].value))
		
	if newValue.value == 1500:
	
		logger = system.util.getLogger("Machine Uptimes A Shift")
		
		uptimeValues = system.tag.readBlocking(uptimePaths)			
		reportValues = [uptimeValues[0].value, uptimeValues[1].value, uptimeValues[2].value]
		AShiftReportPaths = ["[default]Reporting/Uptime/P1UptimeHistoryA", "[default]Reporting/Uptime/P2UptimeHistoryA", "[default]Reporting/Uptime/P3UptimeHistoryA"]
		
		system.tag.writeBlocking(AShiftReportPaths, reportValues)
		
		system.tag.writeBlocking(reportPaths, reportValues)
		system.tag.writeBlocking(uptimePaths, zeroValues)				
		logger.info("Machine Uptimes for Previous Shift - Press 1: %f, Press 2: %f, Press 3: %f" % (uptimeValues[0].value, uptimeValues[1].value, uptimeValues[2].value))
		
	if newValue.value == 2300:
	
		logger = system.util.getLogger("Machine Uptimes B Shift")
		
		uptimeValues = system.tag.readBlocking(uptimePaths)				
		reportValues = [uptimeValues[0].value, uptimeValues[1].value, uptimeValues[2].value]
		BShiftReportPaths = ["[default]Reporting/Uptime/P1UptimeHistoryB", "[default]Reporting/Uptime/P2UptimeHistoryB", "[default]Reporting/Uptime/P3UptimeHistoryB"]
		
		system.tag.writeBlocking(BShiftReportPaths, reportValues)
		
		system.tag.writeBlocking(reportPaths, reportValues)		
		system.tag.writeBlocking(uptimePaths, zeroValues)					
		logger.info("Machine Uptimes for Previous Shift - Press 1: %f, Press 2: %f, Press 3: %f" % (uptimeValues[0].value, uptimeValues[1].value, uptimeValues[2].value))

Did you place this script in an inheritable project, and then inherit it in three leaf projects?

(Inheritable projects cannot properly handle any gateway events.)

So this is essentially what happened - another tech copied this project twice which means the tag change script was executing three times at every interval. However, the project was set as NOT inheritable - but I believe the gateway event scripts are copied anyway? Is there anyway to prevent this when a project is duplicated?

Yes.

No.

What resources were they planning to use? Consider pushing resources that are wanted in multiple projects into a parent project.

Good idea. Thank you Phil.