LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help with reading a .CSV file and using data from file to output

Solved!
Go to solution

I need to read a CSV file and it includes strings and numbers and want to put it in an array. I have to have an input of a serial number which contains a string and using that string then output two specific quantities from the file. 

 

Can someone help?

0 Kudos
Message 1 of 12
(4,283 Views)

We can help if you tell us where you are stuck.

 

Perhaps attach a VI that shows what you've attempted.  Perhaps a CSV file that shows us the data you have.

0 Kudos
Message 2 of 12
(4,252 Views)

I just do not know how to setup the control in order to write the serial number and then have the output come up. I put an example of the csv file below. Can you perhaps put an example code up. Reading the file, then using the serial number in order to output the voltage of that item.

0 Kudos
Message 3 of 12
(4,186 Views)
0 Kudos
Message 4 of 12
(4,173 Views)

Thank you. I am new to Labview and learning, can you explain the process of what you did. It would be beneficial in my learning curve.

0 Kudos
Message 5 of 12
(4,162 Views)

1.  Read an array of strings from the file.

2.  Index out the first (#0) column) to get a 1-D array.

3.  Search the 1-D array for the matching serial number.

4.  Use that index to get the corresponding row as a 1-D array.

5.  Convert that row to an array of numbers.

Message 6 of 12
(4,140 Views)

For some reason, when I do it, its not giving the right result. It always ends up being the true case and not outputing anything

0 Kudos
Message 7 of 12
(4,134 Views)

Look closely at the data in your array, and the way you entered the serial number in the string control.

 

If you still have problems, attach your VI.  First run it.  then pick Edit >> Make Current Values Default.  Save.

Then attach that.  That way we can see the way you have the controls set and the data is present in the VI.

0 Kudos
Message 8 of 12
(4,118 Views)

The attachment is the vi file. I always get no value found maybe you can figure out why. Thanks

And also the CSV file which is an example

Download All
0 Kudos
Message 9 of 12
(4,113 Views)

You didn't follow the instructions I gave but saving data as default!

 

But looking through your VI, I see three mistakes you made.  (By the way, what I attached was a VI snippet which allows you to drag the image from the browser to your desktop, then from the desktop to your block diagram.  Then you will have working code.)

 

1.  Your delimiter input to the Read from File.  You left the tab in there and just entered a comma.  (Change the constant to \codes display and you'll see it.)  Delete everything in that constant and then re-enter the comma.

2.  The index from array.  You wired the 0 index to the wrong input.  It should be wired to the column index input.  Not the Row index input.

3.  You have Voltage wired to the Offset past number output of the String conversion.  Delete the voltage indicator.  Right click on the "number" output and Create Indicator.

0 Kudos
Message 10 of 12
(4,104 Views)