09-26-2012 08:57 AM
Learning more about queues, can someone look at this example and explain why the string never gets dequeued? I followed other examples, but this doesn't work for some reason.
Thanks...
Solved! Go to Solution.
09-26-2012 09:05 AM - edited 09-26-2012 09:07 AM
Make the 1 case default. It is very unlikey there will be exactly 1 element in the queue. Plus, you are looking at the wrong value in the queue status. You should be looking at the # Elements in Queue (on bottom of Queue Status).
09-26-2012 09:12 AM
Thanks. I should problably use the number of elements in the queue node and wire that to a > 0 condition into a true/false conditional box instead too. Thanks a lot.
09-26-2012 09:15 AM
Looking at the example a little more, it would be better to not check the queue status. Just use a Dequeue with a timeout. If you didn't have a timeout, write to the string. You should also be releasing the queue.
Attached is an edited version of your VI.
09-26-2012 09:37 AM
There are several things which create problems with your example.
1. The # pending remove is not the appropriate signal to use for the case structure. Read the detailed help and see if you can figure why it is always zero. Use the # elements in Queue instead.
2. So that you do not need to manually reset the stop button, use another local variable outside the lower loop to reset it to False after the loops stop. Better would be to use a queue or notifier to send the stop command form one loop to the other. Then you can use the Latch mechanical action to reset the button after it is read.
3. If your loops do not run at exactly the same rate, you may have problems with never dequeuing data. This is particularly true if the dequeue loop is slower than the enqueue loop. One of the ideas of the queue as a data transfer mechanism is that it allows the loops to run at different rates. If they are going to run at exactly the same rate, you might as well just have one loop. Change the case to be "1.." rather than "1" so that it will run if the # elements in queue is >= 1. If the number is > 1, you may want to shorten the loop time for the next iteration to read the data faster.
Run your VI with Execution Highlighting turned on to see what is going on. Or put indicators or Probes at various points in the VI to watch the behavior.
Lynn