Sunteți pe pagina 1din 48

LabWindows /CVI Basics I TM TM

Course Manual

le
Course Software Version 8.5
May 2008 Edition
Part Number 320803K-01
LabWindows/CVI Basics I Course Manual
mp
Copyright
19942008 National Instruments Corporation. All rights reserved.
Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including
photocopying, recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written consent
of National Instruments Corporation.
National Instruments respects the intellectual property of others, and we ask our users to do the same. NI software is protected by
copyright and other intellectual property laws. Where NI software may be used to reproduce software or other materials belonging to
others, you may use NI software only to reproduce materials that you may reproduce in accordance with the terms of any applicable
license or other legal restriction.
The following notices relate to certain components used in USI (Xerces C++, ICU, HDF5, Citadel 5, b64 library, and Stingray). For a
listing of the conditions and disclaimers regarding these components, refer to the USICopyrights.chm.
Xerces C++. This product includes software developed by the Apache Software Foundation (http://www.apache.org/).
Copyright 1999 The Apache Software Foundation. All rights reserved.
ICU. Copyright 19952003 International Business Machines Corporation and others. All rights reserved.
HDF5. NCSA HDF5 (Hierarchical Data Format 5) Software Library and Utilities
Copyright 1998, 1999, 2000, 2001, 2003 by the Board of Trustees of the University of Illinois. All rights reserved.
Sa
Citadel 5. In regards to components that use Citadel 5, the following copyright applies. Copyright 1994 Hewlett-Packard Company.
b64 library. Copyright 20042006, Matthew Wilson and Synesis Software. All Rights Reserved.
Stingray. This software includes Stingray software developed by the Rogue Wave Software division of Quovadx, Inc.
Copyright 19952006, Quovadx, Inc. All Rights Reserved.
Trademarks
National Instruments, NI, ni.com, and LabVIEW are trademarks of National Instruments Corporation. Refer to the Terms of Use section
on ni.com/legal for more information about National Instruments trademarks.
The mark LabWindows is used under a license from Microsoft Corporation. Windows is a registered trademark of Microsoft
Corporation in the United States and other countries. FireWire is the registered trademark of Apple Computer, Inc. Other product and
company names mentioned herein are trademarks or trade names of their respective companies.
Members of the National Instruments Alliance Partner Program are business entities independent from National Instruments and have
no agency, partnership, or joint-venture relationship with National Instruments.
Patents
For patents covering National Instruments products, refer to the appropriate location: HelpPatents in your software,
the patents.txt file on your media, or ni.com/legal/patents.
le
mp
Worldwide Technical Support and Product Information
ni.com
Sa
National Instruments Corporate Headquarters
11500 North Mopac Expressway Austin, Texas 78759-3504 USA Tel: 512 683 0100

Worldwide Offices
Australia 1800 300 800, Austria 43 662 457990-0, Belgium 32 (0) 2 757 0020, Brazil 55 11 3262 3599, Canada 800 433 3488,
China 86 21 5050 9800, Czech Republic 420 224 235 774, Denmark 45 45 76 26 00, Finland 358 (0) 9 725 72511,
France 01 57 66 24 24, Germany 49 89 7413130, India 91 80 41190000, Israel 972 3 6393737, Italy 39 02 41309277,
Japan 0120-527196, Korea 82 02 3451 3400, Lebanon 961 (0) 1 33 28 28, Malaysia 1800 887710, Mexico 01 800 010 0793,
Netherlands 31 (0) 348 433 466, New Zealand 0800 553 322, Norway 47 (0) 66 90 76 60, Poland 48 22 3390150,
Portugal 351 210 311 210, Russia 7 495 783 6851, Singapore 1800 226 5886, Slovenia 386 3 425 42 00,
South Africa 27 0 11 805 8197, Spain 34 91 640 0085, Sweden 46 (0) 8 587 895 00, Switzerland 41 56 2005151,
Taiwan 886 02 2377 2222, Thailand 662 278 6777, Turkey 90 212 279 3031, United Kingdom 44 (0) 1635 523545

For further support information, refer to the Additional Information and Resources appendix. To comment on National Instruments
documentation, refer to the National Instruments Web site at ni.com/info and enter the info code feedback.
Contents

Student Guide
A. LabWindows/CVI Training and Certification Sequence......................................v
B. Course Description ...............................................................................................v
C. What You Need to Get Started .............................................................................vi
D. Installing the Course Software..............................................................................vii
E. Course Goals.........................................................................................................vii

le
F. Course Conventions ..............................................................................................viii

Lesson 1
Introduction to LabWindows/CVI
Introduction.................................................................................................................1-1
A. Menus and Toolbars...............................................................................................1-17
B. Function Panels ......................................................................................................1-22
C. Data Types and Scope of Variables .......................................................................1-30
mp
D. Debugging Options ................................................................................................1-34

Lesson 2
Graphical User Interface
Introduction.................................................................................................................2-1
A. Graphical User Interface (GUI) .............................................................................2-2
B. Creating a Panel .....................................................................................................2-5
C. Creating Controls ...................................................................................................2-7
D. GUI Controls..........................................................................................................2-16
E. User Interface Library ............................................................................................2-23
F. Controlling a GUI ...................................................................................................2-25
G. Event-Driven Programming...................................................................................2-34
H. CodeBuilder ...........................................................................................................2-42
I. Pop-Up Panels .........................................................................................................2-46
Sa
J. Timer Controls ........................................................................................................2-47
K. Strip Charts ............................................................................................................2-48

Lesson 3
Instrument Drivers
Introduction.................................................................................................................3-1
A. Creating an Instrument Driver ...............................................................................3-6

Lesson 4
Distributing LabWindows/CVI Applications
Introduction.................................................................................................................4-1
A. Creating Release Executables ................................................................................4-4
B. Distributing Executables ........................................................................................4-6

National Instruments Corporation iii LabWindows/CVI Basics I Course Manual


Contents

Lesson 5
Data Acquisition
Introduction.................................................................................................................5-1
A. DAQ System Overview and Configuration ...........................................................5-2
B. Using Measurement and Automation Explorer......................................................5-7
C. Analog Input Configuration Consideration............................................................5-12
D. Single-Point Analog Input .....................................................................................5-16
E. Multiple-Point Acquisition.....................................................................................5-18

le
F. Continuous Acquisition ..........................................................................................5-20
G. Single-Point Analog Output...................................................................................5-22
H. Multiple-Point Voltage Output ..............................................................................5-24
I. Continuous Multiple Voltage Output ......................................................................5-25
J. Digital Input and Output .........................................................................................5-27
K. Counters .................................................................................................................5-32
M. DAQ Assistant.......................................................................................................5-35

Lesson 6 mp
Instrument Control
Introduction.................................................................................................................6-1
A. GPIB Communication............................................................................................6-6
B. Virtual Instrument Software Architecture (VISA).................................................6-13
C. What is the Instrument I/O Assistant? ...................................................................6-19
D. Instrument Drivers .................................................................................................6-22
E. Serial Communication ............................................................................................6-30

Appendix A
Additional Information and Resources

Course Evaluation
Sa

LabWindows/CVI Basics I Course Manual iv ni.com


Lesson 5 Data Acquisition

le
mp
Introduction
This lesson introduces data acquisition.
Sa

National Instruments Corporation 5-1 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
DAQ System Overview and Configuration
The purpose of a data acquisition system is to measure or generate real-world physical signals, such as
light, temperature, pressure, sound, and so on. The building blocks of a data acquisition system are as
follows:
Transducer
Signal
Signal Conditioning eXtensions for Instrumentation (SCXI)
Sa
Data acquisition (DAQ) device
Driver level and application level software
With these five building blocks you can use your computer to measure, analyze, and present the
physical signal. Before a computer-based system can measure a physical signal, a sensor or transducer
must convert the physical signal into an electrical signal, such as a voltage or current. The plug-in DAQ
device is often considered to be the entire DAQ system, although the device is actually only one system
component. Unlike most stand-alone instruments, you cannot always directly connect signals to a plug-
in DAQ device. In these cases, you must use accessories to condition the signals before the plug-in
DAQ device converts the signals to digital information. The software controls the DAQ system by
acquiring the raw data, analyzing the data, and presenting the results.

LabWindows/CVI Basics I Course Manual 5-2 ni.com


Lesson 5 Data Acquisition

Overview and Configuration (cont.)


NI devices are packaged with NI-DAQ driver software. NI-DAQ communicates with and controls
National Instruments measurement devices, which include DAQ devices, such as the E Series,
M Series and S Series multifunction I/O DAQ devices, SCXI signal conditioning modules, and switch
modules. NI-DAQ is an extensive library of functions you can call from LabWindows/CVI to program
all the features of your NI measurement device.
When programming an NI measurement device, you can use NI application software, such as
LabWindows/CVI, or other programming environments that support calling dynamic link libraries

le
(DLLs) through ANSI C interfaces. Using NI application software guarantees integration with your
hardware and greatly reduces development time for data acquisition and control applications.

mp
Sa

National Instruments Corporation 5-3 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Measurement Software Framework
The measurement software framework includes the application software such as LabWindows/CVI,
NI-DAQ, and Measurement & Automation Explorer (MAX), which is a high-level configuration utility
that you can use to test DAQ devices and configure your measurement system.
Sensors and transducers detect physical phenomena. Signal conditioning components condition
physical phenomena so that the measurement device can receive the data. The computer receives the
data through the measurement device. Software controls the measurement system, signaling the
measurement device when and from which channels to acquire or generate data. Software also takes
Sa
the raw data, analyzes it, and presents it in a form you can understand, such as a graph, chart, or file for
a report.
NI measurement devices and application software are packaged with NI-DAQ driver software to
program all the features of your NI measurement device, such as configuring, acquiring, and generating
data from and sending data to NI measurement devices. Using NI-DAQ saves you from having to write
these programs yourself. Application software, such as LabVIEW, LabWindows/CVI, and
Measurement Studio, sends the commands to the device and then displays and analyzes the data
acquired.

LabWindows/CVI Basics I Course Manual 5-4 ni.com


Lesson 5 Data Acquisition

Measurement Software Framework (cont.)


You can use the NI-DAQ driver from NI application software or from any programming environment
that supports calling DLLs through ANSI C interfaces. NI-DAQ consists of two APIs:
Traditional NI-DAQ (Legacy)Traditional NI-DAQ (Legacy) is an upgrade of the earlier version
of NI-DAQ. Traditional NI-DAQ (Legacy) has the same functions and works the same way as
NI-DAQ 6.9.3, except you can use Traditional NI-DAQ (Legacy) and NI-DAQmx on the same
computer, and some hardware is no longer supported.
NI-DAQmx NI-DAQmx is the next generation of the NI-DAQ driver with new functions and

le
development tools for controlling measurement devices.

mp
Sa

National Instruments Corporation 5-5 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Benefits of NI-DAQmx
NI-DAQmx has many new features and advantages over the previous version of NI-DAQ.
The DAQ Assistant is a revolutionary graphical interface for configuring measurement settings,
tasks, channels, and scales. You can launch the DAQ Assistant within LabWindows/CVI or from
MAX to interactively build a measurement channel or task.
Increased performance, including faster single-point analog I/O and multithreading.
A simpler, more intuitive API for creating DAQ applications.
Sa
Similar API and functionality for ANSI C, LabWindows/CVI, and Measurement Studio, including
native .NET and C++ interfaces.
Simulate devices so that you can create code on a computer that does not necessarily have the
hardware present. NI-DAQmx simulated devices simulate the NI-DAQmx hardware, not the full
system.
Use the DAQ Assistant and NI-DAQmx Library to shorten development time and deliver an
optimized, professional application.

LabWindows/CVI Basics I Course Manual 5-6 ni.com


Lesson 5 Data Acquisition

le
mp
Measurement and Automation Explorer (MAX)
MAX is the configuration utility for National Instruments software and hardware, including DAQ
devices. Use MAX to access to all of your National Instruments DAQ, GPIB, IMAQ, IVI, Motion,
VISA, CAN, Modular Instruments, PXI, and VXI devices. You can use MAX primarily to configure
and test your National Instruments hardware, but MAX provides additional functionality, such as
checking to see if you have the latest version of NI-DAQ installed.
When you run an application using NI-DAQmx, the software reads the MAX configuration to
determine the devices you have configured. Therefore, you must configure DAQ devices first with
Sa
MAX. MAX reads the information that the Device Manager records in the Windows Registry and
assigns a logical device number to each device. MAX saves the logical device number and the
configuration parameters in the Windows Registry. Use the device number to refer to the device in
LabWindows/CVI.
The Configuration pane of MAX includes the following sections under My System:
Data NeighborhoodCreate and test virtual channels, aliases, and tags to channels or
measurements configured in Devices and Interfaces.
Devices and InterfacesConfigure resources and other physical properties of installed and
detected hardware and view attributes, such as serial numbers, of one or more devices.
ScalesSet up simple operations to perform on data, such as scaling the temperature reading from
the DAQ Signal Accessory from volts to degrees Celsius.
SoftwareView, launch, and update your installed National Instruments software.

National Instruments Corporation 5-7 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

Measurement & Automation Explorer (MAX) (cont.)


IVI DriversAccess all of your IVI logical names. Use logical names to define and name
multiple driver sessions and switch between them by referencing the logical name in an application
program.
Remote SystemsView and configure devices and systems connected over Ethernet, such as
RT Series PXI Controllers.
After installing a DAQ device in your computer, you must run MAX. With its plug and play capability,
Windows can automatically detect and configure switchless DAQ devices, such as the PCI-6024E or

le
PCI-6221M, when you install the devices in your computer.

mp
Sa

LabWindows/CVI Basics I Course Manual 5-8 ni.com


Lesson 5 Data Acquisition

le
mp
NI-DAQmx Simulated Devices
Use NI-DAQmx simulated devices to try out NI products in your application without the hardware.
Because NI-DAQmx simulated devices simulate NI-DAQmx hardware, not the full system, you cannot
currently customize the stimulated data that is returned from the simulated device. For example, analog
input tasks always return a sine wave with noise. The frequency of the sine wave changes with the
speed of the acquisition.
Note that inside of the driver, you call the exact same code for simulated devices as you do for real
devices. Therefore, if a device does not support a particular feature, such as analog triggering, you will
Sa
get an error if you try to enable analog triggering in a simulated device of that same type. This
functionality enables you to start developing your application before you have the hardware.
You can import the NI-DAQmx simulated device to a physical device using MAX. Select the
simulated device in MAX and delete it. In the dialog box that appears, you can choose to retarget the
tasks and channels that use this device to another device. You also can delete the simulated device and
rename your actual device to the name of the simulated device. All of the tasks and channels that use
the simulated device name now point to the actual device.

National Instruments Corporation 5-9 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
DAQ Signal Accessory
Take a moment to examine the terminal block, which you will be using for this coursethe DAQ
Signal Accessory. The DAQ Signal Accessory is a customized terminal block designed for learning
purposes. Like a standard terminal block, the DAQ Signal Accessory has a connector for a cable, but
instead of having just one connector, the DAQ Signal Accessory has three to accommodate many
different DAQ devices. Instead of screw terminals, the DAQ Signal Accessory has spring terminals to
connect your signals. The DAQ Signal Accessory gives you access to three analog input channels.
Channel 0 is connected to a temperature sensor, and channels 1 and 2 are open. You also have access to
Sa
Analog Output channels 0 and 1. The DAQ Signal Accessory includes a function generator with a
switch to choose the frequency range of the signal and a knob to fine tune the frequency within a
particular range. The function generator can produce a sine wave or a square wave. Between the sine
wave and square wave terminal you will find a connection to ground. A digital trigger button is
provided to produce a TTL pulse for triggering analog input or output. The trigger button signal goes
from 5 volts to 0 volts when pressed and returns back to 5 volts when released. The trigger button is
connected internally to the PFI0/Trig1 pin. Four LEDs are connected to the first four digital lines on the
DAQ device. The LEDs are reverse logic, so when the digital line is high the LED is off and vice
versa. Terminals also are provided for two counters. The DAQ Signal Accessory has a quadrature
encoder that produces two pulse trains when it is spun. The pulse trains will be out of phase by
90 degrees. The direction of rotation determines which pulse train leads the other. The DAQ Signal
Accessory also has a relay, a thermocouple input, and a microphone jack.

LabWindows/CVI Basics I Course Manual 5-10 ni.com


Lesson 5 Data Acquisition

le
mp
Sa

National Instruments Corporation 5-11 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Analog Input Configuration Considerations
Several aspects of analog input circuitry affect how you configure a DAQ device. These include the
measurement system type (single-ended and differential inputs); resolution and range of the Analog-to-
Digital Converter (ADC); the gain applied by the instrumentation amplifier; the combination of the
resolution, range, and gain to calculate a property called the code width; and the sampling rate of the
DAQ device.
Sa

LabWindows/CVI Basics I Course Manual 5-12 ni.com


Lesson 5 Data Acquisition

le
mp
Analog Input Considerations
Measurement System Type, Single-ended versus DifferentialIn a single-ended system, the
measurement is made with respect to ground. In a differential system, inputs are not connected to a
fixed reference but are measured as the difference between two terminals. The system responds only to
the potential difference between its two terminalsthe positive (+) and the negative () inputs. By
measuring the difference in voltage, the noise that each channel acquires can be subtracted effectively
from the end measurement. The drawback is that in differential mode, only half the number of channels
are available, as compared to single-ended mode. Therefore, if the number of channels is critical, the
Sa
voltage levels are high (>1 V), and the distance is relatively short (<15 ft.), single-ended mode might be
the preferred configuration. For the best accuracy and good noise immunity, the preferred input mode
is differential.
ResolutionResolution is the smallest amount of input signal change that a device or sensor can
detect. The number of bits that the ADC uses to represent the analog signal determines the resolution.
The higher the resolution, the higher the number of divisions into which the range is divided, and
therefore, the smaller the detectable voltage change. The figure above shows a sine wave and its
corresponding digital image that a 3-bit ADC obtains. A 3-bit converter divides the range into
eight (23) divisions. A binary code between 000 and 111 represents each division. The digital signal
does not represent the original signal adequately because the converter has too few divisions to
represent the varying voltages of the analog signal. By increasing the resolution from three to 16 bits,
we can increase the ADCs number of codes from eight to 65,536 (216) and the ADC can obtain an
extremely accurate representation of the analog signal.

National Instruments Corporation 5-13 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Analog Input Considerations (cont.)
RangeRange refers to the minimum and maximum voltage levels that the ADC can digitize. DAQ
devices offer selectable ranges, which are typically 0 to 10 V or 10 to 10 V. Use selectable ranges to
match the ADC range to the signal range so you can take advantage of the resolution available to
measure the signal accurately.
GainGain refers to any amplification or attenuation of a signal that might occur before the signal is
digitized. By applying gain to a signal, you can effectively decrease the input range of an ADC and
thus allow the ADC to use as many of the available digital divisions as possible to represent the signal.
Sa
For example, the figure above shows the effects of applying gain to a signal that fluctuates between 0
and 5 V when you use a 3-bit ADC and a range setting of 0 to 10 V.
With no gain applied, or gain = 1, the ADC uses only four of the eight divisions in the conversion. By
amplifying the signal with a gain of two before digitizing, the ADC now uses all eight digital divisions,
and the digital representation is much more accurate. Effectively, the device now has an allowable
input range of 0 to 5 V because any signal greater than 5 V, when amplified by a factor of two, makes
the input to the ADC greater than 10 V. If you specify the voltage limits in your function calls, the
NI-DAQ driver software automatically supplies the correct gain for the ADC.

Note This gain is used only for precision in the analog-to-digital conversion. The voltage
level measured with the NI-DAQ driver is readjusted to the correct level after the signal has
been digitized.

LabWindows/CVI Basics I Course Manual 5-14 ni.com


Lesson 5 Data Acquisition

le
mp
Analog Input Considerations (cont.)
Code WidthThe range, resolution, and gain available on a DAQ device determine the smallest
detectable change in the input voltage. This change in voltage, which is called the code width,
represents one Least Significant Bit (LSB) of the digital value. The smallest detectable change is
calculated as
Code Width = range/(gain * 2resolution in bits)

Sampling RateSampling rate determines how often an analog-to-digital (A/D) or digital-to-analog


(D/A) conversion takes place. A fast sampling rate acquires more points in a given time and therefore
Sa
often can form a better representation of the original signal than a slow sampling rate. All input signals
must be sampled at a fast enough rate to accurately reproduce the analog signal. According to the
Nyquist Sampling Theorem, you must sample at least twice the rate of the maximum frequency
component you want to detect to properly digitize the signal.
For example, audio signals converted to electrical signals often have frequency components of up to
20 kHz; therefore, you need a device with a sampling rate greater than 40 kHz to properly acquire the
signal. On the other hand, temperature transducers usually do not require a high sampling rate because
temperature does not change rapidly in most applications. Therefore, a device with a slower sampling
rate can acquire temperature signals properly.
Sampling too slowly results in a poor representation of the analog signal. Undersampling causes the
signal to appear as if it has a different frequency than it actually does. This misrepresentation of a
signal, as shown in the figure above, is called aliasing.
Note Because of the individual and accumulative effects of these factors, you must
fully understand and preplan your data acquisition system.

National Instruments Corporation 5-15 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Single-Point Analog Input
Acquiring a single sample is an on-demand operation. In other words, NI-DAQmx acquires one value
from an input channel and immediately returns the value. This operation does not require any buffering
or hardware timing. For example, if you periodically needed to monitor the fluid level in a tank, you
acquire single data points. You can connect the transducer that produces a voltage representing the
fluid level to a single channel on your measurement device and initiate a single-channel, single-point
acquisition when you want to know the fluid level.
With NI-DAQmx, you also can gather data from multiple channels. For instance, you might want to
Sa
monitor the fluid level in the tank as well as the temperature. In such a case, you need two transducers
connected to two channels on your device. The flowchart pictured in the figure above depicts the steps
you take to programmatically create an application to measure voltage.

LabWindows/CVI Basics I Course Manual 5-16 ni.com


Lesson 5 Data Acquisition

le
mp
Sa

National Instruments Corporation 5-17 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Multiple-Point Acquisition
One way to acquire multiple samples for one or more channels is to acquire single samples in a
repetitive manner. However, acquiring a single data sample on one or more channels over and over is
inefficient and time consuming. Moreover, you do not have accurate control over the time between
each sample or channel. Instead, you can use hardware timing, which uses a buffer in computer
memory to acquire data more efficiently. Programmatically, you need to include the timing function in
which you specify the sample rate and set the sample mode to finite. As with other functions, you can
acquire multiple samples from a single channel or multiple channels.
Sa

LabWindows/CVI Basics I Course Manual 5-18 ni.com


Lesson 5 Data Acquisition

le
mp
Sa

National Instruments Corporation 5-19 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Continuous Acquisition
If you want to view, process, or log a subset of samples as they are being acquired, you need to
continually acquire samples. For these types of applications, set the sample mode to continuous. The
flowchart pictured in the figure above depicts the main steps required in an NI-DAQmx application for
continuously acquiring voltage.
Sa

LabWindows/CVI Basics I Course Manual 5-20 ni.com


Lesson 5 Data Acquisition

le
mp
Sa

National Instruments Corporation 5-21 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Single-Point Analog Output
The flowchart pictured in the figure above depicts the main steps required in an NI-DAQmx
application to generate a single voltage sample.
Sa

LabWindows/CVI Basics I Course Manual 5-22 ni.com


Lesson 5 Data Acquisition

le
mp
Sa

National Instruments Corporation 5-23 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Multiple-Point Voltage Output
The flowchart depicts the main steps required in an NI-DAQmx application to generate a finite number
of voltage samples in a buffered generation.
Sa

LabWindows/CVI Basics I Course Manual 5-24 ni.com


Lesson 5 Data Acquisition

le
mp
Continuous Multiple Voltage Output
The flowchart depicts the main steps required in an NI-DAQmx application to generate continuous
voltage samples in a buffered generation.
Sa

National Instruments Corporation 5-25 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Sa

LabWindows/CVI Basics I Course Manual 5-26 ni.com


Lesson 5 Data Acquisition

le
mp
Digital Input and Output
You can measure and generate digital values in a variety of applications, including controlling relays
and monitoring alarm states. Generally, digital I/O is used in laboratory testing, production testing, and
industrial process monitoring and control.
You can use digital I/O to read from or write to a line or an entire digital port, which is a collection of
lines.
You can use the digital lines in your DAQ device to acquire or generate a digital value. This acquisition
or generation is based on software timing. On some devices, you can configure the lines individually to
Sa
either measure or generate digital samples. Each line corresponds to a channel in your task.
You can use the digital port(s) in your DAQ device to acquire a digital value from a collection of
digital lines. This acquisition is based on software timing. You can configure the ports individually to
either measure or generate digital samples. Each port corresponds to a channel in your task.

National Instruments Corporation 5-27 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Making Digital I/O Signal Connections
Most DAQ devices have a minimum of eight DIO lines: PO<0..7>, formerly DIO<0..7> and D GND.
PO<0..7> are the signals that make up the DIO port, and D GND is the ground-reference signal for the
DIO port. Signal names vary somewhat depending on your measurement device. For instance, the
digital ground on some devices is called GND. Refer to your device documentation for specific
terminal names. You can program each line individually as an input or output. The figure above shows
signal connections for three typical DIO applications.
The figure shows PO<0..3> configured for digital input and PO<4..7> configured for digital output.
Sa
Digital input applications include receiving TTL signals and sensing external device states, such as the
state of a switch. Digital output applications include sending TTL signals and driving external devices,
such as the LED shown in the figure.

Note Unlike E Series devices that support only static DIO, the M Series devices also can
support multiple sample DIO using hardware timing.

LabWindows/CVI Basics I Course Manual 5-28 ni.com


Lesson 5 Data Acquisition

le
mp
Digital Input
The flowchart in the above figure depicts the main steps required in an NI-DAQmx application to
measure digital values.
Sa

National Instruments Corporation 5-29 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Digital Output
The flowchart in the figure above depicts the main steps required in an NI-DAQmx application to
generate digital values.
Sa

LabWindows/CVI Basics I Course Manual 5-30 ni.com


Lesson 5 Data Acquisition

le
mp
Sa

National Instruments Corporation 5-31 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Counters
A counter is a digital timing device. You typically use counters for edge counting, frequency
measurement, period measurement, position measurement, and pulse generation.
A counter contains the following main components:
Count RegisterStores the current count of the counter. You can query the count register with
software.
SourceInput signal that can change the current count stored in the count register. The counter looks
Sa
for rising or falling edges on the source signal. Whether a rising or falling edge changes the count is
software selectable. The type of edge that is selected is referred to as the active edge of the signal.
When an active edge is received on the source signal, the count changes. Whether an active edge
increments or decrements the current count also is software selectable.
GateInput signal that determines if an active edge on the source will change the count. Counting can
occur when the gate is high, low, or between various combinations of rising and falling edges. Gate
settings are software selectable.

LabWindows/CVI Basics I Course Manual 5-32 ni.com


Lesson 5 Data Acquisition

Counters (cont.)
OutputOutput signal that generates pulses or a series of pulses, otherwise known as a pulse train.
When you configure a counter for simple event counting, the counter increments when an active edge
is received on the source. In order for the counter to increment on an active edge, the counter must be
armed or started. A counter has a fixed number it can count to as determined by the resolution of the
counter. For example, a 24-bit counter can count to
2Counter Resolution 1 = 224 1 = 16,777,215
When a 24-bit counter reaches the value of 16,777,215, the counter has reached the terminal count. The

le
next active edge forces the counter to roll over and start at 0.

mp
Sa

National Instruments Corporation 5-33 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Sa

LabWindows/CVI Basics I Course Manual 5-34 ni.com


Lesson 5 Data Acquisition

le
mp
DAQ Assistant Overview
The DAQ Assistant is a software interface that creates new tasks, channels, and scales. Use the DAQ
Assistant to quickly develop and deploy an application that uses data acquisition. The DAQ Assistant
provides an easy-to-use graphical interface for configuring tasks, triggers, and timing. When you
configure the DAQ Assistant, the assistant creates code that uses the NI-DAQmx functions that you
have used previously in this lesson.
Sa

National Instruments Corporation 5-35 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Creating a New Task with the DAQ Assistant
Select ToolsCreate/Edit DAQmx Tasks and launch the DAQ Assistant. In the Create/Edit DAQmx
Tasks dialog box, you can choose to create a new task in MAX, create a new task in the
LabWindows/CVI project, or edit an existing task.
Creating a new task in MAXCreate a MAX-based task if you want to use the same task in
several application environments. Because MAX-based tasks are global to a computer, you can use
the same MAX-based task in LabWindows/CVI, Measurement Studio, and LabVIEW. If you
select to create a new task in MAX, you can edit the task from LabWindows/CVI or you can edit
Sa
the task directly in MAX. Access the task in MAX by selecting My SystemData Neighborhood
NI-DAQmx Tasks. To use the MAX-based task, call DAQmxLoadTask. The function panel for
DAQmxLoadTask can display a list of all MAX-based DAQmx tasks on your computer. Press
<Enter> on the Task Name control in the DAQmxLoadTask function panel to view the list of tasks.
You also can create a new MAX-based task by selecting New Task in the Task Name control in
the DAQmxLoadTask function panel.
Creating a new task in the LabWindows/CVI projectCreate a project-based task if you want
to use the same task on several different computers. You can use project-based tasks only in
LabWindows/CVI. If you select to create a new task in the LabWindows/CVI project, the DAQ
Assistant generates source code to create the specified task programmatically. To use the project-
based task, call the task creation function declared in the generated header file.
Edit an existing taskIf you select to edit an existing task, you must choose a MAX-based or
project-based task to edit. Selecting this option opens the DAQ Assistant to edit the task. If you
select to create a new task, you must specify the measurement type for the task and select the
channels to add to the task.

LabWindows/CVI Basics I Course Manual 5-36 ni.com


Lesson 5 Data Acquisition

le
mp
Configuring a New Task with the DAQ Assistant
Custom Scaling
You can use the DAQ Assistant to create and edit scales for your tasks and channels. You can use an
NI-DAQmx scale to specify a conversion from the pre-scaled units measured by a channel to the scaled
units associated with your transducer or actuator. You can then associate this scale with one or more
channels. Often, you do not need to create an
NI-DAQmx scale because NI-DAQmx has explicit support for the most common transducers and
actuators. For example, when creating an analog input temperature channel, you can specify which type
Sa
of transducer, such as a thermistor, RTD, or thermocouple is used to make the measurement. However,
if NI-DAQmx does not explicitly support your transducer or actuator, you can create an NI-DAQmx
scale that specifies how to convert from the pre-scaled units to the scaled units. Notice that the same
NI-DAQmx scale can be associated with multiple channels. You do not need to create an NI-DAQmx
scale for each channel if the scale is the same.
To create a new scale, select Create New in the Custom Scaling option. The DAQ Assistant then
prompts you to select the type of scale to use and to enter a name for the scale. Click Finish to
complete the process.

Testing Your Configuration


You can test your configuration and make sure your sensors are connected properly using test panels.
There is a test panel for each type of measurement.
Launch the test panel for your task or channel by clicking Test in the DAQ Assistant.

National Instruments Corporation 5-37 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

Configuring a New Task with the DAQ Assistant (cont.)


Generating CodeProject-Based Tasks Only
When you configure your project-based task in the DAQ Assistant, click OK to generate the necessary
code to perform the task with the specified timing and triggering that you configured. The generated
source and header files define an entry point function that configures the task and returns a task handle.
The assistant also generates a .mxb file that contains a binary description of the task. Double-click the
.mxb file to launch the assistant and edit the task. The DAQ Assistant adds the three generated files to
the project when you create a project-based task. To use your project-based task in a program, you
must call the task creation function that is declared in the generated header file.

le
Using MAX-Based Tasks
When you create a MAX-based task, LabWindows/CVI does not automatically generate code as it does
when you create a project-based task. To use a MAX-based task in a project, call DAQmxLoadTask and
specify the name of the MAX-based task in the Task Name parameter.
When you right-click a call to DAQmxLoadTask in a Source window, a context menu appears. You can
use the commands in the context menu to edit a task, create a project-based task that is a copy of the
selected MAX-based task, show the source code required to create a task equivalent to the MAX-based
task, and generate example code.
mp
Sa

LabWindows/CVI Basics I Course Manual 5-38 ni.com


Lesson 5 Data Acquisition

le
mp
Generating Code for an Existing Task
You can generate example code for a DAQ task by right-clicking a call to DAQmxLoadTask or the
name of the task creation function of a project-based task in a Source window. In the context menu that
appears, select Generate DAQ Example Code. In the dialog box that appears, specify the run task
function name and the source file and then click OK. LabWindows/CVI generates example code that
shows how to run the selected task in a program. 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.
Sa
The generated code is not linked to the original task. Any modifications you make to the original task
are not automatically reflected in the generated code.

National Instruments Corporation 5-39 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Sa

LabWindows/CVI Basics I Course Manual 5-40 ni.com


Lesson 5 Data Acquisition

le
mp
Sa

National Instruments Corporation 5-41 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

le
mp
Lesson 5 Quiz Answers
2. You can generate example code for a DAQ task by right-clicking a call to DAQmxLoadTask or the
name of the task creation function of a project-based task in a Source window.
Sa

LabWindows/CVI Basics I Course Manual 5-42 ni.com


Lesson 5 Data Acquisition

Notes

le
mp
Sa

National Instruments Corporation 5-43 LabWindows/CVI Basics I Course Manual


Lesson 5 Data Acquisition

Notes

le
mp
Sa

LabWindows/CVI Basics I Course Manual 5-44 ni.com