LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving Clusters to a Config File Using Variants

I am attempting to save the contents of a generic cluster to a config file.  I was able to do this perfectly well when there were no clusters or arrays within the cluster I was saving, by stepping through the controls[] array and converting from a variant data type to whatever data type corresponded to that element.  This is shown in the attached VI called save_cluster.

 

I am ignoring the possibility of having arrays, but I want to be able to handle clusters within clusters.  As such, I need to make the VI a recursive (reentrant) VI.  I did this.  The recursive VI is titled save_cluster_sub and the VI that calls it is save_cluster_caller.  I am having trouble converting the variant-type "cluster" within the controls[] array.  I am currently using the Variant To Data Function and passing in an empty cluster, but that doesn't work.  This is probably completely understandable, and I assume I cannot use the Variant to Data function when I don't know what the contents of the cluster will be.  I don't know how else to achieve this goal, though.

 

I therefore have two questions:

How do I convert the Variant data to a cluster?

Is there some better way of saving clusters to a config file?

Message 1 of 7
(12,626 Views)

 

You can use the OpenG VIs which already exist.

 

Write INI Cluster

Write Section Cluster

Read INI Cluster

Read Section Cluster

 

You can install the VI package manager and download the OpenG VIs.

Message 2 of 7
(12,623 Views)

If your clusters are very large, you might also wish to check out MGI's read-write anything VIs (also free), as the OpenG VIs use NI's config VIs under the hood, which have performance implications for large clusters (large was ~200 elements in a nested cluster and ~3500 lines in the INI file in my case).


___________________
Try to take over the world!
Message 3 of 7
(12,609 Views)

Here are instructions on how to get the OpenG libraries in LabVIEW.

John B.
Embedded Networks R&D
National Instruments
Certified LabVIEW Developer
0 Kudos
Message 4 of 7
(12,583 Views)

While I agree that the OpenG are very handy the one complaint I have regarding them is that if you have several ENUMs in your cluster and you would like the user to be able to edit the file externally the OpenG VIs save the ENUMs as numbers. This makes it very difficult for the user to be able to edit the files easily. This is something to consider.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 7
(12,570 Views)

Moore Good Ideas supplies exactly the functions you need in their Read/Write Anything library, for free!

Message 6 of 7
(12,560 Views)

Does it have to be a .ini file? If it can be XML you can always use the cluster to XML vi then write the string it returns to an XML file. The only drawback is it's not as straight forward for the user to edit. What I usually do is make a config dialog when I do this so the user doesn't have to actually open the file its self.

 

If you are sticking with an ini file, you may find "Get Type of Variant.vi" helpful. It can be found at the following path:

 

C:\Program Files\National Instruments\<LabVIEW version>\vi.lib\Utility\GetType.llb

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