11-30-2017 02:16 PM
Hello,
I have a strict type def. that contains a cluster of various arrays:
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.
12-01-2017 02:41 AM
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.
12-01-2017 03:46 AM
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.
12-03-2017 09:00 PM
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.
12-04-2017 02:59 AM
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. 🙂
12-04-2017 03:10 AM
12-04-2017 05:43 AM
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.
12-04-2017 05:47 AM
@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.
12-04-2017 12:57 PM
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.
12-05-2017 03:07 AM
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