LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve all names of objects from Strict Type Def

Hello,

I have a strict type def. that contains a cluster of various arrays:

stricttypedef.png

Is there a way to retrieve all names of the arrays?   and then, is there a way to use those names to retrieve the array from the control?   When I add this control to a block diagram, I try to retrieve a reference to it, but the Create >> Reference option does not exist.

 

Thanks in Advance.

0 Kudos
Message 1 of 12
(4,012 Views)

FrankRalphBob wrote:

I have a strict type def. that contains a cluster of various arrays: Is there a way to retrieve all names of the arrays?  

There are a few ways to do this. Getting a reference is one way, convert to variant is another. It depends on the use case. More on this later on.

 

 and then, is there a way to use those names to retrieve the array from the control? 

Again, it depends on what you want to do with the array. If you make something that "gets" any array, this will always be a variant. You need to convert those variant to a type if you need it. This can be very difficult, or trivial depending on what you want. Since all your arrays are doubles or integers, it will be easy.

 

Obviously, you can get the values from an unbundle. But you seem to need to get them dynamically. Can you explain why? I think it's crucial for a fitting solution.

 

<  When I add this control to a block diagram, I try to retrieve a reference to it, but the Create >> Reference option does not exist. 

 You'll only be able to get a reference from a block diagram with scripting, and that's overkill for what you want. You can get a reference from controls and indicators, but I'm leaning towards variants.

 

So if you have a wire of the cluster, use "Variant To Data" to convert it to an array of variants. In a for loop, you can get the labels of those variants with "GetTypeInfo.vi" from the variant palette.

 

These variants are also the values of the arrays, but in variant form. If you lookup the name you want, you can get the variant from the array by it's index, and use "Variant To Data" to convert it to an array of doubles\integers.

 

 

 

0 Kudos
Message 2 of 12
(3,966 Views)

like this...

 

I have to say that this might seem like a good idea. I'd say it's probably not. For starters, it will be relatively slow. To\From variants is relatively slow.

 

I think it is what you asked for, but I'd say there are other (higher level) solutions that will make this need redundant. A class usually solves these situations for me, but switching to OO over this might not be that tempting. In a class, you could even make a case that switches a static (un)bundle. The index won't be a string, but a type def'd enum. That alone will make it more scalable.

0 Kudos
Message 3 of 12
(3,959 Views)

Hi FRB,

Here's (yet) another way.  If you want to build a list with the names of _all_ the arrays, you could do it in the for loop with a shift-register.

0 Kudos
Message 4 of 12
(3,937 Views)

wiebe@CARYA wrote:

For starters, it will be relatively slow. To\From variants is relatively slow.


Slow? Not in my experience, especially compared to most alternatives.

~70us for this snippet is fast enough in most cases. 🙂

 

Cluster Info.png

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 12
(3,921 Views)

Cluster Info with ref.png

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 12
(3,918 Views)

Just be very careful with that Get Cluster Info.vi! It is useful to get the variant's labels, but it won't return the values, IIRC! That's why I prefer Variant To Data, it will return variants with labels and values.

0 Kudos
Message 7 of 12
(3,910 Views)

@Yamaeda wrote:

Slow? Not in my experience, especially compared to most alternatives.

~70us for this snippet is fast enough in most cases. 🙂


Relatively slow. A case with an unbundle will be much faster. Note you're only returning labels, not values in your example. Try a benchmark when all the arrays are filled with kilobytes of data.

 

If you use the read\write as a databus, it won't perform as fast as other solutions. But if it's fast enough, no need to change it (although it isn't a particular nice solutions either). Optimize when needed.

Message 8 of 12
(3,907 Views)

Thanks all for your help.   It appears I cannot pull a reference off a string typedef, I need to make a control from the strict typedef and then I can pull a reference.   Which make sense once I think about it. 

 

Your answers also helped me think about my processes in all of this.   I am taking them under consideration as code.

 

Thanks again.

Message 9 of 12
(3,882 Views)

wiebe@CARYA wrote:

Relatively slow. A case with an unbundle will be much faster. Note you're only returning labels, not values in your example. Try a benchmark when all the arrays are filled with kilobytes of data.

 

If you use the read\write as a databus, it won't perform as fast as other solutions. But if it's fast enough, no need to change it (although it isn't a particular nice solutions either). Optimize when needed.


True. I suspect the time factor is why the function don't return data as standard, that's what the unbundle is for (I've made a general Read/Write cluster as ini-file through that design though). If the cluster has many large arrays even that it slow and a DVR will be much faster. 🙂

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 12
(3,865 Views)