Gateway Tag Change Script or Local Tag Change Script

Is there any difference between the Gateway Event, Tag Change and the Script function on a tag for value change? I see the Gateway Event can be configured for several items including tag change. I'm just wondering if I should make the script a gateway event or leave it a local tag change. The problem I see is the tag remains on and the tag will not run a second time.


def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	trigger=system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/GetPLC912Data.value")
	trigger=trigger[0].value
	if trigger == 1:
		recname = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Recipe_Name.value")
		recname=recname[0].value
		EndDate = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Times_Input_912/StopTime.value")
		EndDate=EndDate[0].value
		recipe = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Recipe_Number.value")
		recipe=recipe[0].value
		skid = 912
		StartDate = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Times_Input_912/StartTime.value")
		StartDate=StartDate[0].value
		unit = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Unit_Number.value")
		unit=unit[0].value
		params={"EndDate":EndDate,"Recipe":recipe,"RecipeName":recname,"Skid":skid,"StartDate":StartDate,"Unit":unit}
		ret=system.db.runNamedQuery("NXM_OEE","CIP/CIPInsert", params)
		PK=system.db.runNamedQuery("NXM_OEE","CIP/CIPGetPK")
		x=0
		for x in range(38):
			cond = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Conductivity_SP.value")
			cond=cond[0].value
			pumpsp = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Pump_SP.value")
			pumpsp=pumpsp[0].value
			EndDate = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Times_Input_912/Step"+str(x)+"/StopTime.value")
			EndDate=EndDate[0].value
			StartDate = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Times_Input_912/Step"+str(x)+"/StartTime.value")
			StartDate=StartDate[0].value
			stepname = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Step_Name.value")
			stepname=stepname[0].value		
			stepnum = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Step_Number.value")
			stepnum=stepnum[0].value		
			steptimesp = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Step_Time_SP.value")
			steptimesp=steptimesp[0].value
			suptimesp = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Supervision_Step_Time_SP.value")
			suptimesp=suptimesp[0].value
			tempsp = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Temperature_SP.value")
			tempsp=tempsp[0].value
			params={"EndDate":EndDate,"PK":PK,"PumpSP":pumpsp,"StepName":stepname,"StepNum":stepnum,"StartDate":StartDate,"SVTimeSP":suptimesp,"TempSP":tempsp,"TimeSP":steptimesp,"CondSP":cond}
			if (EndDate <> "0002-11-30 00:00:00" and stepname <> ""):
				ret=system.db.runNamedQuery("NXM_OEE","CIP/CIPStepInsert", params)
	system.tag.writeBlocking("[New Castle]NXN-HHC CIP/912_CIP/GetPLC912Data.value",[False])

Here is the script for reference. The script runs when GetPLC912Data goes positive. Thank you for any comments.

Oh, yes. Your script is very much unsuitable for definition on the tag itself. Some reading and further links:

Thank you. I found some discussions about when to use a gateway script. I changed the script to a gateway function today. Thank you for the reply. Have a great weekend!

1 Like