01-05-2012 10:21 AM
Hi
I have included a small VI which is purley two while loops one being a producer and the other a consumer loop. This example is to show someone this method. All I want to do is produce at quicker rate than the consumer rate and when the consumer loop sees no more elements in the queue it stops the VI.
My problem is although the conditional terminal recieves a true to exit it doesn't appear to do it. Can someone have a quick look as I am sure I have done something dumb
Solved! Go to Solution.
01-05-2012 10:45 AM
In your bottom loop, the Dequeue Element will wait and wait for an element that isn't coming. There's a few ways to deal with this, but the easiest for this VI is to simply wire a non-negative number to the Timeout of Dequeue Element. Since your data comes in sequentially with no pauses and should never be empty, a timeout of 1 should work. Give it a try.
01-05-2012 11:14 AM
Who's a clever sausage ![]()
I have included the updated VI if anyone is interested. What I do is wire the wait timer with 1s and because it adds an extra superflous element to the array, I check to see if there is a timeout in the loop and stop the element being passed if its true.
Nice!
01-05-2012 11:52 AM
You should also include a data dependency between the initialization case structure at the top and the consumer loop. If Produce Exit is True when the VI starts, it is possible that the consumer loop could run before both the producer loop and the case structure. Under these conditions the consumer loop would stop on its first iteration. I observed this happening when running with Highlight Execution on. I aborted the first run after Producer Exit was True then started it again.
Other points.
1. Pull the terminal for Number of Samples out of the loop. Use it to Initialize Array(s) of that size for the Producer and Consumer arrays. Inside the loops use Replace Array Subset rather than Insert into Array. This avoids memory reallocations as the array size increases.
2. In the timed out case in the consumer loop just wire the array straight through. No need for local variables.
3. If you put the Get Queue Status after the Dequeue, you would not get an extra iteration of the loop just to stop.
4. If you do not intend to change Number of Samples while the program is running, use for loops and the whole thing gets much simpler.
Lynn
01-06-2012 07:36 AM - edited 01-06-2012 07:43 AM
Thanks for all the tips its working a treat now and doesn't need the timeout at all. This will form part of a DAQ Vi and will need to calculate the array size before the start of each run. I will make the Producer Exit false at the end of each run as well.
I include the finished VI of anyone is interested