We only want use perspective to do it. How could import csv file in perspective through Ignition? Any suggestions?
If you want to import using perspective, you would need to use a file upload component, which requires the user to select and upload a file.
Write a script in the onFileRecieved
handler to either parse the data immediately or save the file somewhere on the gateway and signal Ignition to parse the data in the file. (You could use a message handler on the gateway that passes the saved location of the file, let the data processing run in the background independently of the perspective session)
Thank your for quick replying. I tried to use the File Uploaded component in Perspective through ignition. Following by Download and Upload Files - Ignition User Manual 8.1 - Ignition Documentation
it got error message. Another question will be if uploaded the file successfully, where could find the file? on the gateway or in the ignition designer? Addiction question, for the txt file, do you have format for it?
What was the error? Copy the entire error into a pre-formatted text section in your reply (the </>
button above the text field)
If you go the route of saving a copy of the uploaded file, it will be on the gateway computer/device. Perspective runs on the gateway so that's where everything ends up.
The example given is uploading the file to a database for storage, but as a file. If you want to parse the data as a CSV, then something along the lines of this should work:
import csv
csvFileData = event.file.getBytes()
csvData = csv.reader(csvFileData)
headers = csvData.next()
dataset = system.dataset.toDataSet(headers, list(csvData))
system.tag.writeBlocking(["[default]path/to/dataset/tag"], [dataset])
That will attempt to read the file bytes as a CSV and store the data in a dataset tag that can be retrieved in a different script for uploading to a database.
If your csv headers match your db table column names then it should be a pretty straightforward insert statement. If the headers don't match the column names, then you need to write a script to map the columns accordingly.
I'm not sure what you mean by this, its a .txt. file, so that would be its format. If you are talking about the supportedFileTypes
property of the file upload component, you would probably want "csv"
and "txt"
as items in the array