LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Producer/Consumer (Events) template

I was trying a simple trial program to get a better understanding of the Producer/Consumer (Events) design template.  In it, I wanted to set up a continuous loop that was initiated by a start button and which could be terminated by a stop button.  The first thing I noticed was that the consumer loop only iterates once the way the template is set up.  So I constructed a loop inside the consumer loop.  Now the stop doesn't work.  When I highlight execution it looks like the program is waiting for my loop to stop.  Can anyone help with this?  Should I have used a different template or am I at least on the right track?  I have attached my code.

 

Thanks in advance.

0 Kudos
Message 1 of 4
(2,940 Views)

Use a timeout value for your dequeue elemt function. If it times out, then your perform the 'aquisition'. You can place the timeout value in a shift register, so it is -1 in the beginning, 0 after the start message and again -1 after the stop message.

 

There are other ways as well to design such a system...

 

Felix

Message 2 of 4
(2,934 Views)

Hi VI Joe,

 

The problem is that the while loop inside the consumer is always false. Once your program enters this inner loop, there is no way to exit out of it. Since the outter loop waits for everything to finish within itself before exiting, it is stuck waiting for the inner loop to stop. You will need to wire something to conditional terminal to stop the inner loop when the stop button is pressed.

 

A few other things about your VI:

  • You don't want to directly wire your Obtain Queue to your Release Queue. By doing so, you release reference to that queue, at the very beginning of your program.
  • What exactly are you passing between your producer and consumer? At the moment, you are passing a string that says 'element' (which is the default from our template) but you are not using it in the consumer loop. 
0 Kudos
Message 3 of 4
(2,900 Views)

O54E wrote:

Hi VI Joe,

 

The problem is that the while loop inside the consumer is always false. Once your program enters this inner loop, there is no way to exit out of it. Since the outter loop waits for everything to finish within itself before exiting, it is stuck waiting for the inner loop to stop. You will need to wire something to conditional terminal to stop the inner loop when the stop button is pressed.

 

Yes, the problem is the While Loop that runs forever inside the consumer loop. 

 

A few other things about your VI:

  • You don't want to directly wire your Obtain Queue to your Release Queue. By doing so, you release reference to that queue, at the very beginning of your program.

 

No, while I would normally wire the queue reference through the producer loop, that release queue won't occur at the beginning of the program.  Since the error wire goes through, the producer loop will have to stop first. 

 

  • What exactly are you passing between your producer and consumer? At the moment, you are passing a string that says 'element' (which is the default from our template) but you are not using it in the consumer loop. 

 

0 Kudos
Message 4 of 4
(2,894 Views)