04-13-2016 07:34 AM
Hi,
I´m looking for a possibility to get the dimensions of a cluster.
Background:
I do have a complex cluster that might change its strucuture. If i add a new element to this cluster, lets say this element is another cluster with elements, I will get kind of a deep structure with 3-4 dimensions, right?
Then I could use these Information for writing a VI that extracts my cluster in its elements.
My Idea:
If I use the context help on the defined cluster i can see the content of the cluster, so what i thought is getting this information as a string and then search for EOL/CR/LF signs or however it is shown in the string ( or maybe convert to hex and search for the hex-code). By now I couldnt find a solution. I tried it with OpenG: Get default data from variant (see attached picture). I do get the text, but i cant "work" with it.
04-13-2016 08:28 AM
How about using the Controls[] Property on the Cluster and then recursing on each Control you find that has a ClassName property of Cluster?
04-13-2016 08:45 AM
Or you can get the cluster toolkit from VIPM made by Autotestware. Quite a large library of tools for clusters so I'm sure there is something in it to help you out.
04-13-2016 08:59 AM - edited 04-13-2016 09:01 AM
Normally I love to recommend OpenG but in this case there are native functions that can do it for you. Use the Variant to Data function and turn a cluster into an array of variants, then you can iterate over all elements and use the native Variant functions Get Type Information.vi to get the data types and names (and values if you want)
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-14-2016 04:51 AM
That could be what I´m looking for. Unfortunately I´m using LV 2014 ( sorry, forgot to mention that) and i couldnt find this "get type information" function.
However i tried it in a different way that does return the same (data-types missing, doesnt work so far). See attached picture: Array 1 and 2 basically do the same thing, array 3 returns the elements of the highest level.
But that is my problem, i still dont get the data of lower levels. If one if these highest level elements is a cluster, i need to know how many levels/dimensions are in that cluster. Wiring this number to a for-loop should make it possible to dynamically extract the content of the cluster.
@aputman: Thanks for that one, i´ll try to download the toolkit this weekend.
@Taki1999: Could you explain your suggestion a bit more? I had a look at the available properties, but i couldnt find a property that would match my requirements.
04-14-2016 07:45 AM
So the Get Type Information VI I used was put on the palette in 2015, but was buried in vi.lib for several versions. I'd recommend installing the Hidden Gems package if you haven't already, I think it is in the normal list in VIPM. All it does is put some of the useful features in vi.lib on the palette, it doesn't actually install any new functions. Once installed there is a Variant palette, and it has a function similar to the Get Type Information in 2015. The benefit of this is this will run in an environment that doesn't have OpenG, or the hidden gems installed, since they are installed with LabVIEW just not on the palette. I did some testing and the NI version is generally faster than the OpenG method of getting variant information.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-14-2016 07:57 AM
Here's my idea for getting the depth. I'm pretty sloppy with my recursion sometimes but this looked like it was working. Cluster Depth VI looks like this:
04-14-2016 08:32 AM
That only works if you have a reference to the cluster, instead of just the data type. Still it could be modified to work with the data type instead.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-14-2016 08:40 AM
This is from the Cluster toolkit. Function is called Get Cluster Element Data Types (Nested).