LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with start, pause and stop buttons

Hi guys,

 

Look at my attached VI.

I have three buttons. The start button works.

When I press the pause button, I want to stop right where it is and when I press again I want to continue running.

If I press the stop button, I want the program to stop and the matrix to turn off.

 

Here is what I have so far

 

 

0 Kudos
Message 1 of 5
(6,432 Views)

LabVIEW is unlike languages like Fortran, Basic, and C -- it is driven by DataFlow (meaning a function or a loop doesn't run until all of its inputs have been satisfied, and none of the Outputs are available until it finishes) and is inherently parallel in nature (functions that are not connected by data flow act as through they run simultaneously.

 

You have three buttons, Start, Stop, and Pause, and you want to be able to read these buttons (and respond to their changes) at all times.  This means that you cannot bury the reading of the buttons deep inside a loop that may not run (because if it doesn't, the buttons won't be read).  One way (not necessarily the best way) to handle this is to read the buttons at the start of your While loop.

 

Now think about the logic of what you want to happen.  If Start is false, then you don't want to do the "Process" function at all (it doesn't matter what the value of Pause is if Start is false).  If Start is True, you do "Process" depending on whether Pause is False or True.  Finally, whether or not Start is True, if Stop is True, you exit the loop.

 

Look at this example.  It has your three buttons, read at the beginning of each loop.  Note that once Start is made True, that True value is saved in a Shift Register and keeps the outer Case Statement running (so turning Start "off" does nothing).  If Pause is off, the Clock won't be updated (although the value will change -- you just won't see it).  Finally, Stop can be pressed at any time to end the whole thing.

 

And there are no Local Variables (considered by many LabVIEW programmers to be "avoided, if possible").

 

Simple 3-button Loop.png

 

Bob Schor

0 Kudos
Message 2 of 5
(6,411 Views)

Hi, thanks for your explanation. Where do I put the buttons in my code, since I have two while loops and inside for loops. 

I have tried putting the buttons in the external while loop but the pause and stop buttons dont work.

 

0 Kudos
Message 3 of 5
(6,384 Views)

@johnprogram777 wrote:

... since I have two while loops and inside for loops.  


Here's your problem! Use a single loop and a state machine architecture. Look at the design patterns that ship with LabVIEW.

Message 4 of 5
(6,371 Views)

What is it that you want to control, i.e. cause to Start, and while running Pause?  I'm assuming it is the For loop.  Whatever it is goes inside the inner-most Case Statement in my Dumbed-Down Example where I have the Clock indicator (you'll either have to "shrink" your For loop a lot or expand my Example, of course ...).

 

BS

0 Kudos
Message 5 of 5
(6,341 Views)