04-28-2013 05:06 AM - edited 04-28-2013 05:17 AM
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?
Solved! Go to Solution.
04-28-2013 09:53 AM
04-28-2013 10:27 AM
Thank you Greg. I tried to prepare an outline in accordance with your suggestions. I attached the snippet. Did I understand you right?
04-28-2013 11:52 AM
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.
04-30-2013 07:42 AM
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?
04-30-2013 09:49 AM - edited 04-30-2013 09:50 AM
A picture is worth a thousand words.
But for a few words in a basic description, a picture really shouldn't be necessary.
05-02-2013 08:57 AM - edited 05-02-2013 08:58 AM
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?
05-02-2013 09:30 AM
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.
05-03-2013 04:44 AM
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.
05-03-2013 05:22 AM - edited 05-03-2013 05:23 AM
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