Jump to content

Variant to Name-Value String Pairs


Recommended Posts

Hi all,

I have created a tool that I find very useful and from our meetings at the Cambridge Labview Users Group, I discovered that other people would find this useful also. I think it could make a great edition to the OpenG toolkit, but probably requires a bit of cleaning up.

The purpose is to convert any Labview data structure, including multi-level nested clusters and/or arrays into pairs of name tags and associated string values, such that it can be saved to and loaded from a config file, for example. Labview can already do variant<->flattened string conversions, but if your data structures change between versions, you can no longer load your old data into your new structures. Also, flattened strings aren't exactly friendly to the eye. This tool gets around all that.

I have used this tool in several programs with complex data structures and have had no problems. I had to use some of the OpenG variant tools to make it do what I needed, since building up a complex variant really is very complicated and requires information about type descriptors that I couldn't find in the Labview help files. I suspect there may be a few obscure type descriptors that still need to be catered for.

Please have a look at the VIs attached and let me know if anyone would like this as part of OpenG.

Christie

post-26401-0-01287300-1312454005_thumb.j

post-26401-0-55587200-1312454014_thumb.j

Link to comment

You're saying that this is for saving to config files. OpenG already has VIs which do that (the variant config VIs package). They also use the OpenG variant VIs (I'm assuming in pretty much the same way you did) and they plug into the config file API.

MGI has a similar tool (the read-write anything VIs) which uses built-in functionality, so it should hopefully handle all data types.

Link to comment

Hi all,

...I have created a tool that I find very useful and from our meetings at the Cambridge Labview Users Group...

Hi Christie

Thanks for posting. cool.gif

Following on from Yair, are you able to go into detail on how these VIs differ from the OpenG Variant Configuration API and MGI's Read/Write Anything VIs. Do you have a use case that is not met by the above VIs etc...?

Additionally, are you able to post the VIs, they do not seem to have been attached.

Cheers

-JG

Link to comment

Hah! I was not aware of these VIs. I had a play with it just now and was rather disappointed... that it works quite well.

However, I did find a few restrictions and have a few comments.

1) Data can only be saved to file. I use my VIs to parse data to/from a database and can be used to store it in any other medium that can take strings.

2) The field names are built using "." as separators, which means that a field such as "Cluster..Numeric" can be parsed in two ways, either "Cluster" and ."Numeric" or "Cluster." and "Numeric". Of course this won't be a problem, unless you have both cases in one structure. I know, this is beyond nit picking. In my database, I save each field name as an array of strings.

3) Clusters within the main cluster are saved as sections (I suspect this is intentional). This has the side effect that these cluster names must be unique.

4) <.size> is appended to indicate array size, which also restricts naming of your array. (Again, nit picking.) I am using the raw array name to store the array size to avoid this problem.

5) Recursion is used instead of iteration. This is just a preference, but I feel that one has less control over a recursive solution.

6) I noticed that timestamps are just flattened to strings. I checked this case in particular, because I had trouble with it.

7) The root datatype has to be a cluster. (I assume this is because it maps so nicely to a config file.)

It would be great if there were VIs that work like mine, but also VIs that automatically save to config files.

I have not had a look at the MGI version, but I will.

I have attached my VIs. I hope I have all the dependencies included. It's not very elegant looking and needs some cleaning up. Please have a look. Comments are welcome.

Christie

Strings - Control to & from String.vi

Tool - Array Element Default.vi

Strings - Variant to Strings.vi

Strings - Variant from Strings.vi

Strings - Variant from Strings - Commands.ctl

Link to comment

Hi All,

I just had a look at the MGI components. They are also pretty impressive. I like that it is possible to get the strings back without writing it to file. I would have liked if it returned field names and values separately, but this can be done manually by splitting at "=", assuming there is no other "=" in the name or value. Also, they seem to be able to parse timestamps and waveforms correctly. I still need to do waveforms in my VIs.

Christie

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.