Create Tasks for NI-DAQmx Devices in LabVIEW

Updated Jul 26, 2023

Environment

Software

  • LabVIEW
  • Measurement & Automation Explorer (MAX)

Driver

  • NI-DAQmx

Operating System

  • Windows

This document is part of the Getting Started with NI-DAQmx Series.

This article will walk-through how to create tasks using simulated or physical NI-DAQmx devices in LabVIEW. In order to determine if your device is simulated or real check the icon color in NI Measurement and Automation Explorer (MAX). The icon color of all NI-DAQmx simulated devices are the yellow version of the physical devices. Some physical device colors can be green, black, or grey. Be sure to check for Simulated NI-DAQmx Device Considerations to confirm what you want to accomplish can be done with a simulated device.

There are few ways to create tasks: using the NI-DAQmx API, taking a task create in NI Measurement and Automation Explorer (MAX), or using the DAQ Assistant Express VI. There are different benefits from using the different methods, see each section to device what is best for you and your application.

Confirm that you have a physical DAQ device connected, the compatible N-DAQmx driver installed and you can see the device in NI MAX or have created simulated NI-DAQmx device  available in MAX.

NI-DAQmx API

When using the NI-DAQmx API, it is recommended to use the framework available through a shipping example. 

Starting with an Example (recommended)
  1. Launch LabVIEW
  2. Navigate to Help >> Find Examples... which will launch the NI Example Finder
  3. Confirm you are in the Browse tab and navigate through the folders Hardware Input and Output >> DAQmx
  4. Navigate to the folder for you application needs
  5. Double click the the example you want to use
  6. DO NOT edit this example. Any changes will overwrite the original example. 
    1. Click File >> Save As
    2. Choose the option that suits your needs. Recommendation is to choose Duplicate Hierarchy to new location
    3. Choose the location and click Save
    4. Close out for the example and open Example in the new location
  7.  Once the local copy of the example is opened, you can change the configuration and the channel used in the example. You can use real and simulated devices and channels to run the application
Note: Most examples start with DAQmx Create Virtual Channel and will create an unnamed task automatically. Most examples will also only have 1 channel and 1 device listed. You can channel expand  by modifying one instance of the DAQmx Create Virtual Channel VI to incorporate more channels or devices or by adding more than one DAQmx Create Virtual Channel VI to the same task. If you are adding more devices, be sure they can share a timing resource for the task.
  1. Edit the example as you need

Starting from Scratch 

A good resource is Learn 10 Functions in NI-DAQmx and Handle 80 Percent of Your Data Acquisition Applications.  It will walk-through the main functions you may require in an NI-DAQmx Data Acquisition application.

 

Use NI MAX Task

Creating tasks in MAX to use in LabVIEW allows to set up multiple channels, scales, timing and triggers outside of LabVIEW which can help with cluttered code. It is easier to port task information between different VIs. In comparison with using the DAQ Assistant is giving more control when the task starts and stops, can easily use the same channel setup in multiple instances/VIs, and can edit some aspects of the task for a particular instance/VI without changing the setup of the task.
 
  1. Follow the steps to Create Tasks for NI-DAQmx Devices in NI MAX
  2. To use this task created in NI MAX you need to use a DAQmx Task Name (Task Constant), you have 2 options on how to create this:
    • Drag the Task:
      1. Open NI MAX and the Block Diagram in LabVIEW
      2. Hover over the task in NI MAX
      3. Click and drag over to the Block Diagram
      4. A Task Constant is now created in LabVIEW and will reference the task configurations in NI MAX
  1. You can update the task you want to use in LabVIEW by clicking on the arrow of the constant and clicking Browse. This will create a popup with the list of saved tasks available for use.
  • Place the DAQmx Task Constant (Task Constant) in LabVIEW
  1. Open the Block Diagram in LabVIEW
  2. Open the Functions Pallet (Right-Click on the Block Diagram)
  3. Navigate to Measurement I/O » NI-DAQmx and click Task Constant. Place where you want it.
  4. You can update the task you want to use in by clicking on the arrow of the constant and either choosing a task available in the drop down or clicking Browse. Clicking Browse will create a popup with the list of saved tasks available for use.
  1. You now have a few options on how to use this:
 

DAQ Assistant

Using DAQ Assistant for your application packages the entire DAQmx Task from creation to start to stop, therefore, you do not have to use the DAQmx API components. It's a configuration based tool that walks you through the steps to acquiring simple measurements in LabVIEW. It is great for getting simple measurements, triggering and data logging set up in a short time but has limitations for lower level control.
 
  1. Open the Block Diagram in LabVIEW
  2. Open the Functions Pallet (Right-Click on the Block Diagram)
  3. Navigate to Measurement I/O » NI-DAQmx and click DAQ Assistant. Place where you want it.
  4. Once placed,it will begin initializing and a Create New... window will pop up
  1. The functionality of creating the task will be very similar to NI MAX - Follow Step 5 and onward of Create Tasks for NI-DAQmx Devices in NI MAX .
  2. Once you have configured the task, click OK. This will build the task VI to be used. Note: You can update any configuration information by double-clicking the DAQ Assistant
  3. (Optional) You can use the DAQ Assistant as is.
  4. Right-Click the DAQ Assistant and click Convert to NI-DAQmx Task which will create a DAQmx Name Constant (Task Constant). This will save the task in NI MAX.
  5. You now have a few options on how to use this: