From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Understanding producer consumer

Solved!
Go to solution

Hi,

 

i´m trying to make first experiences with producer, consumer loops and event state machine with queues

Unfortunately my consumer loop doesn´t run as while loop.

Can someone explain it?

Download All
0 Kudos
Message 1 of 14
(3,702 Views)

For a loop to move to the next iteration, everything inside it needs to finish.

 

In your consumer loop, you dequeue first a 'State'. This presumably doesn't change very quickly - I guess you change it only once per program run.

 

Normally, you only place one dequeue node inside a loop. This is often the main part of the consumer (like you have), but you have two dequeues. Can you see the issue?


GCentral
0 Kudos
Message 2 of 14
(3,683 Views)

Two dequeues are making a collision?

What can be the solution?

Later i have more  states  and will make restart the measurement and saving to tdms vor csv

0 Kudos
Message 3 of 14
(3,665 Views)

I think if you turn on Highlight Execution (the lightbulb icon) it will be clearer than I can type.

 

That being said, your first dequeue finishes when it gets a state. Probably the first state is "1", so then the loop finishes. Then, the same (first) dequeue gets a second state, "2". Your second dequeue finishes when the first data arrives. Then, the loop finishes the second iteration. Now, your loop goes back to the first dequeue. This doesn't receive a state for a long time (until you send "3", probably) and so the second dequeue never has another chance to read more data.

 

Setting a timeout on the first dequeue might solve your problem, but it isn't a great architectural design.


GCentral
0 Kudos
Message 4 of 14
(3,663 Views)

What is the optimal design architecture to combine user input events and daq  aquisition?

0 Kudos
Message 5 of 14
(3,657 Views)

you could also have a look at user events,

essentially a queue, where you can subscribe to events with the event structure

(i didn't come up with a good way to end both loops, so i took a local variable 😞 )

 

example-producer-consumer-2014.png

 

added as vi for 2014


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 6 of 14
(3,655 Views)

The producer/consumer is a good architecture - I just meant it's not quite what you have.

 

Your consumer is trying to make some state driven decisions, and its state is controlled by a separate queue.

 

If you make your consumer only "consume", you shouldn't have a problem. At the moment, it's some queue driven state machine around a consumer, which is more tricky.

 

Like I said, I think a timeout on the first dequeue will solve the problem but it's more of a band-aid that a solution. Removing the case structure with the states might be a better choice - your first case is unnecessary (you can initialise a shift register to the blank value) and your third case is just a stop condition. You can use the error wire from the dequeue in the loop if you want to stop the consumer loop. Local variables are another option.


GCentral
0 Kudos
Message 7 of 14
(3,651 Views)

Oh.notifiers. more New themes. I will check next week what i want and need and try again.

Generally following steps should be created:

1) measuring three or more voltages

2) start/stop/reset/save data by user

3) scale  values by customer

So i thought i was on  right way

Thank you for the Moment.

 

0 Kudos
Message 8 of 14
(3,640 Views)

you were .. don't give up


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 9 of 14
(3,636 Views)

I'm attaching two VIs that I wrote some time ago when I was starting out with LabVIEW. They are extensions to the Event Driven Producer Consumer template.

 

Although large numbers of VIs are missing, hopefully you can see some information about how my event loop works and some overview of the data measurement loop.

 

I apologise for the messy front panel and I'm uncertain if I ever used the Timed Loop in the DAQ Loop VI. Previously, I remember it had a normal While loop...

 

Since then I have moved to an Actor Framework based implementation.


GCentral
Download All
0 Kudos
Message 10 of 14
(3,629 Views)