Task Creation and Destruction

DAQmx - Data Acquisition VIs and Functions

Edition Date: January 2019

Part Number: 370469AP-01

»View Product Info
Download Help (Windows Only)

In LabVIEW, you can open or create tasks in two ways: by using a DAQmx task name constant or control to select a task that you created and saved in the DAQ Assistant, or by using the DAQmx Create Virtual Channel VI or DAQmx Create Task VI to create a task programmatically.

When you use a DAQmx task name constant or control to select a task, LabVIEW loads that task into memory one time only, even if the control or constant is inside a loop.

When you use the DAQmx Create Virtual Channel VI and you do not specify a task to which to add the created channels, NI-DAQmx creates a new task and allocates resources for it. LabVIEW does not automatically free up these resources until the application completes. If you use the DAQmx Create Virtual Channel VI within a loop without specifying a task, NI-DAQmx creates a new task in each iteration of the loop and does not destroy any of these tasks until the application completes.

When you use the DAQmx Create Task VI, you create a new task. If you use this VI within a loop, NI-DAQmx creates a new task in each iteration of the loop. The auto cleanup input of the DAQmx Create Task VI determines how long these tasks reside in memory.

If auto cleanup is TRUE, the created tasks remain in memory until the application completes. If auto cleanup is FALSE, the default value, the tasks remain in memory until you exit LabVIEW, rather than when the application completes. This behavior allows you to create a task in one application then use it in another application.

To use the DAQmx Create Virtual Channel VI or DAQmx Create Task VI in a loop without allocating additional memory on each iteration, use the DAQmx Clear Task VI in the same loop after you are finished with the task.

You can use the new task name input on the DAQmx Create Task VI to name a task for later use. If you attempt to create two tasks with the same name, you receive an error. Therefore, you cannot use the DAQmx Create Task VI in a loop when you wire a name to new task name. For example, if you use the DAQmx Create Task VI in a loop and set new task name to myTask, the first iteration of the loop executes normally. On the second iteration of the loop, myTask remains in memory, and the subsequent DAQmx Create Task VI returns an error. To avoid this error, use the DAQmx Clear Task VI in the loop after you are finished with the task.

WAS THIS ARTICLE HELPFUL?

Not Helpful