TOPICS
0
ni.com/training
File Input and Output
TOPICS
A. Understanding Resources
B. File I/O
C. File Formats
D. Creating File Paths
1
ni.com/training
A. Understanding Resources
Definition of Resources
Accessing Resources in LabVIEW
2
ni.com/training
What are Resources?
Resource An addressable file,
hardware device, object, or network
connection available on your system
" LabVIEW includes VIs and functions to
allow you to access your resources.
" Resources are known to the system by a
path, name, port, or other identifier.
3
ni.com/training
Accessing Resources in LabVIEW
A typical resource operation involves the following
process:
Open, Read
Check for
Initialize and/or Close
Errors
or Create Write
" Specify the path or device name.
" The refnum becomes obsolete.
" LabVIEW creates a refnum as a
unique identifier to the resource.
" A refnum is a temporary pointer to the
resource.
4
ni.com/training
Accessing Resources in LabVIEW
Sample refnum wires:
5
ni.com/training
B. File I/O
Understanding File I/O
File Formats
High-Level and Low-Level I/O
6
ni.com/training
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/ Read
Close Check for
Create/ and/or
File Errors
Replace File Write to File
7
ni.com/training
File Formats
LabVIEW can use or create the following file formats:
" Binary Efficient, compact, and allows random access
reading but not a human-readable file. Commonly used
for high-speed and multi-channel DAQ.
" ASCII (text) Human-readable text file where data is
represented as strings. Commonly used for low-speed
DAQ.
" LVM Format built on ASCII, the LabVIEW measurement
data file (.lvm) is a tab-delimited text file you can open
with a spreadsheet application or a text-editing
application.
" TDMS An NI-specific binary file format that contains
data and stores properties about the data.
8
ni.com/training
High-Level File I/O
" High-level File I/O functions:
- 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 File I/O functions:
- Provide individual functions for
each step.
- Are efficient for writing to a file
in a loop.
9
ni.com/training
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.
10
ni.com/training
Understanding Low-Level File I/O
Functions
11
ni.com/training
Exercise:
Logging Data
What would happen if you used the Write to
Measurement File Express VI inside a While loop?
DISCUSSION
C. File Formats
Text (ASCII) Files
Binary Files
TDMS Files
13
ni.com/training
Text (ASCII) Files
" Use ASCII 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 do not need to perform random access reads
or writes.
- Numeric precision is not important.
14
ni.com/training
Binary Files: Writing
Boolean Strings
" LabVIEW represents " series of unsigned 8-bit integers, each of which has
Boolean values as 8-bit a value in the ASCII Character Code Equivalents
values in a binary file Table
" Eight zeroes represents Arrays
False : [00000000] " represented as a sequential list of the elements
" Any other value represents (representation dependent on data type of element)
True: [00000001], " a header contains a 32-bit integer representing the
[01000110], [11111111], size of each dimension
etc.
Integers
Binary Value U8 Value
00000000 0
00000001 1
00000010 2
11111111 255
ni.com/training
Binary Files: Reading
Two methods of accessing data:
" Sequential Access Read each item in order, starting at the
beginning of a file
" Random Access Access data at an arbitrary point within the
file
Random
Sequential
ni.com/training
TDMS Files
(Technical Data Management
Streaming)
TDMS file
" Binary file (.tdms) that contains data and stores properties
about the data
TDMS_Index file
" Binary index file (*.tdms_index) that provides consolidated
information on all the attributes and pointers in the TDMS
file
" Speeds up access to the data while reading
" Automatically regenerated if lost
TDMS file format internal structure is publicly documented
ni.com/training
File I/O: TDMS
Channel
" Stores measurement signals or raw data in a TDMS file
" Each channel can have properties describing the data
" The data stored in the signal is stored as binary data on disk to
conserve disk space and improve efficiency
Channel Group
" Segment of a TDMS file that contains properties and one or
more channels
" Use channel groups to organize your data and to store
information that applies to multiple channels
ni.com/training
File I/O: TDMS
Properties
" You can assign properties to
" entire file
" Channel Groups
" individual Channels
" Examples:
" File: Date/Time of logging, user signed into system
" Channel Groups: Location of sensor group (top of the
bridge), types of sensors (strain, temperature, etc.)
" Channel: Sensor ID, max/min readings
ni.com/training
File I/O: TDMS Functions
" Use the Express VIs :
" quick, but little control of organization
--- Write to Measurement File
--- Read from Measurement File
" Use the TDM Streaming API
" Total control over organization, more involved set-up
" Use the TDM Excel Add-In Tool
" Allows you to read TDMS files in Microsoft Excel
ni.com/training
20
D. Creating File Paths
Methods of Creating Paths
Creating Relative Paths
21
ni.com/training
Methods of Creating File and Folder
Paths
Hard-coded paths
- Useful for quick prototypes.
- Not recommended for applications.
File Dialog
- Allow user to specify the path to a file or directory.
- Customize dialog options to limit file types (*.txt).
Programmatic creation
- Create consistent filenames and extensions.
" Example: testdata_001.txt, testdata_002.txt, etc.
- Specify a consistent location.
ni.com/training
Creating Relative Paths
" Relative paths set paths relative to the application or
system directory.
" Paths differ based on the operating system and user.
" Look up these functions and subpalette on File I/O
functions palette:
ni.com/training
Homework:
Write Spreadsheet File
Use a high-level file I/O VI to write
to a spreadsheet-readable file.
ni.com/training
Homework:
Logging Data
Modify a VI to create an ASCII file using disk
streaming.
Save (create) the file in a path relative to the VI or
project.
ni.com/training
Homework:
Read Spreadsheet File
Use file I/O VIs or functions to read spreadsheet
files created in the previous homeworks.
ni.com/training
Wyszukiwarka
Podobne podstrony:
File Formats And Extensionsinput outputLinux File and Print Services for Macintosh and Windows Userszend layout dir and fileAudio Modular MIXER with 6 and up input ChannelExploiting File and Print SharingInput outputEV (Electric Vehicle) and Hybrid Drive SystemsMadonna Goodnight And Thank YouFound And Downloaded by Amigo2002 09 Creating Virtual Worlds with Pov Ray and the Right Front EndFunctional Origins of Religious Concepts Ontological and Strategic Selection in Evolved Mindsfile8885Found And Downloaded by AmigoBeyerl P The Symbols And Magick of Tarotwięcej podobnych podstron