LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

dynamic event registration + open vi reference = mass confusion! - please help

Hi all,
    I would like to do something fairly simple -- I think!   I have attached the relevant code below.

I have 2 parallel while loops in the mainVI.  An event structure is in one of those loops.  What I want is to have an event that fires only when the subVI is active.  When the subVI is active, I will add code to the corresponding event which I want to happen when that subVI is active (i'll expand on this part below).

Thus far... I think this is definitely reasonable...  the next part - I'm not so sure about.

when subVI is active, this what I want the corresponding code to do.  I want to create(or open??) a reference to an indicator (an array in the example) in the subVI.  Every time there is a change  to the indicator in the subVI, I want have a value(signaling) event occur in mainVI which can be handled by a separate case in the event structure.

I know that last part is a bit confusing, and I know there are other ways to do it.  i.e.  I could just pass a control refnum for an array containted in the mainVI to the subVI and have that update accordingly, but I'm experimenting with getting data from a subVI without explicitly creating a local control and wiring a ctrl refnum to the subVI.

ideas...? suggestions?
thanks
-z

p.s. - the code posted below does not work b/c I couldn't figure out how to wire a reference of subVI to the register event case because subVI isn't open until it is called from mainVI.
0 Kudos
Message 1 of 5
(3,299 Views)

here is a start on how to do it.  There are different ways but I think this will send you down the right path.  One thing to not is that the value changed event is fired in only 2 cases.  1. The user changed the control on the front panel.  2. The Value (signaling) property was set.  I point this out because a change to the indicator from the Blcok Diagram, ie you wired a new value in, will NOT cause the value changed event to fire.  For that reason I set the Value Signaling, and there is no reason to then set the terminal but I just left it.

0 Kudos
Message 2 of 5
(3,277 Views)
Hi Evan,
    That was very helpful.  Unfortunately, I seem to have found a bit of a problem that perhaps you didn't encounter when you wrote that code.  Unfortunately, the register events throws an error if the the subVI isn't open the first time that regEvents is called.  For example... if you just open mainVI and run it, an error occurs (I think it's 1027).  I think this makes sense since the control doesn't actually exist (for lack of a better description) unless the subVI is running.  The only way I could figure out how to get around this was to open the subVI as hidden before teh 'reg events' call, register, and then close it during the initial sequence.  unfortunately, i think this is sort of ugly.  What I would like is a way to register this event the first time the button is pressed, but after the subVI has been called so that it's already open and no error is thrown.

does this make sense?
thanks
-z   
0 Kudos
Message 3 of 5
(3,247 Views)
Hi Evan,
    That was very helpful.  Unfortunately, I seem to have found a bit of a problem that perhaps you didn't encounter when you wrote that code.  Unfortunately, the register events throws an error if the the subVI isn't open the first time that regEvents is called.  For example... if you just open mainVI and run it, an error occurs (I think it's 1027).  I think this makes sense since the control doesn't actually exist (for lack of a better description) unless the subVI is running.  The only way I could figure out how to get around this was to open the subVI as hidden before teh 'reg events' call, register, and then close it during the initial sequence.  unfortunately, i think this is sort of ugly.  What I would like is a way to register this event the first time the button is pressed, but after the subVI has been called so that it's already open and no error is thrown.

does this make sense?
thanks
-z   
0 Kudos
Message 4 of 5
(3,245 Views)
Take a look at this change.  I feel that there are some better ways to do this but I am not sure how this actually works into your app.  For example you may be able to do this with 1 loop rather than the 2. 
0 Kudos
Message 5 of 5
(3,226 Views)