Sunteți pe pagina 1din 43

Lesson 6 Managing Resources

TOPICS
A. Understanding File I/O B. Understanding High-level File I/O C. Understanding Low-level File I/O D. DAQ Programming E. Instrument Control Programming F. Using Instrument Drivers

ni.com/training

A. Understanding File I/O


File I/O writes to or reads from a file A typical file I/O operation involves the following process:

Open/ Create/ Replace File

Read and/or Write to File

Close File

Check for Errors

ni.com/training

A. Understanding File I/O File Formats


LabVIEW can use or create the following file formats: BinaryUnderlying file format of all other file formats ASCIISpecific type of binary file that is a standard used by most programs LVM The LabVIEW measurement data file (.lvm) is a tabdelimited text file you can open with a spreadsheet application or a text-editing application TDMSType of binary file created for NI products consisting of two separate files: a binary file and a binary index file
ni.com/training

A. Understanding File I/O File Formats


In this course, you learn about creating text (ASCII) files Use text files in the following situations:
You want to access the file from another application Disk space and file I/O speed are not crucial You must not perform random access reads or writes Numeric precision is not important

ni.com/training

B. Understanding High-level File I/O


High-level VIs
Perform all three steps (open, read/write, close) for common file I/O operations Might not be as efficient as the functions configured or designed for individual operations

Low-level VIs
Individual VI for each step If you are writing to a file in a loop, use low-level file I/O functions
ni.com/training

B. Understanding High-Level File I/O


Write to Spreadsheet File
Converts an array of double-precision numbers to a text string and writes the string to an ASCII file

Read From Spreadsheet File


Reads a specified number of lines or rows from a numeric text file and outputs a 2D array of double-precision numbers

Write to/Read from Measurement File


Express VIs that write data to or read data from an LVM or TDMS file format

ni.com/training

C. Understanding Low-Level File I/O VIs

ni.com/training

Exercise 6-1 Spreadsheet Example VI

Use a high-level file I/O VI to write to a spreadsheet-readable file. GOAL

Exercise 6-2 Temperature Log VI

Modify a VI to create an ASCII file using disk streaming. GOAL

Exercise 6-2 Temperature Log VI

What would happen if you used the Write to Measurement File Express VI inside the While loop?
DISCUSSION

D. DAQ Programming
1. 2. 3. 4. 5. Signal Terminal Block Cable DAQ Device Computer

ni.com/training

D. DAQ Programming Software Overview


NI-DAQmx
Driver level software Detects DAQ devices Installs NI-DAQmx functions in LabVIEW

Measurement & Automation Explorer


Configure and test DAQ device

DAQ Assistant
Configurable Express VI used to create a DAQ application

DAQmx API
Provides a set of VIs to program DAQ applications

ni.com/training

D. DAQ Programming Basic Flow


A basic DAQmx application involves the following process:
Create Task Configure Task Start Task Acquire or Generate Data Clear Task

ni.com/training

D. DAQ Programming Create Task


Create Virtual Channel VI
Creates a virtual channel and adds it to a task Use pull-down menu to select the appropriate instance of this VI

ni.com/training

D. DAQ Programming Configure Task


Configure timing if reading multiple samples
Sample rate, timing source, etc

Configure triggering if necessary for application


Configures the task to start or stop on a rising or falling digital edge, analog edge, or analog windows

ni.com/training

D. DAQ Programming Start Task


Starts the task after the task has been configured

ni.com/training

D. DAQ Programming Acquire or Generate Data


Acquire or generate data from the DAQ device Make sure pull-down menu selection is compatible with task configuration

ni.com/training

D. DAQ Programming Clear Task


DAQmx Clear Task VI
Stops the task Releases any resources the task reserved Clears the task

ni.com/training

D. DAQ Programming Example


Example acquisition with triggering

ni.com/training

E. Instrument Control Programming


Virtual Instrument Software Architecture (VISA):
High-level API that calls low-level drivers Can control VXI, GPIB, serial, or computer-based instruments and makes the appropriate driver calls depending on the type of instrument used

ni.com/training

VISA

VISA
Virtual Instrument System Architecture

Serial

GPIB

VXI

USB

ni.com/training

VISA Programming Terminology


Resource
Any instrument in the system, including serial and parallel ports

Session
When you open a session to a resource, LabVIEW returns a VISA session number, which is a unique refnum to that instrument

Instrument Descriptor
Specifies the interface type (GPIB,VXI, ASRL), the address of the device, and the VISA session type (INSTR or Event)

ni.com/training

VISA Alias
Assign a user-defined name to a device or resource in place of the instrument descriptor

ni.com/training

VISA Programming
VISA functions operate similar to File I/O functions

Open Session to Instrument(s)

Perform I/O Operation(s)

Close Session to Instrument(s)

Check for Errors

ni.com/training

VISA Open Function


Establishes communication line to resource Generally used once per resource Returns VISA Resource Name

ni.com/training

VISA I/O Functions


VISA Write and VISA Read Functions

ni.com/training

VISA Close Function


Sessions take up system resources Close sessions before program ends

ni.com/training

VISA Write and Read Example

ni.com/training

VISA Serial
The VISA Configure Serial Port VI initializes the port identified by VISA resource name to the specified settings

ni.com/training

F. Using Instrument Drivers


Organized set of VIs that control a programmable instrument
Each VI performs multiple instructions Grouped by operation type (configuration, data, etc)

Reduce development time


Simplify instrument control Reusable Common architecture and interface
ni.com/training

Using Instrument Drivers


When you use an instrument driver, the driver contains the code specific to the instrument If you change instruments, replace the instrument driver VIs with the instrument driver VIs for the new instrument, which greatly reduces your redevelopment time

ni.com/training

Using Instrument Drivers Where are they?


You can locate most LabVIEW Plug and Play instrument drivers in the Instrument Driver Finder
Access within LabVIEW by selecting Tools InstrumentationFind Instrument Drivers or HelpFind Instrument Drivers Connects you with ni.com to find instrument drivers

When you install an instrument driver


An example program using the driver is added to the NI Example Finder Instrument driver VIs are added to the Instrument I/OInstrument Drivers palette in the Functions palette
ni.com/training

Using Instrument Drivers Example

ni.com/training

Choose One: Exercise 6-3 Using DAQmx (DAQ) or Exercise 6-4 NI Devsim VI(GPIB/serial)

6-3: Explore a DAQmx example program that continuously acquires data, and modify it to wait on a digital trigger 6-4: Install an instrument driver and explore the example programs that accompany the instrument driver GOAL

Choose One: Exercise 6-3 Using DAQmx (DAQ) or Exercise 6-4 NI Devsim VI(GPIB/serial)
In Exercise 6-3, what types of VIs did you use outside of the While Loop? In Exercise 6-4, how would modify the example programs if you wanted to continuously acquire data? DISCUSSION

SummaryQuiz
1. Your continuously running test program logs to a single file the results of all tests that occur in one hour as they are calculated. If you are concerned about the execution speed of your program, should you use low-level or high-level File I/O VIs?
a) Low-level file I/O VIs b) High-level file I/O VIs

ni.com/training

SummaryQuiz Answer
1. Your continuously running test program logs to a single file the results of all tests that occur in one hour as they are calculated. If you are concerned about the execution speed of your program, should you use low-level or high-level File I/O VIs?
a) Low-level file I/O VIs b) High-level file I/O VIs

ni.com/training

SummaryQuiz
2. If you want to view data in a text editor like Notepad, what file format should you use to save the data?
a) ASCII b) TDMS

ni.com/training

SummaryQuiz Answer
2. If you want to view data in a text editor like Notepad, what file format should you use to save the data?
a) ASCII b) TDMS

ni.com/training

SummaryQuiz
3. Which of the following conveys the basic DAQmx programming flow?
a) Create TaskConfigure TaskAcquire/Generate DataStart Task b) Acquire/Generate DataStart TaskClear Task c) Start TaskCreate TaskConfigure TaskAcquire/Generate DataClear Task d) Create TaskConfigure TaskStart TaskAcquire/Generate DataClear Task

ni.com/training

SummaryQuiz Answer
3. Which of the following conveys the basic DAQmx programming flow?
a) Create TaskConfigure TaskAcquire/Generate DataStart Task b) Acquire/Generate DataStart TaskClear Task c) Start TaskCreate TaskConfigure TaskAcquire/Generate DataClear Task d) Create TaskConfigure TaskStart TaskAcquire/Generate DataClear Task

ni.com/training

SummaryQuiz
4. VISA is a high-level API that calls low-level drivers.
a) True b) False

ni.com/training

SummaryQuiz Answer
4. VISA is a high-level API that calls low-level drivers.
a) True b) False

ni.com/training

S-ar putea să vă placă și