230 likes | 390 Views
Graphical Programming – fall 2004 Lecture 7 - String Functions, File I/O, Waveform Data Type. Witold Nocoń, Ph.D. http://terminator.ia.polsl.gliwice.pl/ dydaktyka/ virtual. Choose your own display type. String controls and indicators have several options you might find useful. For
E N D
Graphical Programming – fall 2004Lecture 7 - String Functions, File I/O,Waveform Data Type Witold Nocoń, Ph.D http://terminator.ia.polsl.gliwice.pl/dydaktyka/virtual
Choose your own display type String controls and indicators have several options you might find useful. For example, they can display and accept characters that are normally non-displayable, such as backspaces, carriage returns and tabs. \b Backspace \f Formfeed \n New line \r Return \t Tab \s Space \n New line \ \ Backslash Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. String functions We’ve already introduced string controls and indicators (Lecture 1), but let’s look at those more closely. If you choose ‘\’ Codes Display (instead of Normal Display) form string’s pop-up menu, non-displayable characters appear as a backslash (\) followed by the appropriate code.
Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Password Display Strings also have a Password Display option, which sets the string control or indicator to display a “*” for every character entered into it, so that no one can see what you type. While the front panel shows only a stream of “***”, the block diagram reads the actual data in the string.
Scrollbar If you choose Show > Scrollbar option from string pop-up submenu, a vertical scrollbar appears. Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Limit to single line If you choose Limit to Single Line from string’s pop-up submenu, your string cannot exceed one line of text; that is, no carriage returns are allowed in the string.
Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Tables In LabVIEW, a table is a special structure that displays a two-dimensional (2D) array of strings.
The Table’s terminal returns a two-dimensional array of strings: Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Tables Tables have row and column headings that you can show or hide; the headings are separated from the data space by a thin open border space. You can enter text headings using Labeling tool or Operating tool (like everything else). You can also update or read headings using attribute nodes.
... returns a numeric value equal to the number of characters in the string. Concatenates input strings and 1D arrays of strings into a single output string. For array inputs, this function concatenates each element of the array. Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Using string functions As it was the case with arrays for example, strings can be much more useful when you take advantage of the many build-in functions provided by LabVIEW. String Length Concatenate String
Formats string, numeric, path, or Boolean data as text. Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Using string functions In many instances, you must convert strings to numbers or numbers to strings. The Format Into String and Scan From String functions have those capabilities. Format Into String
Scans the input string and converts the string according to format string. Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Using string functions In many instances, you must convert strings to numbers or numbers to strings. The Format Into String and Scan From String functions have those capabilities. Scan From String
Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Using string functions Match Pattern Searches for regular expression in string beginning at offset, and if it finds a match, splits string into three substrings (before substring, match substring and after substring). Example: gp7_1.vi
Converts an array of any dimension to a table in string form, containing tabs separating column elements, a platform-dependent EOL character separating rows, and, for arrays of three or more dimensions, headers separating pages Conversely... Spreadsheet String To Array Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Using string functions Array To Spreadsheet String Example: gp7_2.vi
Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Using string functions A whole bunch of functions converting strings to numbers and vice versa. Example: gp7_3.vi
Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. File I/O The File I/O VIs you use depend on the format of the files. You can read data from or write data to files in two formats—text and binary. The format you use depends on the data you acquire or create and the applications that will access that data. Use the following basic guidelines to determine which format to use: • If you want to make your data available to other applications, such as Microsoft Excel, use text files because they are the most common and the most portable. • If you need to randomly access reads or writes or if speed and compact disk space are crucial, use binary files because they are more efficient than text files in disk space and in speed.
Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. File I/O - text files When to use text files: • to make your data available to other users or applications • if disk space and file I/O speed are not crucial • if you do not need to perform random access reads or writes Text files typically take up more memory than binary files if the data is not originally in text form, such as graph or chart data, because the ASCII representation of data usually is larger than the data itself. For example, you can store the number –123.4567 in 4 bytes as a single-precision floating-point number. However, its ASCII representation takes 9 bytes, one for each character.
Use the high-level File I/O VIs located on the top row of the Functions»File I/O palette to perform common I/O operations, such as writing to or reading from the following types of data: Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. File I/O - text files - high level File I/O VIs • Characters to or from text files • Lines from text files • 1D or 2D arrays of single-precision numerics to or from spreadsheet text files • 1D or 2D arrays of single-precision numerics or signed 16-bit integers to or from binary files Example: gp7_4.vi
Use the principal low-level functions to create or open a file, write data to or read data from the file, and close the file. Use the other low-level functions to perform the following tasks: • Create directories. • Move, copy, or delete files. • List directory contents. • Change file characteristics. • Manipulate paths. Example: gp7_5.vi Write a VI, that will export the computed values into a ready-to-use MATLAB m-file. Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. File I/O - text files - low level File I/O VIs
Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. File I/O - binary files When to use binary files: • if disk space and file I/O speed are crucial • if you do need to perform random access reads or writes A binary file uses a fixed number of storage bytes on disk. For example, storing any number from 0 to 4 billion in binary format, such as 1, 1,000, or 1,000,000, takes up 4 bytes for each number. Use binary files to save numeric data and to access specific numbers from a file or randomly access numbers from a file. Binary files are machine readable only, unlike text files, which are human readable. Binary files are the most compact and fastest format for storing data. You can use multiple data types in binary files, but it is uncommon. refer to LabVIEW help or the User Manual for more information
Waveform control (used as a subVI input for example) uniformly sampled data points time-domain Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Waveform Data Type The waveform control is a special cluster of components that includes time-domain, uniformly sampled waveform information only. Use the waveform functions to access and manipulate individual components. t0 - start time dt - time interval between data points Many of the VIs and functions you use to acquire or analyse waveforms accept and return the waveform data type by default.
build waveform function start time (time-stamp - usually set using Get Time/Date in Seconds function) time interval array of numbers Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Waveform Data Type Creating waveforms on the diagram Example: gp7_6.vi
time-domain information used on the x-axis Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Waveform Data Type Displaying waveforms
When system clock time is provided... ...calendar time is used on the graph. Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Waveform Data Type Displaying waveforms ... and when Ignore Timestamp option in the graph’s pop-up menu is not checked...
Waveform measurements Waveform operations Waveform file I/O Waveform generation Waveform conditioning Waveform monitoring Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Waveform Data Type Different functions are provided to manipulate waveforms...
Example: gp7_7.vi Example: gp7_8.vi Example: gp7_9.vi Waveform generation... Waveform analysis... Waveform file I/O... Graphical Programming Lecture 7- String Functions, File I/O, Waveform Data Type presented by Witold Nocoń Ph.D. Waveform Data Type Examples...