LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Assigning the same action to events in a top- and sub-VI.

Sounds like a strange question.
 
Anyway, I have a VI with a bunch of controls, one of which is an on/off switch. I monitor its events, and perform an action appropriately. Call it VIsub.
 
I would like to call VIsub from another VI, call it VItop. VItop also has an on/off switch, which I'd like to perform the on/off action in VIsub.

What's the best way to do this?
 
I've had a few ideas:
 
1. Register the on/off in VItop to handle events dynamically, and pass this event registration to the VIsub. But this is wasteful, as I need to duplicate the code to do the same stuff when handling "On/Off" (local to VIsub) and <On/Off> (dynamic from VItop).
 
2. Handle the events asynchronously in VIsub using a queue. Pass a queue reference in from VItop, and populate this queue either from VItop or VIsub. The code is no longer duplicated, as it's only handled once in the queue handling loop.
 
3. I'd thought about using the Value(signalling) property, but how can I do this from VItop without knowing the reference to "On/Off" in VIsub? Hold on, I might have just worked it out, using the controls[] array and a VI reference?
 
I would appreciate some advice, maybe there's a simpler way to do this?
 
And another thing, does a queue handling loop take a lot of overhead, i.e. does it continually check the queue to see if it has been added to?
 
PS Bit of a wandering post!
Message 1 of 8
(2,717 Views)

Hello again,

Thanks for your post.

There are a number of methods available for calling VIs, however I would like to clarify exactly what you are trying to achieve. I understand that you wish to have controls affect the behaviour of some subVIs, but I am lacking details.

-You say that you have a number of controls on your 'VItop' front panel (on/off switch(es)), does each switch relate to a subVI, or do these switches all control one subVI?

-Is 'VIsub' present on the block diagram of 'VItop', or are you wishing to call standalone VIs?

Some info on your current code would be helpful. If you could attach the relavent VIs to your reply and note to me which VIs are top/sub, and controls that are important.

I look forward to hearing back from you. Thanks,

National Instruments | Northern California
0 Kudos
Message 2 of 8
(2,702 Views)

Hi Rob,

 

Thanks for the response.

I've included a simple example showing something like my problem, basically duplication of code to handle the same action as generated by two different sources in two different level VIs.

What's the best way round this? As I mused out loud in the previous message:

1. Let each action (i.e. pressing the on/off button in the top and sub VI) generate a user event (in this case, is it possible to generate the event in the "on/off_sub" value change and then handle the user event in the same event structure?)

2. Let each action add an item to a queue, handle this queue asynchronously in VIsub, and let the sub and top level VIs populate this queue?

This is a lack of experience on my part to get to the bottom of this one!

 

 

Message 3 of 8
(2,697 Views)

Hi Probably,

      Your event-registration solution was very clever!  Here's a less sophisticated method that doesn't require an event structure in the subVI.

Cheers.
When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 4 of 8
(2,690 Views)

Thanks for that Dynamik...it seems like a more "tricky" or clever way of doing it than dynamic event registration.

Is your way more efficient though? You are polling controls at ~4 times per second, how does this compare with the overhead of using an event structure?

 

 

0 Kudos
Message 5 of 8
(2,655 Views)

Dynamik, I've just thought about your code a bit more and I think it doesn't address the problem:

1. I don't want two buttons in Main.vi, one to close Main AND Sub and the second just to close Sub. I want one button in Main and one button in Sub, both doing the same thing in Sub.

2. Your Sub can't run as a stand alone VI, which is what I want

Maybe you could refine the idea?

Rob, I'd appreciate your feedback on my original posting.

0 Kudos
Message 6 of 8
(2,650 Views)

Hi probably,

      You're right in that the occurrance's timeout has been wired - in order to loop-periodically to poll the value passed by reference.  The reference was just an Alternate example of how to get FP activity to the sub-VI.  The occurrance, Unwired, would be sufficient - and efficient too. Smiley Happy

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 7 of 8
(2,636 Views)
For future reference, if anyone reads this (!), there are two parts to the solution:
 
1. The "value (signalling)" property
2. Multiplexed queue handling.
 
In the top level VI, open a reference to the sub VI, get a reference to the front panel and then to all the controls. Use a for loop to iterate through the controls searching the label for the one of interest (in this case on/off). Set the value(signalling) property appropriately
This allows the top VI to terminate the subVI.
 
The sub VI can have actions initiated by events using the framework asynchronous event handling with queues.
The joy of this is that queues seem to be global in nature: the top level VI can access the queue as well.
So the top level VI can perform the same actions as the sub VI by accessing the same queue.
Be sure to handle the error when the queue is closed from the top level VI while the sub VI is still handling the queue!
 
 
0 Kudos
Message 8 of 8
(2,602 Views)