Automatically Generate LabVIEW NI-DAQmx Code

Updated Jul 26, 2023



  • LabVIEW


  • NI-DAQmx

This article will walk through how to generate NI-DAQmx code in LabVIEW through the DAQ Assistant Express VI and a Task Constant. A Task Constant can be manually placed into LabVIEW, dragged from NI Measurement and Automation Explorer (MAX) or by converting the DAQ Assistant Express VI. 

Follow the DAQ Assistant or NI MAX sections of Create Tasks for NI-DAQmx Devices in LabVIEW before beginning these steps.

Starting with DAQ Assistant:

When you configure a task using the DAQ Assistant Express VI, the task is local to the application, and you cannot use it in other applications. You can convert a DAQ Assistant Express VI to a DAQmx Task Name control if you want to save the task to MAX and use it in other applications or to generate code. 

Right-click the DAQ Assistant and choose either Converting To NI-DAQmx Task or Generate NI-DAQmx Code.
  • Converting to NI-DAQmx Task
    1. Once this option is clicked, the configuration window will re-open to confirm any configuration changes. Update anything you need.
    2. Click OK
    3. This will create a Task Constant and populate the task in NI MAX under My System >> Data Neighborhood >> NI-DAQmx Tasks
    4. Follow the Task Constant section below
  • Generate NI-DAQmx Code
    1. Once this option is clicked, it will create code using LabVIEW API similar to the Configuration and Example option through the Generate Code option. It was at least include:
      • Any configuration information as constants
      • DAQmx Read VI or DAQmx Write VI
      • DAQmx Stop VI
Note: This option will not save the task in NI MAX
  1. Use this to create the rest of your application.

DAQmx Task Name Constant:

Once you have a DAQmx Task Name (Task Constant), right-click the Task Constant and hover over Generate Code. You have the following options: Example, Configuration, Example and Configuration, and Convert to Express VI.