Perform DAQmx Device Reset or Self-Test Programmatically

Updated Jan 17, 2024

Environment

Software

  • LabVIEW NXG
  • LabVIEW
  • LabWindows/CVI

Driver

  • NI-DAQmx

Programming Language

  • C# .NET
  • Visual Basic .NET

Using NI-DAQmx driver API and NI development software (like LabVIEW or LabWindows/CVI), you can programmatically perform a device self-test on DAQmx devices. This process uses DAQmx functions to perform the device self-test or device reset, similar to the processes found in Measurement & Automation Explorer (MAX).
  • DAQmx Self-Test performs a brief test of device resources and returns information if an error/exception occurs. This can be used throughout code but can be particularly useful at the beginning of DAQmx code to assess if errors exist before continuing on through a task.
  • DAQmx Reset  returns the device to an initialized state -- aborts all active tasks associated with a device and disconnects any routes. Aborting a task puts the task into an unstable state. This function should be used cautiously, but can be a good option to add to the beginning or end of code when troubleshooting a crashing application if you are unable to gracefully close and release references. 

Function Location

You can use the DAQmx Self-Test Device function or the DAQmx Reset function in LabVIEW, and also in text-based environments through our support for LabWindows/CVI or ANSI C, and .NET with C# or Visual Basic.

Note: The Self-Test Device functionality was added to the NI-DAQmx driver in version 8.9.
 

LabVIEW

  • 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();
    • Example:
Device dev = DaqSystem.Local.LoadDevice("Dev1");
dev.Reset();
  • DAQmx Self-Test:
    • Function prototype: void Device.SelfTest();
    • Example:
Device dev = DaqSystem.Local.LoadDevice("Dev1");
dev.SelfTest();
 

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()
    • Example:
Dim dev As Device = DaqSystem.Local.LoadDevice("Dev1")
dev.Reset()
  • DAQmx Self-Test:
    • Function prototype: Public Sub SelfTest()
    • Example:
Dim dev As Device = DaqSystem.Local.LoadDevice("Dev1")
dev.SelfTest()
 

LabVIEW NXG

Note: LabVIEW NXG is not recommended for new applications. The final release of LabVIEW NXG was LabVIEW NXG 5.1 in 2021.
 
The DAQmx Reset VI and Self-Test functions are located in the Hardware Interfaces»NI-DAQmx»Device Configuration palette on the Diagram.

 

 

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.
  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.
    • Optional: A DAQmx Self-Test Device VI can be added to test if the device responds properly after being reset.
  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. 
 Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.