Electronics II Physics 3620 / 6620 Apr 15, 2009 Part 1 Strings and File I/O 4/13/2009 1
Strings A string is a sequence of displayable or - characters (ASCII) Many uses displaying messages, instrument control, file I/O We (should already have in labs 6-8) used strings (both input and output) in controlling the serial port with the ADR101 String control/indicator is in the Controls Modern String & Path subpalette 4/13/2009 2
String Display Modes By right-clicking the control or indicator, you can pick a particular display mode that suits your application. For instrument control (e.g. serial or GPIB) you typically need the \ code display Normal display \ code display Password display Hex display 4/13/2009 3
String Functions String functions can be accessed via the Functions Programming String subpalette These include, for example, the string constant, and String Length (we saw this in the even odd state machine example previously) Concatenate Strings (spaces here) 4/13/2009 4
String Functions String Subset (also used this function in the even odd state machine example) Match Pattern 4/13/2009 5
The build Text assistant starts with a dialog, which allows you to specify the variables AND any extra text to go with each. Converting Numerics to Strings: Build String You can revisit the dialog with rightclick proerties 4/13/2009 6
Converting Strings to Numerics: Scan From String This function can be very useful in parsing output from an instrument, for example, the PTH board that we used to demonstrate serial port programming 4/13/2009 7
Edit Format String You can edit the format string with an editor in Format into String and Scan from String by right clicking the function node and invoking the format xxx string dialog (bottom choice). The format string is then formed from menu choices 4/13/2009 8
File Input and Output The File I/O functions are found in the Functions Programming File I/O subpalette The organization shown below is for Version 7 Version 8 (and each sub-version) has slightly different arrangements Four Hierarchy Levels: High-level File VIs Intermediate File VIs and Functions Advanced File Functions subpalette Express VIs 4/13/2009 9
The Icons for the Spreadsheet read and write functions have changed in version 8 High-level File I/O VIs Write to Spreadsheet File Read from Spreadsheet File Write Characters to File Read Characters from File Read Lines from File 4/13/2009 10
File I/O Programming Model - Intermediate Open/ Create/ Replace File Read and/or Write to File Close File Check for Errors In version 8 there is an Open/Create/Replace File function in the File I/O subpalette, which does not pop up a dialog in the absence of a valid path I could not find the Open/Create/Replace File.vi in the function palettes There is an equivalent Open_Create_Replace File.vi in an example: Find Examples (from the starting menu) Hardware Input Output DAQmx Analog Measurements Voltage Cont Acq&Graph Voltage-To File(Binary).vi C:\Program Files\National Instruments\LabVIEW 8.0\examples\DAQmx\Analog In\Measure Voltage.llb\Cont Acq&Graph Voltage-To File(Binary).vi 4/13/2009 11
Write to File Example Open/Create/Replace opens the existing file TEST1.DAT and generates refnum and error cluster Write File writes the data Close File closes the file Simple Error Handler checks for errors ***I am posting a copy of Open_Create_Replace File.vi in today s section of the Class Materials and Lecture Notes in the class web site 4/13/2009 12
Reading Data from a File Open/Create/Replace opens the file Read File reads the specified number of bytes from the file Close File closes the file Simple Error Handler checks for errors 4/13/2009 13
Formatting a Spreadsheet String Spreadsheets are popular tools for data handling and analysis There are many formats for spreadsheet data. One of the most popular is tab-delimited: Columns are separated by a tab character Rows are separated by an end-of-line character A spreadsheet yields: Tab End of Line 4/13/2009 14
Creating a Spreadsheet File Can replace Format Into String and Write File with Format Into File in above example 4/13/2009 15
Write LabVIEW Measurement File Express VI Includes the open, write, close and error handling functions Handles formatting the string with either a tab or comma delimiter Merge Signals function is used to combine data into the dynamic data type 4/13/2009 16