LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing an array of references from one subvi to another?

Hi,
 
I have a cluster of controls on my top-level front panel which I am passing to a subvi by reference.  I have had no problems working with these controls in the subvi by indexing the Controls[ ] property of the reference.  I would like to access a few of these controls from a VI another level deep.  I have tried putting ref nums in the second subvi and passed the Controls[ ] array to them but when I try to cast them using To More Specific Class, I run into an error (incompatible class or something similar).  What am I missing here?
 
 
I've also had class-conflicts in the past while wiring references to refnums in sub vis which I was only able to resolve by selecting "VI Server Class" and re-selecting the class that was already checked... Suddenly the wire is valid even though the class was not changed.  Has anyone else seen this behavior?
 
Thanks
 
Dave
 
0 Kudos
Message 1 of 11
(4,584 Views)

"Object reference is invalid" is the exact error I am getting.  I tried the code out in the first sub-vi to make sure it does indeed work with the refnums.

I have an object refnum control inside an array in the second vi and that is what I am trying to pass the Controls[ ] array of refnums to... There must be something special I have to do here?  I've tried a few various casts and am out of ideas for the moment...

 

Thanks

0 Kudos
Message 2 of 11
(4,575 Views)
You may have to create actual controls in the 1st subvi, wire them to the values obtained from the reference array, and pass a reference to the newly created controls to the 2nd subvi.  Sort of like:  Main controls -> Reference of controls to 1st subvi -> 1st subvi duplicate controls -> Reference of duplicates to 2nd subvi.
- tbob

Inventor of the WORM Global
0 Kudos
Message 3 of 11
(4,572 Views)
What if I want to update the controls on the top-level VI from the second sub-vi though?  Will I need to have the first sub VI processing while the second sub VI is running?  Perhaps this is easier to do than I think, I'm going to try adding a while loop to the first sub VI to handle the updating- I cringe to think this is the easiest way to accomplish this, but thanks for the idea!!
 
 
0 Kudos
Message 4 of 11
(4,563 Views)
It seems that as long as I pass the entire cluster refnum on to the second sub-vi, things work out ok.  I was hoping that there was a way to just pass the refnum to the controls[ ] array but this should work out okay for me.


0 Kudos
Message 5 of 11
(4,550 Views)
Actually, I didn't like my idea either.  I'm glad that passing the entier cluster refnum has solved your problem.  A little awkward, but if it works then its OK.
- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 11
(4,536 Views)
Problem.
 
I've been able to pass this cluster but not in the program I am working on.
 
I've made 3 blank VIs, passed a cluster from the top to sub1, to sub2 and it has worked no problem.
 
I've tried implementing it in the code I am working on and I always get an "Object reference is invalid" error in the second sub VI at the property node that is trying to extract the Controls[ ] array. 
 
I've tried with and without "Include Data Type" which I still don't fully understand (searching for "red star" didn't bring up much and "Include Data Type" isn't even in the User's Manual PDF attached to the help).  I've implemented the exact same code in the main program I am working on as I did in the 3 small VIs- same custom control, same names... I have had to have tried at least 5 times now, starting out from scratch.  I've recreated the small VIs several times as well, just to make sure I am not forgetting anything. 
 
Top level VI has a custom control cluster.  I create a reference to the cluster.  I drag the cluster reference from the block of the top level to the front of the first sub.  I connect the refnum to the first sub's connector pane.  I add the first sub to the top level block and connect the reference to the sub.  I drag the cluster reference from the block of the top level to the front of the second sub.  I connect the (second) refnum to the second sub's connector pane.  I add the second sub to the first sub block and connect the refnum to the second sub.  In the second sub I create a Controls[ ] property node and wire the second refnum to it.  I connect the property node to an index array and index element 0.  I create a Value property node and wire a constant numeric to it.
 
I was using "to more specific class" between the output of index array and the final property node but I've found this isn't required (something else to understand some day). 
 
Is there a VI property that might cause this not to work??  This problem is really getting to me.
 
Thanks all,
 
Dave.
 
0 Kudos
Message 7 of 11
(4,529 Views)
In the program that I have been working on I just replaced the second sub-vi with a new VI like that I have been making to prove to myself that this can be done.  All it does is update a value on the top-level VI.  THIS works though, so I feel like I have the problem narrowed down to a conflict with the second sub-vi of the program I am modifying.
 
I'm not sure what it means but I can not set the refnums to "Include Data Type," I end up with a "class conflict."  In the examples I have written to try this whole technique out, I have been able to switch them between "Include Data Type" and Cluster class without any noticeable change....
 
Ahh I never thought I'd miss pointers ;).
 
THanks again (and again, these forums sure help with frustration)
 
Dave
0 Kudos
Message 8 of 11
(4,521 Views)

I suspect your are running into issue with the array insisting that all elements be of the same data type. So when you build an array of disimilar types, LV will cast them as generic class refernces.

But I am guessing!

If you posted a small set of demo VI, we may be able to nail this challenge much faster than trying to imagine your code.

Trying to help,

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 11
(4,520 Views)


@davey31415 wrote:
Problem.
 
 
Top level VI has a custom control cluster.  I create a reference to the cluster.  I drag the cluster reference from the block of the top level to the front of the first sub.  I connect the refnum to the first sub's connector pane.  I add the first sub to the top level block and connect the reference to the sub.  I drag the cluster reference from the block of the top level to the front of the second sub.  I connect the (second) refnum to the second sub's connector pane.  I add the second sub to the first sub block and connect the refnum to the second sub.  In the second sub I create a Controls[ ] property node and wire the second refnum to it.  I connect the property node to an index array and index element 0.  I create a Value property node and wire a constant numeric to it.
 

I tried following the directions given above, and I had no errors.  It worked fine.  The main vi was updated with the value written in subvi 2.  You must have a conflict with some other control or cluster in your vi's.
- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 11
(4,516 Views)