In LabVIEW, you often use while loops with a stop button. The process will keep running and looping until you press the button. It then triggers the exit condition and the loop stops.
Here is an example from my Digilent DAQ driver:
The button is inside the loop. Its state gets evaluated at each run. When you click, the process will end as expected.
Problem statement: SubVI with loop will not react on button clicks on the Front Panel
If you want to wrap this whole flow in a SubVI, you'll see that the functionality changes. To get the button on the main form, you have to create a way to connect that button to the loop's stop condition. If you create the SubVI connector (it's called a terminal) inside the loop, it will not check the button status, but keeps using the status that the button had when the SubVI was invoked. The logic within the SubVI will only see any status once, at the time that the parent flow passed the data to the SubVI. Any subsequent clicks are not passed on, so if you click the stop button, the flkow will not stop.
Solution: Use a Channel
LabVIEW has several messaging systems, from very simple to flexible / complex. I'm going for the simplest possible solution: a Channel with Tags. The button will be placed in a loop on the main flow, and send its state into the channel. The SubVI receives the messages (button state) and can react on it
Receive the Button Click
This is the loop, with the button replaced by a channel:
It's not that complex. The channel will take the message, and the channel endpoint converts it to the original type - a boolean. When something (see next section: the stop button does that) shoots a true in the channel, the loop will stop.
Send the Button Click
This is little flow that wraps the button inside a loop, so that it's constantly checked - even when flow is active inside the SubVI:
As long as the button isn't clicked, this little loop keeps running. When the user clicks the stop button, two things happen. The true value is pushed in the channel, and the loop stops.
That last action is a design decision specific to my flow. When I click the stop button, I want that the SubVI is notified, but I also want to end my program. If I would not exit the button loop, the program would keep running until terminated.
Combined Flow:
This is a snippet from a real flow. You 'll regognise the stop button, the Channel and the SubVI that will now receive click events.
side note: You'll see in this example that the button loop is wrapped inside a case condition. That's specific for my application: I only want to have a stop option if the SubVI is set to continuous loop mode. If it is set to single scan, there's no need to interrupt it. And the process would stay active in single scan mode until the user clicks the stop button. Not good. Here's what happens with the button if continuous mode is false: nothing . The loop isn't started