Unit 13 PowerPoint Slides

advertisement
EET 2259 Unit 13
Strings and File I/O


Read Bishop, Chapter 9.
Lab #13 and Homework #13 due next
week.
Floyd, Digital Fundamentals, 10th ed
Strings


A string is a sequence of characters.
Characters include letters, numerals,
punctuation marks, spaces, and certain
non-displayable characters such as
linefeed and tab.
(Bishop, p. 400)
Floyd, Digital Fundamentals, 10th ed
Uses of Strings

Strings have several uses in LabVIEW:



Displaying text messages to the user or
allowing the user to enter text.
Sending commands over cables to instruments
to control those instruments.
Storing data in a file on a disk.
(Bishop, p. 400)
Floyd, Digital Fundamentals, 10th ed
String Display Modes
String controls and string indicators can be
configured to display their contents in any
of the following modes:





Normal Display (the default)
\ Codes Display
Password Display
Hex Display
Hex Display shows the ASCII codes for the
Floyd, Digital Fundamentals,
10 ed
characters.

th
String Functions

You’re already familiar with some of the
functions, constants, and VIs on the
Programming > String palette.
Floyd, Digital Fundamentals, 10th ed
String Subset Function

The function
named String
Subset lets you
pull out a piece of
a string, starting at
any point in the
string that you
want.
Floyd, Digital Fundamentals, 10th ed
Numbers versus Numeric Strings

To understand many of the other functions
and VIs on this palette, answer the
following question: What’s the difference
between the two indicators shown below?
Floyd, Digital Fundamentals, 10th ed
Numbers Functions versus String
Functions
Depending on what you’re trying to do with
numeric information, you may want to have
that information represented as numeric
data or as string data.
Examples: What if you want to….






Multiply it by 2?
Find out how many digits it contains?
Round it to the nearest integer?
See whether it contains a decimal point?
Floyd, Digital Fundamentals, 10th ed
Converting Between Numbers and
Numeric Strings

The functions on the Programming >
String >String/Number Conversion
palette let you convert between numeric
data and string data.
Functions in the 1st row convert numbers to string.
Floyd, Digital 
Fundamentals,
10 ed
Functions
in the 2nd row convert strings to numbers.

th
Scan From String and Format Into
String

I recommend instead using two “superfunctions” that can do the work of all the
other conversion functions:

Use Scan From String to convert strings
to numbers.

Use Format Into String to convert
numbers to strings.
Floyd, Digital Fundamentals, 10th ed
format string Input
These two functions have a format
string input that lets you say exactly
how the number is formatted.


The example below, which uses the
Format Into String function, will format
the number into a string containing at
least 6 characters, with 3 digits following
the decimal point.
Floyd, Digital Fundamentals, 10th ed
Other String Functions

LabVIEW provides other useful string
functions not discussed in the textbook,
including:





String Length
Concatenate Strings
String Subset
To Upper Case & To Lower Case
Search & Replace String
Floyd, Digital Fundamentals, 10th ed
File I/O
Functions and VIs on the Programming >
File I/O palette let you:

Read data from
files on disk

Write data to
files on disk

Move, copy,
rename, and
delete files
(and directories)
on disk
Floyd, Digital Fundamentals,
10 edmore …

And

th
Which Kind of File?
This is a large and complex topic, because
LabVIEW can read from or write to many
different kinds of files.
These file types can be grouped into two
broad categories:




Text files, whose contents are in ASCII format.
You can open and read these files in a text
editor or word processor.
Binary files, which look like gibberish if you
open them in a text editor or word processor.
Floyd, Digital Fundamentals, 10th ed
Choosing Text File versus Binary File



If you have to save LabVIEW data to a file,
how do you decide which kind of file? It’s
a trade-off.
The big advantage of text files is
portability: you can open them in other
programs.
The big advantage of binary files is
efficiency: they take up less disk space
and can be processed more quickly than
text files.
Floyd, Digital Fundamentals, 10th ed
Which Kind of Text File?
LabVIEW can work with the following
specific kinds of text files:






Generic text files, which can contain
any text
Spreadsheet files, which contain
numbers in rows and columns
LabVIEW Measurement (.lvm) files
Configuration (.ini) files
XML files
Floyd, Digital Fundamentals, 10th ed
Which Kind of Binary File?
LabVIEW can work with the following
specific kinds of binary files:


Generic binary files.

LabVIEW TDMS (Technical
Data Management
Streaming) files

LabVIEW Datalog Files

ZIP files
Floyd, Digital Fundamentals, 10th ed
High-Level versus IntermediateLevel

The items on the File I/O palette can be
categorized as high-level or intermediatelevel.
The high-level VIs are
easier to use. They call
the intermediate-level
functions.
The intermediate-level
functions give you more
control, but require more
work on your part.
(Bishop, p. 412)
Floyd, Digital Fundamentals, 10th ed
Three Steps in File I/O

Most file I/O operations involve three steps:
1.
2.
3.


Open an existing file or create a new file.
Read data from or write data to the file.
Close the file.
The high-level VIs combine all three of
these steps into a single VI.
On the other hand, with intermediate-level
functions, you must do each step
separately, as on the next slide.
(Bishop, pp. 410-411)
Floyd, Digital Fundamentals, 10th ed
A Simple Text-File Example

Writing to a text file:

Reading it back from the file:
Floyd, Digital Fundamentals, 10th ed
A Simple Binary-File Example

Writing to a binary file:

Reading it back from the file:
Floyd, Digital Fundamentals, 10th ed
Download