Loop Slows Down While Acquiring and Logging Data to a File

Updated Nov 5, 2019

Reported In


  • LabVIEW


  • NI-DAQmx

Issue Details

  • I am acquiring data from my DAQ device. After the acquisition I need to analyze the data and save it to a file. However, the analysis and logging is slowing down the iteration of my loop. How can I speed up my loop so that I get the data at the right speed?
  • I have my DAQ assistant in my while loop and it is taking data slower than expected/set. Why is this happening? What can I do to speed up my code?
  • My acquisition program works for a few minutes but eventually starts to skip data, or data appears out of order. What is a potential cause of this?


The best practice when you need to process and log data, but don't want to slow down your data acquisition, is to use a Multiple Loop Design Pattern. We can divide our task into two loops, an Acquisition (Producer) Loop and an Analyze/Result (Consumer) Loop, and send data between them using FIFO Queues. 

Since the data acquisition is in its own loop, it can run faster than the loop that is analyzing and logging data. This ensures us that we receive data with desired frequency and have all the data analyzed and presented using slower Consumer Loop. An example of such an application is shown on the screenshot below. This screenshot is from the attached example:
In this example code, the lower consumer loop receives the data from the queue and displays it on a waveform chart. You would place any slower data processing and logging code in the consumer loop.

Also, having a DAQ Assistant in a while loop can cause code to run slow and is not advised for long term solutions. The DAQ Assistant is a bulky express VI that will perform a lot of initialization tasks every time the loop is run. If you are trying to run at fast speeds, this can cause slower than expected data acquisition. It is recommended to just do the initialization once, as is shown in the code above, and just perform your read or write function in a while loop. You can also check your sampling rate in NI MAX to ensure that your card is function properly, and isolate issues from the LabVIEW environment.

Additional Information

Get Queue Status.vi  in the example VI ensures that the consumer loop dequeues and processes all data that was inserted in the queue before the application stops.

For more information on using this type of design pattern, refer to Application Design Patterns: Producer/Consumer .