Reading from .csv file to table

Not sure if I should start a new thread, but it seems related to this one.

I can write the same code that everyone else has above into the script console and it works fine, makes a dataset:

path = 'J:\Industrial Engineering\Productivity Reporting\PDC\Real-time reports\Production\KitFamilySKUs - KenCSV.csv'
import csv
csvData = csv.reader(open(path))
header = csvData.next()
# Create a dataset with the header and the rest of our CSV.
dataset = system.dataset.toDataSet(header ,list(csvData))

I then tried to put this code into a Perspective change script, realized that wouldn't work because I need file upload component instead.

So I then tried it in a gateway change script, and in a tag change script. Both of them seem to fail at

csvData = csv.reader(open(path))

but I don't see any error messages in the console.

What would be the difference here between running it in script console and running on the gateway?

Thanks

When you run it in the script console it executes on the computer running the Designer.

When you run it in the gateway scope it executes on the computer running the Gateway.

1 Like

Thanks Kevin. I've read this a thousand times on the forum, but it didn't register that it was also true of file opening.

So I realized that the network drive I was trying to read from was mounted on my PC where I am using designer, but not on the server that hosts Ignition. So with renewed hope, I mounted this share on the hosting server and still nothing. Can't read it, and it doesn't exist according to system.file.fileExists().

I can ping the share from the server, and I can read the file from a command window, but from Ignition I can't. Ignition can see a file that I store locally on the server, but I can't see it on the network mounted drive.

This is a Windows server, and I am logged in with the same credentials that Ignition is using.

Any other ideas?

Thanks!

Mounted according to whom? Unless you went through this process: Mapping a Network Drive - Ignition User Manual 8.1 - Ignition Documentation, your network drive is still not visible to the gateway service.

3 Likes

Ah ha, it's always something else! The gateway can see it now, but the service can't!

Thanks for that helpful tidbit. I implemented what you pasted, and now my gateway and the Ignition service are now able to see this mounted drive.

Ken

2 Likes

This works well.
Thank you very much Jorden

When running the script in the console it runs fine but in a view it gives me an error "ValueError: max of empty sequence"

Running this in perspective means that the script is executing on the gateway not on the client computer, therefore most likely, it can't find the file since it isn't on the gateway computer.

1 Like

That makes sense can I still connect to the gateway or call the script another way?

The gateway is where Ignition is installed, this is where the perspective session backend is running. The client computer is where the perspective session frontend is running. Therefore, the client cannot browse the client's local file system (best to my knowledge). Using the above script would only work if your files are hosted on the gateway computer. Depending on what you are doing, the Perspective file upload component may be useful.

As @dkhayes117 notes, the correct answer is the upload component. That means the user in front of the browser must be involved in selecting the file to be processed. Anything that doesn't involve the user in that phase is behavior that browsers block, because that is what malware wants to do.