LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

why do i get error 1122 at dequeue element in consumer loop when i hit stop button

Solved!
Go to solution

when i hit stop button from vi, the producer loop stops, the consumer loop gets an error and stops without reading all the elements and then my check queue status loop continues to run becuase it never goes to 0.

 

Any help?

 

 

 



-Matt
0 Kudos
Message 1 of 9
(5,364 Views)

This usually happens when shutting down the Queue.  Here are some suggestions:

  • Don't put any Wait in your Consumer loop (the top loop) -- let the Dequeue Element be the "clock".  
  • Instead, put a 100-msec Timeout on the Dequeue that drives a Case Statement whose True Case (Timed Out) is "Do Nothing" (to prevent the Consumer from "getting stuck").

Bob Schor

0 Kudos
Message 2 of 9
(5,355 Views)

OK.

 

I can impliment that, but then how do i end the consumer loop?



-Matt
0 Kudos
Message 3 of 9
(5,345 Views)

Refnum became invalid.  This would be a time to run with highlight execution turned on.  It could be your file causing the issue.

 

Your consumer should not have a wait in it at all.  Let the consumer run as fast as it can.  If it is faster than the producer, then it sits there and sleeps at the Dequeue until there are elements to process.

 

The producer loop should probably only have a wait in the case where there is no data at the port, just in case your instrument decides to send a ton of data at you.  And 100ms seems like a large wait for instrument communications.  Something more like 10ms would be better.

 

You should not be destroying the queue to stop your consumer loop.  You should supply a command of some type to tell the consumer loop when it should shut down.  The consumer can then destroy the queue.  In this situation, I would send something like "STOP" in the queue to be used as a stop command.  So send the stop command instead of using the polling for queue elements remaining and let the consumer loop destroy the queue.


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 4 of 9
(5,339 Views)

When you destroy the Queue, the Consumer loop will sooner-or-later (within the Timeout of the Dequeue) try to do another Dequeue, which will generate an Error that is wired to the While's Stop indicator, stopping the Consumer.

0 Kudos
Message 5 of 9
(5,334 Views)

Cruz,

 

i believe this is what you were talking about.  If youve got any advice or pointers for this VI please let me know.

 

Thanks,

 

Matt



-Matt
0 Kudos
Message 6 of 9
(5,321 Views)

I think this is expected behaviour. I don't have LV here, so this is off the top of my head, but doesn't LabVIEW's producer/consumer template rely on this error to stop the consumer loop when the producer loop is exited and the queue is released? All you need to do is catch that specific error and ignore it at the end of your program.

0 Kudos
Message 7 of 9
(5,267 Views)

I think you may be right, essentially thats what i ended up doing.  I had connected the error wire to the stop in the consumer loop, so the error came before all the elements had been dequeued, so i just ignored it and input a command to stop the consumer loop.



-Matt
0 Kudos
Message 8 of 9
(5,254 Views)
Solution
Accepted by topic author Wolleee

matt198717 wrote:

i believe this is what you were talking about.  If youve got any advice or pointers for this VI please let me know.


1. Your consumer loop should be using the Dequeue Elements.

2. Your consumer loop should actually be releasing the queue in the STOP case.

3. There is also no need for the polling to see how many elements are left in the queue.

4. Your wait in the producer loop shold only be when there is no data in the buffer (you have it in the wrong case).

5. Do not use the value from the Bytes At Port to tell the VISA Read how many bytes to read.  You tell the VISA Read to read more bytes than you would ever expect the message to be.  Let the termination character stop the read.

6. Use a VISA read right after intializing your port to sync up your messages.


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 9 of 9
(5,245 Views)