Import CSV file

Hello everyone,

I’m somewhat new to Ignition, but have been consulting the forums on a daily basis!

Anyways, I finally ran into an issue I can’t seem to find any information on.

Running on Windows 7 and Ignition version 7.6.1…

From a custom database program, the customer wants to export a CSV file and be able to pull it up onto a table in Ignition. I gave their IT dept. the format that the file needs to be in, per the user manual. When I open the CSV file in, say, Notepad, it looks like a spitting image of what the format should be. When I open it with a shareware CSV viewer, it forms a table correctly, but is double-spaced (which I have a suspicion is the problem). Just to test the importing process, I have a window with nothing but a table and a button that runs the code.

file = "C:\path\coilline.csv" string = system.file.readFileAsString(file) data = system.dataset.fromCSV(string) event.source.parent.getComponent('Table').data = data

When I push the button, I get this error:

Traceback (most recent call last):
File “event:actionPerformed”, line 3, in
ValueError: CSV invalid format: expected #TYPES on line 3

at org.python.core.PyException.fillInStackTrace(
at java.lang.Throwable.<init>(
at java.lang.Exception.<init>(Unknown Source)
at java.lang.RuntimeException.<init>(Unknown Source)
at org.python.core.PyException.<init>(
at org.python.core.PyException.<init>(
at org.python.core.PyException.<init>(
at org.python.core.Py.ValueError(
at com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities.fromCSV(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.__call__(
at org.python.core.PyReflectedFunction.__call__(
at org.python.core.PyObject.__call__(
at org.python.core.PyObject.__call__(
at org.python.pycode._pyx17.f$0(<event:actionPerformed>:4)
at org.python.pycode._pyx17.call_function(<event:actionPerformed>)
at org.python.core.Py.runCode(
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(
at $Proxy17.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$ Source)
at java.awt.EventQueue$ Source)
at Method)
at$1.doIntersectionPrivilege(Unknown Source)
at$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$ Source)
at java.awt.EventQueue$ Source)
at Method)
at$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at Source)

Ignition v7.6.1 (b2278)
Java: Sun Microsystems Inc. 1.6.0_31

I would prefer to email the csv instead of post it here, if you would like to see it!


its tough to say without seeing your csv file, can you post the file or at least maybe the top 15 lines of it? That way we can see what TYPE on line 3 is. thx

Thanks for the reply!

Okay, I’m posting the first lines of the CSV. Also, I noticed something else strange. When my cursor is at the beginning of a line (in Notepad), and I hit backspace, and then Enter (effectively making it the same as it was), and do that for each line, and re-save it, I am able to upload the file! What changed in that process?

I’m interested to know how uploading this file works for someone else!

Thanks so much! :smiley:

EDIT - Removed attachment

Your .csv has a carriage return in it after each line, If you remove the CR, Ignition will parse it correctly.

Generally, Windows does CRLF, *Nix does LF.

Add one line to your code and you’re golden

file = "C:\open\coilline2.csv"
string = system.file.readFileAsString(file)
string = string.replace('\r','')
data = system.dataset.fromCSV(string)
event.source.parent.getComponent('Table').data = data

A million ways to do that, but .replace is just going to get rid of the CR character for you

Just tried it and it worked perfectly! Sometimes you just need to seek advice of one smarter than yourself. :prayer: Thanks so much! :smiley: