Upload
cuenca0089
View
224
Download
1
Embed Size (px)
Citation preview
7/27/2019 Lesson 6 - Managing Resources
1/43
TOPICS
ni.com/training
Lesson 6
Managing Resources
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
7/27/2019 Lesson 6 - Managing Resources
2/43
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
7/27/2019 Lesson 6 - Managing Resources
3/43
ni.com/training
A. Understanding File I/OFile 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 LVMThe LabVIEW measurement data file (.lvm) is a tab-
delimited text file you can open with a spreadsheetapplication or a text-editing application
TDMSType of binary file created for NI productsconsisting of two separate files: a binary file and a binaryindex file
7/27/2019 Lesson 6 - Managing Resources
4/43
ni.com/training
A. Understanding File I/OFile 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
7/27/2019 Lesson 6 - Managing Resources
5/43
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/Ooperations
Might not be as efficient as thefunctions configured or designed forindividual 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
7/27/2019 Lesson 6 - Managing Resources
6/43
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 a2D 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
7/27/2019 Lesson 6 - Managing Resources
7/43
ni.com/training
C. Understanding Low-Level File I/O VIs
7/27/2019 Lesson 6 - Managing Resources
8/43GOAL
Exercise 6-1
Spreadsheet Example VI
Use a high-level file I/O VI to write to a spreadsheet-readable
file.
7/27/2019 Lesson 6 - Managing Resources
9/43GOAL
Exercise 6-2
Temperature Log VI
Modify a VI to create an ASCII file using disk streaming.
7/27/2019 Lesson 6 - Managing Resources
10/43DISCUSSION
Exercise 6-2
Temperature Log VI
What would happen if you used the Write to Measurement
File Express VI inside the While loop?
7/27/2019 Lesson 6 - Managing Resources
11/43
ni.com/training
D. DAQ Programming
1. Signal
2. Terminal Block
3. Cable
4. DAQ Device
5. Computer
7/27/2019 Lesson 6 - Managing Resources
12/43
ni.com/training
D. DAQ ProgrammingSoftware 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
7/27/2019 Lesson 6 - Managing Resources
13/43
ni.com/training
D. DAQ ProgrammingBasic Flow
A basic DAQmx application involves the following process:
Configure
Task
Acquire or
GenerateData
Clear
Task
Create
Task
Start
Task
7/27/2019 Lesson 6 - Managing Resources
14/43
ni.com/training
D. DAQ ProgrammingCreate 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
7/27/2019 Lesson 6 - Managing Resources
15/43
ni.com/training
D. DAQ ProgrammingConfigure 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 digitaledge, analog edge, or analog windows
7/27/2019 Lesson 6 - Managing Resources
16/43
ni.com/training
D. DAQ ProgrammingStart Task
Starts the task after the task has been configured
7/27/2019 Lesson 6 - Managing Resources
17/43
ni.com/training
D. DAQ ProgrammingAcquire or Generate Data
Acquire or generate data from the DAQ device
Make sure pull-down menu selection is compatible with task
configuration
7/27/2019 Lesson 6 - Managing Resources
18/43
ni.com/training
D. DAQ ProgrammingClear Task
DAQmx Clear Task VI
Stops the task
Releases any resources the task reserved
Clears the task
7/27/2019 Lesson 6 - Managing Resources
19/43
ni.com/training
D. DAQ ProgrammingExample
Example acquisition with triggering
7/27/2019 Lesson 6 - Managing Resources
20/43
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 typeof instrument used
7/27/2019 Lesson 6 - Managing Resources
21/43
ni.com/training
VISA
VISA
Virtual Instrument System Architecture
Serial GPIB VXI USB
7/27/2019 Lesson 6 - Managing Resources
22/43
ni.com/training
VISAProgramming Terminology
Resource
Any instrument in the system, including serial and parallel ports
Session
When you open a session to a resource, LabVIEW returns a VISAsession 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)
7/27/2019 Lesson 6 - Managing Resources
23/43
ni.com/training
VISA Alias
Assign a user-defined name to a device or resource in place
of the instrument descriptor
7/27/2019 Lesson 6 - Managing Resources
24/43
ni.com/training
Open Sessionto
Instrument(s)
Perform I/OOperation(s)
CloseSession to
Instrument(s)
Check forErrors
VISA Programming
VISA functions operate similar to File I/O functions
7/27/2019 Lesson 6 - Managing Resources
25/43
ni.com/training
VISA Open Function
Establishes communication line to resource
Generally used once per resource
Returns VISA Resource Name
7/27/2019 Lesson 6 - Managing Resources
26/43
ni.com/training
VISA I/O Functions
VISA Write and VISA Read Functions
7/27/2019 Lesson 6 - Managing Resources
27/43
ni.com/training
VISA Close Function
Sessions take up system resources
Close sessions before program ends
7/27/2019 Lesson 6 - Managing Resources
28/43
ni.com/training
VISA Write and Read Example
7/27/2019 Lesson 6 - Managing Resources
29/43
ni.com/training
VISASerial
The VISA Configure Serial Port VI initializes the port identified
by VISA resource name to the specified settings
7/27/2019 Lesson 6 - Managing Resources
30/43
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
7/27/2019 Lesson 6 - Managing Resources
31/43
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, whichgreatly reduces your redevelopment time
7/27/2019 Lesson 6 - Managing Resources
32/43
ni.com/training
Using Instrument DriversWhere are they?
You can locate most LabVIEW Plug and Play instrument driversin the Instrument Driver Finder
Access within LabVIEW by selecting ToolsInstrumentationFind Instrument Driversor HelpFind
Instrument Drivers Connects you with ni.comto 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
Driverspalette in the Functions palette
7/27/2019 Lesson 6 - Managing Resources
33/43
ni.com/training
Using Instrument DriversExample
7/27/2019 Lesson 6 - Managing Resources
34/43
GOAL
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 trigger6-4: Install an instrument driver and explore the example
programs that accompany the instrument driver
C O
7/27/2019 Lesson 6 - Managing Resources
35/43
DISCUSSION
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?
7/27/2019 Lesson 6 - Managing Resources
36/43
ni.com/training
SummaryQuiz
1. Your continuously running test program logs to a single file theresults 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 VIsb) High-level file I/O VIs
7/27/2019 Lesson 6 - Managing Resources
37/43
ni.com/training
SummaryQuiz Answer
1. Your continuously running test program logs to a single file theresults 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 VIsb) High-level file I/O VIs
7/27/2019 Lesson 6 - Managing Resources
38/43
ni.com/training
SummaryQuiz
2. If you want to view data in a text editor like Notepad, what fileformat should you use to save the data?
a) ASCII
b) TDMS
7/27/2019 Lesson 6 - Managing Resources
39/43
ni.com/training
SummaryQuiz Answer
2. If you want to view data in a text editor like Notepad, what fileformat should you use to save the data?
a) ASCII
b) TDMS
7/27/2019 Lesson 6 - Managing Resources
40/43
ni.com/training
SummaryQuiz
3. Which of the following conveys the basic DAQmx programmingflow?
a) Create TaskConfigure TaskAcquire/Generate DataStart Task
b) Acquire/Generate DataStart TaskClear Task
c) Start TaskCreate TaskConfigure TaskAcquire/GenerateDataClear Task
d) Create TaskConfigure TaskStart TaskAcquire/Generate
DataClear Task
7/27/2019 Lesson 6 - Managing Resources
41/43
ni.com/training
SummaryQuiz Answer
3. Which of the following conveys the basic DAQmx programmingflow?
a) Create TaskConfigure TaskAcquire/Generate DataStart Task
b) Acquire/Generate DataStart TaskClear Task
c) Start TaskCreate TaskConfigure TaskAcquire/GenerateDataClear Task
d) Create TaskConfigure TaskStart TaskAcquire/Generate
DataClear Task
7/27/2019 Lesson 6 - Managing Resources
42/43
ni.com/training
SummaryQuiz
4. VISA is a high-level API that calls low-level drivers.a) True
b) False
7/27/2019 Lesson 6 - Managing Resources
43/43
SummaryQuiz Answer
4. VISA is a high-level API that calls low-level drivers.a) True
b) False