EET 2259 Unit 13 Strings and File I/O

Slides:



Advertisements
Similar presentations
Intro to WinHex CSC 414.
Advertisements

Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 2 Virtual Instruments Read Bishop, Chapter 2. Lab #2 and Homework #2 due next week. Quiz #1 next week.
Based on LabVIEW 2011 Student Edition
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Access - Project 1 l What Is a Database? –A Collection of Data –Organized in a manner to allow: »Access »Retrieval »Use of That Data.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
A.How to create string controls and indicators B.Some string functions C.How to perform file input and output operations D.How to format text files for.
Introduction to LabVIEW Seth Price Department of Chemical Engineering New Mexico Tech Rev. 10/5/14.
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 13 Strings and File I/O  Read Bishop, Chapter 9.  Lab #13 and Homework #13 due next week.
Homework Reading Programming Assignments
Coding for Excel Analysis Optional Exercise Map Your Hazards! Module, Unit 2 Map Your Hazards! Combining Natural Hazards with Societal Issues.
IT253: Computer Organization
Miscellaneous Excel Combining Excel and Access. – Importing, exporting and linking Parsing and manipulating data. 1.
 A database is a collection of data that is organized so that its contents can easily be accessed, managed, and updated. What is Database?
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Office of Education Technology (OET) Active Directory Bulk Import Saturday March 11, 2006 /8:30 – 10:30 AM.
1 The EDIT Program The Edit program is a full screen text editor that allows you to: Create text files Create text files Edit an existing text files Edit.
A Simple Guide to Using SPSS ( Statistical Package for the Social Sciences) for Windows.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Chapter Three The UNIX Editors.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Programmable Logic Controller
Binary Representation in Text
Binary Representation in Text
Topic: Binary Encoding – Part 1
Lesson 5-Exploring Utilities
EET 2259 Unit 13 Strings and File I/O
Fundamentals of Python: First Programs
EET 2259 Unit 4 SubVIs Read Bishop, Chapter 4.
Do-more Technical Training
Miscellaneous Excel Combining Excel and Access.
EET 2259 Unit 11 Charts and Graphs
Topics Introduction Hardware and Software How Computers Store Data
Downloading and Preparing a StudentVoice File for SPSS
An Introduction to Computers and Visual Basic
Guide To UNIX Using Linux Third Edition
EET 2259 Unit 5 Loops Read Bishop, Sections 5.1 and 5.2.
Core LIMS Training: Advanced Administration
How to design a Windows Forms application
Other Kinds of Arrays Chapter 11
EET 2259 Unit 3 Editing and Debugging VIs
Data File Import / Export
An Introduction to Computers and Visual Basic
Intro to PHP & Variables
EET 2261 Unit 11 Controlling LCD and Keypad
Microsoft Word Reviewing Documents.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
EET 2261 Unit 11 Controlling LCD and Keypad
Creating and Modifying Queries
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Topics Introduction to File Input and Output
EET 2259 Unit 5 Loops Read Bishop, Sections 5.1 and 5.2.
Topics Introduction Hardware and Software How Computers Store Data
Benchmark Series Microsoft Word 2016 Level 2
Chapter Four UNIX File Processing.
EET 2259 Unit 6 Shift Registers
Coding Concepts (Data- Types)
An Introduction to Computers and Visual Basic
Homework Reading Programming Assignments Finish K&R Chapter 1
CST-115 Introduction to Computer Programming
EET 2259 Unit 9 Arrays Read Bishop, Sections 6.1 to 6.3.
Topics Introduction to File Input and Output
EET 2259 Unit 7 Case Structures; Sequence Structures
EET 2259 Unit 5 Loops Read Bishop, Sections 5.1 and 5.2.
EET 2259 Unit 11 Charts and Graphs
EET 2259 Unit 2 Virtual Instruments
EET 2259 Unit 4 SubVIs Read Bishop, Chapter 4.
EET 2259 Unit 6 Shift Registers
EET 2259 Unit 3 Editing and Debugging VIs
Presentation transcript:

EET 2259 Unit 13 Strings and File I/O Read Bishop, Chapter 9. Lab #13 and Homework #13 due next week.

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)

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)

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 characters.

String Functions You’re already familiar with some of the functions, constants, and VIs on the Programming > String palette. Let’s look at a few more.

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.

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?

Number 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? Try to connect a string control containing “3.14159” to a Multiply function.

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. Functions in the 2nd row convert strings to numbers. Try to concatenate floating-point numeric control named Enter Your Age with string constants “You are “ and “years old.” Then do it with conversion function.

Scan From String and Format Into String You can use two “super-functions” to do the work of all the conversion functions on the previous slide: Use Scan From String to convert strings to numbers. Use Format Into String to convert numbers to strings.

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. -Redo previous example with Format Into Sting function. Also vary the format string to %d (decimal integer), %b (binary integer), %x (hex integer), %6.3p (engineering prefixes).

Editing the Format String The many obscure symbols used in format strings are borrowed from the C language. Fortunately, you don’t have to use them. Instead, double-clicking the Format Into String function gives you an easier-to-use dialog box.

Scan From String The example below uses the Scan From String function to extract an integer that follows any combination of spaces, upper-case letters, and lower-case letters. Demo it; string control on front panel says “I am 12 years old.” Use format string %[ A-Za-z] %d and display the number in an indicator. (Select “Scan string of characters in set” followed by “Scan decimal integer.”)

Other String Functions LabVIEW provides other useful string functions not discussed in the textbook, including: String Length Concatenate Strings To Upper Case & To Lower Case Search & Replace String Demo a few by labeling two string controls “First name” and “Last name.” Find lengths of strings, concatenate them (and then add a space between and find length of total string), extract a subset, etc.

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 And more … -Point out that even if data is stored in an array when a program is run, the data is all lost when the user exits LabVIEW.

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.

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. Example: in binary format, the number 255 takes up one byte. In ASCII format, it takes three bytes.

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

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

High-Level versus Intermediate-Level The items on the File I/O palette can be categorized as high-level or intermediate-level. 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)

Three Steps in File I/O Most file I/O operations involve three steps: 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) -Closing the file when you’re finished is crucial; failure to do so can result in loss of data.

A Simple Text-File Example Writing to a text file: Reading it back from the file: Since we’re saving to a text file, we must convert all non-string dataypes to strings. -Send them fileIOWriteTextFile.vi and fileIOReadTextFile.vi from h: drive. -Examine the resulting file in Notepad.

A Simple Binary-File Example Writing to a binary file: Reading it back from the file: Since we’re not saving to a text file, we don’t need to convert all non-string dataypes to strings. -Send them fileIOWriteBinaryFile.vi and fileIOReadBinaryFile.vi from h: drive. -Examine the resulting file in Notepad.