# Gateway event script - negative edge

**URL:** <https://forum.inductiveautomation.com/t/gateway-event-script-negative-edge/23904>\
**Category:** Ignition\
**Created:** [April 8, 2019, 12:12am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-negative-edge/23904 "2019-04-08T00:12:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![john.eichler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/john.eichler/32/24632_2.png) [@john.eichler](https://forum.inductiveautomation.com/u/john.eichler)\
**Post date:** [April 8, 2019, 12:12am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-negative-edge/23904/1 "2019-04-08T00:12:27Z")

</div>

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?

```auto

 # 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)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 8, 2019, 2:41am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-negative-edge/23904/2 "2019-04-08T02:41:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![john.eichler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/john.eichler/32/24632_2.png) [@john.eichler](https://forum.inductiveautomation.com/u/john.eichler)\
**Post date:** [April 8, 2019, 4:24am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-negative-edge/23904/3 "2019-04-08T04:24:14Z")

</div>

Thanks! That looks better.

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [April 8, 2019, 7:00am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-negative-edge/23904/4 "2019-04-08T07:00:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![john.eichler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/john.eichler/32/24632_2.png) [@john.eichler](https://forum.inductiveautomation.com/u/john.eichler)\
**Post date:** [April 8, 2019, 8:52am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-negative-edge/23904/5 "2019-04-08T08:52:44Z")

</div>

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](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.
