This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

How to Get Current DAQmx Task State in LabVIEW

Updated Mar 31, 2026

Environment

Software

  • LabVIEW

Driver

  • NI-DAQ™mx

The DAQmx control Task function has multiple states. It is possible to query if the task is done or not with DAQmx is Task Done function. but there are no in-built function that helps query the current task state while the program is running. This document explains how to configure call library function node and use it to retrieve DAQmx current task state in LabVIEW.

Note: This example is for DAQmx version 19.1 and later.

DAQmx 19.1 and Later

There is now an internal task attribute for the task state (via lvgeneratedAttributes.cpp):

EXTERNC LVStatusCode kNILVAIExport kNICCall getTaskI32(
   GenericRefObjSession taskID,
   nNIDMXA::tAttributeID attributeID,
   int32 * paramValue,
   LStrHandle * extendedErrorInfoHdlPtr) 

The attribute ID is kAttributeIDTaskInternalTaskState  which is0x319A . The state attribute has these values (via nidmxa/enums.h):

enum tInternalTaskState
{
   kInternalTaskStateNotVerified = 0,
   kInternalTaskStateVerified = 1,
   kInternalTaskStateReserved = 2,
   kInternalTaskStateCommitted = 3,
   kInternalTaskStateRunning = 4,
};

If you want to call it from a CLN(Call Library Function Node) in LabVIEW, your can configure it like below:

  1. Launch LabVIEW and create a new VI by selecting File>>New VI
  2. Select Window >> Show Block Diagram  to open the block diagram.

        daqtastEN BD.PNG
 

  1. Right click on the block diagram and from the Functions palette that appears, go to Connectivity >> Libraries & Executables >>Call Library Function Node. Click on Call Library Function Node and drop it on the block diagram



      daqtastEN CLN palette (1).png       daqtastEN CLN vierge.PNG
 

  1. Double click on the Call Library Function Node to open its Configuration dialog.



     daqtastEN CLN configure1.PNG

 

  1. On the Function tab, write 「 nilvaiu.*」 as the Library name or path.
  2. Select getTaskI32 function from the Function name drop down menu.
  3. Select Run in any thread from the Thread box, and C from the Calling convention box.



    daqtastEN CLN configure2Function (1).png 

 

  1. Switch to the Parameter tab.
This function returns an integer (the corresponding task state value), so set the return type as a Signed 32-bit Integer (Int32):
  1. Select return type from the parameter list on the left.
  2. In the Current parameter section, pick Numeric from the Type drop down box.
  3. Leave the Data type as the default Signed 32-bit Integer ( Int32).
               daqtastEN CLN configure3parameter1.PNG 

This function takes in 3 integers and 1 string as parameters, so add these as inputs:
  1. Click on the plus sign to add a new parameter. This will create a new parameter that defaults to a Signed 32-bit Integer (Int32) passed by Value.
              Note: You can rename a parameter according to your preferences, this will not affect the way the DLL is called. In This example, the 3 integers will be named taskIDattributeID and value with their Data type set to Unsigned Pointer-sized Integer (uintptr), Unsigned 32-bit Integer (uint32) and Signed 32-bit Integer (Int32) respectively.
  1. For each integer, edit the Name and Data type as specified above. (Click the button to add a new parameter)
               daqtastEN CLN configure3parameter2.PNG 
 
  1. Click the plus button to add last input, Name it as extendedErrorinfo. Pick String as the Type and String Handle as the String format
                daqtastEN CLN configure3parameter3.PNG 
 
  1. Create necessary inputs /outputs and wire them accordingly.
  • Create a control for attributeID with 319A as its value ( to be able to insert letter A in this control, click on the control created and open the property window. Change its Display format to Hexadecimal)

              daqtastEN hex (2).png

  • Drop an Emply String Constant from the Function >> String palette on the block diagram, and wire it to extendedErrorinfo input.
  • Create a Task in control and Task out indicator items and wire the Task in control to the call library function node's taskID input.
  1. Select the case structure from the Function >> Structure palette, and place it on the block diagram.
  2. Place the DAQmx Fill in Error Info function in the default case, and wire its status code, extended error information, and error input terminals, to the call library function node's  Return type, extendedErrorinfo, and error output terminals respectively.

Note: The DAQmx Fill in error Info function is located in the DAQmx\Miscellaneous.llb library located at: (Windows 10 ) C:\Program Files (x86)\National Instruments\[LabVIEW version]\vi.lib\DAQmx\miscellaneous.llb

(Windows 11 )  C:\Program Files\NI\LVAddons\nidaqmx\1\vi.lib\DAQmx

DAQmx fillin Errorinfo (1).png
  1. Right-click on the case structure and select Add Case Before from the pop-up window. Name it 0 and wire the error input to the error out indicator as shown below.

       daqtastEN12.png              daqtastEN122.png

 

Before DAQmx 19.1

There is a public entrypoint in the DAQmx LV API that you can call to get the task state (via lvtask.cpp):

EXTERNC LVStatusCode kNILVAIExport kNICCall DAQGetTaskState(
    GenericRefObjSession taskID,
    int32* state)

The state out-param has these values (via nidmxa/enums.h):

enum tInternalTaskState
{
   kInternalTaskStateNotVerified = 0,
   kInternalTaskStateVerified = 1,
   kInternalTaskStateReserved = 2,
   kInternalTaskStateCommitted = 3,
   kInternalTaskStateRunning = 4,
};

If you want to call it from a CLN, your configuration would look like this:

Follow the same steps as above but before DAQmx 19.1, the  the Function name is DAQGetTaskState 

 

This function takes in 2 integers as inputs and returns 1 integer (the corresponding task state value):

 

The resulting sample program can be downloaded from the attached file and is presented as below.

DAQmx Get Task State Version19 and later.png  

  Get DAQmx Task State, DAQmx 19.1 and Later

 

 

 

 Get DAQmx Task State, before DAQmx 19.1

This document explains the meaning of each task state( unverified, verified, reserved, commited, running)