• No results found

Additional Exercises for Strings and FileI/O

In document LabView Tutorial (Page 192-199)

Exercise 9.14.1

Build a VI that generates a 2D array of 3rows × 100 (columns) of random numbers and writes the data transposed to a spreadsheet le. Add a header to each column. Use the high-level File I/O VIs located on the File I/O palette.

tip: Use the Write Characters To File VI to write the header and the Write To Spreadsheet File VI to write the numeric data to the same le.

Save the VI as More Spreadsheets.vi in the C:\Exercises\LabVIEW Basics I directory.

Exercise 9.14.2

Build a VI that converts tab-delimited spreadsheet strings to comma-delimited spreadsheet strings, that is, spreadsheet strings with columns separated by commas and rows separated by end of line characters. Display both the tab-delimited and comma-delimited spreadsheet strings on the front panel.

tip: Use the Search and Replace String function.

Save the VI as Spreadsheet Converter.vi in the C:\Exercises\LabVIEW Basics I directory.

Exercise 9.14.3

Modify the Temperature Logger VI (Section 9.11) so the VI does not create a new le each time you run the VI. Append the data to the end of the existing temp.dat le that the Temperature Logger VI created. Run the VI several times and use a word processor application to conrm that the VI appended new temperature readings.

185 tip: Delete the Format Into File function and replace it with the Format Into String and Write File functions. Use the pos mode and pos offset parameters of the Write File function to move the current le mark.

Select FileSave As to save the VI as Temperature Logger 2.vi in the C:\Exercises\LabVIEW Basics I directory.

Chapter 10

Data Acquisition and Waveforms

10.1 Overview and Conguration of DAQ Devices

1

LabVIEW includes a set of VIs that let you congure, acquire data from, and send data to DAQ devices.

Often, one device can perform a variety of functionsanalog-to-digital (A/D) conversion, digital-to-analog (D/A) conversion, digital I/O, and counter/timer operations. Each device supports dierent DAQ and signal generation speeds. Also, each DAQ device is designed for specic hardware platforms and operating systems.

Refer to ni.com/daq2 for more information about DAQ devices.

10.1.1 DAQ System Components

Before a computer-based measurement system can measure a physical signal, such as temperature, a sensor or transducer must convert the physical signal into an electrical one, such as voltage or current. You might consider the plug-in DAQ device to be the entire measurement system, but it is actually only one system component. You cannot always directly connect signals to a plug-in DAQ device. In these cases, you must use signal conditioning accessories to condition the signals before the plug-in DAQ device converts them to digital information. The software controls the DAQ system by acquiring the raw data, analyzing, and presenting the results.

Consider the following options for a DAQ system:

• The plug-in DAQ device resides in the computer. You can plug the device into the PCI slot of a desktop computer or the PCMCIA slot of a laptop computer for a portable DAQ measurement system.

• The DAQ device is external and connects to the computer through an existing port, such as the serial port or Ethernet port, which means you can quickly and easily place measurement nodes near sensors.

The computer receives raw data through the DAQ device. The application you write presents and manipulates the raw data in a form you can understand. The software also controls the DAQ system by commanding the DAQ device when and from which channels to acquire data. Typically, DAQ software includes drivers and application software. Drivers are unique to the device or type of device and include the set of commands the device accepts. Application software, such as LabVIEW, sends the drivers commands, such as acquire and return a thermocouple reading. The application software also displays and analyzes the acquired data. NI measurement devices include NI-DAQ driver software, a collection of VIs you use to congure, acquire data from, and send data to the measurement devices.

1This content is available online at <http://cnx.org/content/m12266/1.2/>.

2http://ni.com/daq

Available for free at Connexions <http://cnx.org/content/col10241/1.4>

10.1.1.1 NI-DAQ

NI-DAQ 7.0 contains two NI-DAQ driversTraditional NI-DAQ and NI-DAQmxeach with its own applica-tion programming interface (API), hardware conguraapplica-tion, and software conguraapplica-tion.

• Traditional NI-DAQ is an upgrade to NI-DAQ 6.9.x, the earlier version of NI-DAQ. Traditional NI-DAQ has the same VIs and functions and works the same way as NI-DAQ 6.9.x. You can use Traditional NI-DAQ on the same computer as NI-DAQmx, which you cannot do with NI-DAQ 6.9.x.

• NI-DAQmx is the latest NI-DAQ driver with new VIs, functions, and development tools for controlling measurement devices. The advantages of NI-DAQmx over previous versions of NI-DAQ include the DAQ Assistant for conguring channels and measurement tasks for a device; increased performance, including faster single-point analog I/O and multithreading; and a simpler API for creating DAQ applications using fewer functions and VIs than earlier versions of NI-DAQ.

Traditional NI-DAQ and NI-DAQmx support dierent sets of devices. Refer to the National Instruments Web site3for the list of supported devices. This lesson describes the NI-DAQmx API.

Figure 10.1 shows the measurement software framework.

Figure 10.1

When programming an NI measurement device, you can use NI application software such as LabVIEW, LabWindows—/CVI—, and Measurement Studio, or open ADEs that support calling dynamic link libraries (DLLs) through ANSI C interfaces. Using NI application software greatly reduces development time for data acquisition and control applications regardless of which programming environment you use:

• LabVIEW supports data acquisition with the LabVIEW DAQ VIs, a series of VIs for programming with NI measurement devices.

• For C developers, LabWindows/CVI is a fully integrated ANSI C environment that provides the LabWindows/CVI Data Acquisition library for programming NI measurement devices.

189

• Measurement Studio development tools are for designing your test and measurement software in Mi-crosoft Visual Studio .NET. Measurement Studio includes tools for Visual C#, Visual Basic .NET, and Visual C++ .NET.

10.1.2 DAQ Hardware Conguration

You must complete several steps before you can use the Data Acquisition VIs. The devices are congured for the computers in this class.

10.1.2.1 Windows

The Windows Conguration Manager keeps track of all the hardware installed in the computer, including National Instruments DAQ devices. If you have a Plug & Play (PnP) device, such as an E Series MIO device, the Windows Conguration Manager automatically detects and congures the device. If you have a non-PnP device, or legacy device, you must congure the device manually using the Add New Hardware option in the Control Panel.

You can verify the Windows Conguration by accessing the Device Manager. You can see Data Acquisition Devices, which lists all DAQ devices installed in the computer. Double-click a DAQ de-vice to display a dialog box with tabbed pages. The General tab displays overall information regarding the device. The Resources tab species the system resources to the device such as interrupt levels, DMA, and base address for software-congurable devices. The NI-DAQ Information tab species the bus type of the DAQ device. The Driver tab species the driver version and location for the DAQ device.

LabVIEW installs Measurement & Automation Explorer (MAX), which establishes all device and channel conguration parameters. After installing a DAQ device in the computer, you must run this conguration utility. MAX reads the information the Device Manager records in the Windows Registry and assigns a logical device number to each DAQ device. Use the device number to refer to the device in LabVIEW. Access MAX either by double-clicking the icon on the desktop or selecting ToolsMeasurement & Automation Explorer in LabVIEW. The window in Figure 10.2 is the primary MAX window. MAX is also the means for SCXI and SCC conguration.

Figure 10.2

MAX detects all the National Instruments hardware including the GPIB interface. Refer to Instrument Control (Section 11.2), for more information about GPIB.

The device parameters that you can set using the conguration utility depend on the device. MAX saves the logical device number and the conguration parameters in the Windows Registry.

The plug and play capability of Windows automatically detects and congures switchless DAQ devices, such as the PCI-6024E. When you install a device in the computer, the device is automatically detected.

10.1.3 Channel and Task Conguration

In Traditional NI-DAQ you can congure a set of virtual channels, or a collection of property settings that include a physical channel, the type of measurement or generation specied in the channel name, and scaling information. In Traditional NI-DAQ and earlier versions, virtual channels are a simple method to remember which channels are used for dierent measurements. NI-DAQmx channels are similar to the virtual channels of Traditional NI-DAQ.

NI-DAQmx also includes tasks that are integral to the API. A task is a collection of one or more channels and the timing, triggering, and other properties that apply to the task itself. A task represents a measurement or generation you want to perform.

Channels created only inside a task are local. Channels dened outside a task are global and can be used separately. Conguring virtual channels is optional in Traditional NI-DAQ and earlier versions but is integral to every measurement you take in NI-DAQmx. In Traditional NI-DAQ, you congure virtual channels in MAX. In NI-DAQmx, you can congure virtual channels either in MAX or in a program, and you can congure channels as part of a task or separately.

191

In document LabView Tutorial (Page 192-199)