Performing DAQmx Device Reset or Self-Test Programmatically

Updated Nov 14, 2018

Reported In


  • LabVIEW Full
  • LabVIEW Base
  • LabVIEW Professional
  • LabWindows/CVI Full
  • LabWindows/CVI Base

Programming Language

  • C# .NET
  • Visual Basic .NET

Issue Details

I want to programmatically perform a device self-test or reset, similar to that available in Measurement & Automation Explorer (MAX), but I cannot find the corresponding functions. Where can I find these functions and how should I implement a reset or self-test in my program?


Function Location

In NI-DAQmx 8.9 and later you can use the DAQmx Self-Test Device function or the DAQmx Reset function in LabVIEW. You can also call similar DAQmx Reset and Self-test functions through our support for LabWindows/CVI or ANSI C, and .NET with C# or Visual Basic.


The DAQmx Reset VI and Self-Test functions are located in the Hardware Interfaces»NI-DAQmx»Device Configuration palette on the Diagram.


DAQmx Driver:
The DAQmx Reset VI and Self-Test functions are located in the Measurement I/O»NI-DAQmx»Dev Config palette on the Block Diagram. ​​

Traditional DAQ Driver:
​The Device Reset function is located in the Measurement I/O»Data Acquisition»Calibration and Configuration palette on the Block Diagram.

LabWindows/CVI & ANSI C: 

The DAQmx Reset and Self-test functions can be found in Libraries»NI-DAQmx Library»Advanced»Device Control. 

DAQmx Reset: 
Function prototype: int32 DAQmxResetDevice (const char deviceName[]) 
Example: int errorResult = DAQmxResetDevice("Dev1");

DAQmx Self-Test: 
Function prototype: int32 DAQmxSelfTestDevice (const char deviceName[]) 
Example: int selfTestResult = DAQmxSelfTestDevice("Dev1");

C# .NET:

To perform a DAQmx reset or self-test in C# you must first have a Device object for your DAQ device and then you can call the reset or self-test functions on the Device object.

DAQmx Reset:
Function prototype: void Device.Reset();
   Device dev = DaqSystem.Local.LoadDevice("Dev1");

DAQmx Self-Test:
Function prototype: void Device.SelfTest();
   Device dev = DaqSystem.Local.LoadDevice("Dev1");

Visual Basic. NET:

Similar to C# .NET, to perform a DAQmx reset or self-test in Visual Basic. NET you need a Device object to call the reset and self-test functions.

DAQmx Reset:
Function prototype: Public Sub Reset()
   Dim dev As Device = DaqSystem.Local.LoadDevice("Dev1")

DAQmx Self-Test:
Function prototype: Public Sub SelfTest()
   Dim dev As Device = DaqSystem.Local.LoadDevice("Dev1")


Function Implementation

The Reset Device function is usually used at the beginning or end of a program. If the Reset Device is used in the middle of a program it will immediately abort all active tasks associated with a device, disconnect any routes, and return the device to an initialized state. Aborting a task immediately terminates the currently active operation, such as a read or a write. Aborting a task puts the task into an unstable but recoverable state. To recover the task in NI-DAQmx, use DAQmx Start to restart the task or use DAQmx Stop to reset the task without starting it. The reset process is asynchronous and the function returns before reset completion. For more information on these functions please see the NI-DAQmx help files.

Example Code in LabVIEW

Below is an example code written in LabVIEW that puts the Reset Device at the end of the program.
  1. The DAQmx task is initialized before the main loop and is here represented by the Task In control. The initialization steps are left out in this example. For more information on how to create and set up a DAQmx task see: Learn 10 Functions in NI-DAQmx and Handle 80 Percent of Your Data Acquisition Applications.
  2. Start Task and enter the Acquisition Loop.
  3. The Acquisition Loop handles the acquisition. In this example the data acquisition is set up to continuously read N samples from one channel. If the user presses the stop button or an error occurs, the Acquisition Loop terminates and the program enters the Reset Device Polling loop.
  4. The Reset Device Polling loop clears current error and resets the device. The loop runs until the DAQmx Reset Device VI succeeds.
  5. Stop the current DAQmx task before starting it again, since starting an already started DAQmx task generates an error.
  6. When the program is finished the task is cleared and any remaining errors are handled by the Simple Error Handler VI. 
A DAQmx Self-Test Device VI can be added to test if the device responds properly after being reset.

Additional Information

While there is no Self-Test VI or function in NI-DAQmx prior to 8.9, using the Reset Device function is another option. It provides roughly the same, and slightly more extensive, functionality as the Self-Test in MAX. This reset is a good option to add to the beginning of code in the case that you are aborting or crashing your application and therefore unable to gracefully close and release references. 


Not Helpful