LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping Multiple Loops Simultaneously

Simple question. So I have three loops executing simultaneously for a specific duration. The very bottom one writes a digital trigger and subsequently controls the duration of the trial that I'm performing via a for loop. The other two loops must run constantly, however, as they are part of a producer consumer architecture. What I would like to do is stop the two while loops once the for loop is finished, while still gathering data from the final event. I'll post the vi below.

 

Thanks,

Travis

0 Kudos
Message 1 of 5
(2,357 Views)

Connect the Error out wire of the Dequeue and also the enqueue primitives to the Stop Terminal of the while loop and close the Queue reference after the for loop. So when the Reference is closed, then Automatically the two loops stops.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 2 of 5
(2,353 Views)

For Producer/Consumer setups, I almost always want to process all of the data.  Since you are logging the data, I imagine you don't want to miss any either.

 

So allow your producer to stop with a button.  Once that loop is complete, you want to send some sort of command through the queue that tells the consumer to stop.  In your situation, I like to send something with a -1 as the I32.  When the consumer sees that -1 or the I32, it knows to stop.

 

The FOR loop will stop on its own, so I wouldn't worry about that one.


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
0 Kudos
Message 3 of 5
(2,342 Views)

That method (as suggested by P@Anand) will stop but it does not guarantee that the last data will be acquired and processed. In fact if the data acquisition takes more than a few milliseconds, it may assure that the last data is missed.

 

With 120 ms timeout on the Dequeue and 120 second timeout on the DAQ Assistant, you could grow old waiting for the program to stop.

 

You need to define the condtions under which stop should occur. As I understand your post you have three nominal requirements:

1. The for loop has completed.

2. The Producer loop has completed the last triggered acquisition.

3. The Consumer  loop has completed dequeuing and processing the data from the last acquisition.

4! The unstated requirement: How to handle errors?

 

One possible approach (with very limited error handling possibilities) would be to make all the loops for loops. This will only work for this special case where the Producer and Consumer each iterate once per trigger from the for loop.

 

Rather messy but workable: After the for loop ends use a notifier to tell the Producer to stop after it completes the current acquisition.  The Producer would send to the Consumer notification that the acquisition was complete. This could be done by comparing the iteration number to the Number of Pulses or by other methods. After both the Producer and Consumer lopos have stopped, then Release the queue.

 

Lynn

0 Kudos
Message 4 of 5
(2,330 Views)

I can stop it manually just fine. I'm working with weekend long trials here so the 120s timeout is what I've been using to stop it. I figured notifiers were the way to go. I'll see if I can get a revision up and running.

 

Always a pleasure, Lynn.

0 Kudos
Message 5 of 5
(2,314 Views)