LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make stop button to work again in a while loop

Solved!
Go to solution

1. Stop using infinite loops.  The Abort toolbar button is only there for emergencies, not for normal use.

2. Having conditional loops inside of an Event case is a really bad idea.  In your case, you won't be able to stop that internal loop because the event case will lock the front panel until it completes.  But it won't be able to since it requires pressing the stop button and the button will be locked (unable to click it).  Maybe you should use a FOR loop instead for the data generation.


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 11 of 27
(505 Views)

@crossrulz wrote:

1. Stop using infinite loops.  The Abort toolbar button is only there for emergencies, not for normal use.

2. Having conditional loops inside of an Event case is a really bad idea.  In your case, you won't be able to stop that internal loop because the event case will lock the front panel until it completes.  But it won't be able to since it requires pressing the stop button and the button will be locked (unable to click it).  Maybe you should use a FOR loop instead for the data generation.


I don't see a conditional loop inside the event structure. What I do see is that the stop2 button is generating 2 events - and the second event is locking the front panel. The code can be made to work as is by either making the stop2 button latching (will have to move the button to where the local variable is and use a constant to stop the loop) or by making the event structure not lock the front panel. 

 

I agree with others that this is a poor structure. A state machine would definitely be a better approach. 

0 Kudos
Message 12 of 27
(498 Views)

@johntrich1971 wrote:

I don't see a conditional loop inside the event structure. What I do see is that the stop2 button is generating 2 events - and the second event is locking the front panel. 


I meant a loop with a conditional stop dependent on the GUI.  Regardless, "long" processes should generally not be performed inside of an Event Structure.  Parallel processing with a Queued Message Handler would be more appropriate in what I think the OP is attempting to do here.


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 13 of 27
(487 Views)

@crossrulz

 

I'm still not sure what you meant here.



I meant a loop with a conditional stop dependent on the GUI.  


I generally use my event structure to handle all GUI events - including the stop. I do agree that the loop within a loop thing is bad form.

 


Regardless, "long" processes should generally not be performed inside of an Event Structure. 

I agree. The for loop in the event structure should be its own state in the state machine.

 


Parallel processing with a Queued Message Handler would be more appropriate in what I think the OP is attempting to do here.

I agree here as well.

0 Kudos
Message 14 of 27
(477 Views)

@johntrich1971 wrote:

@crossrulz

I'm still not sure what you meant here..



I'm pretty sure we are at a semantic argument, but in complete agreement on principle.  So I will just end it here.


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 15 of 27
(473 Views)

I thought so to, but just wanted to make sure there wasn't something that I was missing. I'm always willing to learn from good programmers. 🙂

0 Kudos
Message 16 of 27
(469 Views)

@edmonton wrote:

State machine uses case structure in a while loop. It seams difficulty to get out of the issue.


None of your attached code resembles a state machine. Her are some tips:

  1. Please don't maximize front panel and diagram to the screen. We need to be able to look at other windows while working (front panel&diagram&LabVIEw help& web browser, etc.)
  2. You have an outer loop. It can be used for all looping and anchoring of shift registers. No need for loops inside event structures inside loops. Don't do Matryoshka code.
  3. Never have interactive code inside event cases. Your stop button cannot work, because the event locks the front panel until the event completes, but it can never complete because the front panel is locked. Catch 22. (And no, configuring the event to not lock the front panel is not a good solution).
  4. ...

 

0 Kudos
Message 17 of 27
(456 Views)

@altenbach wrote:
You have an outer loop. It can be used for all looping and anchoring of shift registers.

Here's one possible solution. Note that you only need one button for start/stop. See if it makes sense. (It can be further simplified, but start with this).

 

 

0 Kudos
Message 18 of 27
(436 Views)

You need to study up more on the state machine. For instance, you could run your generation code ONCE, check to see if the exit condition has been met (this would be the button in your current setup). If the exit condition is met then you would move to the next state. Otherwise you would return to the generation state. With a simple state machine architecture you could likely get rid of your event structure altogether.

 

You might also study up on Queued Message Handler (QMH) or Queued State Machine.

0 Kudos
Message 19 of 27
(432 Views)

Hi Dr Altenbach and all others who replied my post,

 

First, thank you all for your inputs.

 

The data generation loop represents a part of my data acquisition loop. I prefer to use a condition in a for or while loop to manually stop the data generation as a baseline period, the baseline will continue if the baseline is not stable, user can start a measurement by clicking a conditional button to stop the baseline period. I know we can use code to check if the baseline is horizontally smooth, but need a live linear regression to accurately judge the smoothness of the baseline, which is more complicated than a simple manual stop button. The conditional loop has to be in a case structure if a state machine is used. My posted code previously is not a real state machine code, just wanted to show I have to use a conditional loop.

 

I have a big application VI, and realized that a lot of optimizations can be done if a state machine  architecture is used. Currently, I have a very tight schedule to make my project working first. So, I will stay with my original idea at this movement and do optimization using state machine architecture after. Here below is a VI that I have made it work after reading all replies. The only thing is that the stop data selection button (stop2) need to be clicked twice.

 

Thank you all again.

Gu 

  

0 Kudos
Message 20 of 27
(421 Views)