From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wait for queue element and then flush queue

Solved!
Go to solution

I'm working with a producer consumer design to read data off a DAQ and then process in a separate loop (number crunch, update plots, write results to file).  The data acquisition rate can be highly variable, so there are some cases where the producer fills the queue faster than the consumer can handle it (one element at a time).  So I switched the consumer loop to use flush queue instead of dequeue and batch process all the recent elements.  This works well and allows much faster operation.  The downside I've noticed is that, when the producer loop is running much slower than the consumer loop, flush queue generates executes with no data to pass.

 

What I'm wondering is if there is any way to wait for queue elements (as dequeue element does) and then flush the queue, without using too much overhead.  I imagine I could use the queue status in a loop and then flush the queue, but I'm guessing this would lead to a significant overhead when I'm running at higher speeds.

 

The only other solution I can think of is to put the file writing in a third loop with another queue since it is probably what is slowing down the main consumer loop and then put the main consumer loop back to processing one element at a time.  But it seems like there should be a simpler way to do this.

 

Any thoughts, suggestions, or generally better ways to handle this?

 

Thanks,

Tim

0 Kudos
Message 1 of 5
(4,120 Views)
Solution
Accepted by topic author PolymerTim3

Use Preview Queue, and don't wire the element output. It has a timeout, like Dequeue Element. Put Flush Queue immediately after it. Or, use Dequeue followed by Flush Queue, and add the element output from Dequeue onto the array output from Flush Queue.

Message 2 of 5
(4,112 Views)

@nathand wrote:

Use Preview Queue, and don't wire the element output. It has a timeout, like Dequeue Element. Put Flush Queue immediately after it. Or, use Dequeue followed by Flush Queue, and add the element output from Dequeue onto the array output from Flush Queue.


That sounds like just what I was looking for.  I'll have to wait till Monday to try them out, but either of those should work.

 

Thanks a million!

 

-Tim

0 Kudos
Message 3 of 5
(4,074 Views)

Hi, I have similar problem.

Could you please explain does this mean


@nathand wrote:

 and add the element output from Dequeue onto the array output from Flush Queue.



as shown in snippet or something else ?

0 Kudos
Message 4 of 5
(3,050 Views)

That looks exactly like what NathanD was explaining.

0 Kudos
Message 5 of 5
(3,045 Views)