LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a cluster and/or variant to a text file?

Hi,

Is there a simple way to write a cluster and/or variant to a text file and vice versa? (please see the attached file).  I tried to unbundle each of the components inside the cluster, convert all of them to the same type (i.e. strings).  After that I concatenate them into a string and write to a file.  It works fine, but it's definitely not good for future upgrade. 

thanks very much,
Anh
0 Kudos
Message 1 of 14
(7,636 Views)
OpenG has the variant configuration VIs as part of their file package. It allows you to save and load arbitrary clusters. It's inside implementation is far from simple (it requires parsing all the data types), but it's free.

___________________
Try to take over the world!
0 Kudos
Message 2 of 14
(7,627 Views)
Hi tst,

Thanks for your help.  OpenG has some great functions in their package, but it doesn't seem like any of these make read/write cluster from/to text file a simple task.  I decided to just use standard XML library to load and save cluster in xml format. 
0 Kudos
Message 3 of 14
(7,583 Views)

The Variant Configuration File palette has 2 VIs, one for writing a cluster to a text file and one for reading it back. After reading the file you can pass it through a Variant to Data primitive to convert it to the cluster data type. It really can't get much simpler than that.

The advantage this has over XML is that the files are much easier to read and modify using a simple text editor.


___________________
Try to take over the world!
0 Kudos
Message 4 of 14
(7,579 Views)
Hi tst,

After 3 tries of installation of the VariantPackage, I could not load the Wirte_INI_Cluster since it always looks for the missing Format_Variant_Into_String VI.  I decided to use the xml format, but still very curious to find out how the cluster<-->text file work.  If you happen to have an example of how this work, I'd appreciate it.
thanks,
Anh
0 Kudos
Message 5 of 14
(7,557 Views)
Flatten it into a binary string and write this string to the file. When you read the file it requires a constant for the cluster be wired to the Unflatten from string.
0 Kudos
Message 6 of 14
(7,550 Views)

The VI you're missing is part of the String package. Personally, I think it's best to simply download all the packages and then you don't have these problems.

Anyway, in the attached example (7.0) you can see that the VIs go over the cluster recursively and saves the data from each control by using its label.

Unclebump usually gives good advice, but in this case I would stay far away from his method, because if you need to change the structure of your cluster, you will have to write some additional code to convert the data from the file which you already saved.


___________________
Try to take over the world!
Message 7 of 14
(7,533 Views)

Of course, there's a small bug in the code. The loop on the left should look like this.


___________________
Try to take over the world!
0 Kudos
Message 8 of 14
(7,528 Views)
Thanks tst and unclebump for all the great advices.  For my application I need an editable xml or text output so tst's method work out just great.  Now I need to try it in Linux, I hope it will work the same way.
0 Kudos
Message 9 of 14
(7,509 Views)


@tst wrote:

The VI you're missing is part of the String package. Personally, I think it's best to simply download all the packages and then you don't have these problems.


This was actually a bug in the oglib_variantconfig (OpenG Variant Configuration File) package -- it was not declaring the dependency on oglib_string (OpenG String Tools) package.  I have just released a new version of oglib_variantconfig (version 2.7-2) that fixes this problem.  Now when you try to install oglib_variantconfig, it will automatically install oglib_string, too.

See here for more info on the oglib_variantconfig-2.7-2 release.
0 Kudos
Message 10 of 14
(7,348 Views)