Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I save data as I aquire without getting read error?

I am acquiring with a USB 6251 in continuous mode and programming with LabWindows CVI 8.  I want to acquire 4 channels at 60-90kHz for 5 min.  I want to save the acquired data, so I set It up to save formatted ascii data each time the "everyNsamples" function runs, which runs whenever the board has acquired a certain number of samples.  After its done acquiring, the user can get that data and save it into a file.   The problem is that I'm getting an "attempt to read sample that is no longer available" error during the acquire operation.   I've set up the number of samples such that it runs the "everyNsamples" routine about once a second.   I am convinced the problem is related to the data saving procedure in the everyNsamples function.   If I sample at 60 or 600 Hz, it all works perfectly.  If I sample at 60kHz, it gives the error immediately.  If I comment out the fprintf command, I dont get an error until after its done taking all the allotted samples.   So perhaps it is the time that it takes to save the data that is making a delay so long that the sample data isnt available anymore.   If this is the case, how does anyone save data at 1Ms/s? I've seen the example programs that show you can display data on screen, but none of them show you how to save data while you acquire.  How do people normally save acquired data?  Do you save into RAM while acquiring?  If you save to a file while acquiring, how do you avoid the read error?  Do I have to learn how to do multithreading (ack!)? 

This seems like a very basic problem that should have a very simple common solution.

 

Thanks,

Joel
0 Kudos
Message 1 of 6
(3,804 Views)

The error is caused because you are overwritting your buffer during your acquisition (possibly because of the time it's taking for you to write the data into a file). During a continuous, buffered acquisition, the buffer should be monitored to ensure the data is not overwritten. In DAQmx, a DAQmx Read Property Node must be used to obtain the amount of data remaining in the buffer. Use the property Status » Available Samples Per Channel to monitor this. If the value continuously increases during the acquisition, decrease the sampling rate, increase the buffer size, or increase the number of samples per channel to read.

 

In LabVIEW, we usually place the acquired data in a queue in one thread and have another thread that reads data from the queue and writes it into the file. You could possibly implement this Producer/Consumer architecture in your application.

Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies
0 Kudos
Message 2 of 6
(3,797 Views)
I'm a little confused about the different buffers.  The way I understand it, I start the DAQ operation with a DAQmxStartTask.  Then every time a certain number of samples is read (nSamples) the EveryNCallback procedure is performed, as set up by the DAQmxRegisterEveryNSamplesEvent command.  In the EveryNCallback procedure, the resulting acquired data is stored in to a RAM space that I created with a malloc command (which I call gData) in the command DAQmxReadAnalogF64.  I write this data to disk during the EveryNCallback procedure. 

Where in the program would I do a DAQmx Read Property Node to see whats remaining in the buffer?

0 Kudos
Message 3 of 6
(3,786 Views)

Hi Jgolden,

           Adnan is right in saying that you are probably overwriting your buffer.  To utilize that DAQmx Read Property Node, you would want to place the  DAQmxGetReadAvailSampPerChan function right before your DAQmReadAnalogF64 to see what's remaining in the buffer.  Let me know if this works for you or if you have more questions!

0 Kudos
Message 4 of 6
(3,720 Views)

I have a couple things I can try now, but it sure would go faster if there were an example somewhere. 

 

Does anyone know of a sample program that shows how to acquire and save data?  This seems like a very routine program that everyone (but me) knows how to do, so there should be something somewhere.   It should be part of the NI sample programs.  I've seen the programs that acquire and display, and I think there are a couple that show how to save a file, but I couldnt find any that do both at the same time.  I'm curious to see how the program is set up, and if it can acquire greater than 60kHz on 4 channels without an error, which is my problem. 

 

Joel

0 Kudos
Message 5 of 6
(3,702 Views)

Hi Jgolden,

          I noticed that this thread is the same as THIS one- lets try to keep this on one thread from now on (you can choose which one).  The information that CharlesD gave you is really good- and he's right about those examples.  You'll want to go to the CVI Example Finder and go to Optimizing Applications»Multithreading.  It sounds like you're going to need a producer/consumer type of settup because if you're trying to save to a file as you are reading data in, your processing is going to limit your input rate.  As Charles said as well, you're card is spec'd to do 1MS/s for your channels (cummulative), so I don't think that you're going to have a problem doing 60kHz.  I would take a look at the example BuffNoDataLoss.cws- which demonstrates using queues.  Though this example doesn't do the saving as well, you should be able to combine it with one of the other examples that saves data (simply save the data that is being read from the queue to a file). 

 

Another example that you might find helpful is found in the Example Finder under Fundamentals»File Input and Output »arrayfile.cws .  That example generates a waveform and saves it to file- which could be closer to what you're looking for.  

 

Because it doesn't look like there's an example that going to do exactly what you want, I would recommend posting your code to NI Community when you're done, so that users who come across this in the future have a helpful resource! 

 

 

 

         

0 Kudos
Message 6 of 6
(3,659 Views)