LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Queues: How do I make several consumers all use all data from one producer? And is this wise?

Hello I am new to labview,

Read trough the fundamentals and the getting started and a lot of examples. The problem is I saw an example explaining how to use a queue with one (producer)while loop sampling data and several while loops (consumers) using the *same* data parallel.  I can't find this example anymore though I searched for hours.

 The thing I want to do is: the ADC/DAQ-card must sample data (producer) and consumer 1 must save the data at the same time. Also at the same time consumer 2 must show a graph. And at the same time the consumer 3 must process the data (is the temp too high voltage too low?).
I want to make separate blocks for separate functions (consumers and producer), like one function for saving data, one function for processing, etc. This to enhance the readability etc.

So the questions are:
(1) If I put an enqueue in one (producer)while loop and a dequeue in each of the consumer while loops, will all consumer while loops receive all data? Or will the data be divided among the 3 while loops?
(2) Is this the normal way to code in Labview or is another programming structure a better way to go?


Thanks in advance for the effort.

0 Kudos
Message 1 of 8
(2,907 Views)

1.  No the data will be divided between the 3 consumer loops.  Not necessarily evenly divided either.  If one loop runs fast than the other two, it might get more than 1/3 of the queue elements.

2.  If you want all 3 loops to get the same data, create 3 separate queues and place the same data in all 3 queues.  All 3 consumer loops will get the data and work on it at their own pace.

Message 2 of 8
(2,899 Views)

Another option for this situation is to use an Action Engine.  You Write to it in the Producer and Read from it as many places as you need without losing the data.  Look at Ben's Nugget on Action Engines as a starting place to learn about this useful technique.

 

Lynn 

Message 3 of 8
(2,893 Views)

Hello gimmie code gimmie,,

 

Herewith a simple example. You will find the DADS and the Plotting in the producer loop, when you the loop is awaiting for the sample there will be enough time to plot the data. In the consumer depends on the data rate of the producer loop, so there will be time to do some processing and write the data to (binary) file.

 

As you wish you can adjust this example to your needs.

 

Regards Casper

Message Edited by CasperK on 07-09-2009 04:24 AM
0 Kudos
Message 4 of 8
(2,851 Views)

I can think of a solution but it may be overly complicated. 🙂

 

Basically, the producer loop enqueues elements into a single queue. Each consumer loop then uses the 'Preview Queue Element' to look at the next element in the queue without removing it.

 

The rendezvous then synchronise the loops.

 

I've included a simple picture outlining my thought - i don't know how feasable it is though since it would mean that all three consumer loops would execute (although at different speeds) the same number of times.

 

 

Message Edited by James Mamakos on 07-09-2009 10:53 AM


Never say "Oops." Always say "Ah, interesting!"

0 Kudos
Message 5 of 8
(2,841 Views)

Use User Events instead of Queues.

 

Events can be registered for n consumers and every data piece sent is sent to EACH and each one can work on the data at their own speed.

 

Shane.

0 Kudos
Message 6 of 8
(2,831 Views)
Thank you very much for the answers. I read trough your replies and it helped a lot. Thanks!
0 Kudos
Message 7 of 8
(2,724 Views)

I would concider a hibrid version using both queues and an Action Engine.

 

Use a unique queue for display and logging. Both of them can fall behind and catch up later.

 

To enusre the Safety checks are implemented as quickly as possible, I'd concider using an AE in the DAQ function (producer) to check the conditions and act accordingly if required.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 8
(2,718 Views)