LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer/Consumer or Master/Slave for Acquiring, Control, Analysis, and Record Data

Solved!
Go to solution

Hi all,

I have NI cDaq 9188 and its modules NI 9214 (thermocouple), NI 9203 (AI current), and NI 9263 (AO voltage). I need to measure temperature and pressure and in accordance with these data I need to control a frequency converter to drive a compressor. I preapred acquisition, analysis, and record program by use of state-machine, producer/consumer design pattern and I have no doubts about them. They work all fine. Now, I need to add a control program in to them. The problem is that I have to control the compressor with feedback of temperature data continously, but I do not necessarily record the all acquired data and analyses results continously. For instance, I need to record data once in 30 seconds. Which desing pattern should I use for this task?

 

Edit: I was not able to find advanced program examples relevant to master/slave design pattern. If you know where to find, could you write in this thread please?

Egemen
0 Kudos
Message 1 of 13
(5,401 Views)
Keep your current code and add two new loops, a logger and a controller. When you get temperature data stick it in a queue to the loop that does the compressor control. Queue up any data you need to the log loop. The logging loop will have its own timer and if it is expired it logs the data and if not it throws it away. This keeps all your logging logic in one place which allows for greater flexibility. I would recommend not trying to cram all this new functionality in your existing consumer loop. The more you cram unrelated stuff into a single process the harder it gets to expand and maintain until it eventually breaks down.
0 Kudos
Message 2 of 13
(5,379 Views)

Thank you Greg. I tried to prepare an outline in accordance with your suggestions. I attached the snippet. Did I understand you right?

Egemen
0 Kudos
Message 3 of 13
(5,374 Views)

Your logging loop has problems.  That 30 sec wait is going to slow down your logging loop and cause your queue to fill up.  When the wait ends, the loop will iterate.  It will dequeue the next element in the queue.  Rather than data that was just acquired, it will be the very next sample from 30 seconds ago.  Then when it iterates again, it will be the very next sample which will now be 60 seconds old.  It just keeps plotting staler and staler data.

 

The recommendation was to dequeue all of the.  Determine if the 30 seconds have passed, if so, log the data to the file, if not move on and discard the data.  The Elapsed Time Express VI can be your friend here.

0 Kudos
Message 4 of 13
(5,365 Views)

Hi Ravens Fan, actually I can not understand how to use produce/consumer design pattern here. Because queues buffer data. For instance, I want to acquire data 10 data per sec but I want to log only the last data (10th data, I do not need the previous 9 data)) to text file, instead of logging all of them. How can I utilize your suggestion with use of the elapsed time express vi?  Is there any other function or way to data in dequeue element function? Could you send me an example if you have?

Egemen
0 Kudos
Message 5 of 13
(5,324 Views)

A picture is worth a thousand words.

 

But for a few words in a basic description, a picture really shouldn't be necessary.

 

0 Kudos
Message 6 of 13
(5,316 Views)

I thought that I could not explain what I want clearly. All I want is that one loop produces 10 data once in a second and the other loop save only the 10th data,  not the all 10 data, to a text file. I tried your suggestion and this is not the case I want. The dequeue element buffers all data and send all of them to the recording loop. I cannot prevent not to read all of the data by elapsed time function. Did I misunderstand you? I attached a snippet to compare producer/consumer and master/slave loop. One think that I do not understand is that these two loops operate in the same way. I could not recognize the difference. Notifiers also buffer the data. Where am I missing here?

Egemen
0 Kudos
Message 7 of 13
(5,281 Views)
Solution
Accepted by topic author newbieeng

Notifiers do not buffer data.  Only queues do.  A new notification will overwrite the old value whether it is ever read or not.  You would wind up losing data with notifiers if the consumer loop with a notifier can't keep up with the data it is getting.

 

What I show buffers all data through the queue in the producer loop.  The consumer queue dequeues all the data and will only do stuff with it (such as logging) if the elapsed time has passed.  What is wrong with that? That is what for(imstuck) is describing in his message.

 

The other alternative is that you put the elapsed timer in the producer loop.  Have the TimehasElapsed boolean drive a case structure that only enqueues the data if the time has passed.  In this case, only some of the data gets enqueued, and the consumer loop dequeues all of the data it gets and logs it.

0 Kudos
Message 8 of 13
(5,275 Views)

Hi RavensFan.

 

Your last suggestion seems to be a solution for me. Instead of transferring all data to the recording loop, just transferring the necessary one is so logical. I could not think about it before. Thanks again. I have not tried it but I will as soon as possible.

 

When I run the vi that I attached in the previous post, why did I see that notifiers buffer? Or do I know  definition of "buffer" in wrong way? I attached a printscreen of the results of this vi and it seems that notifiers in the master loop buffers data. Am I wrong here? I attached the vi again here.

Egemen
Download All
Message 9 of 13
(5,259 Views)

First things first, if RavensFan 's post was helpful, hit the kudos button next to his icon.

 

This case study will clear your doubts: http://zone.ni.com/devzone/cda/epd/p/id/3717


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 10 of 13
(5,249 Views)