LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop a buzy loop upon user input

While my program is buzy in a for/while loop, is there any way to get out of it upon a button click? 

In the vi attached I have loaded an array upon clicking the "load file" button (scanseq.txt file should be located beforehand). After loading the array I have put a "start scan" button which scans the array and displays it with some time delay 200 ms. Now I need a "stop scan" button which allows me to stop the scanning and get out of the while loop. How can I do this effectively? I guess I need not mention that I am a novice in labview.

 

Thanx,

Shantonu

Download All
0 Kudos
Message 1 of 4
(2,578 Views)

The simple solution would be to disable the "Lock Front Panel Until Event Case Completes" in your event case with the loop.


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
Message 2 of 4
(2,576 Views)

Tim's suggestion is of course only a bandaid solution. It is not recommended to put lenghty intereactive code inside event structures, and there is never a need to do so.

 

Some other suggestions:

  • There are probably easier ways to read the file. (As a first step remove the shift register and do autoindexing. No built array" needed. Same difference. As a second step, just read the entire file and then parse it. Does the number in the first row indicate the total number of following rows (i.e. redundant information) or something more complicated?)
  • The load file button is latch action, thus the terminal belongs inside its event case.
  • Do the scanning in the timeout case and use the other buttons in brief events to switch the timeout from infinite (-1) to 200ms and back when the stop button is pressed or you run out of elements. Keep the timeout in a shift register of the outer loop. No need for the inner FOR loop. (For reference, your FOR loop in the start case is also overly complicated: Index array wired to [i] is equivalent to autoindexing, now you don't even need to wire [N])
  • Why use two buttons for start and stop? You could use a single switch action button that is either on (scanning) or off (no scanning). You also currently never reset the boolean text.
Message 3 of 4
(2,553 Views)

altenbach wrote:

Some other suggestions:


Here's a quick code skeleton to get you started... It still needs work.

Message 4 of 4
(2,526 Views)