Using the DAQ Assistant in NI LabWindows™/CVI™

Updated Dec 28, 2023

Environment

Software

  • LabWindows/CVI
  • Measurement & Automation Explorer (MAX)

Driver

  • NI-DAQmx

This tutorial explains how to use the DAQ Assistant to quickly develop and deploy a data acquisition (DAQ) application in LabWindows/CVI. The DAQ Assistant is an easy-to-use graphical interface for configuring measurement tasks and channels and for customizing timing, triggering, and scales without programming. Using the DAQ Assistant, you can configure a measurement task for all of your DAQ applications and then generate code to configure and use the task in your application program. The following content is also located in the DAQ Assistant Help.

Before You Begin

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

  • LabWindows/CVI 7.0 or later.
  • NI-DAQmx from NI-DAQ 7.0.1 or later.
  • A DAQ device that is supported by NI-DAQmx. Refer to the NI-DAQ 7.x Readme file for a list of devices supported by NI-DAQmx.


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

Create a Task

You can use the DAQ Assistant to quickly create DAQ tasks. A task is 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.

To launch the DAQ Assistant from LabWindows/CVI, select Tools»Create/Edit DAQmx Tasks. The dialog box shown in Figure 1 appears.
 


Figure 1
 

You have two options when creating tasks for use in a LabWindows/CVI project.

  • MAX-based tasks are global to the machine on which they are created and can be used by other programs on the same machine. You can view, edit, and test this type of task directly from within MAX. You can use MAX-based tasks in multiple projects, even those that are not in created in LabWindows/CVI.
  • Project-based tasks are stored in a project. Tasks stored in the project are local to that project. Project-based tasks can be more convenient if you need to share a task definition among multiple developers or store the task definition in a source code control system.


Create a MAX-Based Task

  1. Select Create New Task in MAX from the Create/Edit DAQmx Tasks dialog box.
  2. Click OK to launch the DAQ Assistant.
  3. In the next dialog box, select the measurement type for your task and click Next.
  4. Select the virtual channels and click Next.
  5. Enter a name for the task and click Finish. The DAQ Assistant creates the task.
  6. The DAQ Assistant panel shown in Figure 2 appears. In this panel, 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.
 

Figure 2
 
  1. When you specify the various settings, you can test the task. Click the Test button to verify that the task works properly.
  2. Click OK when you finish. The DAQ Assistant saves the task to MAX.
For more information about configuring a task with the DAQ Assistant, refer to the DAQ Assistant Help, installed with NI-DAQmx.
 

Create a Project-Based Task

  1. Select Create New Task in Project from the Create/Edit DAQmx Tasks dialog box.
  2. Click OK to launch the DAQ Assistant.
  3. In the next dialog box, select the measurement type for your task and click Next.
  4. Select the virtual channels and click Next.
  5. After you create the task, the DAQ Assistant panel shown in Figure 3 appears. In this panel, 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.
  6. When you specify the various settings, you can test the task. Click the Test button to verify that the task works properly.
  7. Specify a task name, create task function, and a target directory. Enter this information in the area of the DAQ Assistant panel shown in Figure 3.
  • Task Name--The name you associate with the task as well as the prefix to the .c.h, and .mxb files that will be created. For example, use DAQTaskInProject as the task name.
  • Create Task Function--The name of the function that you will call to create and configure the task programmatically. For example, use CreateDAQTaskInProject as the create task function.
  • Target Directory--The directory where the three generated files will be stored.
 

Figure 3
  1. Click OK to generate the task.
The DAQ Assistant creates three files to describe the task in LabWindows/CVI: a source (.c), a header (.h), and a task description
(.mxb) file. LabWindows/CVI automatically adds these files to the project. The generated source and header files define the task creation function, which contains the code necessary to create and configure the specified task programmatically. The generated task description file (.mxb) contains a binary description of the task that is used when you edit the task in the DAQ Assistant. Opening the .mxb file opens the DAQ Assistant for that task. These files are all linked to the task, so any changes you make to your task from the DAQ Assistant are automatically reflected in the generated code.

For more information about configuring a task with the DAQ Assistant, refer to the DAQ Assistant Help, installed with NI-DAQmx.

 

Use a Task in a LabWindows/CVI Project

After you create a task, you can use it in a LabWindows/CVI project.

MAX-Based Tasks

To use the MAX-based task, call DAQmxLoadTask, as shown in Figure 4. The function panel for DAQmxLoadTask contains a list of all MAX-based DAQmx tasks on your computer. Press <Enter> on the Task Name control in this function panel to view the list of tasks.
 

#include <NIDAQmx.h>
#include <cvirte.h>

static int32 samplesPerChan;
static float64 data[1000];
static TaskHandle daqTask;


int main (int argc, char *argv[])
{
     if (InitCVIRTE (0, argv, 0) == 0)
        return -1;    /* out of memory */
 
     /* Function Call to Load a MAX-based Task */
     DAQmxLoadTask ("MyVoltageTask", &daqTask);
     DAQmxReadAnalogF64 (daqTask, DAQmx_Val_Auto, 10.0, 
        DAQmx_Val_GroupByChannel, data, 1000, &samplesPerChan, 0);
     DAQmxClearTask (daqTask);
     return 0;
}

Figure 4
 
Project-Based Tasks To use the project-based task, call the task creation function (CreateDAQTaskInProject in this example) declared in the generated header file. You also must include its header file into your main project file. See Figure 5 for an example.
 

#include <NIDAQmx.h>
#include <cvirte.h>
/* Include Generated Header File */
#include "DAQTaskInProject.h"


static int32 samplesPerChan;
static float64 data[1000];
static TaskHandle daqTask;


int main (int argc, char *argv[])
{
      if (InitCVIRTE (0, argv, 0) == 0)
         return -1;    /* out of memory */
 
      /* Function Call to Create Project Based Task */
      CreateDAQTaskInProject(&daqTask); 
      DAQmxReadAnalogF64 (daqTask, DAQmx_Val_Auto, 10.0,
         DAQmx_Val_GroupByChannel, data, 1000, &samplesPerChan, 0);
      DAQmxClearTask (daqTask);
      return 0;
}

Figure 5
 
Project- and MAX-Based Tasks

After you call DAQmxLoadTask or the task creation function, add other functions necessary to perform the actions you need. For example, if you are reading in data from your analog input channels, you might want to use the DAQmxReadAnalogF64 function.

Call DAQmxClearTask when you finish with a task. This function stops the task and clears the task from memory. 
 

Generate Example Code

You also can use the DAQ Assistant to generate the code needed to run the task.

  • Generate example code for a MAX-based task--In the Source window, right-click the call to DAQmxLoadTask and select Generate DAQ Example Code.
  • Generate example code for a project-based task--In the Source window, right-click the call to the task creation function (for example, CreateDAQTaskInProject) and select Generate DAQ Example Code.


When you select Generate DAQ Example Code for either a project- or MAX-based task, the Generate DAQ Example Code dialog box, shown in Figure 6, appears.


Figure 6
 

In the dialog box, specify the name of the function to run your task and the file to contain the generated example code, then click OK. The generated code includes source and header files that define the run task function. LabWindows/CVI automatically adds these files to the project and modifies the current source file to call the run task function. When called, the run task function programmatically creates a user interface that allows you to start the task and display the data.

The following figure shows an example source file after you select Generate DAQ Example Code for a project-based task.

#include <NIDAQmx.h>
#include <cvirte.h>
#include "DAQTaskInProject.h"
/* Header File for Example Code */ 
#include "DAQTaskInProjectExampleCode.h"

static int32 samplesPerChan;
static float64 data[1000];
static TaskHandle daqTask;

int main (int argc, char *argv[])
{
      if (InitCVIRTE (0, argv, 0) == 0)
         return -1;    /* out of memory */
 
      CreateDAQTaskInProject(&daqTask); 
      /* Function Call to Run the Task */  
      RunDAQTaskInProject (daqTask);
      return 0;
}

Figure 7

 

Edit an Existing Task

There are several ways you can launch the DAQ Assistant to edit a task after creating a task. You can edit any type of task by selecting Tools»Create/Edit DAQmx Tasks. This command launches the Create/Edit DAQmx Tasks dialog box, in which you can select the task you want to edit.

You can edit MAX-based tasks directly from within MAX by selecting My System»Data Neighborhood»
NI-DAQmx Tasks.


You can edit project-based tasks by double-clicking the .mxb file in the Project Tree in LabWindows/CVI.

When you finish editing a task, LabWindows/CVI updates the MAX task or the configuration files in the project, as appropriate, with any changes you make. However, example code you have generated is not automatically updated. Because the example code is not linked directly to the task, if you make any modifications to the task, you must regenerate your example code for the task to reflect the changes you made.

Copy a MAX Task to Project
You can create a new project-based task that is a copy of a MAX-based task. In the Source window, right-click the call to DAQmxLoadTask and select Copy DAQ Task to Project. In the dialog box that appears, you must specify a task name, task creation function, and target directory, just like you specified in the DAQ Assistant for project-based tasks. When you click OK, LabWindows/CVI generates the source (.c), header (.h), and task description file (.mxb) and adds these files to the project; replaces the call to DAQmxLoadTask with a call to the new task creation function; and adds an include statement for the generated header file.

Notice that there is no link between the MAX task and the new project task that you create. Any changes you make to the MAX task will not be automatically reflected in the new project task.

 

Additional Documentation

Refer to the following files for more information about NI-DAQmx and for more information about configuring tasks with the DAQ Assistant.

DAQ Quick Start Guide, located at Start»...»National Instruments»NI-DAQ
NI-DAQmx Help, located at Start»...»National Instruments»NI-DAQ
DAQ Assistant Help, accessible in the right pane of the DAQ Assistant
LabWindows/CVI Help, located at Start»...»National Instruments»LabWindows/CVI