Using the DAQ Assistant to Automatically Generate LabVIEW Code

Publish Date: Apr 03, 2019 | 96 Ratings | 2.77 out of 5 | Print | 3 Customer Reviews | Submit your review

Table of Contents

  1. Overview
  2. Before You Begin
  3. Terms Used in This Tutorial
  4. Launch the DAQ Assistant
  5. Create the Task
  6. Configure the Task
  7. Test the Task
  8. Generate LabVIEW Code
  9. Want More NI-DAQmx Information?

The National Instruments Getting Started with NI-DAQmx Series is aimed at helping you learn NI-DAQmx programming fundamentals. Through video and text tutorials, this series will take you from verifying your device's operation in Measurement & Automation Explorer (MAX) to programming data acquisition applications using LabVIEW. It is intended for both the beginner who wants to learn how to use the DAQ Assistant, as well as the experienced user who wishes to take advantage of advanced NI-DAQmx functionality. 


1. Overview

The DAQ Assistant, is 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. One simple way to overcome these limitations is to use the DAQ Assistant to set up your task then generate LabVIEW code that you can customize to your exact needs.  

This step-by-step tutorial walks through the configuration of an example task using the DAQ assistant and then explains the different code generation options.

Generate code when you want the convenience of the Express features of NI software but want to make some modifications to the configuration or the example code. One example of this is if you want to create a VI that could take user input to adjust certain configuration parameters before running. By generating the configuration code, you could easily turn some of the constants into controls on the front panel. This would especially be useful if you wanted to build an executable using Application Builder since Express VI properties cannot be modified in an executable.

Note: Refer to the "Generating Code" section in the DAQ Assistant Help for more detailed information.


Back to Top

2. Before You Begin

To use this tutorial, you must have the following software and hardware installed in your system:

  • NI-DAQmx API, including LabVIEW 7.x or higher support files
  • A DAQ device that is supported by NI-DAQmx and is connected to a voltage signal or an NI-DAQmx simulated device which has already been created. Refer to the NI-DAQ 7.x Readme file to see if your device is supported in NI-DAQmx. Refer to the NI-DAQmx Simulated Devices tutorial to learn how to create an NI-DAQmx simulated device.

Refer to the DAQ Quick Start Guideand the device documentation for information about installing and configuring the software and hardware.


Back to Top

3. Terms Used in This Tutorial

  • VI (Virtual Instrument) - A program or subprogram in LabVIEW.
  • Physical channel - A terminal or pin at which you can measure or generate an analog or digital signal.
  • Virtual channel - A collection of settings that can include a name, a physical channel, input terminal connections, the type of measurement or generation, and scaling information. In NI-DAQmx, virtual channels are integral to every measurement. You can configure virtual channels with the DAQ Assistant, which you can open from Measurement & Automation Explorer (MAX) or your application software. You also can configure virtual channels with the NI-DAQmx API in your application program.
  • Task - A collection of one or more virtual channels with timing, triggering, and other properties. Conceptually, a task represents a measurement or generation you want to perform. You can set up and save all of the configuration information in a task and use the task in an application. In NI-DAQmx, you can configure virtual channels as part of a task or separate from a task.
  • Local channels - Virtual channels created inside a task.
  • Global channels - Virtual channels defined outside a task. You can create global channels in MAX or in your application software. You can use global channels in any application or add them to a number of different tasks. If you modify a global channel, the change affects all tasks in which you reference that global channel. In most cases, it is simpler to use local channels.


Back to Top

4. Launch the DAQ Assistant

You can launch the DAQ Assistant in several ways. Complete the following steps to launch the DAQ Assistant from a LabVIEW block diagram.

  1. Open LabVIEW and create a New VI. Switch to the block diagram (Ctrl+E).
  2. The DAQ Assistant Express VI can be found on the Functions palette by going to Express » Input. Place the DAQ Assistant on the block diagram by dragging and dropping it from the Functions palette. The Assistant should automatically launch when you drop the VI on the diagram.

Figure 1.


Back to Top

5. Create the Task

In this example, we will configure a simple voltage analog input measurement. For other measurement and signal generation types, you would follow similar steps.

  1. On the first screen, select Acquire Signals and then Analog Input for your Measurement Type.
  2. Next, select Voltage.

Figure 2.

  1. The next screen lets you select the physical channel (or channels) for which you are creating this task. All supported data acquisition hardware devices should appear in the tree control, and you can expand them to view a list of the physical channels that you can select for your task. To select more than one channel, hold down the Ctrl button while clicking on the channel names.

Figure 3.

  1. Click Finish to move on to the configuration stage.


Back to Top

6. Configure the Task

After you create a task, you can configure channel-specific settings such as scaling, input limits, and terminal configuration. You also can configure task-specific settings such as timing and triggering. In this task, you do not need to use scaling or triggering. To configure the voltage measurement task, complete the following steps.

  1. Specify the input limits. You can use the default values of 10 for Max and -10 for Min if you do not know the theoretical limits for the signal you are measuring.
  2. Select the terminal configuration you used for the signal.
  3. On the Configuration tab under the Timing Settings section, select N Samples for the Acquisition Mode. Enter 100 for Samples To Read, and enter 1000 for Rate (Hz) (might default to 1k), as shown in the following figure.

Figure 4.


Back to Top

7. Test the Task

You can test the task in the DAQ Assistant before finalizing it to make sure you connected the sensors properly. You can test each channel/measurement individually. Complete the following steps to test the task.

  1. Select the channel you would like to test.
  2. Select Chart, Table, or Graph for the Display Type (Graph is only available for N Samples or Continuous Samples, while Chart is only available for 1 Sample (On Demand) or 1 Sample (HW Timed) acquisition mode).
  3. Click the Run button at the top of the DAQ Assistant.
  4. Once you are satisfied with the task, click the OK button. The DAQ Assistant saves the voltage task, containing all the configuration information you entered, to MAX. You have created your voltage task.


Back to Top

8. Generate LabVIEW Code

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. Complete the following steps to convert the DAQ Assistant Express VI to a DAQmx Task Name control.

  1. Right-click the DAQ Assistant Express VI and select Convert to NI-DAQmx Task from the shortcut menu.
  2. The DAQ Assistant launches, and you can modify the task, if necessary.
  3. Click the OK button.
  4. A DAQmx Task Name constant replaces the DAQ Assistant Express VI.

Figure 5.

You now have three options for generating code in LabVIEW from a task or channel:

  • Example - Generates all the code necessary to run the task or channel, such as VIs needed to read or write samples, VIs to start and stop the task, loops, and graphs. Choose this option if you want to run the task or channel you created to verify that it works or to use your configuration in a simple application. In LabVIEW, this option adds to the VI you are working in or creates a new VI. The generated code is a simple NI-DAQmx example that you can then modify for your application.

Figure 6.

  • Configuration - Generates the code that replicates the configuration of the tasks and channels. LabVIEW replaces the DAQmx Task Name control with a subVI that contains VIs and property nodes used for channel creation and configuration, timing configuration, and triggering configuration used in the task or channel. Choose this option if you want to deploy your application to another system. Refer to Deployment in the NI-DAQmx Help located at Start»Programs»National Instruments for more information. When you generate Configuration code, the link between the application and the DAQ Assistant is lost. Any changes you make to the configuration code is not reflected in the DAQ Assistant. You can regenerate Configuration code from the DAQ Assistant, but the regenerated code does not incorporate previous changes that you made to the code. The subVI will contain code similar to the image below. 

Figure 7.

Note: Although generated configuration code includes code to create virtual channels and tasks, it does not include code to create scales. If you generate configuration code for deployment of applications that include scales, you must ensure that the scales are configured in the target computer. Refer to Deployment in the NI-DAQmx Help, located at Start»Programs»National Instruments for more information.

  • Configuration and Example - Generates both Configuration code and Example code for the task or channel in one step. The configuration subVI will contain the same code as shown in the above image. 

Figure 8.

Complete the following steps to generate code to run the voltage task.

  1. Right-click the control on the front panel and select Generate Code»Example from the shortcut menu.

Figure 9.

  1. View the block diagram. Notice that the DAQ Assistant generated all the code necessary to run the task.

Note: All of the timing information you set is contained in the DAQmx Task Name constant.

  1. Save the VI as
  2. View the front panel. Click the Run button to run the application.

Note: Any changes you make to the generated code apply only to the VI and are not saved into the task configuration stored in MAX.


Back to Top

9. Want More NI-DAQmx Information?

NI-DAQmx driver software includes the professional tools introduced in this document in addition to many other software tools and measurement services. To learn more about NI-DAQmx visit some of these additional resources:


Back to Top

Customer Reviews
3 Reviews | Submit your review

broken likn  - Oct 3, 2016

Find Answers To Frequently Asked Questions about NI-DAQmx

  - Jun 29, 2011

Doesn't tell how to use multi-point I/O

multiple signals  - Jul 23, 2009

It would be helpful if this article showed an example of reading multiple analog inputs using the DAQ.

Bookmark & Share


Rate this document

Answered Your Question?
Yes No