08-16-2011 09:59 PM
Hello forum,
I am using Producer-Consumer design pattern for data acquisition. While my producer loop acquires data, consumer loop does,analyze, display and save the data. One thing I would like to do is to pass a data from the consumer loop to producer loop. This is for a taring function, where my consumer loop would analyze the acquired data for n-point average and pass the value to produced loop where, this value is subtracted from the acquired data. How would I pass a data from Consumer to Producer?
Many thanks to all,
Zacharia
08-16-2011 10:07 PM
You can use a local variable.
08-16-2011 10:31 PM
Does the producer loop really need to get that value back? If the consumer loop is the one doing the analysis, should it just hold on to the tare value and use that as part of the analysis? If you send it back to the producer, now you've just placed some of the analysis responsibility back there.
Other alternatives to a local variable:
A function global variable or action engine.
You can use a notifier to send the data back to the producer.
Possibly some other ideas.......
08-17-2011 08:04 AM
Some of my dual loop systems pass data one way and commands or status messages the other way. When I need to do this I use a pair of queues, one for each direction.
Lynn
08-17-2011 08:39 AM
@Ravens Fan wrote:
Does the producer loop really need to get that value back? If the consumer loop is the one doing the analysis, should it just hold on to the tare value and use that as part of the analysis? If you send it back to the producer, now you've just placed some of the analysis responsibility back there.
Other alternatives to a local variable:
A function global variable or action engine.
You can use a notifier to send the data back to the producer.
Possibly some other ideas.......
Yeah, exactly this crossed my mind after thinking for a while. In that way I still keep the DAQ loop free of any analysis. I assume, this is best option currently for me. Using a notifier to send the data back to producer seems a good option too, but i have no experience in using them.
Thank you so much!!! Ravens Fane and others!
08-17-2011 09:28 AM
@johnsold wrote:
Some of my dual loop systems pass data one way and commands or status messages the other way. When I need to do this I use a pair of queues, one for each direction.
Lynn
Hmmm. I thought of this but I couldn't get it to work. It sounded like a good idea. It just locked up the program. The fp panel became unresponsive. I had to use the Abort Execution button to stop it. Could you provide a sample of this? Just curious. Thanks.
08-17-2011 09:45 AM
I do not have a simple example available at the moment. If you post your program whihc locks up,perhaps I could modify that or at least figure out why it behaves that way.
Lynn
08-17-2011 09:56 AM
I will get back with you later this afternoon. Thanks.
08-17-2011 10:06 AM
@MoReese wrote:
@johnsold wrote:
Some of my dual loop systems pass data one way and commands or status messages the other way. When I need to do this I use a pair of queues, one for each direction.
Lynn
Hmmm. I thought of this but I couldn't get it to work. It sounded like a good idea. It just locked up the program. The fp panel became unresponsive. I had to use the Abort Execution button to stop it. Could you provide a sample of this? Just curious. Thanks.
Using the two queue method would require the producer to check the status of the queue and move on when it is empty. This ultimately turns it into a form of a polling system.
If the producer is using an event structure you can pass data back via a user event.
Also, the OP mentioned that they handle the UI and analyze the data in the consumer loop. I would recommend for the greatest felxibility and reuse that the UI actually be in its own loop separate from the analysis. The UI loop would use an event structure and the UI updates can be passed to it using user events.
08-17-2011 10:58 AM
@Ravens Fan wrote:
Does the producer loop really need to get that value back? If the consumer loop is the one doing the analysis, should it just hold on to the tare value and use that as part of the analysis? If you send it back to the producer, now you've just placed some of the analysis responsibility back there.
Other alternatives to a local variable:
A function global variable or action engine.
You can use a notifier to send the data back to the producer.
Possibly some other ideas.......
Exactly what I was thinking. Producer should do one thing, and that's gather data and send it somewhere else.
Consumer's the place you'll want to use that tare variable. Maybe just put it in a shift register and pass it around the loop. You can "pull down" the left input-side of the shift register to get the last n values out of it, stuff that into an adder and divide by n to get a rolling average.
If you *have* to send data back into the producer... I would use a 2nd notifier to do that instead of local/global vars.