LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Initialize cluster values from spreadsheet

I’m hoping this is a simpler question than any of my previous posts.  I’m interested in finding a way to initialize clusters and their controls values using a spreadsheet or txt file.  This way, when I run the VI, the initial values are loaded from the spreadsheet or text file. If possible, I’d like to have a two column file that would have the variable (control) name and its value.   I am aware that you can enter these values into the controls manually and “set values as default.”  However, with larger VIs, it seems easier just to be able to change a file that is read at run time. Has anyone ever done this before and is there a post on the forum that explains this?  I did a search was did not have any luck. I've been able to write the values to an XML file and then load that XML and its values.  However, I’m really interested in using a spreadsheet or txt file.  One analogy to this (for anyone who is familiar with Microsoft Flight Simulator) is a .cfg file that can be edited with notepad.  So if a graphics setting needed to be changed, it could be changed within the .cfg file. Any thoughts? Thanks

 

0 Kudos
Message 1 of 13
(4,886 Views)

Hi Philip

 

Check out the config file vi's on the file and dialog pallet.  Plenty of examples exist and I use them all the time.

a config file has the following (generic) format

 

[Section0]

Key0=Value

Key1=Value

[Section1]

Key0=value.... etc

 

Where Section names and keys are Strings and Values are litterals of any scalar type

Message Edited by Jeff Bohrer on 06-02-2009 03:58 PM

"Should be" isn't "Is" -Jay
Message 2 of 13
(4,883 Views)

Functions on File I/O > Configuration File VI's palette will let you create and read exactly the kind of file you are looking for.

 

Missed it by that much!

Message Edited by Wayne.C on 06-02-2009 04:58 PM
Message 3 of 13
(4,882 Views)

Jeff and Wayne, thanks for the help. 

 

However, as Jeff pointed out, these functions only accept scalars.  So wiring a cluster to one of these blocks is not possible.  See attached.  I'm looking to create a config file for cluster values.  Not sure this is possible now without using Flatten to XML function.

 

 

0 Kudos
Message 4 of 13
(4,855 Views)

I have done this before.

 

Write%20Configuration[1]_BD.png

Message 5 of 13
(4,843 Views)
Yes, this is one way of doing it... but can you do it with a cluster with a few hundred elements? Smiley Wink  In theory obviously, but not conveniently.
0 Kudos
Message 6 of 13
(4,836 Views)

Hi Philip,

 

This Nugget on using control references to save and restore cluster contents is one solution. It uses the clusters data structure to generate the Key Names for the ini file. here is a preview

 

 

 

please note: That example uses an array of clusters because getting at cluster elements within an array is not easy. if you are not using arrays, it should still owrk provided you either use the data types I supported or are willing to add support for any that I left out.

 

Ben

Message Edited by Ben on 06-03-2009 10:49 AM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 13
(4,831 Views)

Ben,

 

Thanks for the detailed response... as always.

 

The Nugget looks very useful.  I'll have to read through it later to figure it out.

 

Phil

0 Kudos
Message 8 of 13
(4,822 Views)

There's a VI in OpenG that saves clusters directly to a config file. 

I think it uses the format

[cluster name]

first item=value

second item=value

etc.

 

Of course there's also one for reading the cluster.  It makes life very easy.

--
Tim Elsey
Certified LabVIEW Architect
Message 9 of 13
(4,820 Views)
Message Edited by elset191 on 06-03-2009 11:21 AM
--
Tim Elsey
Certified LabVIEW Architect
Download All
Message 10 of 13
(4,815 Views)