LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop while loop in Event case?

Hello,

I am facing following problem. I am writing program for piezostage movement and data acquisition. I am using event structure. In one Event case I have while loop for data acquisition. This Event case occurs after pushing start button. Problem is that I don't know how to stop acquisition (before it stops itself) if user decides.

I made simple example. Instead of DAQ vis I connected only number indicator. So I want to stop the while loop by pressing STOP button. I made it by unchecking "Lock Front panel until..." But it is dirty solution I think (at least the stop button remains pressed after pushing if inner while loop is not running).
And it would be really nice to start and stop the inner while loop only with the start button, but I really don't know ho do that.

Does anybody know?
Thanks
LV 2011, Win7
0 Kudos
Message 1 of 19
(12,786 Views)
The root of your problem appears to be in misunderstanding how dataflow works. Once the inner loop starts, nothing else will run until that loop quits.

Anything which takes longer to execute than the time it takes the user to perform two actions which would be detected by the event structure should be outside the structure. Your program is an example of what happens when this rule is violated.

Look at the Producer/Consumer (Events) examples. They show two independent, parallel loops. The loop with the event structure only handles user generated events and passes messages to the other loop (your DAQ loop) via queues or other methods.

Lynn
Message 2 of 19
(12,773 Views)
It is not a good idea to block an event structure with a loop. To properly function, it needs to be ready to fire at all times. Easiest solution would be to use the outer loop for everything and place your inner loop code in the timeout case. Now the [stop] and [start] buttons simply manipulate the timeout between finite and infinite. Notice that you now can also [quit] at any time. If you don't want to allow quitting during counting, you could use a filtering event for the quit button an discard the event if it is in timeout mode.
 
Attached is a simple example.
 
I assume that your real inner while loop contains some code and a small wait statement to define the loop rate. A loop without a wait is very greedy for CPU resources.
Message 3 of 19
(12,771 Views)
Thx to both! I think I'll use Altenbachs solution. It seems to me easier and cleaner.
LV 2011, Win7
0 Kudos
Message 4 of 19
(12,750 Views)
Hello,

I would like to try johnsold suggested solution because the timeout solution is getting little messy but I can't find any mentioned examples. Could you show me some simple example? What is the best and professional solution?

thx a lot
LV 2011, Win7
0 Kudos
Message 5 of 19
(12,699 Views)
In LV 8.20 start with the File menu: New.. >> VI >> From Template >> Design Patterns >> Producer/Consumer Design Pattern (Events).

Lynn
Message 6 of 19
(12,693 Views)
I am really sorry for bothering again. I never worked with queues before and I am trying to understand them. The template and examples doesn't help in this very much. It would help me a lot if somebody could remake the StopWhileLoopMODII.vi to program using qeueus as johnsold suggested....
LV 2011, Win7
0 Kudos
Message 7 of 19
(12,687 Views)
OK, I tried to make it using notifiers. But I don't know how to stop counting = how to stop running the wile loop by pressing the stop button
LV 2011, Win7
0 Kudos
Message 8 of 19
(12,663 Views)

You are still trapping yourself in an inner loop because of dataflow issues. Use some execution highlighting to observe your code while running.

There are probably much simpler solutions, but one quick&dirty modification is shown in the attached VI. See if it makes sense. I don't understand why my timeout suggestion mentioned earlier gets too complicated for you. I don' think you can make it simpler by using notifiers and throwing much more code and extra loops at it. 😉

Message 9 of 19
(12,642 Views)
Hello Altenbach,
now everything is clear. The reason why I wanted to try this solution is that I wanted to divide the decision logic and measuring code itself. But finally I used the "timeout" suggested method. It's nicer solution.

THX very much again!
LV 2011, Win7
0 Kudos
Message 10 of 19
(12,581 Views)