07-28-2010 03:52 PM
I have created a type definition that I would like to use across my application. This particular type definition is also the front panel control to my top level VI. I wanted to pass a reference to this control to my SubVi's so that they could dereference as needed and in very rare cases update the values on the front panel. However, as I built the application I noticed that I was breaking the control reference as I updated the type definition. This implies that they type of the reference changes as I change the type definition.
How do I go about building the reference I need or is there some other way to do this that works just as well. Even if I can't make a reference to the control that is tied to the type definition, I'm willing to pass in a variant who can house the reference as long as I can build the data type (the reference) inside my SubVis.
Solved! Go to Solution.
07-29-2010 03:51 AM
Hi,
You should simply pass a generic control reference to the Sub.vi and then cast it to the specific typedef. You will need to place a dummy control of that typdef on your Sub.vis Frontpanel and hide it.
Christian
07-29-2010 07:45 AM
make the control used to pass the ref of the type-def'd control a type def and replace your non-type defined version used on the sub-VI connector pane with the type-def'd version.
I think in earlier version of LV it had trouble with the update, but modern version seem to adapt well.
Ben
07-29-2010 09:02 AM
Okay, so I tried all three approaches in a SubVI, here's what happened.
My approach was simply to create a Type Def control, right-click and create a Reference. Then create a control from that reference by right-clicking the output of the reference and selecting the Create Control option. I then pasted this 'cluster' reference into my SubVi, made it an input and then wired up the reference in the parent to the control in the SubVi.
Result: This breaks when you update the Type Definition.
Next, Ben's approach (or my best effort at doing what he suggested). I created a control from reference to the type def. I cut it from the parent VI and pasted it into a new type def. I then put the type def in the SubVI and set it as an input.
Result: This breaks when you update the Type Definition (but it actually takes a bit longer for the error to propogate).
Finally, Christian's solution (or my best effort). I took the type def reference and put it through a To More Generic Class guy, casting it to a Control Refnum. I put a Control Refnum on the front panel of my SubVI and wired it to a To More Specific Class guy. I created a control of the type def in the subvi, hid it, and created a reference. I wired the reference to the more specific guy and verified I was getting the right data.
Result: It works!
It's possible I just didn't understand how to make the reference type def you were referring to Ben. I would prefer a method with less verbage. I pass this refnum into a class which holds it. Since I can't replicate the type exactly prior to run time (i.e. create a control that is exactly a reference to the type definition of my front panel), I have to save the reference as a Control Refnum and cast it every time I need it (i.e. create a control from the typedef, create a reference frome the type def, etc). More verbage than optimal, but still good!
Thanks for the help.
07-29-2010 09:09 AM
You are using classes!
Forget my appraoch. LVOOP would not like the def of its private dat changing when it was not looking very much anyway.
Ben
01-09-2012 03:36 AM
it's possible to get an example of this code here? i have problem with global variables controling subvi-s and want to change it with passing references.
01-09-2012 05:57 PM
Hi Beebrox,
This forum have been closed for more than a year, I would recommend you to open a new one and explain your issue, you might describe a little more what you are trying to do. Closed forums are not as viewed as new forums.
I found this KB related to control references to subVI’s, I hope this can help you with your application.
Regards,
01-19-2012 05:31 AM