Discussion:
Queue Preventing Loop From Running
(too old to reply)
Pawel Kowalski
2008-08-11 18:40:08 UTC
Permalink
Hello,
 
I am experimenting with the best way to stop 2 different while loops running with different timing. I figured I would try a queue out. However, for some reason when I did this the bottom loop stopped running altogether while the top loop runs fine. Can anyone explain to me why this is happeneing? I'm not aware of there being a data dependancy. And if someone has a better way of stopping 2 loops running at different rates I'd love to hear it. Thank you.


lab_view_example.jpg:
Loading Image...
Pawel Kowalski
2008-08-11 18:40:09 UTC
Permalink
Actually I can't believe I didn't notice this but "element" seems to be constantly true which would explain why the loop isn't running. Why is that?
 
Edit: actually it doesnt look the value is ture, it just never changes since the loop doesnt run.Message Edited by Pawel Kowalski on 08-11-2008 01:30 PMMessage Edited by Pawel Kowalski on 08-11-2008 01:31 PM
Pawel Kowalski
2008-08-11 18:40:10 UTC
Permalink
Cool, that works. So the dequeue function works like the wait function?
altenbach
2008-08-11 18:40:14 UTC
Permalink
Pawel Kowalski wrote:
Cool, that works. So the dequeue function works like the wait function?


Not really, because if the upper loop places an element in the queue, the wait is interrupted immediately. It really depends what kind of behavior you want.
 
You should attach your VI instead of a picture, it will help us to quicker troubleshoot the issues. You should also play with execution highlighting.
 
Do a forum search for e.g. "dataflow". It is important to understand its basic ideas. 
 
In this particular case, the queue is overkill and only complicates the code. I would use event structures (or even local variables to communicate). You also forgot error handling and you're not releasing the queue at the end.
Pawel Kowalski
2008-08-11 19:10:06 UTC
Permalink
Thanks for the help. I don't really have any real code right now, I am doing this since this problem has driven me nuts in the past and since I have some free time on my hands I wanted to experiment. I know I could use local variables and have done so in the past but if I have 2 different loops running at different timing the behavior of the stop button seems to be very awkward. Not only that if there is a wait time on the loop it seems to have to wait for that wait time to finish before it stops the other loop, some thing I don't really want since I would like the program to stop instantly. This is why I figured using a queue might work well in this situation. Do you have any good examples of using an event structure to stop the program?
 
After thinking about this a little more the fact the loop wouldn't run does make sense. The loop will only run again once all the code in it has executed. Since the queue is just sitting there and waiting the loop thinks it is still executing.
 

I will certainly clean up the code in a production enviroment, including using the error clusters and releasing the queue at the end. Thanks again.Message Edited by Pawel Kowalski on 08-11-2008 01:52 PM
altenbach
2008-08-11 18:40:09 UTC
Permalink
Instead of using a delay of 3000 ms, try to set the timeout ouf the dequeue node to 3000ms.
 
RIght now, it waits forever until the upper loop places an element in the queue.
 
PaulG.
2008-08-11 18:40:11 UTC
Permalink
In LabVIEW check under File > New > From Template > Frameworks > Design Patterns > Master Slave Design Pattern.
 
That gives you an example of stopping two while loops.
Loading...