09-29-2014 10:52 AM
I have a while loop that simply reads data from a telnet connection. Strings come across this connection and are inserted into a queue I've called telnet.
I have a separate loop that pops elements out of this queue for processing.
What I'm finding is that there are some strings that get enqueued, but never show up to be dequeued. Below is a screenshot of the applicable part of the code:
I set a breakpoint on the enqueue element in the upper loop. I then kick off a process that sends 2 strings across the telnet connection. The upper breakpoint triggers, and I see string1 at probe #12. I continue (i.e. click Pause) and I see string2 at probe #12. Immediately after this, the breakpoint around the outer case structure hits, but probe #11 only has string 2, never string1.
Am I not handling these queues correctly?
thanks in advance
Solved! Go to Solution.
09-29-2014 11:01 AM
It's hard to debug when you can only see a portion of the code.
But your telnet queue wire is splitting off and going to a third location all the way to the right and between the two loops. What is going on with the queue wire over there? Do you have another dequeue?
09-29-2014 11:37 AM
1) There is no need for that case structure since you will never get a timeout from your queue. Your timeout is set to the default of -1 (wait forever).
2) I would recommend stopping that consumer loop with some sort of command from the queue. It is a lot cleaner than using the local variable and it will help make sure you processed all of your telnet data.
3) As RavensFan asked, where is that queue reference branch going? Another consumer loop? If so, that is your problem. Once an element is dequeued from a queue, it is gone. And there is only one FIFO. So if you have another loop using the dequeue, each loop will only get about half of the elements since the other one will dequeue the others.
09-29-2014 12:10 PM
ah, you're both right (I think)...I have a separate dequeue process for elements that I intended for a specific tab of my VI...I bet that's it...I will verify and get back with you. Thank you for your helpful suggestions.
Can you point me to an example of using a command from the queue to stop the consumer loop?
09-29-2014 12:15 PM
I guarantee that is it.
If you have two loops that both need to get the data, then you need to create two queues, one for eacy consumer loop.
Many producer/consumer examples show a queue that is made of a cluster that is an enum and a variant. An enum that has different items to tell the consumer loop what do do, and a variant that can take different types of data. In your case, you could have an enum with two items (process, stop), and a string like you have now.
09-29-2014 12:47 PM
that indeed fixed my problem. Thanks!