Gateway event script - negative edge

Ignition 7.9,

I’m using a gateway event script to trigger a couple of operations;

  1. Generate the data log file name and check the data log directory to see if the file exists.
  2. Save the data to the file name above.

Ideally, I would like to use 1 boolean tag (AKA “test data logger enable”) to trigger both operations. On the positive edge of the flag, the file name is generated and checked. On the negative edge of the flag, the data is written to disk.

I have configured ignition so that the positive edge works perfectly. However, if I add any logic that should run if the data logger enable flag is zero, it does not run.

Can someone please explain why the code at if Enable == 0; does not run? Does the system not recognise a change from 1 to 0 as a value change?


 # Check the file name if the logger flag is true
 Enable = system.tag.read("ETHICK/Logger/Test logger enable").value
 
 if Enable:
 	# Reset the file number variable
 	FileNumber = 1
 	
 	# Get current date and time.
 	d = system.date.now()
 	Date = system.date.format(d,"yyyy-MM-dd")
 	Time = system.date.format(d,"HH.mm.ss")
 	
 	GridType = system.tag.read("ETHICK/Recipe/GridType").value
 	N_Nbr = system.tag.read("ETHICK/Command/N_Nbr").value
 	CF_Nbr = system.tag.read("ETHICK/Command/CF_Nbr").value
 	
 	# Pasted grid
 	if GridType == 1:
 		FileName = "N" + str(N_Nbr) + "_-_THICKNESS-PG" + str(FileNumber) + "_.csv"
 		GridDesc = "PG"
 	# Unpasted grid
 	elif GridType == 2:
 		FileName = "N" + str(N_Nbr) + "_-_THICKNESS-UPG" + str(FileNumber) + "_.csv"
 		GridDesc = "UPG"
 	# Felt characterisation
 	elif GridType == 3:
 		FileName = "CF" + str(CF_Nbr) + "_-_FABCHR-" + str(FileNumber) + "_.csv"
 		GridDesc = "FabChr"
 	# Calibration
 	elif GridType == 4:
 		FileName = "CAL_-_" + Date + ", " + Time + ".csv"
 		GridDesc = "Calibration"

 	# Build the path
 	FilePath = "D:\\ETHICK\\Thickness\\" + FileName
 	
 	system.tag.write("ETHICK/Logger/FileName", FileName)
 	
 	system.tag.write("ETHICK/Logger/FilePath", FilePath)
 	
 	# Check if the file already exists
 	FileExists = system.file.fileExists (FilePath)
 	
 	if FileExists:
 		#system.tag.write("ETHICK/Logger/DuplicateFile", 1)
 		system.tag.write("ETHICK/Logger/Test logger duplicate", 1)
 	else:
 		system.tag.write("ETHICK/Logger/Test logger duplicate", 0)
 		
 if Enable == 0:
 	# Declare the dataset.
 	Headers = [1,2,3,4,5]
 	Data = []
 		
 	Data.append(["File Name",FileName,"","",""])
 	Data.append(["Date",Date,"","",""])
 	Data.append(["Time",Time,"","",""])
 		
 	# Pasted grid
 	if GridType == 1:
 		Data.append(["N Number",str(system.tag.read("ETHICK/Command/N_Nbr").value),"","",""])
 		Data.append(["Grid/elec weight",str(system.tag.read("ETHICK/Command/Weight_grid").value),"","",""])
 	# Unpasted grid
 	elif GridType ==2:
 		Data.append(["N Number",str(system.tag.read("ETHICK/Command/N_Nbr").value),"","",""])
 		Data.append(["Grid/elec weight",str(system.tag.read("ETHICK/Command/Weight_grid").value),"","",""])
 	# Fabric characterisation
 	elif GridType ==3:
 		Data.append(["CF Number",str(system.tag.read("ETHICK/Command/CF_Nbr").value),"","",""])
 		Data.append(["Felt weight",str(system.tag.read("ETHICK/Command/Weight_Felt").value),"","",""])
 	# Calibration
 	elif GridType ==4:
 		Data.append(["","","","",""])
 		Data.append(["","","","",""])
 			
 	Data.append(["Grid size",str(system.tag.read("ETHICK/Recipe/GridSize").value),"","",""])
 	Data.append(["Tab orientation",str(system.tag.read("ETHICK/Recipe/TabOrientation").value),"","",""])
 	Data.append(["Scan mode","Continuous","","",""])
 	Data.append(["Target thickness",str(system.tag.read("ETHICK/Command/Thickness_Target").value),"","",""])
 	Data.append(["Grid type",GridDesc,"","",""])
 	Data.append(["Recipe",str(system.tag.read("ETHICK/Recipe/RecipeName").value),"","",""])
 	Data.append(["Y points",str(system.tag.read("ETHICK/Recipe/PointsY").value),"","",""])
 	Data.append(["Move speed",str(system.tag.read("ETHICK/Recipe/SpeedMove").value),"","",""])
 	Data.append(["X point origin",str(system.tag.read("ETHICK/Recipe/PosXStart").value),"","",""])
 	Data.append(["X point end",str(system.tag.read("ETHICK/Recipe/PosXStop").value),"","",""])
 	Data.append(["Y point origin",str(system.tag.read("ETHICK/Recipe/PosYStart").value),"","",""])
 	Data.append(["Y point pitch",str(system.tag.read("ETHICK/Recipe/PosXStop").value),"","",""])
 	Data.append(["","","","",""])
 	Data.append(["Y point #","Y position (mm)","X position (mm)","Upper sensor(mm)","Lower sensor (mm)","Thickness (mm)"])
 		
 	Dataset = system.dataset.toDataSet(Headers, Data)
 		
 	Dataset2 = system.dataset.toCSV(dataset = Dataset, showHeaders = 0, forExport = 0)
 		
 	system.file.writeFile(FilePath, Dataset2)

Please edit your post to have a line of just three backquotes (these: `) above your code and again below your code. So it formats neatly for the rest of us.

1 Like

Thanks! That looks better.

Did you tried " if Enable is False: "?
Also, put a print statement ( the best debugging tool :wink: ) after the Enable TAG read, so you can know what value actually is.

Thanks for your help! I had already tried “if Enable is False:” but your pointer on debugging techniques was very helpful.

I found the gateway diagnostic logs on the web page running on the server. This showed loads of errors in my script. In short, I was reading data into variables in the ‘True’ case. However, these variables were not declared in the ‘False’ case meaning the script would error out. I created memory tags to pass the data between the two cases.

https://www.dmcinfo.com/latest-thinking/blog/id/9492/3-tools-for-debugging-scripts-in-ignition

Gateway>Status>Diagnostics>Logs

All is sorted now. Thanks again.

1 Like