LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping multiple while loops with nested queues?

Hello all,

I am having trouble trying to stop my vi. that has multiple while loops with nested queues.  I have attached two versions of my code.  They both take data but the difference is that the all_stop_indicator vi. does not have my main calculation in the while loop and this vi stops fine.  When i insert my calculation (as seen in all_stop) the program will stop properly ever now and then but it mostly hangs up.  I have used the 'stopping parallel while loops with reset" and "basic queue" from the shipping vi's as examples but with no repeatable success.  You can stop the vi with the normal stop button but I am not sure if this is good coding practice as my queues are left hanging along with my while loops.  Any thoughts?

Thanks,

Azazel

LV 7.1
Windows XP
Azazel

Pentium 4, 3.6GHz, 2 GB Ram, Labview 8.5, Windows XP, PXI-5122, PCI-6259, PCI-6115
0 Kudos
Message 1 of 6
(3,972 Views)
I think you have a race condition. Depending on when each loop executes, the Stop local connected to the NOR gate may be resetting to False before the local inside the calculation loop is read.

A better approach is to use a second queue to pass the stop command. I sometimes use two queues to provided two-way communication to confirm that loop 2 has stopped before stopping loop 1, but that may not be necessary in your application. I you use this method, you can set the mechanical action of the Stop button to Latching and then you do not need the local to reset it.

Some programmers use the error caused by releasing a queue as a stop signal, but I prefer the more definite control of a stop command.

Why are you calling the Queue Status and not using any of the status outputs?

Cleaning up the wiring and using left to right data flow makes it much easier to interpret and debug your diagrams.

Lynn
Message 2 of 6
(3,967 Views)
Also, You are using the queue status as one of the potential stop signals on the bottom while loop.  Since the Obtain Queue is inside the loop, this condition will never be true.  Even if the top loop exits correctly and releases the queue, it will be reobtained the next time the bottom loop exicutes.  I recomend moving the Obtain outside the while loop.  And I heartily second all of Lynn's comments.
0 Kudos
Message 3 of 6
(3,951 Views)
Thanks for your reply Lynn.  Do you have an example with a second queue that will pass the stop command that I could work off of?  I was using the queue status when I began to code this as a way to check things to make sure I was passing the data.  I just didn't take it out now that I don't use it anymore.
Azazel

Pentium 4, 3.6GHz, 2 GB Ram, Labview 8.5, Windows XP, PXI-5122, PCI-6259, PCI-6115
0 Kudos
Message 4 of 6
(3,930 Views)
Here is a VI I put together for another purpose which stops all three loops with one stop button. It does not implement the two-way communications I mentioned earlier. For that add status queues which send "Stopped" messages from the Acquire and Save loops back to the Command loop. The Command loop stops if Stop has been pushed AND Acquire status = "Stopped" AND Save status = "Stopped".

Lynn
Message 5 of 6
(3,928 Views)
Thanks for the code Lynn, with some gentle massaging your example worked like a charm. 

Thanks again,

Azazel

Azazel

Pentium 4, 3.6GHz, 2 GB Ram, Labview 8.5, Windows XP, PXI-5122, PCI-6259, PCI-6115
0 Kudos
Message 6 of 6
(3,906 Views)