LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Csv to string arrays

Hi,

I am trying to get data from a csv file into string arrays.

The csv file includes columns tag, module and channel, where a number of tags (item names) correspond to a module number (1-5) and channel count (0-31) (for indexing).

e.g. See simplified table below:

tagcsv.png

Each module requires its own array, which will contain the tag names.

For now I have just tried to create one array for the first module. This is where I am up to so far..

  • import csv
  • read csv
  • remove column names
  • case structure.. If the current module = module 1, then select tag name (column 0) and return array

tag array.png

When I try the above VI the array plots the last tag name of module 1 32 times.

I tried using shift registers, but I can't quite figure out how to use it to keep the value of each row and to plot it in the array.

 

How can I plot the tag name of each row into an array? From there I would replicate the code inside the case structure with the condition equal to module 2 etc.. I know this is probably not a very efficient way of doing it so if anyone has any tips - it would be very helpful.

 

Thanks.

Lisa

0 Kudos
Message 1 of 12
(7,686 Views)

Can you provide the sample CSV file so that i can update you the solution

 

 Also your requirement in points (1., 2. etc..)

0 Kudos
Message 2 of 12
(7,678 Views)

Hi Lisa,

 

When I try the above VI the array plots the last tag name of module 1 32 times.

You have it programmed this way! There's a FOR loop iterating 32 times and in each iteration you index the very same string…

 

I tried using shift registers, but I can't quite figure out how to use it to keep the value of each row and to plot it in the array.

Then you need to learn this very basic LabVIEW element!

 

When you need help for your VI you should attach the VI instead of some JPGs…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 12
(7,664 Views)

Hi there,

attached is the vi and csv file.

 

The requirements are as follows:

  1. string arrays for each module containing 'tag'. i.e. an array per module containing tag names
  2. name of array - 'module' name
  3. index into array is the channel
  4. arrays defined on front panel of VI as indicators
Download All
0 Kudos
Message 4 of 12
(7,648 Views)

Attached is the revised version, see previous comment for csv file.

 

Changes made to VI:

  • moved index array for tag outside the case structure
  • reduced the number of iterations in the for loop to 1
  • added build array function
  • moved module array outside of the for loop

This now works and it plots all 32 tags of module 1. This code will require repetition of code for modules 2-5. Is there a better way of doing this?

Message 5 of 12
(7,635 Views)

I would do something like this.

Use an array of clusters for your modules.  Each cluster element should have a name (for the module), an array of tags, and an array of channels.  I used a seperate array to make it easier to keep track of the names.  So if the module has been defined already, you just add the tags and channels to that cluster's arrays.  If the module has not been found yet, create a module cluster and add it to the array of modules.

 

Also note that I set the module names to be all caps and trimmed the white space to avoid stupid capitalization and space issues.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 12
(7,612 Views)

Thanks very much for your help and suggestions, I really appreciate your time. I need to clarify some things with my manager to check the required formatting, but hopefully it is suitable. Thanks for your time!

 

0 Kudos
Message 7 of 12
(7,592 Views)

There's a single function (in LabVIEW 2016 -- I don't currently have access to earlier versions, but think it's been around for a while) called SpreadSheet String to Array (found on the String Palette).  Tell it the separator is a comma, configure the rest of it, and stand back while it does all the work within a 32x32 pixel area of your Block Diagram!

 

Bob Schor

0 Kudos
Message 8 of 12
(7,563 Views)

Thanks for your comment Bob,

 

I am familiar with the spreadsheet string to array function. However, the csv is already in array form when it is read in. Is there a way to import the csv in string format?

 

Lisa

0 Kudos
Message 9 of 12
(7,553 Views)

Hi Lisa,

 

Is there a way to import the csv in string format?

Yes: read the csv file as ordinary text file…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 12
(7,549 Views)