10-26-2011 10:44 PM
Hello
I've been using "reference clusters" (strict type def) and they make life much easier when you have a Main VI with couple controls and indicators, and want to change a property of one of these objects from a SubVI. Everything works great when I have all objects in one single VI and want to populate the cluster with the "real" and valid references.
Nevertheless, when I have couple objects in many different VIs and want to populate one single cluster with the references, I am getting errors. What is the best way to get that?
Find attached two ZIP files: First Method.zip and Second Method.zip
Unzip First Method.zip to a folder and open VI_1_First_Method.vi. Run the vi and keep your eyes on the white gauge. Everything is working great and VI_2_First_Method is changing the background color of the white gauge.
Unzip Second Method.zip to another folder and open Populate_with_real_references_Second_Method.vi. Take a look at the block diagram. How do I populate the Cluster_Second_Method.ctl with "real" references from objects in VI_1_Second_Method.vi, VI_2_Second_Method.vi and VI_3_Second_Method.vi ??
Thanks a lot.
Dan07
Solved! Go to Solution.
10-27-2011 01:41 PM
Does anyone have suggestions?
Thanks.
10-27-2011 02:17 PM
I first used a static ref (brose to sub-VI once you drop it on digram) to get a ref to the FP and then get a ref to all controls on the FP of the first sub-VI. Then I iterate thru all comparing the label and when I match I terminate the for loop and cast the control as the proper type. The output wire in then availabel for wiring to the cluster.
If you are not familiar with navigating using control refs then this Nugget may give you some ideas.
Ben
10-27-2011 04:26 PM - edited 10-27-2011 04:29 PM
Ben
Your approach will work great with small codes but not with large ones. I was thinking about using one single for loop and feed this loop with all references. The problem is to put references of different classes into the same array. Find attached a VI that looks crazy but has one possible solution for this problem.
Thanks.
Dan07.
10-27-2011 04:36 PM
Dan your solution will not work since you are typecasting the specific control back down ot a generic control. You would have to adjust them back to their specific class.
You could put your cluster in your loop shift register and update the cluster instead of building the array.
10-27-2011 04:47 PM
Hello Matthew
I know that my idea is a little crazy, but how can I put the cluster into the shift register? I can't use the "bundle by name" as a array, I mean: index 0, then index 1, and so on. I can't see that working. Could you draw a draft for me?
Thanks a lot.
Dan07.
10-27-2011 05:11 PM
Here is your VI reworked for your example. Note, I startAll controls instead of All Objects. Sicne you were bundling your control refs, they were all demoted to generic control refs as well. So, I don't make the object the specific calss until I've decided where it belongs.
10-27-2011 05:38 PM - edited 10-27-2011 05:39 PM
Hello Matthew
Your code is great, but is this example I have only 6 controls. In a large VI with many controls, I would have to have many cases in the case structure, and I would have to create one by one and put the right specific class constant inside. I know that this kind of approach will work, but I trying to figure out a way that I don't have to create cases by myself. Suggestions?
Thanks a lot!
Dan07
10-27-2011 05:45 PM
You can do it this way:
10-27-2011 05:49 PM