Ignition 7.9,
I’m using a gateway event script to trigger a couple of operations;
- Generate the data log file name and check the data log directory to see if the file exists.
- 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)