LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer consumer architecture problem

I am trying to understand the use of producer consumer architecture. When I tried the architecture I am facing some issues.

The program is I am sending a random number to the enqueue element in the producer loop and I am viewing the value in the waveform chart in the consumer loop. but after stopping my producer loop I has made a condition that the consumer loop should stop only when all the values are displayed in the chart. But the issue is after all the values are displayed in my chart my queue will be released but I am getting one more value as 0 from my Dequeue element function but in producer loop there is no value like that. I have attached my Vi with this can anyone please explain this.

0 Kudos
Message 1 of 5
(1,958 Views)

Hi Joe,

 

after all the values are displayed in my chart my queue will be released but I am getting one more value as 0 from my Dequeue element function but in producer loop there is no value like that.

Because of your missing error handling when reading from the queue!

The last value is the default value for the datatype of the queue: QueueRead will stop waiting when the queue is killed by the producer, resulting in an error in the error output and the default value in the data output. To avoid displaying that default value you need to place a case structure around your "consumer loop" terminal…

 

Btw. making the consumer slower than the producer is bad design.

It also bad design to kill the queue: use a signalling mechanism instead to stop the consumer gracefully. Just yesterday there was a discussion about this topic…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(1,930 Views)

But for my application My consumer loop should log the data in slower rate, then my consumer should run slowly.

Do you have any examples for that

If you have any Vi can you please send

0 Kudos
Message 3 of 5
(1,914 Views)

@JoelJebaraj wrote:

But for my application My consumer loop should log the data in slower rate, then my consumer should run slowly.

Do you have any examples for that

If you have any Vi can you please send


If I understand that correctly, you don't want a producer consumer (Lossless data transmission) but a "Master-Slave" Pattern (Lossy Data) which would use a similar pair of loops but uses a Notifier instead of a Queue.

Alternately you COULD use a Queue and wire a 1 to the "max queue size" input on Obtain Queue- but I'd prefer the notifier 

Notifier.png


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 5
(1,905 Views)

Mostly rehashing what has already been said...

 

1. A consumer should run as fast as possible, only being limited by the rate that the data is coming in.  This means it should not have a Wait and definitely not a button.  All those do is cause the queue to fill up with more and more data.

2. If you want to process all of the data, then DO NOT have the producer destroy the queue.  I am of the opinion that the consumer should be in full control of the queue.  What this means you is you should have some sentinel of some sort (turn the data type into a cluster with a Boolean and your value, use NaN as the stop condition, etc).  When you detect the sentinel, the the consumer then stops and destroys the queue.

3. You state that you want to log at a slower rate.  Does this mean you only want every X samples logged?  Or an average over the X samples?  Either way, it is just some simple code with some shift registers to keep track of your counts and conditionally perform the math and/or write to the chart.

 

Not showing 3...


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
Download All
Message 5 of 5
(1,863 Views)