LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simpler way to populate controls from csv file

Solved!
Go to solution

Hello

 

I am wondering if there is an easier way to populate large amounts of data in my GUI. I am building a control program for taking measurements inside a “Farm” of environmental chambers. Without getting into the weeds, I am writing a program that needs a lot of individual data points on the GUI. The data is either string or Boolean.

 

To generalize the program:

 

I have a text (or csv) file that I need to read in 200 individual values. When the program launches the csv file is read populating all the controls. The user will then edit some or all these values, hit RUN, stuff will happen and then the new values will saved back to the file, overwriting the original data.

 

I'm used to doing this process using some variation of the image shown below. There is another state where I unbundle by name and update the controls. To write back to the file I basically have the mirror image. This works just fine for small numbers of fields. There has GOT to be an easier way for larger numbers of controls. The program I am working on now has almost 200 fields. These are signal wires and corresponding Open/Closed digital lines. Do I need to hard wire everything like I’ve been doing or is there some way to set this up in a loop? I can see how I would build a loop to create an array of the spreadsheet values to read and write, but how would I use a loop to populate the individual controls?

 

Related question: Is there any way to control/change where the cursor goes when you hit Tab? I would like the operator to be able to Tab through the controls in a sequence I determine. I didn’t create the controls in the order I what them Tabbed through.

Any suggestions?

 

Thank-You,

Ross

ImportSignalLines.jpg

0 Kudos
Message 1 of 9
(5,799 Views)

RossM wrote:

Related question: Is there any way to control/change where the cursor goes when you hit Tab? I would like to operator to be able to Tab through the controls in a sequence I determine. I didn’t create the controls in the order I what them Tabbed through.


Edit->Set Tabbing Order.  It works the same as the Reorder Cluster Items.

 

 

As far as your configuration...You could get a reference to all of the controls on your front panel, run the references through a FOR loop and get the label or caption names.  You could then use this as a lookup.  This would only really work if your csv has 2 columns, name and value.  So you lookup the name in the list of control names (Search 1D Array) and use that control reference (Index Array from the index from the Search 1D Array) to set the value of that control.


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
Message 2 of 9
(5,790 Views)
Solution
Accepted by topic author RossM

Do you need the data to be saved as an array in a CSV file? If not, consider using a text-based format that associates the control name with the value. For example you can serialize to XML, or use the MGI (Moore Good Ideas) "Read/Write Anything" VIs to save a cluster in an INI file. Those are much simpler ways of saving and retrieving the values in a cluster. They're slightly slower than your current approach, but for one read at startup and one save at program exit, you won't notice the difference.

 

If you must use an array saved as a CSV, you might want to rework your cluster so that you can use Array to Cluster for some groups of elements. You will need to add some sub-clusters inside your main cluster to make this work, but then you can take an array subset, use Array to Cluster, and then bundle that into one of the sub-clusters, which will be easier than dealing with individual elements.

 

For front-panel tabbing order, search the LabVIEW help for "tabbing order."

Message 3 of 9
(5,735 Views)

My csv does have two columns. Can you show me a little snipped of that that would look like? This solution sounds like what I'm looking for.

I'm in a design review for the next hour then I'll be back on this.

Thank for the re-order tabs tip. I knew it was somewhere.

~R

0 Kudos
Message 4 of 9
(5,777 Views)

@RossM wrote:

 

I'm used to doing this process using some variation of the image shown below. There is another state where I unbundle by name and update the controls. To write back to the file I basically have the mirror image. This works just fine for small numbers of fields. There has GOT to be an easier way for larger numbers of controls. ImportSignalLines.jpg


First of all, if you want the elements in numerical order, you don't need to wire the indices of "index array".

 

Are these all elements of the cluster (or are there more elements that you don't show/modify)?

Is the cluster order the same as the order of elements in the array?

If the answer to both question is yes, use "array to cluster" and set the cluster size to 22 (right-click...).

 

Message 5 of 9
(5,771 Views)

@RossM wrote:

Thank for the re-order tabs tip. I knew it was somewhere.


I don't see any thanks...

 

 

I'll try to work up an example.  Have to find time to do it myself.


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
Message 6 of 9
(5,765 Views)
Solution
Accepted by topic author RossM

@RossM wrote:

My csv does have two columns. Can you show me a little snipped of that that would look like? This solution sounds like what I'm looking for.


Wow, time just frees up at the end of the work day...


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
Message 7 of 9
(5,757 Views)

Does it have to be a CSV file?  There are functions designed to work with ini files out there for this exact purpose, as well as some good examples of doing exactly this.  If it does have to be a CSV, it looks like those are all just text.  Something like array to cluster should work. 

Message 8 of 9
(5,749 Views)

There is a lot of information here. Kudos to all.

I need to work through some of these replys to figure out which one I will go with but in general I think my problem is solved.

Tomorrow morning I will try a different file format and then make sure my read from file array and my cluster are in the same order and use the array to cluster.

Thank-you all for the links. I will study up!

~Ross

0 Kudos
Message 9 of 9
(5,730 Views)