LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle event from subVI in the main VI?

Hello, I'm doing some measurement. During the measurement I want the user to see some activity dialog - that's easy to do. Before the measurement starts I dynamically run VI (EX_Progress.vi) that shows some activity and then I do the measurement (in my example simulated by random number generation) . After the measurement is done (or error occurs) I can dynamically abort the activity indicator. But on the other hand I want to give to the user chance to abort the measurement manually via the activity dialog by STOP button. There are some ways how to do it via global variable and check every iteration in the main VI it's state but isn't there some better way? Would be nice to run event in the main VI when the user pushes the STOP button in the Progress VI. Is it possible to achieve this using register events? I tried but don't really now how I'm not familiar with this technique. Thanks in advance

Message Edited by ceties on 11-26-2007 01:34 PM
LV 2011, Win7
0 Kudos
Message 1 of 6
(3,486 Views)
This is indeed very possible. Here's another forum post where some of this was discussed in detail. My post (Message 9) gives an example. Hope this helps!


Message Edited by Jarrod S. on 11-26-2007 01:46 PM
Jarrod S.
National Instruments
Message 2 of 6
(3,477 Views)
Hey Jarrod, thanks a lot for your fast reply. I know about this aproach but my problem is that I have the opposite sittuation. I want to handle button push from the subVI in the mainVI. In addition I call the subVI dynamicaly so I can't pass the reference :( Or am I just missing something? Edit: I tried to run the subVI in the beginning to get the reference. But then the Reg Events node sends error - the front panel is not open

Message Edited by ceties on 11-26-2007 02:25 PM
LV 2011, Win7
0 Kudos
Message 3 of 6
(3,459 Views)
Ah, I see. Yes, that's possible too. You're probably going to want to learn about something called User Events, which also uses the Register Events node you've seen. The idea will be that you will provide a communication mechanism for the subVI to send an event to the main VI. Then you'll do this every time there's a button press in the subVI. It takes a little getting used to, but it's a very valuable skill to have.

I'll post a quick example here in a bit that demonstrates this, and how to send data to a VI you launch dynamically.
Jarrod S.
National Instruments
0 Kudos
Message 4 of 6
(3,451 Views)
OK, here's an example using User Events. It doesn't directly have the main VI listen for the Button press event in the subVI. Instead, it has the main VI listen for a custom User Event that the subVI fires every time there's a button press. You could theoretically directly listen to the button press directly from the Main VI, but you would have to somehow get that control's reference to the main VI. That would require storing a copy of it in a global or some such method. This method I will show here is very common and is definitely worth learning.

For more info on User Events, refer to the LabVIEW help. You can learn more by clicking any of the User Event VIs and selecting Help from the shortcut menu.

(I didn't set the subVIs front panel to open automatically, so you'll have to do that yourself to see anything from this demo...)


Message Edited by Jarrod S. on 11-26-2007 02:51 PM
Jarrod S.
National Instruments
Message 5 of 6
(3,445 Views)
Thanks a lot Jarrod! If you aren't a teacher I have to say that you would be pretty good one:) Your example is easy to understand. Thanks a lot and have a nice day!
LV 2011, Win7
Message 6 of 6
(3,418 Views)