Using DAQmx Start Task and Stop Task VIs in LabVIEW

Updated Oct 20, 2022

Reported In

Software

  • LabVIEW Base
  • LabVIEW Full
  • LabVIEW Professional

Driver

  • NI-DAQmx

Issue Details

  • Why do some LabVIEW examples use the DAQmx Start Task VI and the DAQmx Stop Task VI and some do not?
  • When do I have to use these VIs?

Solution

You should use the DAQmx Start Task VI and the DAQmx Stop Task VI when you use the DAQmx Write VI or the DAQmx Read VI repeatedly. 

For example, when using the DAQmx Read VI with the autostart property set to True, the DAQmx Read VI will start the acquisition task and stop the task once the last sample is acquired. If you use the DAQmx Read VI in a loop, the measurement or generation starts and stops in each iteration of the loop due.  To avoid this you can explicitly tell it to start and stop with the DAQmx Start Task VI and the DAQmx Stop Task VI. 

Explicitly starting the task prior to the loop and stopping the task after the execution of the loop significantly improves performance. This is due to the task state of the DAQmx Task. Starting a task before a loop ensures that the task is in the running state, which can help reduce execution time if used before a loop. Stopping a task after the loop will allow the task to remain in the running state within the loop and not return to a previous task state after being stopped. For more information on task states and the DAQmx Task State Model, see the related link below.

Additional Information

For a demonstration of this idea, you can run a test that benchmarks the performance difference as in the example below, which allows you to perform a single-point acquisition on a DAQ device using two methods:
  • Explicitly starting and stopping the task with the DAQmx Start Task VI and DAQmx Stop Task VI outside of the loop.
  • Implicitly starting and stopping the task inside the loop.


Open the Start Stop Compare VI and select to either use the Start and Stop VIs or not using the Boolean Control on the Front Panel. Run the VI in both modes. When you press the Stop button, the Calculate Frequency VI calculates the rate of the acquisition. You should see a significant increase in the acquisition rate when using the DAQmx Start Task VI and the DAQmx Stop Task VI. 

You can read the LabVIEW help topics concerning these two VIs by opening up LabVIEW Help, selecting the Contents tab, and navigating to VI and Function Reference » Measurement I/O VIs and Functions » DAQmx - Data Acquisition VIs and Functions.