03-05-2024 12:42 AM
Hi...
In my application, I'm continuosly reading data and storing it in application cluster. Now I need to log that data for every 10 minutes and clear buffer and start to store data again to application cluster. Here I'm using producer/consumer architecture. So if i click on log data button the data in the application cluster should be logged in to a file and the application cluster should clear the logged data and accumulate new data. There should be no loss of continuosly accquring of data. I have used producer/consumer architecture. Can anyone suggest me how to do it...
I have attached my VI below.
Thankyou...
03-05-2024 07:29 AM
You have not used a Producer/Consumer design, but rather a Queued Message Handler. (You probably don't need a Producer/Consumer pattern if your data rates are slow enough).
Consider what happens when you push "Start". Your "Command Loop" puts you in an "endless Start loop" (I called it "endless" because Start calls itself). Fortunately, you put in a Loop Delay, so if you push "Log Data", you will do the "Log Data" loop when it comes up in the Queue. But after that, then what? All the data in the App Cluster is still there -- you never clear the written data.
Another (serious) problem with your code is you are using something I've named the "Invisi-Queue", an "invisible Queue". I must confess I also used this (as those Queue Wires running "backwards" all over my Block Diagrams drove me crazy, until 2015 when Asynchronous Channel Wires were being beta-tested, and I became a True Believer). Using Invisi-Queues means that Data Flow (the guiding philosophy behind LabVIEW) is compromised.
Bob Schor
03-05-2024 10:09 PM
Hi bob,
How can I use an extra helper loop that acquire data continuously so that there is no data loss when i log that data to a file. I can't figure out how to trigger that helper loop to acquire data continuously and also to trigger the log data state every 5 minutes. Can you help me with this....
Thankyou.
03-06-2024 07:29 AM
Hello, @stark8.
I believe that the problem you are having with your code is you have not designed it, by which I mean you have not thought about all of the things that you want to do, but rather on isolated techniques to handle tiny unrelated parts of the entire picture. I say this because I looked at the rather high-level "framework" that you created, but which has pieces in it that don't make sense.
As I see it, you want to do the following:
Is there a need to start and stop the logging (and if so, why)?
Many tasks in LabVIEW have a "Set-up the Task, Start/Do the Task, Clean-up and end the Task" structure, as does this one (for the two tasks). The Acquire Task often involves hardware (such as A/D converters, etc.) and may use DAQmx to configure and use the hardware. The Set-up involves connecting to the DAQ device, setting its sampling rate and input properties, and starting it. "Doing" the sampling usually uses a While Loop -- if you are using DAQ hardware, and set a sampling rate in the hardware, the DAQmx Read becomes a "clock" that times the loop for you, so if you tell it to sample a single point at 10 Hz, the loop containing the DAQmx Read will try to run at 10 Hz (without needing a "Wait" function). When you push "Stop" to end the Acquisition loop, you stop the Task.
So you now have a loop running at 10 Hz that produces one point every 10 seconds. At the same time you were setting up your Acquire Task, you should also be setting up you "Save the Data" task. Let's simply write the data to a text file. Fine, how do we "initialize" the Text file? Which function on the File I/O palette looks like it can Open/Create a file? Do you know what to do with a file Refnum? Now look inside your Acquisition loop. 10 times/sec you get a single data point that needs to be saved. Great, put a File Write (for this simple demo, I'd use "Write to Text File", as you'll be better able to "read the results" and see if it makes sense) inside the Loop and wire the data coming from the Acquire function into the file. What? Write to Text File only accepts Text, and your data are Dbls? Maybe there's another File I/O function (look at the Palette) that is more appropriate ...
File I/O is pretty fast. Since all you are doing inside the 10 Hz loop is getting one sample and writing one value to an already-opened file, the File I/O is not going to influence the timing of the loop. When you exit the Loop, you'll close the file.
Once you get this simple scenario working, you can "fancy it up" by starting data acquisition and turning on File I/O at a later time (I'll leave it to you how you might do that -- think about when you initialize the File I/O and when you enable writing.
Bob Schor