LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data loss using producer/consumer pattern

Hi,

I am working on a VI to write data I measure with a DAQ USB-6361 to a text file. I already got the hint to use a producer/consumer pattern and a queue to transfer data from the DAQ (producer) loop to the logging (consumer) loop (see attached VI).

Unfortunately, this queue solution results in output files with about 7-9 data points per second although the sample rate of the DAQ instrument is set to 150 kHz. Is there a way to speed up the queue tool so that all data points get logged?

 

 

0 Kudos
Message 1 of 6
(3,088 Views)

Two problems.

 

1.  Your stop button is outside your producer while loop.  It will only be read at the beginning of the program.  Which means the only way to stop your program is to abort it.  Move that button inside the loop.  Also, your stop condiion should be Stop if True and not Continue if True.

 

2.  Your queue is set to be a scalar value.  But the DAQ assistant is creating a dynamic data type of 15,000 samples.  (1/10 th of a second of your 150 kHz rate.)  This is why many expert LabVIEW users consider the dynamic data type evil.  It is hiding the fact that it is automatically  converting those 15,000 datae points into a single scalar value when it goes into the queue, (because that is how the queue is defined.)

 

The best thing to do is to get rid of the DAQ assistant and use real DAQmx functions.  The quick fix is to create an array of scalars and wire that into the Obtain Queue function.  Or put a To DDT Express VI into the input of the Obtain Queue Function.

0 Kudos
Message 2 of 6
(3,079 Views)

Thanks for your advice to use the DAQmx functions. I tried that (see attached VI) but now I keep getting Error -200279 telling me that my application is not able to keep up with the hardware acquisition. I already found the article "Why do I get error -200279 from my DAQmx Read VI" (http://digital.ni.com/public.nsf/allkb/AB7D4CA85967804586257380006F0E62#freq) but the solutions explained there don't seem to work for my application (or at least my attemps to use them to get rid of error -200279 failed so far...). Do you have an idea what else I could try?

Another thing I noticed is that the measured signal isn't shown in the graph any more (in the seconds before the error message pops up). Is this because of the error in the application or did I do something wrong while replacing the DAQ assistant with DAQmx functions?

 

PS: I also tried to feed the source of the sample clock function with the get time function but this bothered the DAQmx start task function - why is this?

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

You are only reading 1 sample at a time because of the 1 channel 1 sample mode.  The loop can't run fast enough to keep up.

 

You need to use the 1 channel N sample mode.  Pick a value for the number of samples to wire into that such as for 1/2 second or 1 second worth of data.

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

Another option instead of the whole Producer/Consumer is to let DAQmx do the logging for you.  There is a function called DAQmx Configure Logging.  Use it to set up DAQmx to stream the data straight to a TDMS file for you.  Makes it so much easier.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 6
(2,975 Views)

Thanks a lot for your new suggestions! I changed the settings of the DAQmx Write tool to 1 Channel/ N Samples and also included the DAQmx Configure Logging tool to store my data (see version 10 of my VI). Now I get a TDMS file with many voltage values but no time stamps. I would like to make sure that I don't loose any data packages any more. But including a second data column including time stamp values doesn't seem to be so easy. Do you have any ideas how I could do it?

I am also trying to include a timing option into my program so that I can set a starting time and a measurement duration. So far (see version 11) the starting part is working but then the program stops tracking time and doesn't stop after the set measurement time. I guess there is something not okay with the way I'm using different loops within this version? Can you see what I'm doing wrong here?

Download All
0 Kudos
Message 6 of 6
(2,939 Views)