LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer Consumer update time

Hi NI Community,

 

I'm setting up a three loop (1 producer, 2 consumers) program. The producer loop collects data then sends data to two other consumer loops for data processing and plotting. The problem I'm seeing is my producer loop has an update time of 100ms so the data that gets sends to the other loops does not look continuous. I attached the image below. As you can see, the producer loop's data looks smooth but the other 2 loops look like dash lines. How do we make it so other loops also look continuous? I also attached the code in this post. producer consumer.PNG

 

Thank you!

0 Kudos
Message 1 of 3
(1,053 Views)

You do not understand the purpose of the Producer/Consumer Design, nor understand how Queues work.

 

The Producer Loop (for your example) should consist of the DAQmx Read and an Enqueue function.  It should not include any data processing, and especially should not include a Plot (which is the entire reason you are using Producer/Consumer in the first place!).

 

When you dequeue something, you remove it from the Queue.  So if you take "smooth data" and send it to two dequeuing "Consumer" Loops, then when one loop removes data from the Queue to process, that data will not be present in the second Queue, so your two "Consumers" will each show some subset of the data, but neither will have the entire data set.

 

If you (for some strange reason) to send the same data to two Consumers, you need two Queues.  You can either have the Producer enqueue the data into two separate Queues, or (a method I've used) you can use Q1 to send the data from Producer to Consumer 1, dequeue in Consumer 1 and send the data to, say, a Plot and also enqueue it in a second Queue, Q2, which goes to your second Consumer.  Note that this makes Consumer 1 become a second Producer 2.

 

Model 1:  P1 puts data on Q1 (to C1) and Q2 (to C2).  C1 processes Data, and C2 processes Data.

Model 2:  P1 puts data on Q1 (to C1).  C1 puts data on Q2 (to C2).  C1 processes Data, and C2 processes Data.

 

In my case of one Producer and two Consumers, the Producer was a DAQ system, C1 (and P2) was a plotting routine, and C2 was a Data Streaming routine to save the data to disk.

 

Bob Schor

Message 2 of 3
(1,024 Views)

Hi Bob,

 

Thank you for your response! This is really helpful. 

 

Yes, you are right that I should not have anything in my producer loop. I just put a waveform there to demonstrate what I was trying to explain. I'm going to remove it in the final program. I have the plot loop to plot items, and another loop to process data or to save data to TDMS.

 

Your explanation makes senses! I will try that right now. 

 

Thank you!

0 Kudos
Message 3 of 3
(1,018 Views)