LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

enqueued element won't dequeue

Solved!
Go to solution

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:

queue.png

 

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

0 Kudos
Message 1 of 6
(3,238 Views)
Solution
Accepted by topic author bmishoe

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?

Message 2 of 6
(3,237 Views)

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.


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
Message 3 of 6
(3,208 Views)

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?

0 Kudos
Message 4 of 6
(3,190 Views)

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.

Message 5 of 6
(3,185 Views)

that indeed fixed my problem.  Thanks!

0 Kudos
Message 6 of 6
(3,171 Views)