LabVIEW Day 6: Saving Files and Making Sub vis

Similar documents
LabVIEW Day 1 Basics. Vern Lindberg. 1 The Look of LabVIEW

Creating a Gradebook in Excel

First Bytes Programming Lab 2

Lab 3: Introduction to Data Acquisition Cards

EET 310 Programming Tools

Exercise 10: Basic LabVIEW Programming

LabVIEW Report Generation Toolkit for Microsoft Office User Guide

Storing Measurement Data

Tutorial 2: Reading and Manipulating Files Jason Pienaar and Tom Miller

Personal Portfolios on Blackboard

Smartboard and Notebook 10 What s New

Excel 2013 What s New. Introduction. Modified Backstage View. Viewing the Backstage. Process Summary Introduction. Modified Backstage View

Lab View with crio Tutorial. Control System Design Feb. 14, 2006

Introduction to LabVIEW

Project 1 - Business Proposal (PowerPoint)

Hands-On: Introduction to Object-Oriented Programming in LabVIEW

Create a Poster Using Publisher

edgebooks Quick Start Guide 4

Lab 4 - Data Acquisition

Excel Reports and Macros

Introduction to Modern Data Acquisition with LabVIEW and MATLAB. By Matt Hollingsworth

MS Excel Template Building and Mapping for Neat 5

Create a New Database in Access 2010

IBM SPSS Statistics 20 Part 1: Descriptive Statistics

Access II 2007 Workshop

CONSTRUCTING SINGLE-SUBJECT REVERSAL DESIGN GRAPHS USING MICROSOFT WORD : A COMPREHENSIVE TUTORIAL

Adobe Dreamweaver CC 14 Tutorial

LabVIEW Report Generation Toolkit for Microsoft Office

Tips and Tricks SAGE ACCPAC INTELLIGENCE

Creating and Viewing Task Dependencies between Multiple Projects using Microsoft Project

MS Excel. Handout: Level 2. elearning Department. Copyright 2016 CMS e-learning Department. All Rights Reserved. Page 1 of 11

EXTRACTING IOS DATABASE

Advanced Microsoft Excel 2010

Appendix A How to create a data-sharing lab

Real Time Monitor. A Real-Time Windows Operator Interface. DDE Compliant. (for remote data display)

MicroStrategy Desktop

BID2WIN Workshop. Advanced Report Writing

2. How to Use SMART Board as a Projector and Whiteboard

Microsoft Word 2013 Tutorial

Microsoft Word Quick Reference Guide. Union Institute & University

paragraph(s). The bottom mark is for all following lines in that paragraph. The rectangle below the marks moves both marks at the same time.

Search help. More on Office.com: images templates

Business Objects InfoView Quick-start Guide

Content Management System (CMS) Training

WebSphere Business Monitor V6.2 Business space dashboards

Introduction to Microsoft Access 2010

A database is a collection of data organised in a manner that allows access, retrieval, and use of that data.

A Guide to Using Excel in Physics Lab

Aras Corporation Aras Corporation. All rights reserved. Notice of Rights. Notice of Liability

Kurz MODBUS Client User s Guide

Working with SQL Server Integration Services

Microsoft Word 2010 Tutorial

LabVIEW Tutorial Manual

MICROSOFT WORD TUTORIAL

Microsoft Access 2010 handout

Introduction to Microsoft Access 2013

Visual Basic 2010 Essentials

Excel Tutorial. Bio 150B Excel Tutorial 1

Using Adobe Dreamweaver CS4 (10.0)

The Power Loader GUI

Excel for Data Cleaning and Management

Microsoft PowerPoint Exercises 4

LabVIEW Lesson 5 Clusters

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

Creating Database Tables in Microsoft SQL Server

MAIL MERGE TUTORIAL. (For Microsoft Word on PC)

SECTION 5: Finalizing Your Workbook

Planning and Managing Projects with Microsoft Project Professional 2013

Data Visualization. Prepared by Francisco Olivera, Ph.D., Srikanth Koka Department of Civil Engineering Texas A&M University February 2004

Setting up Auto Import/Export for Version 7

The Smart Forms Web Part allows you to quickly add new forms to SharePoint pages, here s how:

MICROSOFT ACCESS STEP BY STEP GUIDE

Intellect Platform - Tables and Templates Basic Document Management System - A101

Universal Simple Control, USC-1

Website Development Komodo Editor and HTML Intro

Client Marketing: Sets

Introduction to SharePoint For Team Site Owner/Administrators. Instructional Guide

Petrel TIPS&TRICKS from SCM

Organizational Development Qualtrics Online Surveys for Program Evaluation

MultiExperiment Viewer Quickstart Guide

Introduction to SPSS 16.0

Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick Reference Guide

Using SQL Server Management Studio

Web Intelligence User Guide

Excel macros made easy

POWERPOINT BASICS: MICROSOFT OFFICE 2013

CATIA Basic Concepts TABLE OF CONTENTS

D2L: An introduction to CONTENT University of Wisconsin-Parkside

Microsoft Office. Mail Merge in Microsoft Word

DSP Laboratory: Analog to Digital and Digital to Analog Conversion

ODBC Driver Version 4 Manual

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

Agile ICT Website Starter Guides

Managing your Joomla! 3 Content Management System (CMS) Website Websites For Small Business

Page 1 S5.5 Monitoring Software Manual Rev 1.2 for Software Ver 1.0

Introduction to the TI Connect 4.0 software...1. Using TI DeviceExplorer...7. Compatibility with graphing calculators...9

What is My Teamwork? What s new in this release? MY TEAMWORK 5.0 QUICK START GUIDE

Produced by Flinders University Centre for Educational ICT. PivotTables Excel 2010

What's New in ADP Reporting?

Using Word 2007 For Mail Merge

Transcription:

LabVIEW Day 6: Saving Files and Making Sub vis Vern Lindberg You have written various vis that do computations, make 1D and 2D arrays, and plot graphs. In practice we also want to save that data. We will describe one of the methods that operates at a very elementary level. Since saving data is so fundamental, we will make this a sub-vi, making it so that it can be used in a variety of applications. 1 Steps in writing As an analogy, consider making an entry in your lab book. The following steps would be needed Tab. 1: Steps in saving data If you are writing in lab book Equivalent steps in LabVIEW Find the lab book Create a file path for file to be saved Open the lab book to a desired page Open a file Convert the data you see into pen strokes Change numbers into strings Write in the lab book Write to the file Close the lab book Close the file Check to see if your pen has run out of ink Process errors 1.1 File paths and file IDs A new data type, the File Path Type, contains information that tells the program where the file is located. On a MAC the path to a folder looks like Macintosh HD:Users:vernlindberg:Desktop:2012 Labview Course:Storage while on a PC it looks like \\neon\home$\vwlsps\my Documents\Labview2012. In addition to the path to the folder, we would need to include the filename. Once we Build this path and connect it the the Open File icon, we will use a briefer File ID to let the various file operations refer to the file in a briefer manner. 1

1 Steps in writing 2 (a) Place a File I/O File Constants Path constant on the block diagram. (b) On a Mac, right click on the Path Constant and Browse for Path. Navigate to the folder that will contain the folder for your documents and click New Folder. The folder will have been created and the path to it will be in the path constant. On a PC, create a folder in Documents called YournameLabVIEW. Now right click on the Path Constant and Browse for Path to the folder, enter the folder and click Current Folder. Finally, right click on the Path constant and Change to Control. The control will have the content you found by browsing. (c) Next add a string control for filename to the front panel, and a string constant.xls to the block diagram. Use a Strings Concatenate Strings to combine these. (d) Complete the path by placing a File I/O Build Path on the block diagram and connecting the Path Constant to base path and the file name with extension to name. The appended path output will be a complete File Path to a specific file, located in the folder you created, and having a name supplied by you with a.xls extension. 1.2 Opening a file Place a Programming File I/O Open/Create/Replace File on the block diagram. Wire the Build Path output to the file path input. Just below this terminal is an operation: right click on it and Create a constant. A ring will appear, allowing 6 choices: (a) Open (a existing file) (b) Replace (an existing file) (c) Create (a new file) (d) Open or Create (e) Replace or create (f) Replace or Create with confirmation Usually we want to create a new data, and not replace a file containing data that might be good. Choose Create in the ring. This icon will create a new file located at the file path. If a file with that name already exists, an error will result.

1 Steps in writing 3 1.3 Writing to the file (a) Place a File I/O Write to text file to the right of the open file icon. Wire the ref num out of the open to the file input on the write file. This tells the write where the file is. Wire error out to error in. We will discuss this in a bit. (b) Next we need data to be written (a string). For now, we will choose a 2D array. Go to the Front Panel, and deposit a Array, Matrix, Cluster Array, to create an array shell and insert a Numeric Control to make it a 1D numerical array. Right click on the Index Array and Add Dimension to produce a 2D array it is a null array having no information, but that is fine for now. Real data will come from the calling program. The array must be converted into a string using a String Array to Spreadsheet string. Connect the array to the input of this icon, and the output to the Write File. Connect the error lines also. (c) We must also format the numbers that go into the string. Formats start with a %. A string like %.3f means floating point format with 3 digits after the decimal point. The number is rounded. Some format strings are shown in Table 2. Tab. 2: Some formatting examples Number Format Result 12.34567 %.3f 12.346 12.34567 %.1f 12.3 12345 %.2e 1.23E4 12345 %.2e 12.34E3 12345 %.2p 12.35k 12345 % 2p 12k 12.3 %#g 12.3 123456789 %#g 1.234568E8 1.4 Closing a File Place a Programming File I/O Close file just to the right of the Write File. If you position it correctly the refnum and error lines will automatically connect, otherwise wire them.

1 Steps in writing 4 1.5 Error display Errors can occur, as we will see in a little while. Because of the way we have interconnected the error lines, the Open File must succeed before it sends an error cluster to the Write File. Likewise the Write File must complete its job before it sends an error cluster to the Close File. If an error occurs, subsequent icons connected via the error lines will not execute, and the error cluster will contain information about the error. One way to display the error cluster is to connect a Programming Dialog & Human Interface Simple Error Handler to the error output of the Close File. The simple error handler will not show anything unless a error occurs, then a pop-up window will display information about the error. 1.6 Running the program and seeing errors Enter a filename and enter some data into the array control, Run the program. Go to the location of the file and open it and you should see the array you entered. Run the program again and there will be an error shown in Figure 1. The error cluster contains a Boolean (the red X means error is true) a number for the error, here 10, and a string explaining the error. Fig. 1: Error message since we are trying to create a file that already exists. Change the File Name and run again and the program will work. 1.7 Avoiding the error, adding information to the file (a) It would be nice to avoid the error. One way to do this is to add information about the time the file was created. Add Timing Format Date/Time String. Create a

1 Steps in writing 5 constant at the time format string. You can see formatting codes on the Context Help, try %d%b%h%m%s to produce a string like 25Apr210334, i.e. 25 April at 21:03 and 34 seconds. Disconnect the.xls, increase the size of the Concatenate strings, and wire so that the file will have a name like Name25Apr210334.xls. Unless you run the program twice within the same second, this will produce unique filenames and eliminate the errors. (b) While we are at it, let s make the file more informative. Adding a date and time to the file would be good, along with comments about the program. Finally having column headers would be nice. (i) This will be accomplished with another Concatenate Strings. Place it on the block diagram and expand it to have lots of inputs. You will adjust the size later. Disconnect the old wire to the Write File and instead connect the output of the concatenate. The first row of the spreadsheet will have the date and the time. Use a Timing Get Date/Time String. One optional input is the date format which is short (1/21/94) by default, but can also be long (Friday, January 21, 1994) or abbreviated (Fri, Jan 21, 1994). Connect the date string to the first input of the concatenate. Next we want to tab to the next cell. Use a String Tab Constant and connect to the second concatenate input. Connect the time string to the third input. That is everything for the first row of the spreadsheet, use String Carriage Return Constant to go to the next row. (ii) The next row should have our comment. On the front panel place a Modern String String Control and on the block diagram wire it to the next concatenate input. Connect a Carriage Return Constant to the next concatenate input. (You can wire the same constant to more than one input.) (iii) Now for the headers this takes a little work. Start by placing on the front panel a Modern Array, Matrix, Cluster Array and inside the shell put Modern String & Path String Control. This creates a 1D array of strings of variable size. If we wired this straight to the concatenate, the elements of the array would all appear in one cell. We want to tab between cells. To do so, add a small For Loop, auto indexed (nothing connected to N) and inside place a Tab Constant connected to the second input of a Concatenate Strings. Wire the Header Array through a tunnel to the top input of the concatenate inside the For, and connect the output to the next input on your large concatenate. Follow with a Carriage Return Constant.

2 Making this a SubVI 6 (iv) Finally, connect the Spreadsheet To String output. Reduce the size of the large concatenate to just have the inputs you have connected. Enter a comment, some headers, and, run the program and examine the results. Rerun the program with the same file name to make sure that it works. 2 Making this a SubVI The program just written could be quite useful in a number of applications, so it is a good candidate for converting to a subprogram, a subvi. (a) The subvi will be easily created from our program. Inputs to the subvi will be controls, and outputs will be indicators. In order to make the program most useful, we should carefully think about what inputs and outputs we want. In this subvi we can anticipate that the File Path, File Name, Comments, Headers, Format, and Data would be useful inputs. Most of these are already controls, but you need to right click on the Path Constant and Change to Control. Likewise change the Format String Constant to a Control. Finally move the Array to the left of the other icons. There are no outputs. To aid in documentation, make the labels meaningful (b) Next drag around all the icons except the 6 controls, and Edit Create SubVI. Everything except the controls (and indicators if there were some) will disappear and a generic icon will take its place. A possible result is in Figure 2. Fig. 2: Result just after creating the subvi. I rearranged the control icons for neatness. The sub vi is just the default for LabVIEW.

3 Using a sub vi that you have written 7 (c) Hover over the generic icon and look at the Context Help and you will see the connections (6 inputs for this subvi). The names of the connectors to the subvi are just those that you gave to the controls when you wrote the program. Since there was no control for the array, this input is just called by the data type, Array. (d) Double click on the sub-vi icon and the front panel of the sub-vi will appear, with default values that you had earlier entered. Save it to a meaningful name. In the upper right corner is the Connector Panel. From either the Block Diagram or the Front Panel, you can right click on the connector panel and Edit Icon to bring up a rudimentary image editor so you can create a unique icon for your vi. Figure 3 is what I created. Fig. 3: Icon created for sub vi. This can be done from the Front Panel or the Block Diagram of the subvi. (e) From the Front Panel only, you can right click on the connector panel to Show Connector. This shows the inputs and outputs of the vi, with rectangles color coded to match the data types. (f) Documentation of the vi is very helpful. This begins with choosing good labels for the controls, for example using time delay (s) rather than Numeric Input. Another layer of help can be inserted when you have the subvi open. Use File VI Properties and use Category Documentation to enter a brief description that will appear on the Context Help. Figure 4 shows an example of how the context help could appear. 3 Using a sub vi that you have written (a) Start with a blank vi and go to the block diagram. Go to Select a VI and you will be able to search for the vi that you just created. Click on it, click Open, and you will then be able to deposit the icon on your block diagram. (b) Right click on the various inputs and outputs and create Constants or Controls for the inputs, and Indicators for any outputs. Notice that the default values of the constants or controls are what you programmed in the subvi.

4 Utility of subvis 8 Fig. 4: Context help including the icon and connectors, and documentation. If you double click on the icon for the subvi you will open the subvi and can observe its front panel and block diagrams. You can make changes to these and save the results. 4 Utility of subvis There are at least three reasons to use subvis. First it makes the main vi much easier to follow, since the detaiis of the subvi are hidden from view unless you want to look. Second, the subvi is a smaller program and can be checked and debugged on its own. Third, the subvi can be useful in more than one application. This requires that you carefully think about what inputs and outputs should come from your subvi. The subvi that we have written assumes a 2D array of numeric data to be written. This subvi is NOT polymorphic! If we want to write a 1D array of numbers, or a 2D array of Booleans, we would need a different subvi. It is possible to write your own polymorphic subvis, but we will not discuss the methods.