LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer Consumer Architecture

Hello I want to program with the Architecture Producer-Consumer but I have some question, I have read some books and manual about this architecture but the example are simple only the structure and my question are

1.- there are two cycles: the consumer loop have a case structure and producer loop have event structure and my architecture is producer-consumer for events but i am waiting for a digital input for start the program and the program for read the daq is in the loop consumer but the consumer loop in enable when the producer is activated or has occurred events so how can read this variable in this loop or is necessary add another loop for this digital input?

 

Thanks you. 

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

Events are primarily for user interactions, but you can possibly use DAQmx events (simple example) or simpler, just poll the device.

0 Kudos
Message 2 of 5
(1,114 Views)

Open LabVIEW.  In the File menu, choose the second entry ("New ..."), expand "From Template", "Frameworks", "Design Pattern".  You will find two examples of the Producer/Consumer Design Pattern, one for Data, one for Events.

 

My only complaint about this example is the clumsy way it stops the Consumer by forcing an Error in it.  There are better ways to do this.

 

Bob Schor

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

Thank you for your answer, I Know the architecture producer-consumer(in level Basic) if the user push the button or interactive with the UI the queue send message to other loop consumer and the loop case-structure change the state but if I have a daq or tag for plc inside the routine the Labview where I can add the program for the data acquisition if I want to integrate it all, this pulse the daq or plc I need that modify the consumer loop for execute something rutine, I think to add other while loop as request but I don't know if is the solution only for read the pulse external.

 

 

Thanks. 

0 Kudos
Message 4 of 5
(1,039 Views)

I'm sorry, but I don't understand what you are asking.  Let me see if I can explain something about the Producer/Consumer loop for Data Acquisition.

 

In Data Acquisition, you have a process that "Produces Data" (say, by asking for 1000 samples at 1 kHz) running in a loop.  Since the Producer has to run at some minimum rate to avoid losing data, you don't want to put inside the same loop processing code that might "take too much time" (for example, doing FFTs, writing to Spreadsheets, etc.).

 

In a well-designed Producer loop, there should be no problem capturing the data and putting it on a Queue.  The Consumer waits on the Queue, doing nothing if there's nothing in the Queue.  As data come in, they are processed as fast as the Consumer can run.  If, perchance, some loops take a little more time, so that more items are put on the Queue while the Consumer is processing, it should not matter, as the Queue is designed to "expand and contract" as needed (though you can specify a fixed length for the Queue, in which case a Full Queue will "block" the Producer from putting more stuff on the Queue, unless the Queue is designated as a "Lossy Queue", but let's not go there now ...).

 

So as long as, on average, the Consumer can "consume" as fast as the Producer can "produce", you should be in no trouble.  Note that most Producers spend most of their time "Waiting for Data" (the Event Loop "waits for an Event", a DAQmx Producer loop "waits for a Buffer to be full"), so most of the CPU time is available to the Consumer.

 

Bob Schor

0 Kudos
Message 5 of 5
(999 Views)