11-17-2010 01:49 AM
So I'm using a USB-6009 with NI-DAQmx drivers. I have it set to continuous capture mode and to grab all available samples. When I get the message "Attempted to read samples that are no longer available," I understand that I took too long before reading from my device and the circular buffer overflowed. Ok, fine. So some older samples were overwritten. How do I tell LabVIEW to just give me what samples it does have without triggering any errors? For my application, it doesn't matter if some data gets discarded. If my loops finish quickly, then I'll grab all the samples that have accumulated since the last iteration. If my loops take a little longer to complete, then I just want to grab N samples, where N is the size of the buffer. If some older data was overwritten, I don't care.
Second question. I also tried having LabVIEW grab the newest samples, using an offset and the pointer to the most recent sample. In this case, I have the opposite problem. The buffer underflows if I try to grab more samples than are present. How do I tell LabVIEW to only give me the 25 newest samples, but if my loop finishes quickly and there are say only 20 samples, then to grab just those instead?
The advice I've seen on this board has always revolved around matching the sampling rate to the loop speed, but for what I'm doing the loop speed can change drastically, depending on what settings have been toggled on my front panel. These toggles are "live," in the sense that they are checked on every iteration, so I can't set up the data acquisition differently depending on their status prior to the onset of the loops.
Thanks!
11-22-2010 09:25 PM - edited 11-22-2010 09:27 PM
I would use the Producer/Consumer design; it will alow you to easily handle multiple processes at the same time while iterating at individual rates. When there are multiple processes running at different speeds, buffered communication between processes becomes vital. For example, the pattern would queue the data in the producer loop, and have the actual processing done in the consumer loop. This in effect will allow the consumer loop to process the data at its own pace, while allowing the producer loop to queue additional data at the same time.
-Ciao