LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Queue between acquisition and processing loop

Hi guys,

 

I would like to acquire and process data in parallel. I have bought a queue between the two loops. The problem is that the program is really instable. Sometimes it looks working and some time you see the processing loop doesn't have any iteration. Could you please help me to understand where is the problem? I have bought a simplefied .vi to better focus the problem.

 

Thank you in advance, this probably simple problem is making me crazy.

 

j_crash_0-1611154149550.png

 

0 Kudos
Message 1 of 9
(1,559 Views)

Your simplified example runs fine here.  Well, mostly fine.  Loop termination isn't handled well, but that wasn't the issue you were asking about.   I see the processing loop iterate just fine whenever the GUI boolean is True, and pause when it's False as it gets stuck waiting at the Dequeue with a (default) infinite timeout.

 

Can you explain your question more completely?  Exactly what problem(s) do you have with this example code?

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 2 of 9
(1,548 Views)

You are not stopping your consumer loop properly. Since you have no timeout on the Dequeue, the consumer loop will wait forever. Even though you hit the stop button and terminated the producer loop, your consumer loop is still waiting on the queue and therefor does not stop. For any producer/consumer framework I prefer to use a message oriented approach for the data. Rather than passed the raw data, I would use a cluster with a message ID and data (a variant). This way you can send a Stop message to the consumer which will allow it to dequeue the data and stop. this makes it easier to expand your functionality if needed. The there way to ensure that the loop will exit is to destroy the queue immediately when exiting your producer loop. However, then you will need to use a case structure in your consumer to catch the error when the queue gets destroyed. Again, this will allow your consumer loop to exit.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 3 of 9
(1,546 Views)

You definitely should be using some type of message to tell the consumer loop to stop instead of relying on a local variable.  In this situation, I have used an empty array as a sentinel to tell the consumer to stop.  The consumer should then destroy the queue.

 

For a more robust setup here, you might want to look into using Channel Wires.  The Channel Wires have the added benefit of being able to insert a "final value" (or something similar) flag, a much better way to tell the loop to stop.


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
(1,532 Views)

Remove the local variable and connect the error wire instead. Move the destroy queue to after the top loop.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 9
(1,526 Views)

Hi Kevin,

 

thank you for your reply.

 

The problem is that sometimes it doesn't work. I think it is caused by the fact that the stop does not work properly and when the .vi is relaunched the program sometimes fails to build a queue. 

 

I've tried to build the stop according to the example but it doesn't work. Can you help me to understand why?

 

Thank you in advance.

 

P.s. attached the screenshot of the example from Labview.

 

 
 

example.jpg

 

 

0 Kudos
Message 6 of 9
(1,521 Views)

@Yamaeda wrote:

Remove the local variable and connect the error wire instead. Move the destroy queue to after the top loop.


I have the opinion that this is a HORRIBLE idea.  If you destroy the queue while there are more samples in the queue, then you lost all of that data that still has to be processed.  As previously stated, we need to send a flag of some sort telling the consumer that it has processed the last data point.


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
0 Kudos
Message 7 of 9
(1,504 Views)

@crossrulz wrote:

For a more robust setup here, you might want to look into using Channel Wires.  The Channel Wires have the added benefit of being able to insert a "final value" (or something similar) flag, a much better way to tell the loop to stop.


And here's the Producer-Consumer Design using the Stream Channel Wire.  Note there's not even a place for an Error Wire in this design!  The top (Producer) loop has a "Save" button which is wired to the "Element Valid?" input of the Stream Writer, so no Case Statement is needed to turn on and off the flow of data.  Similarly, the Stop button that ends the Producer Loop is also wired to the "Last Element?" input of the Stream Writer to tell the Consumer when the Producer has finished.

 

I have placed the Producer Loop below the Consumer Loop, and have "snaked" the Channel so that it comes into the Consumer Loop from the left.  Note that you could also place them side-by-side, with a very short Channel going out from the Producer and in to the Consumer.  Note that the Case Statement removed from the Producer has appeared in the Consumer -- if "Element Valid?" is false, it is not added to the Output Array.  Furthermore, the "Last Element?" output is used to stop the Consumer Loop.  Finally, the Stream is created by the Stream Reader, and is released when Last Element? is asserted. 

Producer-Consumer with Streams.png

 

Bob Schor

0 Kudos
Message 8 of 9
(1,503 Views)

Thank you all for your help.

 

Many interessting solutions.

 

I've chosen the solution of "crossrulz", (genial trick) and I found interessting the solution of the main stream. 

 

Thanks anyway to everyone for your time and your promptness.

 

Un saluto,

crash

 

0 Kudos
Message 9 of 9
(1,488 Views)