How to Get Current DAQmx Task State in LabVIEW

Updated Jan 11, 2024

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.

  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 DAQGetTaskState function from the Function name drop down box.
  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 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 if you would like, this will not affect the way the DLL is called. In This example,
the 3 integers will be named taskIDattributeID and value with Data type set as  Unsigned Pointer-sized Integer (uintptr),
nsigned 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 plus button to add 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 control for attributeID with 310A 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 palette>> 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 C:\Program Files (x86)\National Instruments\[LabVIEW version]\vi.lib\DAQmx\miscellaneous.llb

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

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

DAQmx Get Task State Version19 and later.png
 DAQmx 19.1 and Later Get DAQmx Task State 
Note: Even though the taskID wire appears to be broken, the VI works perfectly as it is.