LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

detect an event from a subVI

Hi all,

 

I have read through a number of posts and knowledge base articles and I'm not sure if what I am trying to do is possible.

 

In short, I have a subVI that is always running in a while loop of the main VI. When i close the front pannel of the subVI I would like to change the status of a boolean switch in the main VI. Note that the subVI is still running even after I close it's front pannel.

 

I know it's not recommended, but I am already using several global valiables to pass several statuses ('control system running', 'front pannel visible', 'test running' etc) between the main VI and subVI.

 

When I change the boolean switch that I mentioned before to a 'true', this changes the global variable 'control system running' to 'true' so that the subVI knows to execute a certain state. When I manually close the subVI (using a stop button), the status of the global variable 'constrol system running' gets changed to 'false.' I would like for the boolean switch to be changed back to 'false' after the subVI front panel closes.

 

Any help would be appreciated. Thanks in advance.

0 Kudos
Message 1 of 12
(3,682 Views)

Generate a user event in the sub-vi which the main vi listens to.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 12
(3,659 Views)

How would I get the main VI to listen to the subVI? Get the subVI to write the user generated event to a global variable, and have the main VI continiously poll the global variable? I was hoping there would be a more efficient way than polling.

0 Kudos
Message 3 of 12
(3,650 Views)

You create a user event in the main vi and register to it. You send the event-ref as input to the sub-vi so it can generate this event. No polling.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 12
(3,645 Views)

You can also send the boolean button ref to the sub-vi and generate a value change-event on the button, which you'll need to listen to.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 12
(3,643 Views)

I would recommend a user event.  You create the user event and register for it in the main VI.  The event structure in the main VI can then be watching for the event.  You can also have whatever data you want in the user event, so it isn't just limited to the boolean.

 

So then you just pass the User Event reference into the subVI.  The subVI can then generate the event when you close the panel.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 12
(3,631 Views)

Yamaeda: What is the point in sending a reference to the boolean button to the subVI? As I understand you cannot write to a reference, and I want the information to flow from the subVI to the main VI, not vice versa.

 

Crossrulz: For the user event in the main VI, what do I use as the 'event source'? I can't access the subVI's 'STOP' button from the main VI.

0 Kudos
Message 7 of 12
(3,600 Views)

Once you understand how to fix this problem, you will also understand how to avoid using the globals to pass data out of your subVI, too.  It's not only not recommended to use globals for this purpose, it's dangerous.  You'll never know if you are reading stale data.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 12
(3,592 Views)

When you define your event you also decide which data it should work with, it could e.g. be a typedef'd enum of Commands. Thus you can send a bunch of different commands with the same event. If you want it very general you make it a cluster with 2 elements, a command enum and a variant.

The point being that the event doesn't affect your main boolean, it fires an event you catch and react to, by e.g. switching the boolean.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 12
(3,572 Views)

DarkMarc86 wrote:

Crossrulz: For the user event in the main VI, what do I use as the 'event source'? I can't access the subVI's 'STOP' button from the main VI.


I recommend going into the LabVIEW Example Finder (Help->Find Examples) and do a search for User Event.  That should get you started with using user events.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 12
(3,555 Views)