Hi All,
Ignition v7.9
I'm using an event script to save a CSV file to disk. The CSV has a header which is built up from several different tags, depending on the configuration of the machine in question.
I have created a data set with 5 columns (the maximum width of my CSV) and I am appending data to this. All the data in this header is acquired from OPC tags. At the end of this process I convert the data set and save to a CSV.
The last line of the CSV has the headers for the section that will contain the process data. This data is currently stored in an SQL server. The next part of the project will be to fetch the SQL data and write it to the bottom of the file.
Questions:
- Is there a more elegant way to achieve the same result?
- Is there a good way to append SQL data to the end of an existing CSV? I have previously used "dataset to CSV" functions previously to create a new CSV.
- When I store a value of 1.44 in the data set, it is saved as 1.44000005722. How do I fix this?
Thanks!
John
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)