The built-in template for continuous measurement and logging (NI-DAQmx) template is a pretty impressive example of queued data acquisition. However I ran into a problem whilst playing with it:
However, now the beginning of the TDMS files after the first will have some data from the previous start/stop cycle.
I think the problem is with the Logging module. In Logging.lvlib:Logging Message Loop.vi, the Data Queue is not being flushed when the system is changing from the "Idle" state. See my fix (flush the Data Queue) in the diagram below, stuffed into the left side of the "Idle" case. It now behaves as I expected.
So is this a bug or a feature of the template?
EDIT: Attached the final PNG as well, not sure why it is mucked up by forum software.
I've been looking into this. Looking through the code, when you click "Stop" from the Main Front Panel, eventually the Logging.lvlib:Flush Data to Log File.vi should eventually be called. This would flush the queue and write the last few elements to the TDMS file.
Since there is still some old data left when you restart acquisition, it appears that this last step of flushing and writing the last few data points never occurs. With the "Flush Queue" step that you added, this ensures the queue is flushed before acquisition begins again. However, you may be losing your last few data points here since they are only flushed from the queue, not flushed and written.
I'm still wokrking on tracing this further to determine how to ensure the Flush Data to Log File VI is called at all necessary points. I just wanted to give you a brief update.
Thanks for the information!
If I had to guess, I'd guess that the "bug" was in your Acquire routine in Acquisition.lvlib. The Template itself looks fine -- when you push Stop, it sends a Stop message to the Acquisition Message Loop, which calls Stop Acquisition and puts nothing on the Data Queue. It also sends Stop to the Logging Message Loop, which calls Flush Data to Log File, which flushes the Data Queue and writes it to the Log File, closing the file afterwards. This seems logically correct.
The one thing that's missing in the Template is the actual code to acquire data. I'm assuming you are not using the Dreaded DAQ Assistant (if you are, all bets are off -- don't combine an elementary "Even a Sales Guy Can Set This Up" Express VI (sorry, my prejudice is showing) with a (fairly) sophisicated Project Template that creates a multi-loop (five loops are shown on Main) Acquisition Template that allows logging to be turned on and off. Why don't you attach the VIs in Acquisition.lvlib? [The easiest way to do that is to compress the Acquisition folder that contains them all, and attach the resulting .ZIP file].