Before You Begin
To use this tutorial, you must have the following software and hardware installed on your system:
-
LabWindows/CVI 7.x or later
-
NI-DAQmx with LabWindows/CVI support selected
-
A DAQ device supported by NI-DAQmx and connected to a voltage signal or a simulated DAQ device. Refer to the NI-DAQ Readme for a list of NI-DAQmx supported devices.
|
Note If you do not have any hardware installed, you can complete the tutorial using an NI-DAQmx simulated device with NI-DAQmx 7.4 and later. If you use an NI-DAQmx simulated device to complete this tutorial, you must choose a multifunction NI-DAQmx simulated device with analog input support, such as the NI PCI-6289. To create an NI-DAQmx simulated device in MAX, refer to the Measurement & Automation Explorer Help for NI-DAQmx. |
Refer to the DAQ Getting Started Guide and the device documentation for information about installing and configuring software and hardware.
1. Launch the DAQ Assistant
Complete the following steps to launch the DAQ Assistant.
-
In LabWindows/CVI, select Tools»Create/Edit DAQmx Tasks.
-
In the Create/Edit DAQmx Tasks dialog box, select Create New Task In MAX.
-
Click OK.
The DAQ Assistant launches, starting with the Create New NI-DAQmx Task dialog box.
2. Create the Task
In the Create New NI-DAQmx Task dialog box of the DAQ Assistant, select the measurement type for the task, add channels to the task, and name the task.
Complete the following steps to create a task to measure voltage from the DAQ device.
-
Select Acquire Signals.
-
Select Analog Input for the measurement type.
-
Select Voltage to open a list of supported physical channels.
-
Select the physical channel on the DAQ device to which you connected the voltage signal. Click Next. This action creates a local virtual channel inside the task.
-
Enter a name for the task.
-
Click Finish when you are done. The configuration panel opens.
3. Configure the Task
After you create a task, you can configure channel-specific settings such as custom scaling, input range, and terminal configuration. You also can configure task-specific settings such as timing and triggering.
In the task you created, you do not need to use custom scaling or triggering. To configure the voltage measurement task, complete the following steps.
-
Specify the signal input range on the Settings tab under Voltage Input Setup. You can use the default values of 10 for Max and –10 for Min, as shown in the following figure.
|
Note To display the context help for the input parameters in the DAQ Assistant, click the Show Help button in the DAQ Assistant. |
-
Select the terminal configuration you used to connect the signal. In the following figure, the terminal configuration is Differential. For more information about terminal configurations, refer to Measurement Systems in the NI-DAQmx Help.
-
Under Timing Settings, select N Samples as the Acquisition Mode. Enter 100 for Samples To Read, and enter 1k for Rate (Hz), as shown in the following figure.
4. Test the Task
You can view data acquired in the DAQ Assistant to test the task and signal connection. Click Run to test the task. Data acquired appears in the graph. Verify that you are acquiring expected data and that you connected the signal properly. If necessary, modify any settings and run your task again.
Click OK when you finish testing your task.
5. Load the Task in a Program
To load the task in a program, create a new project in LabWindows/CVI and add the following code to a new source file in the project.
#include
int main(int argc, char *argv[])
{
TaskHandle task;
if( InitCVIRTE(0,argv,0)==0 )
return -1; /* out of memory */
DAQmxLoadTask("MyVoltageTask",&task);
DAQmxClearTask(task);
return 0;
}
6. Generate Example Code
Complete the following steps to generate example code
-
Right-click the DAQmxLoadTask call and select Generate DAQ Example Code.
-
In the dialog box, specify the Run Task Function and a target source file in which to generate the example code. Modify the default values as needed and click OK.
-
LabWindows/CVI generates a .c file and a .h file and adds them to the project. The generated code shows how to run the selected task in a program. A call to the Run Task function is inserted after the original call to DAQmxLoadTask.
-
Run the project.
7. Edit the Task
You can use the DAQ Assistant to make changes to your task. To edit the task you created, complete the following steps:
-
Right-click the DAQmxLoadTask call and select Edit DAQ Task. The DAQ Assistant opens.
-
In the Voltage Input Setup, change Max to 5 and Min to -5.
-
Click OK to save your task.
-
Run the project again.
8. Copy the Task to the Project
In this tutorial, you created a MAX-based task by selecting Create New Task in MAX when you first launched the DAQ Assistant from LabWindows/CVI. You can also create project-based tasks or copy a MAX-based task to the project.
To copy your MAX-based task to the project, complete the following steps:
-
Right-click the DAQmxLoadTask call.
-
Select Copy DAQ Task to Project.
-
A dialog box prompts you for a task name, Create Task Function name, and target directory. Modify the default values as needed and click OK. LabWindows/CVI performs the following actions:
-
Generates source (.c), header (.h), and binary (.mxb) files and adds them to the project. The generated source and header files define the task creation function. This function contains the code necessary to create a task that is equivalent to the selected MAX-based tasks. The generated binary file (.mxb) contains a binary description of the task that is used when you edit the task in the DAQ Assistant.
-
Replaces the call to DAQmxLoadTask with a call to the new task creation function.
-
Adds an include statement for the generated header file.
You have now copied the task to the project. You can open the generated source file to view the generated code.
Summary
In this tutorial, you completed the following tasks:
-
Launched the DAQ Assistant from the Tools menu in LabWindows/CVI
-
Configured a task in the DAQ Assistant
-
Tested the task using test panels
-
Loaded the task in a program
-
Generated example code to run the task
-
Edited the task in the DAQ Assistant
-
Copied the task to the project
To learn more about tasks, channels, and other NI-DAQmx concepts, refer to the NI-DAQmx Help located at Start»Programs»National Instruments»NI-DAQmx Help.
For more information about using tasks in LabWindows/CVI, refer to the LabWindows/CVI Help.
用户377235 2013-8-30 17:13
有错误
13510179723_912348475 2012-3-1 18:42