 LabVIEW Help Contents

LabVIEW is a program development application that uses a graphical programming language, G, to create programs in block diagram form. This help file describes programming with G and explains how to start using LabVIEW to develop applications. The following topics are available.

Getting Started
Introduction to LabVIEW	Learn LabVIEW with Activities
Overview
Creating and Customizing VIs	Strings and File I/O
Loops and Charts	Front Panel Object Attributes
Case and Sequence Structures and the Formula Node	Program Design
Arrays, Clusters and Graphs	Error Codes
Reference
G Programming Language	Instrument I/O VIs
Data Acquisition VIs	Code Interface Node Functions
Analysis VIs	Network and Interapplication Communication
Additional Topics
Resources for Advanced Topics	Common Questions
Technical Support and Training	Related Products
About This File	Additional Documentation
© Copyright 1992, 1998	Part Number 321782A-01
National Instruments Corporation. All rights reserved.	January, 1998


How To Use Help

Welcome to an overview of the various forms of help available to you. This hypertext help file is only one of the forms of help available to you. LabVIEW also comes with its own built-in help mechanisms and a comprehensive set of paper manuals. Some information appears in printed and on-line form, some information only appears in on-line form. Each device server has its own online documentation.

For instance, the LabVIEW User Manual and G Programming Reference Manual appear in printed and on-line formats. The LabVIEW User Manual includes LabVIEW and basic G tutorial information. The G function help is only online. The G Programming Reference Manual includes fundamental concepts of the G programming language.

See the topics below for more information:

Using LabVIEW’s Built-In Help

Getting Help

Using This Hypertext Help File and Creating Your Own

Hints for Using this Help File

Creating Your Own Help Files

Getting Started/More Help

Learn LabVIEW with Activities

Where Should I Start?

How to Contact NI


Hints for Using This Help File

This topic explains how to navigate through an online help file. On each platform G supports, there are different features to help you navigate to the information you are seeking. The common information is included here. Click on the platform you use for information specific to it.

This is a hypertext help file. That means you navigate by clicking on buttons, such as those at the top of this window and on clickable items, or hotspots, in the text. Topic hotspots are green and have a solid underline. Click here for an example. Pop-up hotspots are green and have a dotted underline. Click here for an example.

Many menu and palette pictures are clickable as well. If the cursor changes to a pointing hand over an element of a picture, you are over a hotspot. Click to see more information. Move the cursor over the following picture until the pointing hand appears and click.

Windows 95/NT Help

Windows 95 (and Windows NT 4.0) help files use a new interface featuring a contents, index and find tab. The contents tab gives you an expandable, collapsible hierarchical guide to all the topics in the help file. The index tab contains a keyword search engine that can span multiple help files in one help suite. The find tab is a full text search engine that you can use to find things not indexed. To learn how to use the features see the Windows 95 help file for a complete introduction.


Example Topic

Clicking on these spots send you to a new topic, like this one. Click on the Back button above to go back to the hints topic.


Pop-up Example

Information shows up in a floating window. Click anywhere to go back to the original topic.


Example Graphic Hotspot Topic

Click anywhere to go back to the original topic.


Example Graphic Hotspot Topic

Click anywhere to go back to the original topic.


Example Graphic Hotspot Topic

Click anywhere to go back to the original topic.


Example Graphic Hotspot Topic

Click anywhere to go back to the original topic.


Example Graphic Hotspot Topic

Click anywhere to go back to the original topic.


Example Graphic Hotspot Topic

Click anywhere to go back to the original topic.


Example Graphic Hotspot Topic

Click anywhere to go back to the original topic.


Examples

If you are using data acquisition (DAQ) or Instrument I/O (GPIB, Serial, or VXI) and want to find examples, go through the Solution Wizard by starting LabVIEW and selecting the Solution Wizard button.  To find any other type of examples, go through the Search Examples on-line help file by starting LabVIEW and selecting the Search Examples button.


Introduction to LabVIEW

LabVIEW is a program development application, much like C or BASIC, or National Instruments LabWindows. However, LabVIEW is different from those applications in one important respect. Other programming systems use text-based languages to create lines of code, while LabVIEW uses a graphical programming language, G, to create programs in block diagram form.

LabVIEW, like C or BASIC, is a general-purpose programming system with extensive libraries of functions and subroutines for any programming task. LabVIEW also contains application-specific libraries for data acquisition, GPIB and serial instrument control, data analysis, data presentation, and data storage. LabVIEW also includes conventional program development tools, so you can set breakpoints, animate the execution to see how data passes through the program, and single-step through the program to make debugging and program development easier.

For more information about G, see any of the topics in the G Programming Language Help File section of this help file.

Related Topics

Required System Configuration

Where Should I Start?

Organization of the LabVIEW System


Required System Configuration

This section describes the minimum system requirements needed to run LabVIEW 5.0 on Windows, Macintosh, or UNIX>out1.

Windows

LabVIEW for Windows is distributed primarily on CD, which contains versions for Windows 3.1, Windows 95, and Windows NT. This CD also includes the complete instrument driver library that was available when LabVIEW 5.0 released.

If you do not have a CD-ROM drive, the Windows 3.1 and Windows 95 versions are available on floppy disks. The floppy disk versions for Windows 3.1 and Windows 95 are available separately as a Base Development System and a Full Development System. The Base Development System consists of a set of disks for installing LabVIEW and the associated VIs. The Full Development System includes the Base Development System disks as well as a second set of disks for installing the advanced analysis VIs.

The LabVIEW Online Tutorial default configuration requires the LabVIEW 5.0 distribution CD to be in your CD-ROM drive. If this configuration is not suitable for your needs, you can install the LabVIEW Online Tutorial files on your hard drive. You need approximately 40 MB of hard disk space to do this.

The LabVIEW Online Tutorial and LabVIEW Help files contain 256-color graphics. Your video driver, configured through Control Panels»Display, must be configured for 256 colors. Minimum requirements to view the tutorial are 800 × 600 pixel resolution and the Microsoft Video for Windows driver. For viewing Help files, National Instruments recommends that you configure your video driver for 256 colors with 800 × 600 pixel resolution.

Note	(Windows NT 4.0) If your display is in 16-bit mode, you might want to change it to 256 or 24-bit color for better performance when viewing the LabVIEW Online Tutorial.

(Windows 3.1) LabVIEW 5.0 for Windows 3.1 runs on Windows 3.1 and Windows for Workgroups 3.1 in 386 enhanced mode. National Instruments recommends that you have a minimum of 8 MB of RAM. LabVIEW can run on an 80386-based PC, but a computer with an 80486 CPU is strongly recommended. In addition, LabVIEW for Windows requires a math coprocessor if you are using an 80386- or 80486-based PC.

(Windows 95) LabVIEW 5.0 for Windows 95 runs on any system that supports Windows 95. You should have a minimum of 8 to 12 MB of RAM for this version to run effectively.

(Windows NT) LabVIEW 5.0 for Windows NT only runs on Windows NT version 3.5.1 or greater. You should have a minimum of 12 to 16 MB of RAM for this version to run effectively. LabVIEW for Windows NT only runs on Windows NT 80x86 computers. It does not run on other processors, such as the DEC Alpha, MIPS, or PowerPC, because LabVIEW uses 80386 instructions. DEC Alpha, MIPS, and PowerPC 80x86 emulators must emulate 80386 instructions to run LabVIEW.

Note	On Windows systems, you need approximately 50 MB of disk storage space for a minimal installation of LabVIEW or 70 MB for a full installation.

Macintosh

LabVIEW for Macintosh is distributed either on a CD containing both 680x0 and Power Macintosh software, or on a set of floppies for the 680x0 Macintosh. The Power Macintosh software is only available on CD. In addition to the LabVIEW application, the CD also contains an instrument driver directory that includes all the LabVIEW instrument drivers available when LabVIEW 5.0 was released.

The floppy disk version of LabVIEW for the 680x0-based Macintosh is available as a Full Development System, which contains a set of disks for installing LabVIEW and the associated VIs. In addition, you also can install the VXI VI library.

LabVIEW for the 680x0-based Macintosh requires a math coprocessor. You cannot use a 68000-based computer, such as the Macintosh SE. If you are using a Macintosh IIsi or a Macintosh LC, you might not have a math coprocessor in your computer. Also, computers using the 680LC40 processor (Centris 610s and some low-end Centris 650s) do not have the math coprocessor functions, and therefore cannot run LabVIEW.

LabVIEW requires a minimum of 6 MB of available RAM, in addition to the RAM requirements for your system software and any other applications that you want to run simultaneously. National Instruments recommends that you have at least 8 MB of RAM. You might need more memory, depending on the size of the application you design in LabVIEW and the amount of data that your application manipulates.

The preferred color configuration is thousands of colors (16-bit color) or better.

LabVIEW requires System 7 or 8 and cannot run on System 6 or any previous versions of the Macintosh operating system.

For more accurate timing, install the Apple QuickTime extension. When you use QuickTime, timing accuracy should increase from 16.6 ms resolution to approximately 1 ms resolution. System response varies depending on background applications, other extensions, networking activity, and disk caching.

Note	On Macintosh systems, you need approximately 50 MB of disk storage space for a minimal installation of LabVIEW or 70 MB for a full installation.

UNIX

LabVIEW for Sun and HP-UX is distributed on CD only. LabVIEW for Concurrent PowerMAX is distributed on 4 mm DAT tape. These versions are not available on floppy disks. LabVIEW requires an X Window System server, such as OpenWindows 3, HP-VUE, or X11R6. LabVIEW does not require a specific graphical user interface (GUI) such as Motif or OpenLook, because LabVIEW uses Xlib to create its own GUI.

LabVIEW for Sun runs on SPARCstations with SunOS 4.1.3 or later, and Solaris 2.4 or later. LabVIEW for HP-UX runs on Hewlett-Packard Model 9000 Series 700 computers with HP-UX 9.0.5 or later. LabVIEW for Concurrent PowerMAX runs on PowerMAX version 4.1 or later.

The workstation should have 32 MB of RAM, with 32 MB or more of swap space storage for LabVIEW to run effectively. In addition, the workstation must have a minimum of 65 MB of disk storage space if you want to install the entire LabVIEW package. If you want to save space, install only the VIs you plan to use.

LabVIEW uses a directory for storing temporary files. Some of the temporary files are large, so keep several megabytes of disk space available for this temporary directory. The default for the temporary directory is /tmp. You can change the temporary directory by selecting Edit»Preferences….

If LabVIEW aborts unexpectedly, it might leave files behind in the temporary directory. Remove old files occasionally to avoid depleting your disk space.

(Sun) You can use a TMPFS file system for this directory to improve performance. For Solaris 1.x, refer to the Sun System and Network Administration manual, part number 800-3805-10, for more information about the TMPFS file system. Solaris 2 uses TMPFS by default.

Operating System Patches on Sun

If you plan to run LabVIEW on SunOS 4.1.3, you need to obtain the latest revision of the following patch from Sun:

•	100458-xx: Setitimer sometimes fails to deliver SIGALRM

You do not need any other patches to run LabVIEW on Solaris 2.4 or later.

You need at least the following patches to run LabVIEW on Concurrent PowerMAX 4.1. The base patches are odd numbers only.

patch	base-001	Base System Patch 001
patch	base-003	Base System Patch 003
patch	base-005	Base System Patch 005
patch	base-007	Base System Patch 007
patch	base-009	Base System Patch 009


Organization of the LabVIEW System

After you complete the installation, as described in the LabVIEW 5.0 Release Notes that come with your software, your LabVIEW directory contains the following files:

File Name	Description
LABVIEW.EXE	This is the LabVIEW program. Launch this program to start LabVIEW.
vi.lib directory	Contains libraries of VIs that ship with LabVIEW, including GPIB, analysis, and data acquisition (DAQ) VIs, among others. LabVIEW adds the VIs in vi.lib to the Functions menu.
examples directory	Contains numerous subdirectories of examples. This directory also contains a VI called readme.vi that serves as a guide to the examples.
gpibdrv/ serpdrv/ daqdrv	These files serve as part of LabVIEW's interface to GPIB,  serial port, and DAQ communication, respectively. These files must be in the same directory as vi.lib.
lvdevice.dll	This file provides timing services to LabVIEW and must be in the same directory as vi.lib for LabVIEW to run.
lvimage.dll	This file allows LabVIEW to load images created using a variety of graphics programs.
WIBCONF.EXE	You can use this program to configure your GPIB hardware.
WDAQCONF.EXE	You can use this program to configure your DAQ hardware. In addition, the LabVIEW installation utility installs several driver files so that you can use GPIB and/or DAQ plug-in boards.
WINDOWS\ GPIB.DLL	LabVIEW uses DLL for GPIB communication.
WINDOWS\ GPIB.INI	This is the configuration file for the GPIB DLL. You use WIBCONF.EXE to edit this file.
WINDOWS\SYSTEM \ATWDAQ.DLL or MCWDAQ.DLL	These are the DAQ DLLs that LabVIEW uses to communicate with data acquisition.
WINDOWS\SYSTEM \NIVISRD.386	This is a virtual driver that handles LabVIEW interrupt services. It is optional; you do not have to install it to run LabVIEW DAQ VIs.
WINDOWS\SYSTEM \NIVDMAD.386	This installer works with EISA and Micro Channel computers. On EISA computers, the installer modifies the SYSTEM.INI file to use it instead of the built-in Windows VDMAD driver. On Micro Channel computers, this DMA auto-initialization mode allows high-speed data acquisition and generation.


Support and Training
Technical Support and Training                    {button How to Contact NI,JumpId(`LVHelp.HLP>out1’, `How_to_Contact_NI’)}

National Instruments offers hands-on LabVIEW courses designed to save you and your company time and money by getting you up the learning curve and shortening your application development time. We offer the courses at our corporate headquarters in Austin, Texas, our international branch offices, regionally in cities around the world, or in your facility. Contact us for a course schedule, a detailed course outline, or to arrange a course at your facility.

Technical Support

How To Contact NI

National Instruments Technical Support

Technical Support Form VI

Training Courses

LabVIEW Basics Course

LabVIEW Advanced Course

LabVIEW Topics Course

Data Acquisition Course

GPIB Course

VXI Course

LabVIEW Basics-Interactive

LabVIEW Instructional Video

Note	The LabVIEW courses are offered on Windows and Macintosh. Because LabVIEW is functionally similar on all platforms, the training offered pertains to all LabVIEW platforms.


How To Contact NI

National Instruments has technical assistance through electronic, fax, and telephone systems to quickly provide the information you need. Our electronic services include a bulletin board service, an FTP site, a Fax-on-Demand system, and e-mail support. If you have a hardware or software problem, first try the electronic support systems. If the information available on these systems does not answer your questions, we offer fax and telephone support through our technical support centers, which are staffed by applications engineers.

Note	Before contacting National Instruments for technical support, fill out the Technical Support Form VI.

National Instruments Technical Support


National Instruments Technical Support

Bulletin Board Support

National Instruments has BBS and FTP sites dedicated for 24-hour support with a collection of files and documents to answer most common customer questions. From these sites, you can also download the latest instrument drivers, updates, and example programs. For recorded instructions on how to use the bulletin board and FTP services and for BBS automated information, call 512 795 6990. You can access these services at:

United States:  512 794 5422 Up to 14,400 baud, 8 data bits, 1 stop bit, no parity

United Kingdom:  01635  551422 Up to 9,600 baud, 8 data bits, 1 stop bit, no parity

France: 01 48 65 15 59 Up to 9,600 baud, 8 data bits, 1 stop bit, no parity

FTP Support

To access our FTP site, log on to our Internet host:

ftp://ftp.natinst.com

Enter anonymous and use your Internet address, such as joesmith@anywhere.com, as your password. The support files and documents are located in the /support directories.

WWW Support

Point your Web browser to:

http://www.natinst.com/

Fax-on-Demand Support

Fax-on-Demand is a 24-hour information retrieval system containing a library of documents on a wide range of technical information. You can access Fax-on-Demand from a touch-tone telephone at 512 418 1111.

E-Mail Support (Currently USA Only)

You can submit technical support questions to the applications engineering team through e-mail at the Internet address listed below. Remember to include your name, address, and phone number so we can contact you with solutions and suggestions.

support@natinst.com

Telephone and Fax Support

National Instruments has branch offices all over the world. Use the list below to find the technical support number for your country. If there is no National Instruments office in your country, contact the source from which you purchased your software to obtain support.

Country	Phone	Fax
Australia	03 9879 5166	03 9879 6277
Austria	0662 45 79 90 0	0662 45 79 90 19
Belgium	02 757 00 20	02 757 03 11
Brazil	011 288 3336	011 288 8528
Canada (Ontario)	905 785 0085	905 785 0086
Canada (Québec)	514 694 8521	514 694 4399
Denmark	45 76 26 00	45 76 26 02
Finland	09 725 725 11	09 725 725 55
France	1 48 14 24 24	1 48 14 24 14
Germany	089 741 31 30	089 714 60 35
Hong Kong	2645 3186	2686 8505
Israel	03 6120092	03 6120095
Italy	02 413091	02 41309215
Japan	03 5472 2970	03 5472 2977
Korea	02 596 7456	02 596 7455
Mexico	5 520 2635	5 520 3282
Netherlands	0348 433466	0348 430673
Norway	32 84 84 00	32 84 86 00
Singapore	2265886	2265887
Spain	91 640 0085	91 640 0533
Sweden	08 730 49 70	08 730 43 70
Switzerland	056 200 51 51	056 200 51 55
Taiwan	02 377 1200	02 737 4644
United Kingdom	01635 523545	01635 523154
United States	512 795 8248	512 794 5678


Technical Support Form VI

Complete all categories of the Technical Support Form.vi before you contact National Instruments for technical support. Completing this form accurately helps our applications engineers answer your questions more efficiently.

You can advance through the fields of a category by pressing the Tab key.

After completing the form, save it by selecting Save from the File menu, or by pressing the Save .tsf File button. The .tsf (technical support form) file, a binary file that can only be opened by the Technical Support Form.vi, contains all of the information that you enter in the Technical Support Form.vi. You must save a .tsf file to retain this information for future problems. The Technical Support Form.vi displays the last .tsf file accessed when it starts.

Update the form each time you make changes to your software or hardware. You can use the same .tsf file for every problem by simply changing the Problem Description, or you can save a different .tsf file for each problem by selecting Save As… from the File menu of the Technical Support Form.vi.

To change the name of a technical support form (.tsf) file, select Save As… from the File menu. If Form name is untitled.tsf, a .tsf file has not been saved to disk. You can save the file by selecting Save from the File menu, or by pressing the Save .tsf File button.

After you have completed the technical support form, you can save the information to a text file. To create an ASCII file, select Save Text File… from the File menu, or press the corresponding button. You can then submit this to National Instruments for technical support. For e-mail support, attach the text file you created to your e-mail. For fax support, print the text file you created by using a text editor application, and fax this document. For telephone support, have the completed information available for the support engineer.

You can get help for an item by selecting Show Help from the Help menu of the Technical Support Form.vi, and then placing the cursor over the item.

National Instruments has electronic technical support on the Instrumentation Web, an electronic BBS, and an FTP site. For more information, select How to Contact NI… from the Help menu of the Technical Support Form.vi.


Basics Course

This 3-day hands-on course, designed for new or novice users, shortens the initial learning curve and gives you a head start on your application. The course progresses from LabVIEW fundamentals and the construction of simple virtual instruments (VIs) to building a complete application involving data acquisition, analysis, and presentation.


Advanced Course

This 2-day hands-on course builds on topics covered in the Basics course and extends your understanding of LabVIEW so that you can take full advantage of its features, such as attribute nodes, local variables, the Control Editor, and bundle and unbundle by name functions. It also covers techniques to reduce memory requirements, optimize execution speed, and build the highest performance, most efficient VIs.


Data Acquisition Course

This 2-day hands-on course is for users who want to use LabVIEW to control plug-in data acquisition (DAQ) boards. In the LabVIEW DAQ course, we teach you how to select the right components to implement a computer-based data acquisition and control system. Beginning with an introduction to transducers and signal conditioning, the course continues with how to correctly wire signals to your signal conditioning hardware or DAQ board to minimize noise and avoid ground loops. The course discusses all components of a DAQ system, including analog, digital, and counter/timer I/O. Practical hands-on exercises use thermocouples, strain gauges, and SCXI signal conditioning hardware connected to a multifunction DAQ board. We recommend that you have prior LabVIEW experience or attend the LabVIEW Basics course prior to attending this course.


GPIB Course

This two day, hands-on GPIB course teaches you how to build, configure, and control GPIB applications using LabVIEW. This course includes information on using LabVIEW’s GPIB VIs, serial polling devices, instrument drivers, and using GPIB to communicate with multiple computers.


VXI Course

This two day, hands-on VXI course teaches you how to build, configure, and control a VXIbus system using LabVIEW. This course teaches you to create and run applications that perform A/D data acquisition, waveform generation, counter/timer operations, and digital multimeter operations.


LabVIEW Basics-Interactive!

LabVIEW Basics - Interactive! is a self-paced multimedia course on CD-ROM that teaches LabVIEW concepts through an interactive user interface. Experience high quality video and audio as a National Instruments applications engineer builds example VIs onscreen. Based on material from the highly acclaimed LabVIEW Basics course, LabVIEW Basics - Interactive! progresses from LabVIEW fundamentals and the construction of simple VIs to developing data acquisition and instrument control applications.

LabVIEW Basics - Interactive! ships on a single CD-ROM that will run on PC's under Windows 95, Windows 3.1 or greater, and Macintosh/Power Macintosh running System 7.1 or greater. LabVIEW version 4.0 or greater must be installed separately.


LabVIEW Instructional Video

Using LabVIEW -Introduction is a two-hour instructional video that will help you to begin building your LabVIEW applications more quickly. This video is based on the LabVIEW Basics course, and it provides you with LabVIEW fundamentals, including dataflow programming, building simple VIs, creating subVIs, and using array and graphs.


LabVIEW Topics Course

This 2-day course teaches advanced topics, such as memory management, communications, and calling external devices. The types of LabVIEW communication you can learn about are TCP/IP, UDP, DDE, and OLE. You will learn how to call external devices using the code interface node and the call library function.


Related Products

National Instruments Device Server software is available for a variety of protocols, PLCs, and buses. National Instruments is continually expanding this support, so please contact us by using the Technical Support Form VI to determine the current list of servers available.

Add-On Toolkits

Each add-on toolkit adds application-specific functionality to the base BridgeVIEW and LabVIEW system. Toolkits include VI libraries and complete documentation. Most toolkit VIs are delivered in G block diagram source code, so you can make modifications to VIs as required by your application. The family of G toolkits includes:

Internet Toolkit for G

SQL Toolkit

SPC Toolkit

PID Control Toolkit

Picture Control Toolkit

Fuzzy Logic Toolkit

Joint Time-Frequency Analysis Toolkit

Third Octave Toolkit

Digital Filter Toolkit

Wavelet Toolkit

G Math Toolkit

Contact NI

Instrument Drivers

An instrument driver is software that controls an instrument using GPIB, Serial, VISA or CAMAC interface. LabVIEW and BridgeVIEW are suited for creating instrument drivers because you can model the panel of the instrument on a VI front panel and use the block diagram to send the necessary control commands to the instrument. Therefore you no longer need to remember or type in the commands to control that instrument. You simply use the controls on the VI front panel. Controlling the instrument from a software front panel is of little value. The real advantage is that you can use the instrument driver as a subVI in conjunction with other subVIs in a larger VI to control an entire system. Use the links below to find out how to get instrument drivers.

To find out how to access the latest instrument drivers, see the Technical Support Form VI topic.


Test Executive
Test Executive Toolkit

Features

•	Test sequencing with dependencies

•	Test results logged and ASCII test reports created

•	Halt and loop capabilities on individual test failure

•	Force conditions

•	Continuous UUT testing mode

•	User prompts, pass/fail banners, and error reporting

•	Pre-run and post-run routines

•	Halt and loop capabilities on individual test failure

•	Three operating levels

Overview

The LabVIEW Test Executive Toolkit is a multi-purpose LabVIEW add-on package for automated test execution. Using this toolkit, you can control the execution of sequences of tests for production and manufacturing test applications. The Test Executive Toolkit includes a ready-to-run Test Executive application developed in LabVIEW that you can use as delivered or customize to meet your organization’s specific requirements and standards. The toolkit delivers the Test Executive in block diagram source code with high-level modules, making it easy to modify to meet your application needs.

Ready-to-Run Test Executive Application

The Test Executive Toolkit also includes a ready-to-run Test Executive application that you can use immediately for your automated test application. This application includes capabilities for test sequencing based upon pass/fail results, logging of test results, ASCII test report generation, three-level password-protected access, and system setup and shutdown routines.

The Test Executive also includes an intuitive, multilevel user interface for displaying test results, operator and UUT serial number prompts, pass/fail banners, and run-time error reporting. A single-window operator interface presents only the information that is relevant to the operator for a given test situation. Three levels of operators, determined by the password string, have access to different levels of functionality. The first level, called Operator, restricts the user to loading sequences from the file and running them to completion. The second level, called Technician, may run individual tests for diagnostic purposes. The third level, called Developer, has access to the full sequence editing capabilities of the Test Executive.

Limit checking and test dependencies give you complete control of your test process. Using an intuitive tabular format, you can specify a set of passes or failures of previous tests required for a given test to run. You can also force the skipping of a test or simulate a pass or fail condition, so you can develop and debug test sequences without being connected to the actual test hardware. You configure all these options using the Sequence and Dependencies Editors included with the Toolkit. Test sequences you create with the Sequence Editor are stored in files for retrieval on the actual test system.

Developed and Delivered in LabVIEW Source Code

The Test Executive is written in the LabVIEW graphical programming language. You receive the block diagrams for block diagrams for all VIs in the Toolkit. Because it is written in the LabVIEW graphical programming language, you can easily modify the Test Executive or any of its components. Common modifications made to the Test Executive include changes to the password criterion, pass/fail banners, UUT serial number prompt, and the test report generation.

The existing program gives you direction on how to implement key Test Executive functions so you don’t have to start from scratch. Because the same language is used for both the Test Executive and test programs, you have to learn only one development language to satisfy all your automated test needs.


SQL
SQL Toolkit

Features

•	Direct interaction with a local or remote database

•	Connection to most popular databases

•	High-level, easy-to-use VIs for common database operations

•	Complete SQL operation

•	Low-level VIs for direct access on columns, records, and tables.

Overview

DatabaseVIEW is a collection of BridgeVIEW and LabVIEW VIs for direct interaction with a local or remote database. High-level Access VIs simplify database access by intelligently encapsulating common database operations into easy-to-use VIs. For example, the Easy SQL VI performs a complete structured query language (SQL) operation on a connected database. First, the SQL statement is executed, then any resulting query data is directly retrieved into the BridgeVIEW or LabVIEW block diagram. Low-level Interface VIs directly access the database, operating on columns and records in database tables.

Structured Query Language

Medium VIs use the SQL, which is a set of commands used to describe, insert, and retrieve information in databases tables. It is a nonprocedural language with which you can refer to and process sets of records in a database. There are three classes of SQL commands – statements to define the structure of the database and control access to it; statements to manipulate the content of data tables; and statements used to query or retrieve data from database tables.

Examples of data definition commands include CREATE, ALTER, and DROP, which are used to define, change, and delete tables, respectively. Data manipulation commands include INSERT, UPDATE, and DELETE, which are used to place data into the database record by record, change a particular record, or delete a record. Queries are carried out with the SELECT command. This statement is interpreted as “retrieve the columns ‘build_time’ from the ‘prodstats’ table, selecting only those rows where the value of the ‘lot’ column equals the specified value.

Front End and Back End Database Connections

By integrating Medium products into your application productivity will increase for all information intensive problems. You can create front ends to databases that present information with the powerful GUI of BridgeVIEW and LabVIEW. You can create database back ends using BridgeVIEW or LabVIEW data acquisition, instrument drivers, and graphical programming to populate database tables with vital process, test, or research information.

You can more easily create automated test equipment (ATE) systems by using a database to organize and retrieve complex test regiments and also store vast amounts of data and summary results. Manufacturing SPC, and supervisory control and data acquisitions (SCADA) systems benefit from the flexibility of DatabaseVIEW to connect to more than two dozen industry-standard databases, facilitating easy multiapplication integration with a database as an information exchange and repository.

You don’t even need to own a database to build these powerful systems. DatabaseVIEW comes with a database engine capable of creating flat-file databases that you can populate with information, update, and query with indexing, record locking, and transaction handling, all directly from BridgeVIEW or LabVIEW. You can even share these database tables among networked BridgeVIEW or LabVIEW applications!


SPC
SPC Toolkit

Features

•	Integrate SPC directly into your BridgeVIEW or LabVIEW applications

•	Perform online SPC while collecting data or analyze recorded data

•	Create control charts

•	Display process statistics and histograms

•	Perform Pareto analysis

Integrate SPC into Your Data Acquisition Applications

Now you can use BridgeVIEW or LabVIEW not only to monitor your process, but also to identify problems and actually improve the quality of the process. The G SPC Toolkit is a VI library for statistical process control (SPC) applications. Using this toolkit, you can apply SPC methods to analyze and track process performance. In addition to subVIs that perform the SPC computations, the toolkit contains numerous example virtual instruments (VIs) and custom controls that demonstrate how to incorporate typical SPC methods and displays into BridgeVIEW or LabVIEW applications.

Capabilities of the SPC Toolkit

The SPC Toolkit includes all the functions you need to incorporate SPC analysis and presentations into your applications. The toolkit addresses three areas of SPC – control charts, process statistics, and Pareto analysis. For each of these areas, the toolkit contains analysis functions to compute important information from your data as well as plotting functions for displaying analysis results.

Control Charts

The control chart libraries include VIs that can compute points to be plotted for different types of attributes and variables charts. Select from chart types such as X-bar and s, X-bar and R, p, and np. Apply run rules (AT&T/Western Electric or Nelson) to detect out-of-control points or process shift. The Chart Draw VIs create X-Y graphs with center line and upper and lower limits, control charts with zones, control charts with variable limits, and run and tier plots for displaying the spread of subgroups against specification limits.

Process Statistics

The SPC Toolkit includes several VIs for analyzing the process capability. It features graphing VIs that can fit a normal distribution curve to a histogram to evaluate if the process is normally distributed. Additional VIs calculate process capability ratios, such as Cp and Cpk, as well as fraction nonconforming for normally distributed processes.

Pareto Analysis

You can use Pareto Analysis VIs in the G SPC Toolkit to display the relative importance of problems or assignable causes in your process. Create Pareto charts to graphically represent the number of occurrences or percentage occurrence of particular causes.


PID Control
PID Control Toolkit

Features

•	PI, PD, and PID

•	Error-squared PID

•	PID with external-reset feedback

•	Lead-lag compensation

•	Setpoint ramp generation

•	Multiloop cascade control

•	Feedforward control

•	DAQ board example

•	Override (minimum/maximum selector) control

•	Ratio/bias control

Overview

The PID Control Toolkit adds sophisticated control algorithms to BridgeVIEW and LabVIEW. With this package, you can quickly build data acquisition and control systems. By combining the PID Control Toolkit with the math and logic functions in BridgeVIEW and LabVIEW, you can quickly develop programs for control.

PID Algorithms

The PID VIs implement a wide range of PID algorithms with error-squared and external-reset feedback. VIs also implement lead-lag compensation and setpoint ramp generation. Control parameters include multiloop cascade, feedforward, minimum and maximum override, and ratio/bias. The PID algorithms feature bumpless auto/manual transfer, anti-reset windup, direct/inverse action, manual output adjustment, and a Run/Hold switch.

Control Strategy Design

Using the PID Control Toolkit, you can design the control strategies of the PID algorithms. You scale I/O values from engineering units to percentages. You can also set up timing of the PID algorithms. Finally, you can use tuning procedures for both Closed-Loop (Ultimate Gain) and Open-Loop (Step Test).

Process Control Examples

The PID Control VIs implement the algorithms using BridgeVIEW and LabVIEW functions and library subVIs without any code interface nodes (CINs), so you can modify the VIs for your applications in BridgeVIEW or LabVIEW without writing any conventional code. This package also includes a complete set of working simulations and demonstrations using National Instruments I/O boards. Documentation for each VI is included in its Get Info... box. In addition, Description boxes document each control and indicator.


JTFA
JTFA Toolkit

Features

•	Award-winning Gabor Spectrogram

•	STFT (sliding-window FFT)

•	Wigner-Ville Distribution

•	Choi-Williams Distribution

•	Cone-Shaped Distribution

•	Adaptive Spectrogram

Overview

The Joint Time-Frequency Analysis (JTFA) Toolkit is a BridgeVIEW and LabVIEW add-on for precise signal analysis of data whose frequency content changes with time. Applications include speech processing, sound analysis, sonar, radar, vibration analysis, and dynamic signal monitoring. The package also contains the Joint Time-Frequency Analyzer, a run-only application that runs independently from the BridgeVIEW or LabVIEW application, which uses any of the six joint time-frequency algorithms to analyze your stored data files and view the resulting spectrogram on an intensity plot. You may also save the spectrogram to disk for future use.

Joint Time-Frequency Analysis

Traditionally, signals have been analyzed in either the time or the frequency domain, but not jointly in time and frequency. For signals that do not change their spectral content in time, standard spectral analysis reveals what frequencies are present and their relative intensities. For many signals, however, the frequency content changes over time. While Fourier analysis indicates what frequencies were present, it does not show when those frequencies occurred in time. It is the aim of JTFA to describe and determine how the frequencies of nonstationary signals change over time.

Gabor Spectrogram – represents the original signal as a linear combination of time-and-frequency-shifted Gaussian functions. After computing the Gabor coefficients, you apply the WVD to the to obtain the spectrogram. The Gabor Spectrogram produces a better SNR in the output intensity plot than the short time Fourier Transform (STFT) because the Gabor coefficients better reflect the local behavior of a signal, resulting in a higher energy concentration in the joint time-frequency domain.

Wigner-Ville Distribution – displays the highest resolution of all known JTFA algorithms and is one of the reasons that the Gabor Spectrogram has such good resolution. The Wigner-Ville distribution, however, suffers from interference problems that can be quite severe for some signals.

Choi-Williams Distribution – a smoothed version of the Wigner-Ville distribution. This smoothing reduces the interference obtained with the Wigner-Ville distribution at the price of longer computation time.

Cone-Shaped Kernel Distribution – considered as a smoothed version of the Wigner-Ville distribution. Although similar to the Choi-Williams distribution, which uses a parabola shape as the smoothing filter, the cone-shaped kernel distribution uses a filter with a cone shape.

Adaptive Spectrogram – has the best joint time-frequency resolution for the analysis of quasistationary signals, which are signals that do not change rapidly in time or frequency. The Gabor Spectrogram uses a Gaussian function with uniform variance to compare the analyzed signals at a fixed time-frequency grid, while the adaptive approach adjusts the variance, time, and frequency centers of the Gaussian functions to best match the analysis signal.


Picture Control
Picture Control Toolkit

Features

•	Versatile graphics display

•	Standard front panel control integration

•	Easy-to-use VI library for drawing commands

•	High-level examples for common displays

Overview

The G Picture Control Toolkit is a versatile graphics add-on package for creating arbitrary front panel displays. The toolkit adds the Picture control and a library of VIs to your BridgeVIEW or LabVIEW system.  You can create diagrams using a set of VIs to describe the drawing operations to build these images dynamically.  With these tools, you can create new front panel displays like specialized bar graphs, pie charts, and Smith charts. You can also display and even animate arbitrary objects such as robot arms, test equipment, a UUT, or a 2D display of a real-world process.

Examples

The best aspect of the Picture Control Toolkit may be the examples. They include high-level graph VIs which may be useful “as is” in your applications. Examples include plotting VI libraries, create waveform, XY and multi-xy displays with scales and grids, and a variety of plot styles (bar, point, line, and so on). There are specialized examples for Polar plots, Smith plots (see Figure 1), and Waterfall plots. In addition, there is a robot arm example that demonstrates animation of real-world processes.

If you build off the examples, you’ll find many valuable subVIs for drawing waveforms in a variety of styles. You can also create grids and specify range and format for scales. In addition there are also custom controls for most of the example inputs and outputs to aid in creating and passing the picture data.


Wavelet and Filter Bank
Wavelet and Filter Bank Toolkit

The Wavelet and Filter Bank Toolkit provides an infinite number of selections of filter banks and wavelet functions.  This toolkit contains stand-alone applications and add-on tools for G and Windows DLL users.


Third Octave
Third Octave Analysis Toolkit

The Third Octave Toolkit enables you to quickly measure sound, vibration, and noise signals using third octave analysis and data acquisition.


Digital Filter
Digital Filter Toolkit

The Digital Filter Toolkit is a general-purpose tool for designing finite impulse response (FIR) and infinite impulse response (IIR) filters.


G Math
G Math Toolkit

The G Math Toolkit enables you to interface real-world measurements to the mathematical algorithms in order to obtain practical solutions.  The G Math Toolkit is intended for use by scientists, engineers, and mathematicians, and by anyone needing to solve mathematical problems in a simple, quick and efficient manner. It can also be used as an educational aid by those interested in learning and expanding their knowledge of mathematics.


Fuzzy Logic
Fuzzy Logic Toolkit

The Fuzzy Logic Toolkit for G is used to implement rule-based process control in an intuitive linguistic format.  A fuzzy membership function editor allows the user to quantitatively define linguistic terms for input parameters, such as hot or cold for temperature.  A rule-base editor is used to define heuristic rules for the controller output based on the linguistic terms defined.  A fuzzy controller VI provided is then used in the application VI to process input data based on the fuzzy controller designed.  The toolkit is well-suited for control applications on non-linear or complex systems that are difficult to model mathematically but may be controlled by human operators.


Internet
Internet Toolkit

Scientists and engineers are finding that important functions can be performed across the Internet, such as research, publishing conclusions, displaying data across the web, or even controlling source code versions and tracking for test development teams. In addition to taking advantage of the Internet, virtual instruments are addressing remote or distributed applications more and more. Using an Internet Developers Toolkit, you can easily incorporate a variety of electronic communications capabilities, such as e-mail, FTP transfers, or the WWW into your virtual instrumentation applications.

Features include:

•	Viewing your virtual instruments across the Internet from a Web browser

•	Incorporating access control and security in your servers for displaying sensitive data

•	Building Common Gateway Interface (CGI) programs in G to perform server operations

•	Sending e-mail from your applications

•	Sending files or raw data to an FTP server


  About This File

LabVIEW Help Version 5.0

	Edition Date: January 1998 Part Number: 321782A-01
Copyright

© Copyright 1992, 1998, National Instruments Corporation. All rights reserved.

Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including photocopying, recording, storing in an information retrieval system or translating, in whole or in part, without the prior written consent of National Instruments Corporation.

For more information, see the Warranty, Trademarks, Medical Warning and Technical Support topics.


Warranty, Trademarks, and Medical Warning

This topic contains very important information about your Limited Warranty, National Instruments trademarks, and Medical Warning.

Limited Warranty

The media on which you receive National Instruments software are warranted not to fail to execute programming instructions, due to defects in materials and workmanship, for a period of 90 days from date of shipment, as evidenced by receipts or other documentation. National Instruments will, at its option, repair or replace software media that do not execute programming instructions if National Instruments receives notice of such defects during the warranty period. National Instruments does not warrant that the operation of the software shall be uninterrupted or error free.

A Return Material Authorization (RMA) number must be obtained from the factory and clearly marked on the outside of the package before any equipment will be accepted for warranty work. National Instruments will pay the shipping costs of returning to the owner parts which are covered by warranty.

National Instruments believes that the information in this document is accurate. The document has been carefully reviewed for technical accuracy. In the event that technical or typographical errors exist, National Instruments reserves the right to make changes to subsequent editions of this document without prior notice to holders of this edition. The reader should consult National Instruments if errors are suspected. In no event shall National Instruments be liable for any damages arising out of or related to this document or the information contained in it.

Except as specified herein, National Instruments makes no warranties, express or implied, and specifically disclaims any warranty of merchant ability or fitness for a particular purpose. Customer’s right to recover damages caused by fault or negligence on the part of National Instruments shall be limited to the amount theretofore paid by the customer. National Instruments will not be liable for damages resulting from loss of data, profits, use of products, or incidental or consequential damages, even if advised of the possibility thereof. This limitation of the liability of National Instruments will apply regardless of the form of action, whether in contract or tort, including negligence. Any action against National Instruments must be brought within one year after the cause of action accrues. National Instruments shall not be liable for any delay in performance due to causes beyond its reasonable control. The warranty provided herein does not cover damages, defects, malfunctions, or service failures caused by owner’s failure to follow the National Instruments installation, operation, or maintenance instructions; owner’s modification of the product; owner’s abuse, misuse, or negligent acts; and power failure or surges, fire, flood, accident, actions of third parties, or other events outside reasonable control.

Trademarks

BridgeVIEW™, ComponentWorks™, CVI™, DAQArb™, DAQCard™, DAQ Designer™, DAQMeter™, DAQPad™, DAQPnP™, DAQ-STC™, DAQWare™, HiQ™, Hi-Q-Script™, HS488™, LabVIEW™, Measure™, MITE™, natinst.com™, National Instruments™, NI-488™,
NI-488.2™, NI-DAQ™, NI-DSP™, NI-PGIA™, NI-VISA™, NI-VXI™, PXI™, RTSI™, SCXI™, VirtualBench™, and VXIpc™ are trademarks of National Instruments Corporation.

Product and company names referenced in this document are trademarks or trade names of their respective companies.

WARNING REGARDING MEDICAL AND CLINICAL USE OF NATIONAL INSTRUMENTS PRODUCTS

National Instruments products are not designed with components and testing intended to ensure a level of reliability suitable for use in treatment and diagnosis of humans. Applications of National Instruments products involving medical or clinical treatment can create a potential for accidental injury caused by product failure, or by errors on the part of the user or application designer. Any use or application of National Instruments products for or involving medical or clinical treatment must be performed by properly trained and qualified medical personnel, and all traditional medical safeguards, equipment, and procedures that are appropriate in the particular situation to prevent serious injury or death should always continue to be used when National Instruments products are being used. National Instruments products are NOT intended to be a substitute for any form of established process, procedure, or equipment used to monitor or safeguard human health and safety in medical or clinical treatment.


Error Codes

The following topics contain tables listing numeric error codes, names, and descriptions returned by the G system. The tables are arranged in ascending order, from negative to positive values. Tables with negative number values are arranged from the smallest absolute value to the largest absolute value. Notice that error codes 5000 to 9999 are reserved for your own use.

Connect error handler VIs to other VIs to return a description of an error, if one occurs. Error handler VIs also can display a dialog box with an error message description and buttons that can stop or continue execution.

•	G Function Error Codes 0 to 85

•	Data Acquistion VI Error Codes -10001 to -10920

•	Analysis Error Codes -20001 to -20065

•	TCP and UDP Error Codes 53 to 66

•	DDE Error Codes 14001 to 14020

•	PPC Error Codes -900 to -932

•	LabVIEW Specific PPC Error Codes 1 to 5

•	AppleEvent Error Codes -1700 to -1719

•	LabVIEW Specific Error Codes for Apple Events1000 to 1004

•	GPIB Error Codes 0 to 32

•	Instrument Driver Error Codes  -1200 to -13xx

•	Serial Port Error Codes 61 to 65

•	VISA Error Codes  -10738077360 to -1073807231


Common Questions

This topic contains commonly asked questions about G.  If you are having problems or are unsure about a G concept, the answer or explanation may be contain herein.

•	Charts and Graphs

•	Error Messages and Crashes

•	Miscellaneous

•	Platform Issues and Compatibilities

•	Printing

•	DAQ

•	Communication

•	GPIB

•	Serial I/O

•	Contact NI


Additional Documentation

In addition to this online documentation, your LabVIEW CD contained PDF versions of the manuals that shipped with LabVIEW 5.0. If you would like to view these documents online, you must have Adobe Acrobat 3.0 or later. If you do not already have it, you can download the latest reader from Adobe at http://www.adobe.com/prodindex/acrobat/main.html.

Resources for Advanced Topics

Other Useful Resources

LabVIEW Documentation

Click the following links to open the PDF documents.

QuickStart Guide

LabVIEW User Manual

G Programming Reference Manual

LabVIEW Function and VI Reference Manual

LabVIEW Data Acquisition Basics Manual

LabVIEW Code Interface Reference Manual

LabVIEW VXI VI Reference Manual


The Acrobat file was not found on your hard drive.
 LabVIEW Help Version 5.0

	Edition Date: January 1998 Part Number: 321782A-01
The Acrobat file you are trying to access was not found on your hard drive.  Insert the LabVIEW CD and open the Acrobat file from the Manuals directory.


Where Should I Start?

This help file provides basic information on how to build an application in LabVIEW. To become familiar with the LabVIEW environment, go through the LabVIEW Online Tutorial (Windows only), the LabVIEW QuickStart Guide, and the Overview topics listed in the Contents window.

Then practice building applications in LabVIEW by completing the LabVIEW Activities.

Most LabVIEW applications are divided into the following tasks: I/O interface to sensors or instruments, data display on the front panel, data analysis, data storage, and data transfer across a network. To learn more about each of these tasks, refer to Data Acquisition VIs, Instrument I/O VIs, Analysis VIs, Network and Interapplication Communication, and Code Interface Node Functions. For advanced G programming techniques, refer to the G Programming Language Help File.

To generate or find examples similar to your application, refer to the Solution Wizard (Windows and PCI Macintosh only) or Search Examples online help file (Windows only), which you can access from the LabVIEW startup dialog.


LabVIEW Activities

We encourage you to work through all the activities in this help file before you begin building your applications. Save all of the VIs you create with the LabVIEW activities in the LabVIEW\Activity directory. Before you begin the activities, see the Important Information about Activities topic.

Basic G Programming	Advanced Analysis
Activity 1. Create a VI	Activity 28. Learn More about Normalized
Activity 2. Document a VI	Activity 29. Use the Sine Wave and Sine Pattern VIs
Activity 3. Create an Icon and Connector	Activity 30. Build a Function Generator
Activity 4. Call a SubVI	Activity 31. Use the Real FFT VI
Activity 5. Debug a VI	Activity 32. Compare a Windowed and Nonwindowed Signal
Activity 6. Use Setup Options for a SubVI	Activity 33. Use the Amplitude and Phase Spectrum VI
Activity 7. Experiment with Chart Modes	Activity 34. Compute the Frequency and Impulse Response
Activity 8. Use a While Loop and a Chart	Activity 35. Calculate Harmonic Distortion
Activity 9. Change the Mechanical Action of a Boolean Switch	Activity 36. Extract a Sine Wave
Activity 10. Control Loop Timing	Activity 37. Use the Curve Fitting VIs
Activity 11. Use a Shift Register	Activity 38. Use the General LS Linear Fit VI
Activity 12. Create a Multiplot Chart and Customize your Trends	Activity 39. Use the Nonlinear Lev-Mar Fit VI
Activity 13. Use a For Loop	Activity 40. Compute the Inverse of a Matrix
Activity 14. Use the Case Structure	Activity 41. Solve a System of Linear Equations
Activity 15. Use the Sequence Structure	Activity 42. Use the Normal Distribution VI
Activity 16. Use the Formula Node
Activity 17. Use an Attribute Node
Activity 18. Create an Array with Auto-Indexing
Activity 19. Use Auto-Indexing on Input Arrays
Activity 20. Use the BuildArray Function
Activity 21. Use the Graph and Analysis VIs
Activity 22. Concatenate a String
Activity 23. Use Format Strings
Activity 24. String Subsets and Number Extraction
Activity 25. Write to a Spreadsheet File
Activity 26. Append Data to a File
Activity 27. Read Data from a File
Related Topics

Where to Go from Here


Important Information about Activities

There is a Solutions directory (LabVIEW\Activity\Solution) that contains the completed VIs for each activity in this help file. You can view the VI for an activity that you have not completed yet, or use the VIs in this directory as a means of verifying your work.

If you are using data acquisition (DAQ) or instrument I/O, which includes GPIB, Serial, or VXI, and want to find examples, go through the Solution Wizard for I/O Interfaces by starting LabVIEW and pressing the Solution Wizard button. To find other types of examples, go through the Search Examples online help file by starting LabVIEW and pressing the Search Examples button.

Another good place to start is the Examples directory. Use the VI called readme.vi, at the top level of the directory, to browse through the available examples.

Note	(Windows 3.1) You must save the VIs you create in the activities in VI libraries. VI libraries allow you to use file names that are longer than eight characters. Also, the VIs needed for the activities are located in the VI library LabVIEW\Activity\Activity.llb. Refer to the Saving VIs topic for more information on VI libraries.


Activity 1. Create a VI

Your objective is to build a VI.

Imagine that you have sensors that read temperature and volume readings as voltage. You will use a VI in the LabVIEW\Activity directory to simulate the temperature and volume measurements in volts. You will write a VI to scale these measurements to degrees Fahrenheit and liters, respectively.

Front Panel

1.	Open a new front panel by selecting File»New. If you have closed all VIs, select New VI from the LabVIEW dialog box.

Note	If the Controls palette is not visible, select Windows»Show Controls Palette to display the palette. You also can access the Controls palette by popping up in an open area of the front panel. To pop up, right-click on your mouse (<Option>-click for Macintosh).

2.	Select Tank from Controls»Vessels, and place it on the front panel.

3.	Type Volume in the label text box and click anywhere on the front panel.

Note	If you click outside the text box without entering text, the label disappears. To show the label again, pop up on the control and select Show»Label.

4.	Rescale the tank indicator to display the tank volume between 0.0 and 1000.0.

a.	Using the Labeling tool, double click on 10.0 on the tank scale to highlight it.

b.	Type 1000 in the scale and click the mouse button anywhere on the front panel. The intermediary increments are scaled automatically.

5.	Place a thermometer from Controls»Numeric on the front panel. Label it Temp and rescale it to be between 0 and 100.

6.	Your front panel should look like the following illustration.

Block Diagram

7.	Open the block diagram by choosing Windows»Show Diagram. Select the objects listed below from the Functions palette and place them on the block diagram.

Note	If the Functions palette is not visible, select Windows»Show Functions Palette to display the palette. You also can access the Functions palette by popping up in an open area of the block diagram.

8.	Place each of the following objects on the block diagram.

 Process Monitor (Functions»Select a VI from the LabVIEW\Activity directory)—Simulates reading a temperature voltage and volume value from a sensor or transducer.

 Random Number Generator (Functions»Numeric)—Generates a number between 0 and 1.

 Multiply function (Functions»Numeric)—Multiplies two numbers and returns their product. In this activity, you need two of these. Drop one from the palette and copy and paste to create the other.

 Numeric Constant (Functions»Numeric)—You need two of these. Drop one from the palette. Using the Labeling tool, change its value to 10.00. Copy and paste it.

Note	Another way to create a constant is to pop up on the terminal of a function or VI using the Wiring tool. Select Create Constant from the floating menu. A constant of the appropriate data type appears.

9.	To view the inputs and outputs of a function or a VI, select Show Help from the Help menu and then drag the cursor over each function and VI. The Help window for the Process Monitor VI is shown below.

10.	Using the Wiring tool [image] , wire the objects as shown.

Note	To move objects around on the block diagram, click on the Positioning tool in the Tools palette.

11.	Select File»Save and save the VI as Temp & Vol.vi in the LabVIEW\Activity directory.

12.	From the front panel, run the VI by clicking on the Run button [image] . Notice values for Volume and Temperature are displayed on the front panel.

13.	Close the VI by selecting File»Close.

End of Activity 1. Create a VI


Activity 2. Document a VI

Your objective is to document a VI that you have created.

Front Panel

1.	Open the Temp & Vol.vi created in Activity 1. Create a VI from the LabVIEW\Activity directory.

2.	Select Windows»Show VI Info.... Type the description for the VI, as shown in the following illustration, and click OK.

3.	Pop up on the tank and choose Data Operations»Description…. Type the description for the indicator, as shown in the following illustration, and click OK.

4.	Pop up on the thermometer and choose Data Operations»Description…. Type in the description: Displays simulated temperature (deg F) measurement. Click OK.

5.	Select Show Help from the Help menu. Place the cursor on Volume and then on Temp. You can see the descriptions you typed in appear in the help window.

6. 	Save and close the VI.

End of Activity 2. Document a VI


Activity 3. Create an Icon and Connector

Your objective is to make an icon and connector for a VI.

To use a VI as a subVI, you must create an icon to represent it on the block diagram of another VI, and a connector pane to which you can connect inputs and outputs. LabVIEW provides several tools with which you can create or edit an icon for your VIs.

The icon of a VI represents it as a subVI in the block diagram of other VIs. It can be a pictorial representation of the purpose of the VI, or a textual description of the VI.

Front Panel

1.	Open Temp & Vol.vi, as modified and saved in Activity 2. Document a VI, in the LabVIEW\Activity directory.

2.	From the front panel, pop up on the icon in the top right corner and select Edit Icon…. You also can double click on the icon to invoke the icon editor.

Note	You only can access the icon/connector for a VI from the front panel.

3.	Erase the default icon. With the Select tool, click and drag over the section you want to delete, and press the <Delete> key. You also can double click on the shaded rectangle in the tool box to erase the icon.

4.	Draw a thermometer with the Pencil tool [image] .

5.	Create the text with the Text tool [image] . To change the font, double click on the Text tool. Your icon should look similar to the following illustration.

6.	Close the Icon Editor by clicking OK. The new icon appears in the icon pane.

7.	Define the connector terminal pattern by popping up in the icon pane on the front panel and choosing Show Connector. By default, LabVIEW selects a terminal pattern based on the number of controls and indicators on the front panel. Because there are two objects on the front panel, the connector has two terminals.

8.	Pop up on the connector pane and select Rotate 90 Degrees. Notice how the connector pane changes.

9.	Assign the terminals to Temp and Volume.

a.	Click on the top terminal in the connector. The cursor automatically changes to the Wiring tool [image] , and the terminal turns black.

b.	Click on the Temp indicator. A moving dashed line frames the indicator, as shown in the following illustration. The selected terminal changes to a color consistent with the datatype of the control/indicator selected.

If you click in an open area on the front panel, the dashed line disappears and the selected terminal appears dimmed, indicating that you have assigned the indicator to that terminal. If the terminal is white, you have not made the connection correctly.

b.	Repeat Steps a and b to associate the bottom terminal with the Volume indicator.

c.	Pop up on the connector and select Show Icon....

10.	Save the VI by choosing File»Save.

Now, this VI is complete and ready for use as a subVI in other VIs. The icon represents the VI in the block diagram of the calling VI. The connector (with two terminals) outputs the temperature and volume.

Note	The connector specifies the inputs and outputs of a VI when you use it as a subVI. Remember that front panel controls can be used as inputs only; front panel indicators can be used as outputs only.

11.	Close the VI by choosing File»Close.

End of Activity 3. Create an Icon and Connector


Activity 4. Call a SubVI

Your objective is to build a VI that uses the Temp & Vol.vi as a subVI.

The Temp & Vol VI you built and modified in the previous three activities returns a temperature and volume. You will take a volume reading and convert the value to gallons when a switch is pressed.

Front Panel

1.	Open a new front panel by selecting File»New.

2.	Select a Horizontal Switch from the Controls»Boolean palette and label it volume. Place free labels on the front panel to indicate Liters and Gallons by using the Labeling tool [image] .

3.	Select a meter [image] from Controls»Numeric and place it on the front panel. Label it Tank Volume.

4.	Change the range of the meter to accommodate values ranging between 0.0 and 1000.0. With the Operating tool [image] , double click on the high limit and change it from 10.0 to 1000.0. Switch to the Positioning tool and resize the meter by dragging out one of the corners and expanding the control.

Block Diagram

5.	Go to the block diagram by selecting Windows»Show Diagram.

6.	Pop up in a free area of the block diagram and choose Functions»Select a VI.... A dialog box appears. Select Temp & Vol.vi in the LabVIEW\Activity directory. Click Open in the dialog box. LabVIEW places the Temp & Vol VI on the block diagram.

7.	Add the other objects to the block diagram as shown in the following illustration.

 Numeric Constant (Functions»Numeric)—Add a numeric constant to the block diagram. Assign the value 3.785 to the constant by using the Labeling tool. This is the conversion factor for switching from liters to gallons.

 Select Function (Function»Comparison)—Returns the value wired to the TRUE or FALSE input, depending on the Boolean input.

 Divide function (Functions»Numeric)—Divides the value in liters by 3.785 to convert it to gallons.

8.	Wire the diagram objects as shown.

9.	Return to the front panel and click the Run button [image] in the toolbar. The meter shows the value in liters.

10.	Click on the switch to select Gallons and click the Run button. The meter shows the value in gallons.

11.	Save the VI as Using Temp & Vol.vi in the LabVIEW\Activity directory.

End of Activity 4. Call a SubVI


Activity 5. Debug a VI

Your objective is to use the probe tool and the probe window and to examine data flow in the block diagram using the execution highlighting feature.

1.	Open Using Temp & Vol.vi, as created in Activity 4. Call a SubVI, from the LabVIEW\Activity directory.

Block Diagram

2.	Select Windows»Show Diagram.

3.	If the Tools palette is not open, select Windows»Show Tools Palette.

4.	Select the Probe tool [image] from the Tools and click on the wire coming out of the Divide function. A Probe window pops up with the title Probe 1 and a yellow glyph with the number of the probe, as shown in the following illustration. The Probe window remains open, even if you switch to the front panel.

Front Panel

5.	Return to the front panel. Move the Probe window so you can view both the probe and volume values as shown in the following illustration. Run the VI. The volume in gallons appears in the Probe window while Tank Volume displays the value in liters.

Note	The volume values that appear on your screen may be different than what is shown in this illustration. Refer to the Numeric Conversion topic for more information.

6.	Close the Probe window by clicking in the close box at the top of the Probe window title bar.

Another useful debugging technique is to examine the flow of data in the block diagram using the execution highlighting feature.

Block Diagram

7.	Return to the block diagram of the VI.

8.	Begin execution highlighting by clicking the Highlight Execution button [image] , in the toolbar. The Highlight Execution button changes to an illuminated light bulb [image] .

9.	Click the Run button to run the VI, and notice that execution highlighting animates the VI block diagram execution. Moving bubbles represent the flow of data through the VI. Also notice that data values appear on the wires and display the values contained in the wires at that time, as shown in the following block diagram, just as if you had probed the wire.

You also can use the single stepping buttons if you want to walk through the graphical code, one step at a time.

10.	Begin single-stepping by clicking the Step Over button [image] in the toolbar.

11.	Step into the Temp & Vol subVI by clicking the Step Into button [image] in the toolbar. Clicking on this button opens the front panel and block diagram of your Temp & Vol subVI. Click the Step Over button [image] until the VI finishes executing.

12.	Finish executing the block diagram by clicking the Step Out button [image] in the toolbar. Clicking this button completes all remaining sequences in the block diagram.

End of Activity 5. Debug a VI


Activity 6. Use Setup Options for a SubVI

Your objective is to build a VI that prompts the operator to enter information.

You will create a VI that launches a dialog box to obtain information from the user upon execution. Once the user enters the information and clicks a button, the dialog box disappears.

Front Panel

1.	Open a new front panel and add some string controls and the button shown in the following illustration.

Block Diagram

2.	Build the block diagram shown in the following illustration.

3. 	Create the icon for the VI as illustrated [image] . To access the Icon Editor, pop up on the icon pane of the front panel and select Edit Icon.

4.	Switch to the connector pane by popping up on the icon pane and selecting Show Connector.

5.	Build the connector. Notice that the default connector pane is not what you see illustrated [image] . To get the correct connector pane, choose Patterns from the pop-up menu on the connector. Choose the pattern with three inputs and two outputs. Then choose Flip Horizontal. Now you can connect the Date and Time controls to the two connectors on the left side of the icon, and the Name Answer, Date Answer, and Time Answer indicators to the three connectors on the right side of the icon, as shown in the following illustration. After creating the connector, return to the icon display.

6.	Save the VI as Get Operator Info.vi in the LabVIEW\Activity directory.

7.	Now you can customize the VI with the VI setup options to make it look like a dialog box.

a.	Pop up on the icon and select VI Setup. Configure the Execution Options as shown in the following illustration.

b.	Select Window Options and make the selections shown in the following illustration.

8.	After you finish with the VI Setup options, resize the front panel as shown in the following illustration so you do not see the three string indicators.

9.	Save and close the VI. Now you can use this VI as a subVI.

Front Panel

10.	Open a new front panel.

11.	Place a Waveform Chart (Controls»Graph) on the front panel and label it Temperature Data.

12.	Modify the scale of the chart, so that its upper limit is set to 90.0 and its lower limit is set to 70.0. Pop up on the chart and choose Show»Legend to hide the legend. Pop up on the chart again and choose Show»Palette to hide the palette.

13.	Build the rest of the front panel as shown in the following illustration.

Block Diagram

14.	Create a Sequence structure and add the following objects to frame 0, as shown in the following illustration.

 Get Date/Time String function (Functions»Time & Dialog)—Outputs the current date and time.

 Get Operator Info VI (Functions»Select a VI... from the LabVIEW\Activity directory)—Opens its front panel and prompts the user to enter a name, the date, and the time.

 Boolean constant (Functions»Boolean)—Controls whether the input date and time string are TRUE. To set this option to TRUE, click on the constant with the Operating tool.

15.	Pop up on the Sequence structure and select Add Frame After from the pop-up menu.

16.	Place a While Loop [image] inside frame 1 of the Sequence structure by selecting it from Functions»Structures.

17.	Add the objects shown in the following illustration.

 Temp & Vol VI (Functions»Select a VI... from the LabVIEW\Activity directory)—Returns one temperature measurement from a simulated temperature sensor.

 Wait Until Next ms Multiple function (Functions»Time&Dialog)—Causes the While Loop to execute in ms.

 Numeric constant (Functions»Numeric)—You also can pop up on the Wait Until Next Tick Multiple function and select Create Constant to create and wire the numeric constant automatically. The numeric constant delays execution of the loop for 500 ms (0.5 seconds).

 Not function (Functions»Boolean)—Inverts the value of the STOP button so that the While Loop executes repeatedly until you click STOP.

18.	Save the VI as Pop-up Panel Demo.vi in the LabVIEW\Activity directory.

19.	Run the VI. The front panel of the Get Operator Info VI opens and prompts you to enter your name, the date, and the time. Click the Continue button to return to the calling VI. Then temperature data is acquired until you click the STOP button.

Note	The front panel of the Get Operator Info VI opens because of the options you selected from the VI Setup dialog box. Do not try to open the front panel of the subVI from the block diagram of the My Pop-up Panel Demo VI.

20.	Close all windows.

End of Activity 6. Use Setup Options for a SubVI


Activity 7. Experiment with Chart Modes

Your objective is to view a chart as your VI runs in strip chart mode, scope chart mode, and sweep chart mode.

1.	Open Charts.vi, located in the following directory: LabVIEW\Examples\General\Graphs\charts.llb.

2.	Run the VI.

The strip chart mode has a scaling display similar to a paper tape strip chart recorder. As each new value is received, it is plotted at the right margin and old values shift to the left.

The scope chart mode has a retracing display similar to an oscilloscope. As the VI receives each new value, it plots the value to the right of the last value. When the plot reaches the right border of the plotting area, the VI erases the plot and begins plotting again from the left border. The scope chart is significantly faster than the strip chart because it is free of the processing overhead involved in scrolling.

The sweep chart mode acts much like the scope chart, but it does not go blank when the data hits the right border. Instead, a moving vertical line marks the beginning of new data and moves across the display as the VI adds new data.

3.	With the VI still running, pop up on any chart, and select Update Mode, and change the current mode to that of another chart. Notice the difference between the various charts and modes.

4.	Stop and close the VI.

End of Activity 7. Experiment with Chart Modes


Activity 8. Use a While Loop and a Chart

Your objective is to use a While Loop and a chart for acquiring and displaying data in real time.

You will build a VI that generates random data and displays it on a chart. A knob control on the front panel adjusts the loop rate between 0 and 2 seconds and a switch stops the VI. You will change the mechanical action of the switch so you do not have to turn on the switch each time you run the VI. Use the front panel in the following illustration to get started.

Front Panel

1.	Open a new front panel by selecting File»New.

2.	Place a vertical switch (Controls»Boolean) on the front panel. Label the switch Enable.

3.	Use the Labeling tool to create free labels for ON and OFF. Select the Labeling tool, and type in the label text. With the Color tool [image] , make the border of the free label transparent by selecting the T in the bottom left corner of the Color palette.

4.	Place a waveform chart [image] (Controls»Graph) on the front panel. Label the chart Random Signal. The chart displays random data in real time.

Note	Make sure that you select a waveform chart and not a waveform graph. In the Graph palette, the waveform chart appears closest to the left side.

5.	Pop up on the chart and choose Show»Palette and Show»Legend to hide the palette and legend. The digital display shows the latest value. Then pop up on the chart and choose Show»Digital Display and Show»Scroll Bar.

6.	Rescale the chart from 0.0 to 1.0. Use the Labeling tool [image] to replace the high limit of 10.0 with 1.0.

7.	Place a knob [image] (Controls»Numeric) on the front panel.

Label the knob Loop Delay (sec). This knob controls the timing of the While Loop. Pop up on the knob and deselect Show»Digital Display to hide the digital display.

8.	Rescale the knob. Using the Labeling tool, double click on 10.0 in the scale around the knob, and replace it with 2.0.

Block Diagram

9.	Open the block diagram and create the diagram in the following illustration.

a.	Place the While Loop [image] in the block diagram by selecting it from Functions»Structures. The While Loop is a resizable box that is not dropped on the diagram immediately. Instead, you have the chance to position and resize it. To do so, click in an area above and to the left of all the terminals. Continue holding down the mouse button and drag out a rectangle that encompasses the terminals.

b.	Select the Random Number (0–1) function [image] from Functions»Numeric.

c.	Wire the diagram as shown in the Block Diagram, connecting the Random Number (0–1) function to the Random Signal chart terminal and the Enable switch to the conditional terminal of the While Loop. Leave the Loop Delay terminal unwired for now.

10.	Return to the front panel and turn on the vertical switch [image] by clicking on it with the Operating tool.

11.	Save the VI as Random Signal.vi in the LabVIEW\Activity directory.

12.	Run the VI.

The While Loop is an indefinite looping structure. The diagram within it executes as long as the specified condition is TRUE. In this example, as long as the switch is on (TRUE), the diagram continues to generate random numbers and display them on the chart.

13.	Stop the VI by clicking on the vertical switch. Turning the switch off sends the value FALSE to the loop conditional terminal and stops the loop.

14.	Scroll through the chart. Click and hold down the mouse button on either arrow in the scrollbar.

15.	Clear the display buffer and reset the chart by popping up on the chart and choosing Data Operations»Clear Chart.

Note	The display buffer default size is 1,024 points. You can increase or decrease this buffer size by popping up on the chart and choosing Chart History Length.... You only can use this feature when the VI is not running.

End of Activity 8. Use a While Loop and a Chart


Activity 9. Change the Mechanical Action of a Boolean Switch

Your objective is to experiment with the different mechanical actions of Boolean switches.

1.	Open the Random Signal.vi, as saved in Activity 8. Use a While Loop and a Chart, from the LabVIEW\Activity directory. The default value of the Enable switch is FALSE.

2.	Modify the vertical switch so it is used only to stop the VI. Change the switch so that you do not need to turn on the switch each time you run the VI.

a.	Turn on the vertical switch with the Operating tool.

b.	Pop up on the switch and choose Data Operations»Make Current Value Default. This makes the ON position the default value.

c.	Pop up on the switch and choose Mechanical Action»Latch When Pressed.

3.	Run the VI. Click the Enable switch to stop the acquisition. The switch moves to the OFF position momentarily and is reset back to the ON position.

4.	Save the VI.

Note	For your reference, LabVIEW contains an example that demonstrates these behaviors, called Mechanical Action of Booleans.vi. It is located in Examples\General\Controls\booleans.llb.

End of Activity 9. Change the Mechanical Action of a Boolean Switch


Activity 10. Control Loop Timing

Your objective is to control loop timing and ensure that no iteration is shorter than the specified number of milliseconds.

1.	Open Random Signal.vi, as modified and saved in Activity 9. Change the Mechanical Action of a Boolean Switch from the LabVIEW\Activity directory.

2.	Modify the VI to generate a new random number at a time interval specified by the knob, as shown in the following illustration.

 Wait Until Next ms Multiple function (Functions»Time & Dialog)—Multiply the knob terminal by 1,000 to convert the knob value in seconds to milliseconds. Use this value as the input to the Wait Until Next ms Multiple function.

 Multiply function (Functions»Numeric)—The multiply function multiplies the knob value by 1,000 to convert seconds to milliseconds.

 Numeric constant (Functions»Numeric)—The numeric constant holds the constant by which you must multiply the knob value to get a quantity in milliseconds. Thus, if the knob has a value of 1.0, the loop executes once every 1,000 milliseconds (once per second).

3.	Run the VI. Rotate the knob to get different values for the loop delay. Notice the effects of the loop delay on the update of the Random Signal display.

4.	Save the VI as Random Signal with Delay.vi in the LabVIEW\Activity directory. Close the VI.

End of Activity 10. Control Loop Timing


Activity 11 Use a Shift Register
Activity 11. Use a Shift Register

Your objective is to build a VI that displays a running average on a chart.

Front Panel

1.	Open a new front panel and create the objects shown in the following illustration.

2.	Change the scale of the Waveform chart to range from 0.0 to 2.0.

3.	After adding the vertical switch, pop up on it and select Mechanical Action»Latch When Pressed and set the ON state to be the default by choosing Operate»Make Current Values Default.

Block Diagram

4.	Build the block diagram shown in the following illustration.

5.	Add the While Loop (Functions»Structures) in the block diagram and create the shift register.

a.	Pop up on the left or right border of the While Loop and choose Add Shift Register.

b.	Add an extra element by popping up on the left terminal of the shift register and choosing Add Element. Add a third element in the same manner as the second.

 Random Number (0–1) function (Functions»Numeric)—This function generates random data ranging between 0 and 1.

 Compound Arithmetic function (Functions»Numeric)—In this activity, the compound arithmetic function returns the sum of random numbers from two iterations. To add more inputs, pop up on an input and choose Add Input from the pop-up menu.

 Divide function (Functions»Numeric)—In this activity, the divide function returns the average of the last four random numbers.

 Numeric Constant (Functions»Numeric)—During each iteration of the While Loop, the Random Number (0–1) function generates one random value. The VI adds this value to the last three values stored in the left terminals of the shift register. The Random Number (0–1) function divides the result by four to find the average of the values (the current value plus the previous three). Then the average is displayed on the waveform chart.

 Wait Until Next ms Multiple function (Functions»Time & Dialog)—This function ensures that each iteration of the loop occurs no faster than the millisecond input. The input is 500 milliseconds for this activity. If you pop up on the icon and choose Show»Label, the label Wait Until Next ms Multiple appears.

6.	Pop up on the input of the Wait Until Next ms Multiple function and select Create Constant. A numeric constant appears and is automatically wired to the function.

7.	Type 500 in the label [image] . The numeric constant wired to the Wait Until Next ms Multiple function specifies a wait of 500 milliseconds (one half-second). Thus, the loop executes once every half-second.

Notice that the VI initializes the shift registers with a random number. If you do not initialize the shift register terminal, it contains the default value or the last value from the previous run and the first few averages are meaningless.

8.	Run the VI and observe the operation.

9.	Save this VI as Random Average.vi in the LabVIEW\Activity directory.

Note	Remember to initialize shift registers to avoid incorporating old or default data into your current data measurements

End of Activity 11. Use a Shift Register


Activity 12. Create a Multiplot Chart

Your objective is to create a chart that can accommodate more than one plot.

Front Panel

1.	Open the Random Average.vi you created in Activity 11. Use a Shift Register.

2.	Modify the Front Panel as shown in the following illustration.

a.	Using the Positioning tool, stretch the legend to include two plots.

b.	Show the digital display by popping up on the chart, and choosing Show»Digital Display. Move the legend if necessary.

c.	Rename Plot 0 to Current Value by double clicking on the label with the Labeling tool [image] and typing in the new text. You can resize the label area by dragging either of the left corners with the Positioning tool. Rename Plot 1 to Running Avg in the same way.

d.	For the Current Value plot, change the interpolation to unconnected, the point style to square, and the color to green. You can change the plot style and color by popping up on the legend.

Block Diagram

3.	Modify the block diagram, as shown in the following illustration, to display both the average and the current random number on the same chart.

 Bundle function (Functions»Cluster)—In this activity, the Bundle function bundles the average and current value for plotting on the chart. The bundle node appears as shown at left when you place it in the block diagram. You can add additional elements by using the Resizing cursor [image] (accessed by placing the Positioning tool at the corner of the function) to enlarge the node.

Note	The order of the inputs to the Bundle function determines the order of the plots on the chart. For example, if you wire the raw data to the top input of the Bundle function and the average to the bottom, the first plot corresponds to the raw data and the second plot corresponds to the average.

4.	From the front panel, run the VI. The VI displays two plots on the chart. The plots are overlaid. That is, they share the same vertical scale.

5.	From the block diagram, run the VI with execution highlighting turned on to see the data in the shift registers.

6.	Turn execution highlighting off. From the front panel, run the VI. While the VI is running, use the buttons from the palette to modify the chart. You can reset the chart, scale the X or Y axis, and change the display format at any time. You also can scroll to view other areas or zoom into areas of a graph or chart.

You can use the X and Y buttons [image] [image] to rescale the X and Y axes, respectively. If you want the graph to autoscale either of the scales continuously, click on the lock switch [image] to the left of each button to lock on autoscaling.

You can use the other buttons [image] to modify the axis text precision or to control the operation mode for the chart. Experiment with these buttons to explore their operation, scroll the area displayed, or zoom in on areas of the chart.

7.	Format the scales of the waveform chart to represent either absolute or relative time. To select the x scale time format, pop up on the x scale and select Formatting....

a.	Choose absolute time by selecting the Time & Date option from the Format and Precision menu ring. This changes the dialog box to the one shown below. For the waveform chart to start at a certain time and increment at certain intervals, you can edit the Xo and dX values respectively.

b.	Format the chart to display the data starting from noon, Oct. 24, 1996, and increment every 10 minutes, as shown above.

Note	Modifying the axis text format often requires more physical space than was originally set aside for the axis. If you change the axis, the text may become larger than the maximum size that the waveform can correctly present. To correct this, use the Resizing cursor to make the display area of the chart smaller.

8.	To select the relative time format, select Numeric from the Format and Precision menu ring. Then you can select the Relative Time (seconds) option in the dialog box and represent the time in seconds. Modify the dialog box, as shown in the following illustration, and then click OK.

9.	Run the VI.

10.	Save the VI as Multiple Random Plot.vi in the LabVIEW\Activity directory.

End of Activity 12. Create a Multiplot Chart


Activity 13. Use a For Loop

Your objective is to use a For Loop and shift registers to calculate the maximum value in a series of random numbers.

Front Panel

1.	Open a new front panel and add the objects shown in the following illustration.

a.	Place a digital indicator [image] on the front panel and label it Maximum Value.

b.	Place a waveform chart [image] on the front panel and label it Random Data. Change the scale of the chart to range from 0.0 to 1.0.

c.	Pop up on the chart and choose Show»Scrollbar and Show»Digital Display. Pop up and hide the palette and legend.

d.	Resize the scrollbar with the positioning tool.

Block Diagram

2.	Open the block diagram and modify it as shown in the following illustration.

3.	Place a For Loop [image] (Functions»Structures) on the block diagram.

4.	Add the shift register [image] by popping up or right clicking on the right or left border of the For Loop and choosing Add Shift Register.

5.	Add the following objects to the block diagram.

 Random Number (0–1) function (Functions»Numeric)—This function generates the random data.

 Numeric Constant (Functions»Numeric)—The For Loop needs to know how many iterations to make. In this case, you execute the For Loop 100 times.

 Numeric Constant (Functions»Numeric)—You set the initial value of the shift register to zero for this exercise because you know that the output of the random number generator is from 0.0 to 1.0.

You must know something about the data you are collecting to initialize a shift register. For example, if you initialize the shift register to 1.0, then that value is already greater than all the expected data values, and is always the maximum value. If you did not initialize the shift register, then it would contain the maximum value of a previous run of the VI. Therefore, you could get a maximum output value that is not related to the current set of collected data.

 Max & Min function (Functions»Comparison)—Takes two numeric inputs and outputs the maximum value of the two in the top right corner and the minimum of the two in the bottom right corner. Because you only are interested in the maximum value for this exercise, wire only the maximum output and ignore the minimum output.

6.	Wire the terminals as shown. If the Maximum Value terminal were inside the For Loop, you would see it continuously updated, but because it is outside the loop, it contains only the last calculated maximum.

Note	Updating indicators each time a loop iterates is time-consuming and you should try to avoid it when possible to increase execution speed.

7.	Run the VI.

8.	Save the VI as Calculate Max.vi in the LabVIEW\Activity directory.

End of Activity 13. Use a For Loop


Activity 14. Use the Case Structure

Your objective is to build a VI that checks a number to see if it is positive. If the number is positive, the VI calculates the square root of the number; otherwise, the VI returns an error.

Front Panel

1.	Open a new front panel and create the objects as shown in the following illustration.

The Number control supplies the number. The Square Root Value indicator displays the square root of the number. The free label acts as a note to the user.

Block Diagram

2.	Build the diagram as shown in the following illustration.

3.	Place a Case structure [image] in the block diagram by selecting it from (Functions»Structures). The Case structure is a resizable box that is not dropped on the diagram immediately. Instead, you have the chance to position it and resize it. To do so, click in an area above and to the left of all the terminals you want to be inside the Case structure. Continue holding down the mouse button and drag out a rectangle that encompasses the terminals.

 Greater Or Equal To 0? function (Functions»Comparison)—Returns a TRUE if the number input is greater than or equal to 0.

 Square Root function (Functions»Numeric)—Returns the square root of the input number.

 Numeric Constant (Functions»Numeric)—In this activity, the constant indicates the numeric value of the error.

 One Button Dialog function (Functions»Time & Dialog)—In this activity, the function displays a dialog box that contains the message Error...Negative Number.

 String Constant (Functions»String)—Enter text inside the box with the Labeling tool.

The VI executes either the TRUE case or the FALSE case. If the number is greater than or equal to zero, the VI executes the TRUE case and returns the square root of the number. The FALSE case outputs –99999.00 and displays a dialog box with the message Error...Negative Number.

Note	You must define the output tunnel for each case. When you create an output tunnel in one case, tunnels appear at the same position in all the other cases. Unwired tunnels appear as white squares.

4.	Return to the front panel and run the VI. Try a number greater than zero and a number less than zero by changing the value in the digital control you labeled Number. Notice that when you change the digital control to a negative number, LabVIEW displays the error message you set up in the FALSE case of the Case structure.

5.	Save the VI as Square Root.vi in the LabVIEW\Activity directory.

VI Logic

The block diagram in this activity has the same effect as the following pseudocode in a text-based language.

if (Number >= 0) then

Square Root Value = SQRT(Number)

else

Square Root Value = -99999.00

Display Message "Error...Negative Number"

end if

End of Activity 14. Use the Case Structure


Activity 15. Use the Sequence Structure

Your objective is to build a VI that computes the time it takes to generate a random number that matches a given number.

Front Panel

1.	Open a new front panel and build the front panel shown in the following illustration. Be sure to modify the controls and indicators as described in the text following the illustration.

The Number to Match control contains the number you want to match. The Current Number indicator displays the current random number. The # of iterations indicator displays the number of iterations before a match. Time to Match indicates how many seconds it took to find the matching number.

Modifying the Numeric Format

By default, LabVIEW displays values in numeric controls in decimal notation with two decimal places (for example, 3.14). You can use the Format&Precision… option of a control or indicator pop-up menu to change the precision or to display the numeric controls and indicators in scientific or engineering notation. You can also use the Format&Precision… option to denote time and date formats for numerics.

2.	Pop up on the Time to Match digital indicator and choose Format&Precision…. The front panel must be the active window to access the menu.

3.	Enter 3 for Digits of Precision and click OK.

4.	Pop up on the Number to Match digital control and choose Representation»I32.

5.	Repeat Step 4 for the Current Number and the # of iterations digital indicators.

Setting the Data Range

With the Data Range… option, you can prevent a user from setting a control or indicator value outside a preset range or increment. Your options are to ignore the value, coerce it to within range, or suspend execution. The range error symbol [image] appears in place of the Run button in the toolbar when a range error suspends execution. Also, a solid, dark border frames the control that is out of range.

6.	Pop up on the Number to Match indicator and choose Data Range….

7.	Fill in the dialog box as shown in the following illustration and click OK.

Block Diagram

8.	Open the block diagram.

9.	Place the Sequence structure (Functions»Structures) in the block diagram.

10.	Enlarge the structure by dragging one corner with the Resizing cursor.

11.	Create a new frame by popping up on the frame border and choose Add Frame After. Repeat this step to create frame 2.

12.	Build the block diagram shown in the following illustrations.

Frame 0 in the previous illustration contains a small box with an arrow in it.  That box is a sequence local variable which passes data between frames of a Sequence structure. You can create sequence locals on the border of a frame. Then, the data wired to a frame sequence local is available in subsequent frames. However, you cannot access the data in frames preceding the frame in which you created the sequence local.

13.	Create the sequence local by popping up on the bottom border of Frame 0 and choosing Add Sequence Local.

The sequence local appears as an empty square. The arrow inside the square appears automatically when you wire a function to the sequence local.

14.	Finish the block diagram as shown in the opening illustration of the Block Diagram section in this activity.

 Tick Count (ms) function (Functions»Time & Dialog)—Returns the number of milliseconds that have elapsed since power on. For this activity, you need two Tick Count functions.

 Random Number (0–1) function (Functions»Numeric)—Returns a random number between 0 and 1.

 Multiply function (Functions»Numeric)—In this activity, the function multiplies the random number by 100.

 Numeric Constant function (Functions»Numeric)—In this activity, the numeric constant represents the maximum number that can be multiplied.

 Round to Nearest function (Functions»Numeric)—In this activity, the function rounds the random number between 0 and 100 to the nearest whole number.

 Not Equal? function (Functions»Comparison)—In this activity, the function compares the random number to the number specified in the front panel and returns a TRUE if the numbers are not equal. Otherwise, this function returns FALSE.

 Increment function (Functions»Numeric)—In this activity, the function increments the While Loop count by 1.

 Subtract function (Functions»Numeric)—In this activity, the function returns the time (in milliseconds) elapsed between frame 2 and frame 0.

 Divide function (Functions»Numeric)—In this activity, the function divides the number of milliseconds elapsed by 1,000 to convert the number to seconds.

 Numeric constant (Functions»Numeric)—In this activity, the function converts the number from milliseconds to seconds.

In Frame 0, the Tick Count (ms) function returns the current time in milliseconds. This value is wired to the sequence local, where the value is available in subsequent frames. In Frame 1, the VI executes the While Loop as long as the number specified does not match the number that the Random Number (0–1) function returns. In Frame 2, the Tick Count (ms) function returns a new time in milliseconds. The VI subtracts the old time (passed from Frame 0 through the sequence local) from the new time to compute the time elapsed.

15.	Return to the front panel and enter a number inside the Number to Match control and run the VI.

16.	Save the VI as Time to Match.vi in the LabVIEW\Activity directory.

End of Activity 15. Use a Sequence Structure


Activity 17. Use an Attribute Node

Your objective is to create a VI that indicates a high limit condition using attribute nodes. You will use the Fill Color attribute of a Tank indicator to indicate whether a randomly generated tank level has gone above the user-defined limit.

Front Panel

1.	Open a new front panel and create it as shown in the following illustration.

2.	Rescale the tank from 0.0 to 100.0.

3.	Set the default Limit Setting to 50.00.

Block Diagram

4.	Create the block diagram as shown below.

 Not function (Functions»Boolean)—In this exercise, the Not function inverts the value of the STOP button so that the While Loop executes repeatedly until you click the STOP button. (The default state of the button is FALSE.)

 Random Number Generator (Functions»Numeric)—Generates raw data between 0 and 1 to fill the tank on your front panel. You multiply this value by 100 to create a value between 0 and 100.

 Greater or Equal? (Functions»Comparison)—Compares the raw data to the Limit Setting input. If the value is greater than or equal to the limit input, a TRUE value is passed to the Case structure.

 Attribute Node (Pop up on the Tank terminal)—Select Create»Attribute Node from the Tank terminal. Pop up on the attribute and choose Select»Fill Color.

 Color Box Constant (Functions»Numeric»Additional Numeric Constants)—Wire this constant to define a red color to Fill Color in the TRUE case and a blue color in the FALSE Case. Click on the constant with the Operating tool to select the color.

 Wait Until Next ms Multiple (Functions»Time & Dialog) —Wire a numeric constant of 1,000 to execute the loop every second.

5.	Run the VI. The level of the tank is compared to the Limit Setting control. If the tank value is greater than or equal to the Limit Setting value, the tank color turns red. If the data falls below the limit, the tank turns blue.

6.	Save the VI as Tank Limit.vi in the LabVIEW\Activity directory.

End of Activity 17. Use an Attribute Node


Activity 18. Create an Array with Auto-Indexing

Your objective is to create an array using the auto-indexing feature of a For Loop and plot the array in a waveform graph.

You will build a VI that generates an array using the Generate Waveform VI and plots the array in a waveform graph. You also will modify the VI to graph multiple plots.

Front Panel

1.	Open a new front panel.

2.	Place an array shell from Controls»Array & Cluster in the front panel. Label the array shell Waveform Array.

3.	Place a digital indicator [image] from Controls»Numeric inside the element display of the array shell, as the following illustration shows. This indicator displays the array contents.

4.	Place a waveform graph from Controls»Graph in the front panel. Label the graph Waveform Graph.

5.	Enlarge the graph by dragging a corner with the Resizing cursor [image] .

6.	Hide the legend and palette.

7.	Disable autoscaling by popping up on the graph and deselecting Y Scale»Autoscale Y.

8.	Use the Text tool [image] to rescale the Y axis to range from –0.5 to 1.5.

Block Diagram

9.	Build the block diagram shown in the following illustration.

 Generate Waveform VI (Functions»Select a VI… from the LabVIEW\Activity directory)—Returns one point of a waveform. The VI requires a scalar index input, so wire the loop iteration terminal [image] to this input.

Notice that the wire from the Generate Waveform VI becomes thicker as it changes to an array at the loop border.

The For Loop automatically accumulates the arrays at its boundary. This is called auto-indexing. In this case, the numeric constant wired to the loop count numeric input has the For Loop create a 100-element array (indexed 0 to 99).

 Bundle function (Functions»Cluster)—Assembles the plot components into a cluster. You need to resize the Bundle function icon before you can wire it properly. Place the Positioning tool on the lower-left corner of the icon. The tool transforms into the Resizing cursor [image] . When the tool changes, click and drag down until a third input terminal appears. Now, you can continue wiring your block diagram as shown in the previous illustration.

 Numeric Constant (Functions»Numeric)—Three numeric constants set the number of For Loop iterations, the initial X value, and the delta X value. Notice that you can pop up on the For Loop count terminal [image] and select Create Constant to add and wire a numeric constant for that terminal automatically.

10.	From the front panel, run the VI. The VI plots the auto-indexed waveform array on the waveform graph. The initial X value is 0 and the delta X value is 1.

11.	Change the delta X value to 0.5 and the initial X value to 20. Run the VI again.

Notice that the graph now displays the same 100 points of data with a starting value of 20 and a delta X of 0.5 for each point (see the X axis). In a timed test, this graph might correspond to 50 seconds worth of data starting at 20 seconds.

12.	You can view any element in the waveform array by entering the index of that element in the index display. If you enter a number greater than the array size, the display dims, indicating that you do not have a defined element for that index.

If you want to view more than one element at a time, you can resize the array indicator. Place the Positioning tool on the lower right corner of the array. The tool transforms into the array Resizing cursor [image] . When the tool changes, drag to the right or straight down. The array now displays several elements in ascending index order, beginning with the element corresponding to the specified index, as the following illustration shows.

In the previous block diagram, you specified an initial X and a delta X value for the waveform. The default initial X value is zero and the delta X value is 1. So, you can wire the waveform array directly to the waveform graph terminal without the initial X and delta X specified, as the following illustration shows.

13.	Return to the block diagram. Delete the Bundle function and the numeric constants wired to it. To delete the function and constants, select the function and constants with the Positioning tool then press <Delete>. Select Edit»Remove Bad Wires. Finish wiring the block diagram as shown in the previous illustration.

14.	Run the VI. Notice that the VI plots the waveform with an initial X value of 0 and a delta X value of 1.

Multiplot Graphs

You can create multiplot waveform graphs by building an array of the data type normally passed to a single-plot graph.

15.	Continue building your block diagram as shown in the preceding diagram.

 Sine function (Functions»Numeric»Trigonometric)—In this activity, you use the function in a For Loop to build an array of points that represents one cycle of a sine wave.

 Build Array function (Functions»Array)—In this exercise, you use this function to create the proper data structure to plot two arrays on a waveform graph, which in this case is a 2D array. Enlarge the Build Array function to create two inputs by dragging a corner with the Positioning tool.

 Pi constant (Functions»Numeric»Additional Numeric Constants)—Remember that you can find the Multiply and Divide functions in Functions»Numeric.

16.	Switch to the front panel. Run the VI.

Notice that the two waveforms plot on the same waveform graph. The initial X value defaults to 0 and the delta X value defaults to 1 for both data sets.

Note	You can change the appearance of a plot on the graph by popping up in the legend for a particular plot. For example, you can change from a line graph to a bar graph by choosing Common Plots»Bar Graph.

17.	Save the VI as Graph Waveform Arrays.vi in the LabVIEW\Activity directory.

End of Activity 18. Create an Array with Auto-Indexing


Activity 19. Use Auto-Indexing on Input Arrays

Your objective is to open and operate a VI that uses auto-indexing in a For Loop to process an array.

1.	Open the Separate Array Values VI by selecting File»Open.... The VI is located in Examples\General\arrays.llb.

Block Diagram

2.	Open the block diagram. The following illustration shows the block diagram with both TRUE and FALSE cases visible.

Notice that the wire from Input Array changes from a thick wire outside the For Loop, indicating it is an array, to a thin wire inside the loop, indicating it is a single element. The ith element of the array is indexed automatically from the array during each iteration.

Using Auto-Indexing to Set the For Loop Count

Notice that the count terminal [image] is left unwired. When you use auto-indexing on an array entering a For Loop, the loop executes according to the size of the array, eliminating the need to wire a value to the count terminal. If you use auto-indexing for more than one array, or if you set the count in addition to auto-indexing an array, the actual number of iterations is the smallest number possible.

3.	Run the VI. Of the eight input values, you will see four in the Positive Array and four in the Negative Array.

4.	From the block diagram, wire a constant of 5 to the count terminal of the For Loop. Run the VI. You will see three values in the Positive Array and two in the Negative Array, even though the input array still has eight elements. This demonstrates that if N is set and you are auto-indexing, the smaller number is used for the actual number of iterations of the loop.

5.	Close the VI and do not save changes.

End of Activity 19. Use Auto-Indexing on Input Arrays


Activity 20. Use the Build Array Function

Your objective is to use the Build Array function to combine elements and arrays into one bigger array.

Front Panel

1.	Create a new front panel, as shown in the following illustration.

2.	Place a digital control from the Controls»Numeric palette and label it scalar 1. Change its representation to I32.

3.	Copy and paste it to create two other digital controls and label them scalar 2 and scalar 3.

4.	Create an array of digital controls and label it array 1. Copy and paste it and label it array 2.

5.	Expand the arrays and enter the values 1 through 9 in array 1, scalar 1, scalar 2, array 2, and scalar 3, as shown in the illustration above.

6.	Copy the array and paste it and change it to an indicator. Label it 1D array. Expand it to show nine values.

Block Diagram

7.	Place a Build Array function (Functions»Array) on the block diagram. Expand it with the Positioning tool to have five inputs.

8.	Pop up on the first input in the Build Array node and select Change to Array. Do the same for the fourth input.

9.	Wire the arrays and scalars to the node. The output array is a 1D array composed of the elements of array 1 followed by scalar 1, scalar 2, and the elements of array 2 and scalar 3, as the following illustration shows.

10.	Run the VI. You can see the values in scalar 1, scalar 2, scalar 3, array 1, and array 2 appear in a single 1D array.

11.	Save the VI as Build Array.vi in the LabVIEW\Activity directory.

End of Activity 20. Use the Build Array Function


Activity 21. Use the Graph and Analysis VIs

Your objective is to build a VI that measures temperature and displays the values in real time. It also displays the average, maximum, and minimum temperatures.

Front Panel

1.	Create a new front panel as shown in the following illustration. You can modify the point styles of the waveform chart and waveform graph by popping up on their legends. Scale the charts as shown.

The Temperature waveform chart displays the temperature as it is acquired. After acquisition, the VI plots the data in Temp Graph. The Mean, Max, and Min digital indicators display the average, maximum, and minimum temperatures.

Block Diagram

2.	Build the block diagram as shown in the following illustration.

 Thermometer VI (Functions»Select a VI from the LabVIEW\Activity directory)—Returns one temperature measurement.

 Wait Until Next ms Multiple function (Functions»Time & Dialog)—In this exercise, this function ensures the For Loop executes every 0.25 seconds (250 milliseconds).

 Numeric constant (Functions»Numeric)—You also can pop up on the Wait Until Next ms Multiple function and select Create Constant to automatically create and wire the numeric constant.

 Array Max & Min function (Functions»Array)—In this activity, this function returns the maximum and minimum temperatures measured during the acquisition.

 Mean VI (Functions»Analysis»Probability and Statistics, or Functions»Base Analysis»Probability and Statistics)—Returns the average of the temperature measurements.

 Bundle function (Functions»Cluster)—Assembles the plot components into a cluster. The components include the initial X value (0), the delta X value (0.25), and the Y array (temperature data). Use the Positioning tool to resize the function by dragging one of the corners.

The For Loop executes 40 times. The Wait Until Next ms Multiple function causes each iteration to take place every 250 milliseconds. The VI stores the temperature measurements in an array created at the For Loop border (auto-indexing). After the For Loop completes execution, the array is passed on to the subVIs and Temp Graph.

Your completed VI bundles the data array with an initial X value of 0 and a delta X value of 0.25. The VI requires a delta X value of 0.25 so that the VI plots the temperature array points every 0.25 seconds on the waveform graph.

3.	Return to the front panel and run the VI.

4.	Save the VI as Temperature Analysis.vi in the LabVIEW\Activity directory.

End of Activity 21. Use the Graph and Analysis VIs


Arrays, Clusters, and Graphs

This topic introduces the basic concepts of polymorphism, arrays, clusters, and graphs and provides activities that explain auto-indexing and the Graph and Analysis VIs.

Arrays

What is Polymorphism?

Clusters

Graphs

Activity 18. Create an Array with Auto-Indexing

Activity 19. Use Auto-Indexing on Input Arrays

Activity 20. Use the Build Array Function

Activity 21. Use the Graph and Analysis VIs

For more information about these topics, see the following topics in the G Language Help File:

Array and Cluster Controls and Indicators

Graph and Chart Controls and Indicators


Arrays

An array is a collection of data elements that are all the same type. An array has one or more dimensions and up to 231 – 1 elements per dimension, memory permitting. You access each array element through its index. The index is in the range 0 to n – 1, where n is the number of elements in the array. The following 1D array of numeric values illustrates this structure. Notice that the first element has index 0, the second element has index 1, and so on.

How Do You Create and Initialize Arrays?

Array Controls, Constants, and Indicators

Auto-Indexing

Using Array Functions

Build Array

Initialize Array

Array Size

Array Subset

Index Array

Efficient Memory Usage: Minimizing Data Copies

Activity 18. Create an Array with Auto-Indexing

Activity 19. Use Auto-Indexing on Input Arrays

Activity 20. Use the Build Array Function

Return to Arrays, Cluster, and Graphs


How Do You Create and Initialize Arrays?

If you need an array as a source of data in your block diagram, you can choose Functions»Array and then select and place the array shell on your block diagram. Using the Operating tool, you can choose a numeric constant, Boolean constant, or string constant to place inside the empty array. The following illustration shows an example array shell with a numeric constant inserted into the array shell.

To create an array, select Array & Cluster from the Controls palette and place the array shell on your front panel. Then select an object (numeric, for example) and place that inside the array shell. This creates an array of numerics.

Note	You also can create an array and its corresponding control on the front panel and then copy or drag the array control to the block diagram to create a corresponding constant.

For more information on how to create array controls and indicators on the front panel, see Array and Cluster Controls and Indicators.

There are several ways to create and initialize arrays on the block diagram. Some block diagram functions also produce arrays, as the following illustration shows.

Activity 18. Create an Array with Auto-Indexing


Array Controls, Constants, and Indicators

You create array controls, constants, and indicators on the front panel or block diagram by combining an array shell with a numeric, Boolean, string, or cluster. An array element cannot be another array, chart, or graph. For examples of arrays, see Examples\General\arrays.llb.


Auto-Indexing

For Loop and While Loop structures can index and accumulate arrays at their boundaries automatically. These capabilities collectively are called auto-indexing. When you enable auto-indexing and wire an array of any dimension from an external node to an input tunnel on the loop border, components of that array enter the loop, one at a time, starting with the first component. The loop indexes scalar elements from 1D arrays, 1D arrays from 2D arrays, and so on. The opposite action occurs at output tunnels—elements accumulate sequentially into 1D arrays, 1D arrays accumulate into 2D arrays, and so on.

Note	Auto-indexing is the default for every array wired to a For Loop. You can disable auto-indexing by popping up on the tunnel (entry point of the input array) and selecting Disable Indexing.

By default, auto-indexing is disabled for every array wired to a While Loop. Pop up on the array tunnel of a While Loop to enable auto-indexing.

Activity 18. Create an Array with Auto-Indexing

Activity 19. Use Auto-Indexing on Input Arrays


Using Array Functions

G has many functions to manipulate arrays located in Functions»Array. These functions include Replace Array Element, Search 1D Array, Sort 1D Array, Reverse 1D Array, and Multiply Array Elements. For more information about arrays and the array functions available, refer to Array and Cluster Controls and Indicators or array function descriptions or cluster function descriptions.

Build Array

Initialize Array

Array Size

Array Subset

Index Array

Activity 20. Use the Build Array Function


Build Array

 Build Array function (Functions»Array)—You can use it to create an array from scalar values or from other arrays. Initially, the Build Array function appears with one scalar input.

You can add as many inputs as you need to the Build Array function, and each input can be either a scalar or an array. To add more inputs, pop up on the left side of the function and select Add Element Input or Add Array Input. You also can enlarge the Build Array node with the Resizing cursor [image] (place the Positioning tool at the corner of an object to transform it into the Resizing cursor). You can remove inputs by shrinking the node with the Resizing cursor, or by selecting Remove Input.

The following illustrations show two ways to create and initialize arrays with values from block diagram constants. On the left, five string constants are built into a 1D array of strings. On the right, three groups of numeric constants are built into three 1D numeric arrays. Then, the three arrays are combined into a 2D numeric array. The result is a 3 x 3 array with the rows 3, 4, 7; –1, 6, 2; and 5, –2, 8.

You also can create an array by combining other arrays along with scalar elements. For example, suppose you have two arrays and three scalar elements that you want to combine into a new array with the order array 1, scalar 1, scalar 2, array 2, and scalar 3.

Activity 20. Use the Build Array Function


Initialize Array

Use this function to create an array whose elements all have the same value. In the following illustration, this function creates a 1D array.

The element input determines the data type and the value of each element. The dimension size input determines the length of the array. For example, if element is a long integer with the value of five and dimension size has a value of 100, the result is a 1D array of 100 long integers all set to five. You can wire the inputs from front panel control terminals, as shown in the preceding illustration, from block diagram constants, or from calculations on other parts of your diagram.

To create and initialize an array that has more than one dimension, pop up on the lower-left side of the function and select Add Dimension. You also can use the Resizing cursor [image] to enlarge the Initialize Array node and add more dimension size inputs, one for each additional dimension. You can remove dimensions to shrink the node by selecting Remove Dimension from the function pop-up menu or with the Resizing cursor.

The following block diagram shows how to initialize a 3D array.

If all the dimension size inputs are zero, the function creates an empty array of the specified type and dimension.


Array Size

Array Size returns the number of elements in the input array.


Array Subset

You can use this function to extract a portion of an array or matrix.

Array Subset returns a portion of an array starting at index and containing length elements. The following illustrations show examples of Array Subsets. Notice that the array index begins with 0.


Index Array

The Index Array function accesses an element of an array.

The following illustration shows an example of an Index Array function accessing the third element of an array. Notice that the index of the third element is 2 because the first element has index 0.

You also can use this function to slice off one or more dimensions of a multi-dimensional array to create a subarray of the original. To do this, stretch the Index Array function to include two index inputs, and select the Disable Indexing command on the pop-up menu of the second index terminal as shown in the following illustration. Now you have disabled the access to a specific array column. By giving it a row index, the result is an array whose elements are the elements of the specified row of the 2D array. You also can disable indexing on the row terminal.

Notice that the index terminal symbol changes from a solid to an empty box when you disable indexing. To restore a disabled index, use the Enable Indexing command from the same menu.

You can extract subarrays along any combination of dimensions. The following illustration shows how to extract 1D row or column arrays from a 2D array.

From a 3D array, you can extract a 2D array by disabling two index terminals, or a 1D array by disabling a single index terminal. The following figure shows several ways to slice a 3D array.

The following rules govern the use of the Index Array function to slice arrays:

•	The dimension of the output object must equal the number of disabled index terminals. For example:

−	Zero disabled = scalar element

−	One disabled = 1D component

−	Two disabled = 2D component

•	The values wired to enabled terminals must identify the output elements.

Thus, you can interpret the lower left preceding example as a command to generate a 1D array of all elements at column 0 and row 3. You can interpret the upper-right example as a command to generate a 2D array of page 1. The new, 0th element is the one closest to the original, as shown in the preceding illustration.


Efficient Memory Usage: Minimizing Data Copies

To save memory, you can use single-precision arrays instead of double-precision arrays. For information about how memory is allocated, see Monitoring Memory Usage.


What is Polymorphism?

Polymorphism is the ability of a function to adjust to input data of different types, dimensions, or representations. Most G functions are polymorphic. For example, the following illustrations show some of the polymorphic combinations of the Add function.

In the first combination, the two scalars are added together, and the result is a scalar. In the second combination, the scalar is added to each element of the array, and the result is an array. An array is a collection of data. In the third combination, each element of one array is added to the corresponding element of the other array. You also can use other combinations, such as clusters of numerics or arrays of clusters.

You can apply these principles to other G functions and data types. G functions are polymorphic to different degrees. Some functions might accept numeric and Boolean inputs, others might accept a combination of any other data types. For more information about polymorphism, see polymorphism.

Return to Arrays, Cluster, and Graphs


Clusters

A cluster is a data type that can contain data elements of different types. In Activity 21. Use the Graph and Analysis VIs, the cluster in the block diagram groups related data elements from multiple places on the block diagram, reducing wire clutter. When you use clusters, your subVIs require fewer connection terminals. A cluster is analogous to a record in Pascal or a struct in C. You can think of a cluster as a bundle of wires, much like a telephone cable. Each wire in the cable would represent a different element of the cluster. The components include the initial X value (0), the delta X value (1), and the Y array (waveform data, provided by the numeric constants on the block diagram). In G, use the Bundle function to assemble a cluster. For more information about Clusters refer to Array and Cluster Controls and Indicators.

Return to Arrays, Cluster, and Graphs


Graphs

A graph is a two-dimensional display of one or more data arrays called plots. There are three types of graphs in the Controls»Graph palette:

•	XY graph

•	Waveform graph

•	Intensity graph

The difference between a graph and a chart is that a graph plots data as a block, whereas a chart plots data point by point, or array by array. See Loops and Charts for more information.

For examples of graph VIs, see Examples\General\Graphs.

Customizing Graphs

Graph Cursors

Graph Axes

Data Acquisition Arrays

Intensity Plots

Activity 21. Use the Graph and Analysis VIs

Return to Arrays, Cluster, and Graphs


Customizing Graphs

Both waveform and XY graphs have a number of optional parts that you can show or hide using the Show submenu of the pop-up menu for the graph. The options include a legend, through which you can define the color and style for a given plot, a palette from which you can change scaling and format options while the VI is running, and a cursor display. The following illustration of a graph shows all of the optional components except for the cursor display.

Graph Cursors

Graph Axes


Graph Cursors

You can place cursors and a cursor display on all the graphs in G, and you can label the cursor on the plot. You can set a cursor to lock onto a plot, and you can move multiple cursors at the same time. There is no limit to the number of cursors a graph can have. The following illustration shows a waveform graph with the cursor display.

For more detailed information on customizing graphs, see Graph and Chart Controls and Indicators.

Refer to the ZoomGraph VI in Examples\General\Graphs\zoom.llb for an example that reads cursor values and programmatically zooms in and out of a graph using the cursors.


Graph Axes

You can format the scales of a graph to represent either absolute or relative time. Use absolute time format to display the time, date, or both for your scale. If you do not want G to assume a date, use relative time format. To select absolute or relative time format, pop up on the chart and select the scale you want to modify. Select Formatting.... This enables the Formatting dialog box, which you can use to specify different attributes of the chart.


Data Acquisition Arrays

Data returned from a plug-in data acquisition board using the Data Acquisition VIs can be in the form of a single value, a 1D array, or a 2D array. You can find a number of graph examples located in Examples\General\Graphs, which contains VIs to perform varied functions with arrays and graphs.


Intensity Plots

LabVIEW has two methods for displaying three-dimensional data: the intensity chart and the intensity graph. Both intensity plots accept two-dimensional arrays of numbers, where each number is mapped to a color. You can define the color mapping interactively, using an optional color ramp scale, or programmatically, using an attribute node for the chart. For examples using the intensity chart and graph, refer to intgraph.llb in the Examples\General\Graphs directory.


Front Panel Object Attributes

This topic describes objects called attribute nodes, which are special block diagram nodes that control the appearance and functional characteristics of controls and indicators.

With attribute nodes, you can set attributes such as display colors, visibility, position, blinking, and many more. To create an attribute node, select Create»Attribute Node from the pop-up menu of the front panel object or from the terminal in the block diagram, as shown in the following illustration.

Initially, the attribute node displays a single characteristic. You can expand the node to display multiple characteristics. To expand the node, select the attribute node with the Positioning tool. Place your cursor over the node near the bottom-right corner, and when your cursor changes to a frame, drag it to create the desired number of characteristics. Then, you can change attributes by clicking the node with the Operating tool and choosing the new attribute from the pop-up menu, as shown in the following illustration.

Because there are many different attributes for front panel objects, you can use the Help window to display the descriptions, data types, and acceptable values of attributes. Access the Help window by selecting Help»Show Help.

For more information about accessing help in LabVIEW, see How to Use Help.

With attribute nodes, you can assign characteristics or read the current state of an attribute by popping up on the attribute and selecting Change to Read.

Activity 17. Use an Attribute Node

For more information about these topics, see the following topic(s) in the G Language Help File:

Attribute Nodes


Creating and Customizing VIs

This topic introduces the basic concepts of virtual instruments and how to customize your VIs. It also contains activities that illustrate how to accomplish the following tasks:

•	How to create the icon and connector

•	How to use a VI as a subVI

•	How to use the VI Setup... option

•	How to use the SubVI Node Setup... option

For examples of custom VIs, see Examples\General\viopts.llb.

What is a Virtual Instrument?

How Do You Build a VI?

What is a SubVI?

How Do You Debug a VI?

How Do You Customize a VI?

Activity 1. Create a VI

Activity 2. Document a VI

Activity 3. Create an Icon and Connector

Activity 4. Call a SubVI

Activity 5. Debug a VI

Activity 6. Use Setup Options for a SubVI

For more information about these topics, see the following topic(s) in the G Language Help File:

Editing VIs


What is a Virtual Instrument?

A virtual instrument (VI) is a program in the graphical programming language G. Virtual instrument front panels often have a user interface similar to physical instruments. G also has built-in functions that are similar to VIs, but do not have front panels or block diagrams as VIs do. Function icons always have a yellow background.


How Do You Build a VI?

One of the keys to creating LabVIEW applications is understanding and using the hierarchical nature of the VI. After you create a VI, you can use it as a subVI in the block diagram of a higher-level VI.

VI Hierarchy

Controls, Constants, and Indicators

Terminals

Wires

VI Documentation

Activity 1. Create a VI

Activity 2. Document a VI

Return to Creating and Customizing VIs


VI Hierarchy

When you create an application, you start at the top-level VI and define the inputs and outputs for the application. Then, you construct subVIs to perform the necessary operations on the data as it flows through the block diagram. If a block diagram has a large number of icons, group them into a lower-level VI to maintain the simplicity of the block diagram. This modular approach makes applications easy to debug, understand, and maintain.

As with other applications, you can save your VI to a file in a regular directory. With G, you also can save multiple VIs in a single file called a VI library.

If you are using Windows 3.1, you should save your VIs into VI libraries because you can use long file names (up to 255 characters) with mixed cases.

You should not use VI libraries unless you need to transfer your VIs to Windows 3.1. Saving VIs as individual files is more effective than using VI libraries because you can copy, rename, and delete files more easily than if you are using a VI library. For a list of the advantages and disadvantages of using VI libraries and individual files, see Saving VIs.

VI libraries have the same load, save, and open capabilities as other directories. VI libraries, however, are not hierarchical. That is, you cannot create a VI library inside of another VI library. You cannot create a new directory inside a VI library, either. There is no way to list the VIs in a VI library outside the LabVIEW environment.

After you create a VI library, it appears in the LabVIEW File dialog box as a folder with VI on the folder icon. Regular directories appear as a folder without the VI label.

Even though you might not save your own VIs in VI libraries, you should be familiar with how they work. In the various activities in this help file, you will save your VIs in the LabVIEW\Activity directory. Solutions to these activities are provided in the LabVIEW\Activity\Solution directory.


Controls, Constants, and Indicators

A control is an object you place on your front panel for entering data into a VI interactively or into a subVI programmatically. An indicator is an object you place on your front panel for displaying output. Controls and indicators in G are similar to input and output parameters, respectively, in traditional programming languages.

An alternative to dropping controls and indicators on the front panel and then wiring them to functions or VIs on the block diagram, is to create controls or indicators directly from the block diagram. To do this, pop up on the input terminal of a function or VI on the block diagram and select Create Control. This creates a control of the correct data type and wires it to the terminal.

You can create an indicator and wire it to an output terminal by popping up on the terminal and selecting Create Indicator. As an alternative to placing constants on the block diagram and wiring them to functions and VIs, you can pop up on a function or VI terminal and select Create Constant. You cannot delete a control or indicator from the block diagram. As with all front panel objects, you must go to the front panel, select the Positioning tool, and then delete the object.

Each time you create a new control or indicator on the front panel, LabVIEW creates the corresponding terminal in the block diagram. The terminal symbols suggest the data type of the control or indicator. For example, a DBL terminal represents a double-precision, floating-point number; a TF terminal is a Boolean; an I16 terminal represents a regular, 16-bit integer; and an ABC terminal represents a string. For more information about data types in G, and their graphical representations, see the G Programming Quick Reference Card.


Terminals

Terminals are regions on a VI or function through which data passes. Terminals are analogous to parameters in text-based programming languages. It is important that you wire the correct terminals of a function or VI. You can view the icon connector to make correct wiring easier. To do this, pop up on the function or VI and choose Show»Terminals. To return to the icon, pop up on the function and select Show»Terminals again.


Wires

A wire is a data path between nodes. Wires are colored according to the kind of data each wire carries. Blue wires carry integers, orange wires carry floating-point numbers, green wires carry Booleans, and pink wires carry strings. For more information about wire styles and colors, see the G Programming Quick Reference Card.

To wire from one terminal to another, click the Wiring tool on the first terminal, move the tool to the second terminal, and click on the second terminal. It does not matter at which terminal you start. The hot spot of the tool [image] is the tip of the unwound wiring segment.

In the wiring illustrations in this section, the arrow at the end of this mouse symbol [image] shows where to click and the number printed on the mouse button indicates how many times to click the mouse button.

When the Wiring tool is over a terminal, the terminal area blinks, to indicate that clicking connects the wire to that terminal. Do not hold down the mouse button while moving the Wiring tool from one terminal to another. You can bend a wire once by moving the mouse perpendicular to the current direction. To create more bends in the wire, click the mouse button. To change the direction of the wire, press the spacebar. Click with the mouse button to tack the wire down and move the mouse perpendicularly.

Tip Strips

Wire Stretching

Selecting and Deleting Wires

Bad Wires

Activity 1. Create a VI


Tip Strips

When you move the Wiring tool over the terminal of a node, a tip strip for that terminal pops up. Tip strips consist of small, yellow text banners that display the name of each terminal. These tip strips should help you to wire the terminals. The following illustration displays the tip strip that appears when you place the Wiring tool over the output of the Simple Error Handler VI.

Note	When you place the Wiring tool over a node, G displays wire stubs that indicate each input and output. The wire stub has a dot at its end if it is an input to the node.


Wire Stretching

You can move wired objects individually or in groups by dragging the selected objects to a new location with the Positioning tool [image] .


Selecting and Deleting Wires

You might wire nodes incorrectly. If you do, select the wire you want to delete and then press <Delete>. A wire segment is a single horizontal or vertical piece of wire. The point where three or four wire segments join is called a junction. A wire branch contains all the wire segments from one junction to another, from a terminal to the next junction, or from one terminal to another if there are no junctions in between. You select a wire segment by clicking on it with the Positioning tool. Double clicking selects a branch, and triple clicking selects the entire wire.


Bad Wires

 A dashed wire represents a bad wire. You can get a bad wire for a number of reasons, such as connecting two controls, or connecting a source terminal to a destination terminal when the data types do not match (for instance, connecting a numeric to a Boolean). You can remove a bad wire by clicking on it with the Positioning tool [image] and pressing <Delete>. Choosing Edit»Remove Bad Wires or <Ctrl-B> deletes all bad wires in the block diagram. This is a useful quick fix to try if your VI refuses to run or returns the Signal has Loose Ends error message.

Note	Do not confuse a black, dashed wire with a dotted wire. A dotted wire represents a Boolean data type, as the following illustration shows.


VI Documentation

You can document a VI by choosing Windows»Show VI Info.... Type the description of the VI in the VI Information dialog box. Then, you can recall the description by selecting Windows»Show VI Info... again.

You can edit the descriptions of objects on the front panel (or their respective terminals on the block diagram) by popping up on the object and choosing Data Operations»Description….

Note	You cannot change the description of a VI or its front panel objects while the VI is running.

The following illustration is an example pop-up menu that appears while your are running a VI. You cannot add to or change the description while running the VI, but you can view any previously entered information.

You also can view the description of a front panel object by showing the Help window (Help»Show Help) and moving the cursor over the object.

Activity 2. Document a VI


What is a SubVI?

A subVI is much like a subroutine in text-based programming languages. It is a VI that is used in the block diagram of another VI.

You can use any VI that has an icon and a connector as a subVI in another VI. In the block diagram, you select VIs to use as subVIs from Functions»Select a VI.... Choosing this option produces a file dialog box, from which you can select any VI in the system. If you open a VI that does not have an icon and a connector, a blank, square box appears in the calling VI's block diagram. You cannot wire to this node. For more information about icons and connectors, see the LabVIEW Online tutorial, which you can access from the startup dialog box.

A subVI is analogous to a subroutine. A subVI node (icon/connector) is analogous to a subroutine call. The subVI node is not the subVI itself, just as a subroutine call statement in a program is not the subroutine itself. A block diagram that contains several identical subVI nodes calls the same subVI several times.

Hierarchy Window

Icon and Connector

Opening, Operating, and Changing SubVIs

Activity 3. Create an Icon and Connector

Activity 4. Call a SubVI

Return to Creating and Customizing VIs


Hierarchy Window

The Hierarchy window displays a graphical representation of the calling hierarchy for all VIs in memory, including type definitions and global variables. You use the Hierarchy window (Project»Show VI Hierarchy) to display the dependencies of VIs by providing information on VI callers and subVIs. This window contains a toolbar that you can use to configure several types of settings for displayed items. The following illustration shows an example of the VI hierarchy toolbar. Your cursor becomes a hand icon as it passes over certain items in the following illustration. You can click on those items for more information

You can use buttons on the Hierarchy window toolbar or the View menu, or pop up on an empty space in the window to access these options. See Using the Hierarchy Window for more information about the Hierarchy window.

In addition, the View menu and pop-up menus include Show all VIs and Full VI Path in Label options that you cannot access on the toolbar.

As you move the Operating tool [image] over objects in the Hierarchy window, LabVIEW displays the name of the VI below the VI icon.

Use the <Tab> key to toggle between the Positioning and Scroll window tools. This feature is useful for moving nodes from the Hierarchy window to the block diagram.

You can drag a VI or subVI node to the block diagram or copy it to the clipboard by clicking on the node. <Shift>-click on a VI or subVI node to select multiple objects for copying to other block diagrams or front panels. Double clicking on a VI or subVI node opens the front panel of that node.

Any VIs that contain subVIs have an arrow button next to the VI that you can use to show or hide subVIs. Clicking on the red arrow button or double clicking on the VI itself opens the subVIs in that VI. A black arrow button on a VI node means that all subVIs are displayed. You also can pop up on a VI or subVI node to access a menu with options, such as showing or hiding subVIs, opening the VI or subVI front panel, editing the VI icon, and so on.

Search Hierarchy


Search Hierarchy

You also can search currently visible nodes in the Hierarchy window by name. You initiate the search by typing in the name of the node, anywhere on the window. As you type in the text, a search string appears, which displays the text as you type it in and concurrently searches through the hierarchy. The following illustration shows the search hierarchy.

After finding the correct node, you can press <Enter> to search for the next node that matches the search string, or you can press <Shift-Enter> to find the previous node that matches the search string.


Icon and Connector

Every VI has a default icon displayed in the upper-right corner of the front panel and diagram windows. For VIs, the default is the LabVIEW VI icon and a number indicating how many new VIs you have opened since launching LabVIEW. You use the Icon Editor to customize the icon by turning individual pixels on and off. To activate the Icon Editor, pop up on the default icon in the top right corner of the panel window and select Edit Icon.

The following illustration shows the Icon Editor window. You use the tools on the left of the window to create the icon design in the pixel editing area. An image of the actual icon size appears in one of the boxes to the right of the editing area. You use the buttons in the lower-right corner of the window to save your icon or cancel without saving changes. Your cursor becomes a hand icon as it passes over the tools and buttons in the following illustration. You can click on those items for more information about their specific functions.

Depending on the type of monitor you are using, you can design a separate icon for monochrome, 16-color, and 256-color mode. You design and save each icon version separately. The editor defaults to Black & White, but you can click on one of the other color options to switch modes.

Note	If you design a color icon only, the icon does not show up in a subpalette of the Functions palette if you place the VI in the *.lib directory, nor will the icon be printed or displayed on a black and white monitor.

The connector is the programmatic interface to a VI. If you use the panel controls or indicators to pass data to and from subVIs, these controls or indicators need terminals on the connector pane. You define connections by choosing the number of terminals you want for the VI and assigning a front panel control or indicator to each of those terminals.

To define a connector, select Show Connector from the icon pane pop-up menu on the panel window.

The connector icon replaces the icon in the upper-right corner of the panel window. LabVIEW selects a terminal pattern appropriate for your VI with controls on the left side of the connector pane, and terminals for indicators on the right. The number of terminals selected depends on the number of controls and indicators on your front panel.

Each rectangle on the connector represents a terminal area, and you can use the rectangles either for input or output from the VI. If necessary, you can select a different terminal pattern for your VI. To do this, pop up on the icon, select Show Connector, pop up again, and select Patterns.

Activity 3. Create an Icon and Connector


Opening, Operating, and Changing SubVIs

You can open a VI used as a subVI from the block diagram of the calling VI by double clicking on the subVI icon or by selecting Project»This VI's SubVIs. You will see a palette containing all the subVIs of the calling VI. Select the subVI you want to open.

Any changes you make to a subVI alter only the version in memory until you save the subVI. The changes affect all instances of the subVI and not just the node you used to edit the VI.

Activity 4. Call a SubVI


How Do You Debug a VI?

A VI cannot compile or run if it is broken. Normally, the VI is broken while you are creating or editing it, until you wire all the icons in the diagram. If it still is broken when you finish, try selecting Remove Bad Wires from the Edit menu. Often, this fixes a broken VI.

When your VI is not executable, a broken arrow appears instead of the Run button. To list the errors, click on the broken Run button. Click on one of the errors listed and then click on Find to highlight the object or terminal that reported the error.

You can animate the VI block diagram execution by clicking on the Highlight Execution button. Execution highlighting is commonly used with single-step mode to trace the data flow in a block diagram.

For debugging purposes, you might want to execute a block diagram node by node. This is known as single-stepping. To enable the single-step mode, click on the Step Into button or Step Over button. This action then causes the first node to blink, denoting that it is ready to execute. Then you can click on either the Step Into or Step Over button again to execute the node and proceed to the next node. If the node is a structure or VI, you can select the Step Over button to execute the node but not single-step through the node. For example, if the node is a subVI and you click on the Step Over button, you execute the subVI and proceed to the next node but cannot see how the subVI nodes execute. To single-step through a structure or subVI, select the Step Into button.

Click on the Step Out button to finish execution of the block diagram nodes and/or complete single-stepping. For more information about debugging, see Executing and Debugging VIs and SubVIs.

Activity 5. Debug a VI

Return to Creating and Customizing VIs


How Do You Customize a VI?

You can configure VI execution in several ways. You access these options by popping up on the icon pane in the upper right corner of the front panel and choosing VI Setup....

A VI Setup dialog box appears showing setup options for execution of the VI, appearance of the panel, documentation, and menu bar appearance at run time. For more detailed information, see Setting up VIs and SubVIs.

Set Window Options

SubVI Node Setup

Activity 6. Use Setup Options for a SubVI

Return to Creating and Customizing VIs


Set Window Options

Use Window Options [image] control the appearance of the VI when running. To switch from Execution Options to Window Options, click the downward pointing arrow in the menu bar.


SubVI Node Setup

You also can configure how a subVI executes. The configuration options are available by popping up on the subVI icon in the block diagram of the calling VI, and choosing SubVI Node Setup.... The following illustration shows the SubVI Node Setup dialog box.

Note	If you select an option from the VI Setup... dialog box of a VI, the option applies to every instance of that VI. If you select an option from the SubVI Node Setup dialog box, the option applies only to that particular node.

Activity 6. Use Setup Options for a SubVI


 Redraw

Rearranges nodes after successive operations on hierarchy nodes if you need to minimize line crossings and maximize symmetric aesthetics. If a focus node exists, you then scroll through the window so that the first root that shows subVIs is visible.


 Switch to vertical layout

Arranges the nodes from top-to-bottom, placing roots at the top.


 Switch to horizontal layout

Arranges the nodes from left-to-right, placing roots on the left side.


 Include/Exclude VIs

Toggles the hierarchy graph to include VI libraries, or exclude VIs in VI libraries.


 Include/Exclude global

Toggles the hierarchy graph to include variables, or exclude global variables.


 Include/Exclude typedefs

Toggles the hierarchy graph to include or exclude typedefs.


 Pencil tool

Draws and erases pixel by pixel.


 Line tool

Draws straight lines. Press <Shift>and then drag this tool to draw horizontal, vertical, and diagonal lines.


 Color Copy tool

Copies the foreground color from an element in the icon.


 Fill bucket tool

Fills an outlined area with the foreground color.


 Rectangle tool

Draws a rectangular border in the foreground color. Double click on this tool to frame the icon in the foreground color.


 Filled rectangle tool

Draws a rectangle bordered with the foreground color and filled with the background color. Double click to frame the icon in the foreground color and fill it with the background color.


 Select tool

Selects an area of the icon for moving, cloning, or other changes.


 Text tool

Enters text into the icon design.


 Foreground/Background

Displays the current foreground and background colors. Click on each to get a color palette from which you can choose new colors.


OK

Saves your drawing as the VI icon and returns to the front panel.


Cancel

Returns to the front panel without saving any changes.


Case and Sequence Structures and the Formula Node

This topic introduces the basic concepts of Case and Sequence structures and the Formula Node, and provides activities that explain the following:

•	How to use the Case structure

•	How to use the Sequence structure

•	What sequence locals are and how to use them

•	What the Formula Node is and how to use it

Both Case and Sequence structures can have multiple subdiagrams, configured like a deck of cards, of which only one is visible at a time. At the top of each structure border is the subdiagram display window, which contains a diagram identifier in the center and decrement and increment buttons at each side. The diagram identifier indicates which subdiagram currently is displayed. For Case structures, a diagram identifier is a list of values which select the subdiagram. For Sequence structures, a diagram identifier is the number of the frame in the sequence (0 to n – 1). The following illustration shows a Case structure and a Sequence structure.

Clicking on the decrement (left) or increment (right) button displays the previous or next subdiagram, respectively. Incrementing from the last subdiagram displays the first subdiagram, and decrementing from the first subdiagram displays the last.

For more information about Case and Sequence structures, refer to the following topics:

Case Structures

Sequence Structures

Formula Node

Activity 14. Use the Case Structure

Activity 15. Use the Sequence Structure

Activity 16. Use the Formula Node

For more information about these topics, see the following topic(s) in the G Language Help File:

Structures


Case Structures

The Case structure has two or more subdiagrams, or cases, exactly one of which executes when the structure executes. This depends on the value of the integer, Boolean, string, or enum value you wire to the external side of the selection terminal or selector. A Case structure is shown in the following illustration.

Note	Case statements in other programming languages generally do not execute any case if a case is out of range. In G, you must either include a default case that handles out-of-range values or explicitly list every possible input value.

Activity 14. Use the Case Structure


Sequence Structures

The Sequence structure, which looks like frames of film, executes block diagrams sequentially. In conventional programming languages, the program statements execute in the order in which they appear. In data flow programming, a node executes when data is available at all of the node inputs, although sometimes it is necessary to execute one node before another. G uses the Sequence structure as a method to control the order in which nodes execute. G executes the diagram inside the border of Frame 0 first, it executes the diagram inside the border of Frame 1 second, and so on. As with the Case structure, only one frame is visible at a time.

A Sequence structure is shown in the following illustration.

Activity 15. Use the Sequence Structure


Formula Node

The Formula Node is a resizable box that you can use to enter formulas directly into a block diagram. You place the Formula Node on the block diagram by selecting it from Functions»Structures. This feature is useful when an equation has many variables or is otherwise complicated. For example, consider the equation below:

y = x2 + x + 1

If you implement this equation using regular G arithmetic functions, the block diagram looks like the one in the following illustration.

You can implement the same equation using a Formula Node, as shown in the following illustration

With the Formula Node, you can directly enter a complicated formula, or formulas, in lieu of creating block diagram subsections. You enter formulas with the Labeling tool. You create the input and output terminals of the Formula Node by popping up on the border of the node and choosing Add Input (Add Output). Type the variable name in the box. Variables are case sensitive. You enter the formula or formulas inside the box. Each formula statement must end with a semicolon ( ; ).

The operators and functions available inside the Formula Node are listed in the Help window for the Formula Node, as shown in the following illustration. A semicolon terminates each formula statement.

The following example shows how you can perform a conditional assignment inside a Formula Node.

Consider the following code fragment that computes the square root of x if x is positive, and assigns the result to y. If x is negative, the code assigns –99 to y.

if (x >= 0) then

y = sqrt(x)

else

y = -99

end if

You can implement the code fragment using a Formula Node, as shown in the following illustration.

Artificial Data Dependency

Activity 16. Use the Formula Node


Artificial Data Dependency

Nodes not connected by a wire can execute in any order. Nodes do not necessarily execute in left-to-right, top-to-bottom order. A Sequence structure is one way to control execution order when natural data dependency does not exist.

Another way to control execution order is to create an artificial data dependency, a condition in which the arrival of data rather than its value triggers execution of an object. The receiver may not actually use the data internally. The advantage of artificial dependency is that all of the nodes are visible at one level, although, in some cases, the confusion created by the artificial links between the nodes can be a disadvantage.

You can open the Timing Template (data dep).vi from Examples\General\structs.llb to see how the Timing Template has been altered to use artificial data dependency rather than a sequence structure.


Loops and Charts

This topic introduces structures and explains the basic concepts of charts, the While Loop, and the For Loop. This topic also provides activities that illustrate how to accomplish the following:

•	Learn about different chart modes

•	Use a While Loop and a chart

•	Change the mechanical action of a Boolean switch

•	Control loop timing

•	Use a shift register

•	Create a multiplot chart

•	Use a For Loop

What is a Structure?

Charts

While Loops

Shift Registers

For Loops

Activity 7. Experiment with Chart Modes

Activity 8. Use a While Loop and a Chart

Activity 9. Change the Mechanical Action of a Boolean Switch

Activity 10. Control Loop Timing

Activity 11. Use a Shift Register

Activity 12. Create a Multiplot Chart

Activity 13. Use a For Loop

For more information about these topics, see the following topic(s) in the G Language Help File:

Structures

Graph and Chart Controls and Indicators


What is a Structure?

A structure is a program control element. Structures control the flow of data in a VI. G has five structures: the While Loop, the For Loop, the Case structure, the Sequence structure, and the Formula Node. This topic introduces the While Loop and For Loop structures along with the chart and the shift register. The Case structure, Sequence structure, and Formula Node are explained in Case and Sequence Structures and the Formula Node.

While and For Loops are basic structures for programming with G, so you can find them in most of the G examples as well as the activities in this tutorial. You also can find more information on loops in Structures.

For examples of structures, see Examples\General\structs.llb. For examples of charts, see Examples\General\Graphs\charts.llb.

Return to Loops and Charts


Charts

A chart is a numeric plotting indicator that is updated with new data periodically. You can find two types of charts in the Controls»Graph palette: waveform chart and intensity chart. You can customize charts to match your data display requirements or to display more information. Features available for charts include: a scrollbar, a legend, a palette, a digital display, and representation of scales with respect to time. For more information about charts, see Graph and Chart Controls and Indicators.

Chart Modes

Faster Chart Updates

Overlaid Versus Stacked Plots

Activity 7. Experiment with Chart Modes

Return to Loops and Charts


Chart Modes

The following illustration shows the three chart display options available from the Data Operations»Update Mode submenu—Strip chart, Scope chart, and Sweep chart. The default mode is Strip chart.

Activity 7. Experiment with Chart Modes


Faster Chart Updates

You can pass an array of multiple values to the chart. The chart treats these inputs as new data for a single plot. Refer to the charts.vi example located in Examples\General\Graphs\charts.llb.


Overlaid Versus Stacked Plots

You can display multiple plots on a chart using a single vertical scale, called overlaid plots, or using multiple vertical scales, called stacked plots. Refer to the charts.vi example located in Examples\General\Graphs\charts.llb.


While Loops

A While Loop is a structure that repeats a section of code until a condition is met. It is comparable to a Do Loop or a Repeat-Until loop in traditional programming language.

The While Loop, shown in the following illustration, is a resizable box you use to execute the diagram inside it until the Boolean value passed to the conditional terminal (an input terminal) is FALSE. The VI checks the conditional terminal at the end of each iteration; therefore, the While Loop always executes at least once. The iteration terminal is an output numeric terminal that outputs the number of times the loop has executed. However, the iteration count always starts at zero, so if the loop runs once, the iteration terminal outputs 0.

The While Loop is equivalent to the following pseudocode:

Do

Execute Diagram Inside the Loop (which sets the condition)

While Condition is TRUE

Mechanical Action of Boolean Switches

Timing

Preventing Code Execution in the First Iteration

Activity 8. Use a While Loop and a Chart

Activity 9. Change the Mechanical Action of a Boolean Switch

Activity 10. Control Loop Timing

Return to Loops and Charts


Mechanical Action of Boolean Switches

You might notice that each time you run the VI, you must turn on the vertical switch and then click on the Run button in the toolbar. With G, you can modify the mechanical action of Boolean controls.

There are six possible choices for the mechanical action of a Boolean control.

•	Switch When Pressed

•	Switch When Released

•	Switch Until Released

•	Latch When Pressed

•	Latch When Released

•	Latch Until Released

Below are figures depicting each of these Boolean switches, as well as a description of each of these mechanical actions.

 Switch When Pressed action—Changes the control value each time you click on the control with the Operating tool. The action is similar to that of a ceiling light switch, and is not affected by how often the VI reads the control.

 Switch When Released action—Changes the control value only after you release the mouse button, during a mouse click, within the graphical boundary of the control. The action is not affected by how often the VI reads the control. This action is similar to what happens when you click on a check mark in a dialog box; it becomes highlighted but does not change until you release the mouse button.

 Switch Until Released action—Changes the control value when you click on the control. It retains the new value until you release the mouse button, at which time the control reverts to its original value. The action is similar to that of a doorbell, and is not affected by how often the VI reads the control.

 Latch When Pressed action—Changes the control value when you click on the control. It retains the new value until the VI reads it once, at which point the control reverts to its default value. (This action happens regardless of whether you continue to press the mouse button.) This action is similar to that of a circuit breaker and is useful for stopping While Loops or having the VI do something only once each time you set the control.

 Latch When Released action—Changes the control value only after you release the mouse button. When your VI reads the value once, the control reverts to the old value. This action guarantees at least one new value. As with Switch When Released, this action is similar to the behavior of buttons in a dialog box; clicking on this action highlights the button, and releasing the mouse button latches a reading.

 Latch Until Released action—Changes the control value when you click on the control. It retains the value until your VI reads the value once or until you release the mouse button, depending on which one occurs last.

Activity 9. Change the Mechanical Action of a Boolean Switch


Timing

When you ran the VI in the previous activity, the While Loop executed as quickly as possible. However, you can slow it down to iterate at certain intervals with the functions in the Functions»Time & Dialog palette.

The timing functions express time in milliseconds (ms), however, your operating system might not maintain this level of timing accuracy.

•	(Windows 95/NT) The timer has a resolution of 1 ms. However, this is hardware-dependent, so on slower systems, such as an 80386, you might have lower resolution timing.

•	(Windows 3.1) The timer has a default resolution of 55 ms. You can configure LabVIEW to have 1 ms resolution by selecting Edit»Preferences…, selecting Performance and Disk from the Paths ring, and unchecking the Use Default Timer checkbox. LabVIEW does not use the 1 ms resolution by default because it places a greater load on your operating system.

•	(Macintosh) For 68K systems without the QuickTime extension, the timer has a resolution of 16 2/3 ms (1/60th of a second). If you have a Power Macintosh or have QuickTime installed, timer resolution is 1 ms.

•	(UNIX) The timer has a resolution of 1 ms.

Activity 10. Control Loop Timing


Preventing Code Execution in the First Iteration

The While Loop always executes at least once because G performs the loop test for continuation after the diagram executes. You can construct a While Loop that pretests its conditional terminal by including a Case structure inside the loop. Wire a Boolean input to the Case structure selector terminal so the subdiagram for the FALSE condition executes if the code in the While Loop should not execute. See Case and Sequence Structures and the Formula Node for more information about using Case structures.

The subdiagram for the TRUE condition contains the work of the While Loop. The test for continuation occurs outside the Case structure, and the results are wired to the conditional terminal of the While Loop and the selector terminal of the Case structure. In the following illustration, labels represent the pretest condition.

This example has the same result as the following pseudocode.

While (pretest condition)

Do actual work of While Loop

Loop


Shift Registers

Shift registers (available for While Loops and For Loops) transfer values from one loop iteration to the next. You can create a shift register by popping up on the left or right border of a loop and selecting Add Shift Register.

The shift register contains a pair of terminals directly opposite each other on the vertical sides of the loop border. The right terminal stores the data upon the completion of an iteration. That data shifts at the end of the iteration and appears in the left terminal at the beginning of the next iteration, as shown in the following illustration. A shift register can hold any data type—numeric, Boolean, string, array, and so on. The shift register automatically adapts to the data type of the first object you wire to the shift register.

You can configure the shift register to remember values from several previous iterations. This feature is useful for averaging data points. You create additional terminals to access values from previous iterations by popping up on the left or right terminal and choosing Add Element. For example, if a shift register contains three elements in the left terminal, you can access values from the last three iterations, as shown in the following illustration.

Using Uninitialized Shift Registers

Activity 11. Use a Shift Register

Activity 12. Create a Multiplot Chart

Return to Loops and Charts


Using Uninitialized Shift Registers

You initialize a shift register by wiring a value from outside a While Loop or For Loop to the left terminal of the shift register. Sometimes, however, you want to execute a VI repeatedly with a loop and a shift register, so that each time the VI executes, the initial output of the shift register is the last value from the previous execution. To do that, you must leave the left shift register terminal unwired from outside the loop. Leaving the input to the left shift register terminal unwired preserves state information between subsequent executions of a VI.

The following illustration shows an example of a subVI that calculates the running average of four data points. The VI uses an uninitialized shift register (with three additional elements) to store previous data points.

Each time the VI is called, running average is computed from the new input and the previous three values. Then the new value is saved into the shift register, and the previous two values are moved up in the shift register. There is no input value wired to the input side of the left shift registers, so all three values are preserved for the next execution of the VI.

Because this subVI has nothing wired to the conditional terminal, it executes exactly once when called. The While Loop in this subVI is not used to loop several times, but to store values in the loop registers between calls.

When the Running Averages VI is loaded into memory, the uninitialized shift registers are set to zero automatically. If the shift registers are wired to Boolean values, the initial value is FALSE.

Activity 12. Create a Multiplot Chart


For Loops

A For Loop executes a section of code a defined number of times. It is a resizable structure, and like the While Loop, it is not dropped on the block diagram immediately. Instead, a small icon representing the For Loop appears in the block diagram, and you have the opportunity to size and position it. To do so, first click in an area above and to the left of all the terminals. While holding down the mouse button, drag out a rectangle that encompasses the terminals you want to place inside the For Loop. When you release the mouse button, G creates a For Loop of the size and position you selected. You place the For Loop on the block diagram by selecting it from Functions»Structures.

The For Loop executes the diagram inside its border a predetermined number of times. The For Loop has two terminals, explained below.

 Count terminal (an input terminal)—The count terminal specifies the number of times to execute the loop.

 Iteration terminal (an output terminal)—The iteration terminal contains the number of times the loop has executed.

The For Loop is equivalent to the following pseudocode:

For i = 0 to N-1

Execute Diagram Inside The Loop

The following illustration shows a For Loop that generates 100 random numbers and displays the points on a chart.

Numeric Conversion

Activity 13. Use a For Loop

Return to Loops and Charts


Numeric Conversion

Until now, all the numeric controls and indicators you have used have been double-precision, floating-point numbers represented with 32 bits. G, however, can represent numerics as integers (byte, word, or long) or floating-point numbers (single-, double-, or extended-precision). The default representation for a numeric is a double-precision, floating-point.

If you wire two terminals together that are of different data types, G converts one of the terminals to the same representation as the other terminal. As a reminder, G places a gray dot, called a coercion dot, on the terminal where the conversion takes place.

For example, consider the For Loop count terminal [image] . The terminal representation is a long integer. If you wire a double-precision, floating-point number to the count terminal, G converts the number to a long integer. Notice the gray dot in the count terminal of the first For Loop.

Note	When the VI converts floating-point numbers to integers, it rounds to the nearest integer. If a number is exactly halfway between two integers, it is rounded to the nearest even integer. For example, the VI rounds 6.5 to 6, but rounds 7.5 to 8. This is an IEEE standard method for rounding numbers. See the IEEE Standard 754 for details.


Program Design

Now that you are familiar with many aspects of G programming, you need to apply that knowledge to develop your own applications. This topic suggests some techniques to use when creating programs and offers programming style recommendations.

Use Top-Down Design

Plan Ahead with Connector Panes

Good Diagram Style


Use Top-Down Design

When you have a large project to manage, incorporate top-down design. G has an advantage over other programming languages with respect to top-down design because you can start with the final user interface and then animate it.

Make a List of User Requirements

Design the VI Hierarchy

Create the Program

Return to Program Design


Make a List of User Requirements

Create a list of the panels with which the user can interact, the number and type of controls and indicators for these panels, the need for real-time analysis, data presentation, and so on. Next, create some mock-up front panels you can show to the prospective users (or manipulate yourself, if you are the user). Think about and discuss functions and features. Use this interactive process to redesign the user interface, as necessary. You might need to do some low-level research at this early stage to be sure you can meet specifications.


Design the VI Hierarchy

The power of G lies in the hierarchical nature of VIs. After you create a VI, you can use it as a subVI in the block diagram of a higher level VI. You can have an essentially unlimited number of layers in the hierarchy.

Divide the task to be accomplished into manageable, logical pieces. As the following flowchart illustrates, you can expect several major blocks one form or another on every data acquisition system.

In some cases, you might not need all of these blocks or you might need different blocks. For example, some applications do not include any file I/O operations. Alternatively, you might need additional blocks, such as blocks representing user prompts. The main objective is to divide your programming task into high-level blocks that you can manage easily.

After you determine the high-level blocks you need, try to create a block diagram that uses those high-level blocks. For each block, create a new stub VI (a nonfunctional prototype representing a future subVI). For this stub VI, create an icon and as well as a front panel that contains the necessary inputs and outputs. You do not have to create a block diagram for this VI yet. Instead, see if this stub VI is a necessary part of your top-level block diagram.

After you assemble a group of these stub VIs, try to understand, in general terms, the function of each block and how each block provides the desired results. Ask yourself whether any given block generates information that a subsequent VI needs. If so, make sure that your top-level block diagram contains wires to pass the data between VIs.

Try to avoid using unnecessary global variables because they hide the data dependency between VIs. Use memory tags only when you need this information in the engine for historical logging or alarms. As your system gets larger, it becomes difficult to debug if you depend upon global variables as your method for transferring information between VIs.


Write the Program
Create the Program

Now you are ready to create the program in G.

•	Use a modular approach by building subVIs where you find a logical division of labor or the potential for code reuse.

•	Solve the more general problems along with your specific ones.

•	Test your subVIs as you write them. You might need to construct higher-level test routines, but you can catch the bugs in one small module than in a hierarchy of several VIs.

As you consider the details of your subVIs, you might find that your initial design is incomplete. For example, you might realize you need to transfer more information from one subVI to another. You might have to reevaluate your top-level design at this point. Using modular subVIs to accomplish specific tasks makes it easier to manage your program reorganizations.


Plan Ahead with Connector Panes

If you think that you might need to add additional inputs or outputs later on, select a connector-pane pattern with extra terminals. You can leave these extra terminals unconnected. With these extra terminals, you do not have to change the connector pane for your VI if you find you need another input or output later. This flexibility enables you to make these changes with minimal effect on your hierarchy.

When linking controls and indicators to the connector, place inputs on the left and outputs on the right. This prevents complicated, unclear wiring patterns in your VIs.

If you create a group of subVIs that are used together often, try to give the subVIs a consistent connector pane, with common inputs in the same location. You then can remember where to locate each input more easily without using the Help window. If you create a subVI that produces an output that is used as the input to another subVI, try to align the input and output connections. This technique simplifies your wiring patterns.

SubVIs with Required Inputs

Return to Program Design


SubVIs with Required Inputs

On the front panel, you can edit required inputs for subVIs by clicking on the icon pane, on the upper-right side of the window and choosing Show Connector»This Connection Is. From the submenu, choose between the Required, Recommended, or Optional options. The following illustration displays the submenu options.

If you want to return to the icon pane in the front panel, pop up on the connector pane and select Show Icon.


Good Diagram Style

In general, avoid creating a block diagram that uses more than one or two screens of space. If a diagram becomes very large, decide whether you can reuse some components of your diagram in other VIs, or whether a section of your diagram fits together as a logical component. If so, consider dividing your diagram into subVIs.

With forethought and careful planning, it is much easier to design diagrams that use subVIs to perform specific tasks. Using subVIs helps you manage changes and debug your diagrams quickly. You can determine the function of a well-structured program after only a brief examination.

Watch for Common Operations

Use Left-to-Right Layouts

Check for Errors

Watch Out for Missing Dependencies

Avoid Overuse of Sequence Structures

Study the Examples

Return to Program Design


Watch for Common Operations

As you design your programs, you might find that you perform a certain operation frequently. Depending on the situation, consider using subVIs or loops to perform an action repetitively.

For example, consider the following diagram, in which three similar operations run independently.

An alternative to this design is a loop, which performs the operation three times. You can build an array of the different arguments and use auto-indexing to set the correct value for each iteration of the loop.

If the array elements are constant, you can use an array constant instead of building the array on the block diagram.


Use Left-to-Right Layouts

G is designed to use a left-to-right (and sometimes top-to-bottom) layout. Organize all elements of your program in this layout when possible.


Check for Errors

When you perform any kind of I/O, you should consider the possibility of errors occurring. Almost all I/O functions return error information. If you use direct I/O, make sure that your program checks for errors and you handle them appropriately.

LabVIEW does not handle errors automatically because users usually want very specific error-handling methods. For example, in an I/O VI in your block diagram times out, you might or might not want your entire program to stop. You also might want the VI to retry for a certain period of time. In LabVIEW, you can make these error-handling decisions in the block diagram of your VI.

The following list describes situations in which errors frequently occur:

•	Incorrect initialization of communication or data that has been written to an external device improperly

•	Loss of power in an external device, or a broken or improperly working external device

•	Change in functionality of an application or library when upgrading operating system software

When an error occurs, you might not want certain subsequent operations to occur. For instance, if an analog output operation fails because you specify the wrong device, you might not want a subsequent analog input operation to take place.

One method for managing such a problem is to test for errors after every function, and put subsequent functions inside Case structures. However, this method can complicate your diagrams and ultimately hide the purpose of your application.

An alternative approach, which has been used successfully in a number of applications and many of the VI libraries, is to incorporate error handling in the subVIs that perform I/O. Each VI can have an error input and an error output. You can design the VI to check the error input to see if an error has occurred previously. If an error exists, you can configure the VI to do nothing and pass the error input to the error output. If there is no error, the VI can execute the operation and pass the result to the error output.

Note	In some cases, such as a Close operation, you might want the VI to perform the operation regardless of the error that is passed into it.

Using the preceding technique, you can wire several VIs together, connecting error inputs and outputs to propagate errors from one VI to the next. At the end of the series of VIs, you can use the Simple Error Handler VI to display a dialog box if an error occurs. The Simple Error Handler VI is located in Functions»Time & Dialog. In addition to encapsulating error handling, you can use this technique to determine the order of several I/O operations.

One of the main advantages in using the error input and output clusters is that you can use them to control the execution order of dissimilar operations.

The error information generally is represented using a cluster containing a numeric error code, a string containing the name of the function that generated the error, and an error Boolean for quick testing. The following illustration shows how you can use this technique in your own applications. Notice that the While Loop stops if it detects an error.


Watch Out for Missing Dependencies

Make sure that you have explicitly defined the sequence of events when necessary. Do not assume left-to-right or top-to-bottom execution when no data dependency exists.

In the following example, no dependency exists between the Read File VI and the Close File VI. This program might not work as expected.

The following version of the block diagram establishes a dependency by wiring an output of the Read File VI to the Close File VI. The operation cannot end until the Close File VI receives the output of the Read File VI.

Notice that the preceding example still does not check for errors. For instance, if the file does not exist, the program does not display a warning. The following version of the block diagram illustrates one technique for handling this problem. In this example, the block diagram uses the error I/O inputs and outputs of these functions to propagate any errors to the Simple Error Handler VI.


Avoid Overuse of Sequence Structures

Because VIs can operate with a great deal of inherent parallelism, avoid using Sequence structures. Using a Sequence structure guarantees the order of execution but prohibits parallel operations. For instance, asynchronous tasks that use I/O devices (GPIB, serial ports, and data acquisition boards) can run concurrently with other operations if Sequence structures do not prevent them from doing so.

Sequence structures tend to hide parts of the program and interrupt the natural left-to-right flow of data. You do not sacrifice performance by using Sequence structures. However, when you need to sequence operations, you might consider using data flow instead. For instance, in I/O operations you might use the error I/O technique described previously to ensure that one I/O operation occurs before another.


Study the Examples

For further information on program design, you can examine the many example block diagrams included in LabVIEW. These sample programs can provide you with insights into G programming style and technique. To view these block diagrams, open any of the VIs in the Examples directory.


Activity 22. Concatenate a String

LabVIEW has many functions to manipulate strings. For this activity, your objective is to use some of the string functions to convert a number to a string and concatenate that string with other strings to form a single output string.

1.	Open a new front panel and add the objects shown in the following illustration. Be sure to modify the controls and indicators as shown.

Front Panel

The two string controls and the digital control can be combined into a single output string and displayed in the string indicator. The digital indicator displays the string length.

The Combined String output in this activity has a similar format to command strings used to communicate with GPIB (IEEE 488) and serial (RS-232 or RS-422) instruments. Refer to the Instrument I/O topic to learn more about strings used for instrument commands.

Block Diagram

2.	Build the block diagram shown in the following illustration.

 Format Into String function (Functions»String) concatenates and formats numbers and strings into a single output string. Use the Resizing cursor on the icon to add three argument inputs.

 String Length function (Functions»String) returns the number of characters in the concatenated string.

3.	Run the VI. Notice that the Format Into String function concatenates the two string controls and the digital control into a single output string.

4.	Save the VI as Build String.vi in the LabVIEW/Activity directory. You will use this VI in the next exercise.

End of Activity 22. Concatenate a String


Activity 23. Use Format Strings

Your objective is to create a string according to the format you specify.

You will use the Build String VI that you created in the previous activity to create a format string. With format strings, you can specify the format of arguments, including the field width, base (hex, octal, and so on), and any text that separates the arguments.

Front Panel

1.	Open the Build String VI, as saved in Activity 22. Concatenate a String, from the LabVIEW\Activity directory.

Block Diagram

2.	Switch to the block diagram. Pop up on the Format Into String VI and select Edit Format String.

The following dialog box appears.

Note	You can also double click on the node to access the Edit Format String dialog box.

Notice that the Current Format Sequence contains the argument types, in the order that you wired them.

3.	Set the precision of the numeric to 4.

a.	Highlight Format fractional number in the Current Format Sequence list box.

b.	Click in the Use Specified Precision checkbox.

c.	Highlight the numeric beside the Use Specified Precision checkbox, type in 4, and press <Enter> (Windows); <return> (Macintosh); <Return> (Sun); or <Enter> (HP-UX). The following illustration shows the selected options to set the precision of number.

4.	Press the Create String button. Pressing this button automatically inserts the correct format string information and wires format string to the function, as shown in the following illustration.

5.	Return to the front panel and type text inside the two string controls and a number inside the digital control. Run the VI.

6.	Save the VI as Format String.vi and save it in the LabVIEW\Activity directory

End of Activity 23. Use Format Strings


Activity 24. String Subsets and Number Extraction

Your objective is to take a subset of a string that contains the string representation of a number and convert it to a numeric value.

Front Panel

1.	Open the Parse String.vi from Examples\General\strings.llb. Run the VI with the default inputs. Notice that the string subset of DC is chosen for the input string. Also, notice that the numeric part of the string was parsed out and converted to a number. You can try different control values (remember that strings, like arrays, are indexed starting with zero), or you can show the block diagram to see how to parse the components out of the input string.

Block Diagram

2.	Open the block diagram of the Parse String VI, shown in the following illustration.

LabVIEW uses the String Subset and Scan From String functions to parse the input string.

 String Subset function (Functions»String) returns the substring beginning at Subset Offset and contains the number of characters specified in Subset Length. The first character offset is zero.

In many instances, you must convert strings to numbers, such as when you convert a data string received from an instrument into the data values.

 Scan From String function (Functions»String) scans a string and converts valid numeric characters (0 to 9, +, –, e, E, and period) to numbers. If you wire a format string, Scan From String makes conversions according to the format. If you do not wire a format string, Scan From String makes default conversions for each default input terminal in the function. This function starts scanning the Input String at Number Offset. The first character offset is zero.

The Scan From String function is useful when you know the header length (VOLTS DC in the example here), or when the string contains only valid numeric characters.

3.	Close the VI by selecting File»Close. Do not save the VI.

End of Activity 24. String Subsets and Number Extraction


Activity 25. Write to a Spreadsheet File

Your objective is to modify an existing VI to use a file I/O function so that you can save data to a new file in ASCII format. Later you can access this file from a spreadsheet application.

Front Panel

1.	Open Graph Waveform Arrays.vi, which you built in Activity 18. Create an Array with Auto-Indexing, from the LabVIEW\Activity directory. As you recall, this VI generates two data arrays and plots them on a graph. You modify this VI to write the two arrays to a file where each column contains a data array.

Block Diagram

2.	Open the block diagram of Graph Waveform Arrays.vi and modify the VI by adding the block diagram functions that have been added to the lower right of the following illustration.

 Write To Spreadsheet File VI (Functions»File I/O) converts the 2D array to a spreadsheet string and writes it to a file. If you have not specified a path name, then a file dialog box pops up and prompts you for a file name. The Write To Spreadsheet File VI writes either a 1D or 2D array to file. Because you have a 2D array of data in this example, you do not have to wire to the 1D input. With this VI, you can use a spreadsheet delimiter or string of delimiters, such as tabs or commas in your data.

 Boolean Constant (Functions»Boolean) controls whether or not G transposes the 2D array before writing it to file. To change the value to TRUE, click on the constant with the Operating tool. In this case, you want the data transposed because the data arrays are row specific (each row of the two-dimensional array is a data array). Because each column of the spreadsheet file contains a data array, the 2D array must first be transposed.

3.	Return to the front panel and run the VI. After the data arrays have been generated, a file dialog box prompts you for the file name of the new file you are creating. Type in a file name and click OK.

Caution	Do not attempt to write data in VI libraries, such as the mywork.llb. Doing so may result in overwriting your library and losing your previous work.

4.	Save the VI, name it Waveform Arrays to File.vi, and close the VI.

5.	You now can use spreadsheet software or a text editor to open and view the file you just created. You should see two columns of 100 elements.

In this example, the data was not converted or written to file until the entire data arrays had been collected. If you are acquiring large buffers of data or would like to write the data values to disk as they are being generated, then you must use a different File I/O VI.

End of Activity 25. Write to a Spreadsheet File


Activity 26. Append Data to a File

Your objective is to create a VI to append temperature data to a file in ASCII format. This VI uses a For Loop to generate temperature values and store them in a file. During each iteration, you will convert the data to a string, add a comma as a delimiting character, and append the string to a file.

Front Panel

1.	Open a new front panel and place the objects as shown in the following illustration.

The front panel contains a digital control and a waveform chart. Select Show»Digital Display. The Number of points control specifies how many temperature values to acquire and write to file. The chart displays the temperature curve. Rescale the Y axis of the chart for the range 70.0 to 90.0, and rescale the X axis for the range 0 to 20.

2.	Pop up on the Number of points digital control and choose Representation»I32.

Block Diagram

3.	Open the block diagram.

4.	Add a For Loop and enlarge it. This VI generates the number of temperature values specified by the Number of points control.

5.	Add a Shift Register to the loop by popping up on the loop border. This shift register contains the path name to the file.

6.	Finish wiring the objects.

 Empty Path constant (Functions»File I\O»File Constants). The Empty Path constant initializes the shift register so that the first time you try to write a value to file, the path is empty. A file dialog box prompts you to enter a file name.

 Digital Thermometer VI returns a simulated temperature measurement from a temperature sensor.

 Format Into String function (Functions»String) converts the temperature measurement (a number) to a string and concatenates the comma that follows it.

 String constant (Functions»String). This format string specifies that you want to convert a number to a fractional format string and follow the string with a comma.

 Write Characters To File VI (Functions»File I/O) writes a string of characters to a file.

 Boolean Constant (Functions»Boolean) sets the append to file? input of the Write Characters To File VI to TRUE so that the new temperature values are appended to the selected file as the loop iterates. Click the Operating tool on the constant to set its value to TRUE.

7.	Return to the front panel and run the VI with the Number of points set to 20. A file dialog box prompts you for a file name. When you enter a file name, the VI starts writing the temperature values to that file as each point is generated.

8.	Save the VI as Write Temperature to File.vi in the LabVIEW\Activity directory.

9.	Use any word processing software such as Write for Windows, Teach Text for Macintosh, or a text editor in UNIX to open that data file and view the contents. You should get a file containing 20 data values (with a precision of three places after the decimal point) separated by commas.

End of Activity 26. Append Data to a File


Activity 27. Read Data from a File

Your objective is to create a VI that reads the data file you wrote in the previous example and displays the data on a waveform graph. You must read the data in the same data format in which you saved it. Therefore, because you originally saved the data in ASCII format using string data types, you must read it in as string data with one of the file I/O VIs.

Front Panel

1.	Open a new front panel and build the front panel shown in the following illustration.

The front panel contains a string indicator and a waveform graph. The String Read from File indicator displays the comma delimited temperature data from the file you wrote in the previous activity. The graph displays the temperature curve.

Block Diagram

2.	Build the block diagram as shown in the following illustration.

 Read Characters From File VI (Functions»File I/O) reads the data from the file and outputs the information in a string. If no path name is specified, a file dialog box prompts you to enter a file name. In this example, you do not need to determine the number of characters to read because there are fewer characters in the file than the default of 512.

You must know how the data was stored in a file in order to read the data back out. If you know how long a file is, you can use the Read Characters From File VI to determine the known number of characters to read.

 Extract Numbers VI (Examples\General\strings.llb) takes an ASCII string containing numbers separated by commas, line feeds, or other non-numeric characters and converts it to an array of numerics.

3.	Return to the front panel and run the VI. Select the data file you just wrote to disk when the file dialog box prompts you. You should see the same data values displayed in the graph as you saw in the Write Temperature to File VI example.

4.	Save the VI, name it Temperature from File.vi, and close the VI.

End of Activity 27. Read Data from a File


Strings and File I/O

This topic introduces string controls and indicators and file input and output operations and provides activities that illustrate how to accomplish the following:

•	Create string controls and indicators

•	Use string functions

•	Perform file input and output operations

•	Save data to files in spreadsheet format

•	Write data to and read data from text files

Strings

File I/O

Activity 22. Concatenate a String

Activity 23. Use Format Strings

Activity 24. String Subsets and Number Extraction

Activity 25. Write to a Spreadsheet File

Activity 26. Append Data to a File

Activity 27. Read Data from a File

For more information about these topics, see the following topic(s) in the G Language Help File:

String Controls and Indicators

File I/O Function Overview


Strings

A string is a collection of ASCII characters. In instrument control, you can pass numeric data as character strings and then convert these strings to numbers. Storing numeric data to disk can also involve strings. To store numbers in an ASCII file, you must first convert numbers to strings before writing the numbers to a disk file.

For examples of strings, see Examples\General\strings.llb.

Creating String Controls and Indicators

Activity 22. Concatenate a String

Activity 23. Use Format Strings

Activity 24. String Subsets and Number Extraction

Return to Strings and File I/O


Creating String Controls and Indicators

  You can find the string control and indicator, shown at left, in Controls»String & Table. You can enter or change text inside a string control using the Operating tool or Labeling tool. Enlarge string controls and indicators by dragging a corner with the Positioning tool.

If you want to minimize space that a front panel string control or indicator occupies, select Show»Scrollbar. If this option is dimmed, you must increase the vertical size of the window to make it available.

For more information, see String Controls and Indicators in the G Language Help File.


File I/O

The G file I/O functions (Functions»File I/O) are a powerful and flexible set of tools for working with files. In addition to reading and writing data, the LabVIEW file I/O functions move and rename files and directories, create spreadsheet-type files of readable ASCII text, and write data in binary form for speed and compactness.

You can store or retrieve data from files in three different formats.

•	ASCII Byte Stream —You should store data in ASCII format when you want to access it from another software package, such as a word processing or spreadsheet program. To store data in this manner, you must convert all data to ASCII strings.

•	Datalog files —These files are in binary format that only G can access. Datalog files are similar to database files because you can store several different data types into one (log) record of a file.

•	Binary Byte Stream —These files are the most compact and fastest method of storing data. You must convert the data to binary string format and you must know exactly what data types you are using to save and retrieve the data to and from files.

This section discusses ASCII byte stream files because that is the most common data file format. For examples of file I/O, see Examples\File.

File I/O Functions

Using the File I/O Functions

Specifying a File

Paths and Refnums

File I/O Examples

Writing to a Spreadsheet File

Datalog Files

Activity 25. Write to a Spreadsheet File

Activity 26. Append Data to a File

Activity 27. Read Data from a File

Return to Strings and File I/O


File I/O Functions

Most file I/O operations involve three basic steps: opening an existing file or creating a new file; writing to or reading from the file; and closing the file. Therefore, LabVIEW contains many utility VIs in Functions»File I/O. This section describes the nine, high-level utilities. These utility functions are built upon intermediate-level VIs that incorporate error checking and handling with the file I/O functions.

 The Write Characters To File VI writes a character string to a new byte stream file or appends the string to an existing file. This VI opens or creates the file, writes the data, and then closes the file.

 The Read Characters From File VI reads a specified number of characters from a byte stream file beginning at a specified character offset. This VI opens the file beforehand and closes it afterwards.

 The Read Lines From File VI reads a specified number of lines from a byte stream file beginning at a specified character offset. This VI opens the file beforehand and closes it afterwards.

 The Write To Spreadsheet File VI converts a 1D or 2D array of single-precision numbers to a text string and writes the string to a new byte stream file or appends the string to an existing file. You can optionally transpose the data. This VI opens or creates the file beforehand and closes it afterwards. You can use this VI to create text files readable by most spreadsheet programs.

 The Read From Spreadsheet File VI reads a specified number of lines or rows from a numeric text file, beginning at a specified character offset, and converts the data to a 2D, single-precision array of numbers. You can optionally transpose the array. This VI opens the file beforehand and closes it afterwards. You can use this VI to read spreadsheet files saved in text format.

For additional File I/O functions, select Function»File I/O»Binary File VIs or Function»File I/O»Advanced File Functions.

Activity 25. Write to a Spreadsheet File

Activity 26. Append Data to a File

Activity 27. Read Data from a File


Writing to a Spreadsheet File

One very common application for saving data to a file is to format the text file so that you can open it in a spreadsheet. In most spreadsheets, tabs separate columns and EOL (End of Line) characters separate rows, as shown in the following figure.

Opening the file using a spreadsheet program yields the following table.

Activity 25. Write to a Spreadsheet File


Using the File I/O Functions

Sometimes the high-level file I/O functions do not provide the functionality you might need for saving data to disk. At this point, you must use the functions from Functions»File I/O»Advanced.

Specifying a File

Paths and Refnums

File I/O Examples


Specifying a File

There are two ways to specify a file — programmatically or through a dialog box. In the programmatic method, you supply the filename and the pathname for the VI.

(Windows) A pathname consists of the drive name (for example, C), followed by a colon, followed by backslash-separated directory names, followed by the filename. An example is C:\DATADIR\TEST1 for a file named TEST1 in the directory DATADIR on the C drive.

(Macintosh) A pathname consists of the drive name, followed by a colon, followed by colon-separated folder names, followed by the filename. An example is HardDrive:DataFolder:Test1 for a file named Test1 in the folder DataFolder on the volume named HardDrive.

(UNIX) A pathname consists of slash-separated directory names followed by the filename. An example is /usr/datadirectory/test1 for a file named test1 in the directory /usr/datadirectory.

(All Platforms) Using the dialog box method, the File Dialog function displays a dialog box that you can use to interactively search for a directory and then type in a filename.


Paths and Refnums

  A path is a G data type that identifies files. You can enter or display a file path using the standard syntax for a given platform with the path control and path indicator. In many ways, the path control and indicator works like a string control or indicator, except that G formats the path appropriately for any platform supported by G.

  A refnum consists of a G data type that identifies open files. When you open a file, G returns a refnum associated with the file. All operations performed on open files use the file refnums to identify each file. A refnum is only valid for the period during which the file is open. If you close the file, G disassociates the refnum with the file. If you subsequently open the file, the new refnum may be different from the refnum that G used previously.

In addition to associating an operation with a file, G remembers information for each refnum, such as the current location for reading from the file and the degree of access to the file that other users are permitted, so that you can have concurrent but independent operations on a single file. If you open a file multiple times, each open file operation returns a different refnum.


File I/O Examples

You can use the following examples to see how to use the File I/O functions complete with proper error checking and handling techniques:

The Write to Text File VI (in Examples\File\smplfile.llb) writes an ASCII text file that contains data values with time-stamps.

The Read from Text File VI (in Examples\File\smplfile.llb) reads an ASCII text file that contains data values with time-stamps.


Datalog Files

The examples shown in this topic illustrate simple methods for dealing with files that contain data stored as a sequence of ASCII characters. This approach is common when creating files that other software packages read, such as a spreadsheet program. G has another file format, called a datalog file. A datalog file stores data as a sequence of records of a single, arbitrary data type, which you determine when you create the file. G indexes data in a datalog file in terms of these records. While all the records in a datalog file must be of a single type, that type can be complex. For instance, you can set each record so that the record contains a cluster with a string, a number, and an array.

If you are going to retrieve the data with a VI, you may not want to write data to ASCII files, because converting data to and from strings can be time consuming. For instance, converting a two-dimensional array to a string in a spreadsheet format with headers and time-stamps is a complicated operation. If you do not need to have the data stored in a format that other applications can read, you may want to write data out as a datalog file. In this form, writing data to a file requires little manipulation, making writing and reading much faster. It also simplifies data retrieval, because you can read the original blocks of data back as a log or record without having to know how many bytes of data the records contain. G records the amount of data for each record of a datalog file.

The Write Datalog File Example (in Examples\File\datalog.llb) creates a new datalog file and writes the specified number of records to the file. Each record is a cluster containing a string and an array of single precision numbers.

To read a datalog file, you must match the data type that was used to write to the file. The Read Datalog File Example (in Examples\File\datalog.llb) reads a datalog file created by the Write Datalog File Example one record at a time. The record read consists of a cluster containing a string and an array of single precision numbers.


Where to Go from Here

We hope you have completed the activities and they have prepared you to create LabVIEW applications. Before you start your own applications, you might want to examine the following additional resources available to you.

Other Useful Resources

Resources for Advanced Topics


Other Useful Resources

The following sections overview resources you can use to create your applications successfully.

Examples and Solutions for Your LabVIEW Programs

Data Acquisition Applications

G Programming Techniques

Function and VI Reference


Examples and Solutions for Your LabVIEW Programs

(Windows, Macintosh) If you are using data acquisition (DAQ) or instrument I/O and want to find examples or generate solutions for your LabVIEW programs, launch the DAQ Solution Wizard by clicking Solution Wizard in the LabVIEW dialog box. For more information about the Solution Wizard, see Chapter 3, Data Acquisition, and Chapter 4, Instrumentation, of the LabVIEW QuickStart Guide.

(Windows) To find any other type of example, open the Search Examples Help File by clicking Search Examples in the LabVIEW dialog box.

(Macintosh and UNIX) The examples directory contains a VI named readme.vi. With this VI, you can find the available examples. When you select a VI, you can see the documentation that was entered for that VI by choosing Window»Show VI Info…. To open a VI, choose File»Open.


Data Acquisition Applications

(Windows, Macintosh) The Data Acquisition VIs section of this help file provides information about starting data acquisition applications that use analog input, analog output, digital I/O, and counter/timers. This section also explains the basic concepts behind data acquisition and the VIs used to implement those concepts.


G Programming Techniques

To learn more about the capabilities of G, refer to G Programming Language, which provides further information about execution and debugging, VI setup, front panel objects, wiring, structures, and attribute nodes. It also provides information about printing, customizing the G environment using Preferences, custom controls, multithreading, and performance issues.


Function and VI Reference

For an overview of the functions and VIs available in LabVIEW, refer to the G Function and VI Reference, which provides brief descriptions of the functions and VIs, organized in the same order in which they appear in the Functions palette.


Resources for Advanced Topics

The LabVIEW Online Reference teaches you the fundamentals of building a LabVIEW application. LabVIEW contains several advanced features that are either not discussed or only discussed in a limited fashion in this help file. The following sections overview these features and provide additional resources so you can apply them as necessary in your applications.

Attribute Nodes

VI Setup and Preferences

Local and Global Variables

Creating SubVIs

VI Profiles

Control Editor

List and Ring Controls

Call Library Function

Code Interface Nodes


Attribute Nodes

Front Panel Object Attributes briefly describes attribute nodes. Using attribute nodes, you can manage settings related to controls and indicators programmatically. For example, you can change the visibility of controls. Use an attribute node if you need to change the options in a ring or list control, clear the contents of a chart, or change the scales on a chart or graph programmatically. The Attribute Nodes topic in the G Programming Language section of this help file describes attribute nodes in detail.


VI Setup and Preferences

You can programmatically control various attributes of VIs as well as attributes of LabVIEW using the VI Server feature. You can load VIs into memory, run VIs, change the appearance of VIs, and change the execution behavior of a VI. Some of the options that you can set interactively in Preferences and VI Setup… you also can set programmatically. The options available in Preferences are considered application settings because they affect all VIs shown in LabVIEW. The VI Setup… options are VI settings because they only affect one VI and all instances in which you use the VI as a subVI.

In addition to changing attributes, which are called properties, you can perform an action on LabVIEW or an individual VI. For example, you can set an action, also called a method, to save a VI. You can set properties and methods for LabVIEW and VIs on the local machine, across a TCP/IP network, or through another ActiveX application. For more information about ActiveX capabilities, refer to the ActiveX Overview topic. For more information about TCP/IP settings and how to use this feature, refer to the Customizing Your G Environment and VI Servertopics.


Local and Global Variables

Use local variables to read from controls in multiple locations of the block diagram. Also use local variables when you need to treat a front panel object as a control in some locations and an indicator in other locations. Use local variables sparingly because they hide the data flow of your diagrams, which makes it difficult to see the purpose of your program and to debug local variables. See the Global and Local Variables topic for a discussion of local variables.

Global variables store data used by several VIs. Use global variables judiciously because they hide the data flow of your diagram. Although you need global variables in some applications, do not use them if you can structure your program using an alternate data flow method for transferring data. See the Global and Local Variables topic for details.


Creating SubVIs

You can create subVIs from a selection on the block diagram by choosing Edit»Create SubVI from Selection. In addition, LabVIEW automatically wires the correct inputs and outputs to the subVI. In some instances, you cannot create a subVI from a VI. See the Using SubVIs topic for details.


VI Profiles

You can use the VI profile feature (Project»Show Profile Window) to access detailed information about a timing statistics and timing details of a VI. This feature helps you optimize the performance of your VIs. See the Performance Issues topic for details about the profile feature.


Control Editor

Use the Control Editor to customize the look of your front panel controls. You also can use the editor to save customized controls so you can reuse them in other applications. See the Custom Controls and Type Definitions topic for a detailed discussion of the Control Editor.


List and Ring Controls

Use list and ring controls when you need to present the user with a list of options. See the List and Ring Controls and Indicators topic for a detailed discussion of these front panel objects.


Call Library Function

LabVIEW provides a Call Library function you can use to call a shared library or DLL. With this function, you can create an interface in LabVIEW to call an existing code or driver. See the Calling Code from Other Languages topic for a discussion of the Call Library functions.


Code Interface Nodes

You can use code interface nodes (CINs) as an alternative method for calling source code written in a conventional, text-based programming language from LabVIEW block diagrams. Use CINs for tasks that conventional programming languages can perform more quickly than LabVIEW, for tasks that you cannot perform directly from the block diagram, and for linking existing code to LabVIEW. However, the Call Library function generally is easier to use when calling source code than CINs. Use CINs when you need tighter integration with LabVIEW and the source code. See the LabVIEW Code Interface Reference Manual, available in Portable Document Format (PDF) only, and the Calling Code from Other Languages topic for further information about CINs.


Activity 28. Learn More about Normalized Frequency

Your objective is to learn more about normalized frequency by adjusting the frequency, sampling rate, and number of samples and observing the effects on a sine wave.

Front Panel

1. 	Open a new front panel and create the objects as shown in the following illustration.

Block Diagram

2. 	Build the block diagram shown in the following illustration.

 Sine Wave VI (Analysis»Signal Generation palette).

3.	Save the VI as Normalized Frequency.vi in the LabVIEW\Activity directory.

4.	Select a frequency of 2 cycles (frequency = 2 and f type = cycles) and number of samples = 100. Run the VI. Note that the plot will show 2 cycles.

5.	Increase the number of samples to 150, 200, and 250. How many cycles do you see?

6.	Now keep the number of samples = 100. Increase the number of cycles to 3, 4, and 5. How many cycles do you see?

Thus, when you choose the frequency in terms of cycles, you will see that many cycles of the input waveform on the plot. Note that the sampling rate is irrelevant in this case.

7.	Change f type to Hz and sampling rate (Hz) to 1,000.

8.	Keeping the number of samples fixed at 100, change the frequency to 10, 20, 30, and 40. How many cycles of the waveform do you see on the plot for each case? Explain your observations.

9.	Repeat the above step by keeping the frequency fixed at 10 and change the number of samples to 100, 200, 300, and 400. How many cycles of the waveform do you see on the plot for each case? Explain your observations.

10.	Keep the frequency fixed at 20 and the number of samples fixed at 200. Change the sampling rate (Hz) to 500, 1,000, and 2,000. Make sure you understand the results.

End of Activity 28. Learn More about Normalized Frequency


Activity 29. Use the Sine Wave and Sine Pattern VIs

Your objective is to generate a sinusoidal waveform using both the Sine Wave VI and the Sine Pattern VI and to understand the differences.

Front Panel

1. 	Open a new front panel and create the objects as shown in the following illustration.

Block Diagram

2. 	Build the block diagram shown in the following illustration.

 Sine Pattern VI (Analysis»Signal Generation palette).

 Sine Wave VI (Analysis»Signal Generation palette).

3.	Save the VI as Wave and Pattern.vi in the LabVIEW\Activity directory.

4.	Set the controls to the following values:

cycles/freq:	2.00

sampling freq:	100

phase in:	0.00

reset phase:	OFF

Run the VI several times.

Observe that the Sine Wave plot changes each time you run the VI. Because reset phase is set to OFF, the phase of the sine wave changes with each call to the VI, being equal to the value of phase out during the previous call. However, the Sine Pattern plot always remains the same, showing 2 cycles of the sinusoidal waveform. The initial phase of the Sine Pattern plot is equal to the value set in the phase in control.

Note	Phase in and phase out are specified in degrees.

5.	Change phase in to 90 and run the VI several times. Just as before, the Sine Wave plot changes each time you run the VI. However, the Sine Pattern plot does not change, but the initial phase of the sinusoidal pattern is 90 degrees — the same as that specified in the phase in control.

6.	With phase in still at 90, set reset phase to ON and run the VI several times. The sinusoidal waveforms shown in both the Sine Wave and Sine Pattern plots start at 90 degrees, but do not change with successive calls to the VI.

7.	Keeping reset phase as ON, run the VI several times for each of the following values of phase in: 45, 180, 270, and 360. Note the initial phase of the generated waveform each time that the VI is run.

End of Activity 29. Use the Sine Wave and Sine Pattern VIs


Activity 30. Build a Function Generator

Your objective is to build a simple function generator that can generate the following waveforms.

•	Square Wave

•	Triangle Wave

•	Sawtooth Wave

Front Panel

1. 	Open a new front panel and create the objects as shown in the following illustration.

The Signal Source control selects the type of waveform that you want to generate.

The square duty cycle control is used only for setting the duty cycle of the square wave.

The samples control determines the number of samples in the plot.

Notice that these are all wave VIs, and therefore they require the frequency input to be the normalized frequency. So, you divide frequency by the sample rate and the result is the normalized frequency wired to the f input of the VIs.

Block Diagram

2. 	Build the block diagram shown in the following illustration.

 Sine Wave VI (Analysis»Signal Generation palette) generates a sine wave of normalized frequency f.

 Triangle Wave VI (Analysis»Signal Generation palette) generates a triangular wave of normalized frequency f.

 Square Wave VI (Analysis»Signal Generation palette) generates a square wave of normalized frequency f with specified duty cycle.

 Sawtooth Wave VI (Analysis»Signal Generation palette) generates a sawtooth wave of normalized frequency f.

3.	Save the VI as Function Generator.vi in the LabVIEW\Activity directory.

4.	Select a sampling rate of 1000 Hz, amplitude = 1, samples = 100, frequency = 10, reset phase = ON, and signal source = sine wave. Because sampling rate = 1000 and frequency = 10 Hz, every 100 samples corresponds to one cycle.

5.	Run the VI and observe the resulting plot.

6.	Change samples to 200, 300, and 400. How many cycles of the waveform do you see? Explain why.

7.	With samples set to 100, change reset phase to OFF. Do you notice any difference in the plot?

8.	Change frequency to 10.01 Hz. What happens? Why?

9.	Change reset phase to ON. Now what happens? Explain why.

10.	Repeat Steps 4 through 9 for different waveforms selected in the signal source control.

End of Activity 30. Build a Function Generator


Activity 31. Use the Real FFT VI

In this activity, your objective is to display the two-sided and the one-sided Fourier transform of a signal using the Real FFT VI, and to observe the effect of aliasing in the frequency spectrum.

Front Panel

1.	Build the front panel shown in the following illustration.

Block Diagram

2.	Build the block diagram shown in the following illustration.

Array Size function (Functions»Array palette) scales the output of the FFT by the # of samples so as to obtain the correct amplitude of the frequency components.

 Sine Wave function (Functions»Analysis»Signal Generation palette) generates a time domain sinusoidal waveform.

 Real FFT function (Functions»Analysis»Digital Signal Processing palette) computes the FFT of the input data samples.

 Complex to Polar function (Functions»Numeric»Complex palette) separates the complex output of the FFT into its real and imaginary (magnitude and phase) parts. The phase information is in units of radians. Here you are displaying only the magnitude of the FFT.

The frequency spacing, Δf, is given by dividing the sampling freq by the # of samples.

3.	Save this VI as FFT_2sided.vi in the LabVIEW\Activity directory.

4.	Select frequency (Hz) = 10, sampling freq = 100, and # of samples = 100. Run the VI.

Notice the plots of the time waveform and the frequency spectrum. Because sampling freq = # of samples = 100, you are in effect sampling for 1 second. Thus, the number of cycles of the sine wave you see in the time waveform is equal to the frequency (Hz) you select. In this case, you will see 10 cycles. (If you change the frequency (Hz) to 5, you will see five cycles).

Two-Sided FFT

5.	Examine the frequency spectrum (the Fourier transform). You will notice two peaks, one at 10 Hz and the other at 90 Hz. The peak at 90 Hz is actually the negative frequency of 10 Hz. The plot you see is known as the 2-sided FFT because it shows both the positive and the negative frequencies.

6.	Run the VI with frequency (Hz) = 10 and then with frequency (Hz) = 20. For each case, note the shift in both peaks of the spectrum.

Note	Also observe the time domain plot for frequency (Hz) = 10 and 20. Which one gives a better representation of the sine wave? Why?

7.	Because fs = 100 Hz, you can accurately sample only signals having a frequency < 50 Hz (Nyquist frequency = fs/2). Change the frequency (Hz) to 48 Hz. You should see the peaks at ± 48 Hz on the spectrum plot.

8.	Now change the frequency (Hz) to 52 Hz. Is there any difference between the result of Step 5 and what you see on the plots now? Because 52 > Nyquist, the frequency of 52 is aliased to |100 – 52| = 48 Hz.

9.	Change frequency (Hz) to 30 Hz and 70 Hz and run the VI. Is there any difference between the two cases? Explain why.

One-Sided FFT

10.	Modify the block diagram of the VI as shown below. You have seen that the FFT had repetition of information because it contained information about both the positive and the negative frequencies. This modification now shows only half the FFT points (only the positive frequency components). This representation is known as the 1-sided FFT. The 1-sided FFT shows only the positive frequency components. Note that you need to multiply the positive frequency components by two to obtain the correct amplitude. The D.C. component, however, is left untouched.

 Equal To O? function (Functions»Comparison palette) tests to see if the array index is equal zero. If so, it corresponds to the D.C. component and should not be multiplied by two.

11.	Run the VI with the following values: frequency (Hz) = 30, sampling freq = 100, # of samples = 100.

12.	Save the VI as FFT_1sided.vi in the LabVIEW\Activity directory.

13.	Change the value of frequency (Hz) to 70 and run the VI. Do you notice any difference between this and the result of Step 9?

End of Activity 31. Use the Real FFT VI


Activity 32. Compare a Windowed and Nonwindowed Signal

Your objective is to observe the difference (both time and frequency domains) between a windowed and nonwindowed signal.

Front Panel

1.	Open a new front panel and create the objects as shown in the following illustration.

Block Diagram

2.	Build the block diagram shown in the following illustration.

 The Sine Pattern VI (Functions»Analysis»Signal Generation palette) generates a sine wave with the number of cycles specified in the cycles control.

 The time waveform of the sine wave is windowed using the Hamming Window VI (Functions»Analysis»Windows palette), and both the windowed and nonwindowed time waveforms are displayed on the left two plots on the front panel.

 The Amplitude and Phase Spectrum VI (Functions»Analysis»Measurement palette) obtains the amplitude spectrum of the windowed and nonwindowed time waveforms. These waveforms are displayed on the two plots on the right side of the front panel.

3.	Save the VI as Windowed & Unwindowed Signal.vi in the LabVIEW\Activity directory.

4.	Set cycles to 10 (an integral number) and run the VI. Note that the spectrum of the windowed signal is broader (wider) than the spectrum of the nonwindowed signal. But both the spectra are concentrated near 10 on the x-axis.

5.	Change cycles to 10.25 (a nonintegral number) and run the VI. Note that the spectrum of the nonwindowed signal is now more spread out than it was before. This is because now you have a noninteger number of cycles, and when you repeat the waveform to make it periodic, you get discontinuities. The spectrum of the windowed signal is still concentrated, but that of the nonwindowed signal has now smeared all over the frequency domain. (This is spectral leakage.)

6.	Change cycles to 10.5 and observe the frequency domain plots. Spectral leakage of the original signal is clearly apparent.

End of Activity 32. Compare a Windowed and Nonwindowed Signal


Activity 33. Use the Amplitude and Phase Spectrum VI

In this activity, your objective is to compute the amplitude and phase spectrum of a signal.

Front Panel

1.	Open the Amp Spectrum Example VI found in the Examples\analysis\measure\measxmpl.llb library. The signal is generated by the Simple Function Generator VI, which simulates a multi-function generator with additive white noise.

Block Diagram

2.	Open and examine the block diagram.

 The Amplitude and Phase Spectrum VI calculates the amplitude spectrum and the phase spectrum of a time domain signal. The connections to this VI are discussed below.

The input time domain signal is applied at the Signal (V) control. The magnitude and phase of the spectrum of the input signal is available at the Amp Spectrum Mag (Vrms) and the Amp Spectrum Phase (radians) outputs respectively. The Spectrum Unit Conversion VI is used to convert the original Vrms output of the Amplitude and Phase Spectrum to any other common units (Vrms, Vpk, Vrms^2, Vpk^2, [image] Vrms^2/Hz, and Vpk^2/Hz). The last four units are amplitude spectral density [image] and power spectral density (Vrms^2/Hz, and Vpk^2/Hz). The window constants output cluster from the Scaled Time Domain Window VI contains constants for the selected window which are required for spectral density measurements.

3.	Run the VI.

4.	Run the Amp Spectrum example continuously with the Simple Function Generator front panel open so that you can change the simulated frequency and waveform type as well as the amplitude and noise level of the signal. Notice the changes to the amplitude spectrum.

End of Activity 33. Use the Amplitude and Phase Spectrum VI


Activity 34. Compute the Frequency and Impulse Response

Your objective is to compute the Frequency Response and Impulse Response of a system, and to compute the Coherence function and understand how it is used to validate your Frequency Response measurements.

Front Panel

1.	Open a new front panel and add the objects shown in the following illustration. This front panel shows the Frequency Response magnitude and the Impulse Response function for a bandpass filter. The Coherence function is plotted on the same scale as the Frequency Response magnitude because it is also a spectral measurement.

Block Diagram

2.	Open the block diagram and modify it as shown in the following illustration. Here we are measuring the system response of a bandpass filter (Butterworth Filter VI) by passing white noise (Uniform White Noise VI) as the system stimulus and collecting the filter output as the system response. Both the stimulus and response are windowed by the Hanning window (Scaled Time Domain Window VI) and the entire system is monitored for a number of frames, or averages. The stimulus and response data is then sent to the Network Functions (avg) VI where all the actual computations related to the system frequency response are made.

 The Network Functions (avg) VI computes the frequency response (magnitude and phase), cross power spectrum (magnitude and phase), coherence function, and impulse response. By increasing the number of frames of input and output data (increasing averages on the front panel), the estimates of the system response functions improve. In this diagram, only the frequency response magnitude, coherence, and impulse response are plotted.

The Coherence function measures how much of the output signal is correlated with the input signal, and thus it gives an indication of the validity of your frequency response estimate. Injected noise and nonlinear system behavior at certain frequencies cause the Coherence function to dip below unity at those frequencies. For uncorrelated system noise, the more averages are taken, the more the Coherence function approaches unity, and the better the frequency response estimate. One last bit of information to remember about the Coherence function is that it is only defined when you are averaging more than one frame of input and output data. For only one average, coherence will be unity at all frequencies, even where your frequency response estimates may be poor.

End of Activity 34. Compute the Frequency and Impulse Response


Activity 35. Calculate Harmonic Distortion

Your objective is to use the Harmonic Analyzer VI for harmonic distortion calculations.

Block Diagram

1.	Open the THD Example VI from Examples\analysis\measure\measxmpl.llb and view the block diagram.

Some of this will already be familiar to you. Your System is the nonlinear system that you saw previously. Its output is windowed, and the power spectrum calculated and given to the Harmonic Analyzer VI.

The Sine Wave VI generates a fundamental of frequency specified in the fundamental frequency control.

Front Panel

2.	View the front panel. At the bottom, you see a plot of the power spectrum of the output of the nonlinear system. On the top right side are the array indicators for the frequencies and amplitudes of the fundamental and its harmonics. The size of the array depends on the value entered in the # harmonics control.

3.	Change the fundamental frequency to 1000, # harmonics to 2, and run the VI several times. Each time, note the values in the output indicators (Harmonic Frequencies, Harmonic Amplitudes, % THD, and % THD + Noise).

Why do you get different values each time you run the VI?

Which of the values, % THD or % THD + Noise, is larger? Can you explain why?

4.	Run the VI with different selections of the window control and observe the peaks in the power spectrum.

Which window gives the narrowest peaks? The widest? Can you explain why?

5.	Change the fundamental frequency to 3000 and run the VI.

Why do you get an error?

Hint: Consider the relationship between the Nyquist frequency and the frequency of the harmonic(s).

6.	When you finish, close the VI and exit LabVIEW.

End of Activity 35. Calculate Harmonic Distortion


Activity 36. Extract a Sine Wave

Your objective is to filter data samples that consist of both high-frequency noise and a sinusoidal signal.

In this activity, you combine a sine wave generated by the Sine Pattern VI with high-frequency noise. (The high-frequency noise is obtained by highpass filtering uniform white noise with a Butterworth filter.) The combined signal is then lowpass filtered by another Butterworth filter to extract the sine wave.

Front Panel

1.	Open a new VI and build the front panel as shown below.

Block Diagram

2.	Build the block diagram as shown below.

 Sine Pattern VI (Functions»Analysis»Signal Generation palette) generates a sine wave of the desired frequency.

 Uniform White Noise VI (Functions»Analysis»Signal Generation palette) generates uniform white noise that is added to the sinusoidal signal.

 Butterworth Filter VI (Functions»Analysis»Filters palette) highpass filters the noise.

Notice that you are generating 10 cycles of the sine wave, and there are 1000 samples. Also, the sampling frequency to the Butterworth Filter VI on the right side is specified as 1000 Hz. Thus, effectively you are generating a 10 Hz signal.

3.	Save the VI as Extract the Sine Wave.vi in the LabVIEW\Activity directory.

4.	Switch back to the front panel. Select a Frequency of 10 Hz, a Cut-Off Frequency of 25 Hz, and a Filter Order of 5. Run the VI.

5.	Reduce the Filter Order to 4, 3, and 2, and observe the difference in the filtered signal. Explain what happens as you lower the filter order.

6.	When you finish, save the VI as Extract the Sine Wave.vi in the Dig.filt.llb library.

7.	Close the VI.

End of Activity 36. Extract a Sine Wave


Activity 37. Use the Curve Fitting VIs

Your objective is to use and compare the Linear, Exponential and Polynomial Curve Fit VIs to obtain the set of least square coefficients that best represent a set of data points.

Front Panel

1.	Open the Regressions Demo VI from the library regressn.llb. The front panel and block diagram are already built for you.

This VI generates “noisy” data samples that are approximately linear, exponential, or polynomial. It then uses the corresponding analysis curve fitting VIs to determine the parameters of the curve that best fits those data points. (At this stage, you do not need to worry about how the noisy data samples are generated.) You can control the noise amplitude with the Noise Level control on the front panel.

Block Diagram

2.	Select Linear in the Algorithm Selector control, and set the Noise Level control to about 0.1. Run the VI. Notice the spread of the data points and the fitted curve (straight line).

3.	Experiment with different values of Order and Noise Level. What do you notice? How does the mse change?

4.	Change the Algorithm Selector to Exponential and run the VI. Experiment with different values of Order and Noise Level. What do you notice?

5.	Change the Algorithm Selector to Polynomial and run the VI. Experiment with different values of Order and Noise Level. What do you notice?

6.	In particular, with the Algorithm Selector control set to Polynomial, change the Order to 0 and run the VI. Then change it to 1 and run the VI. Explain your observations.

7.	Depending on your observations in Steps 2, 3, 4, and 5, for which of the algorithms (Linear, Exponential, Polynomial) is the Order control the most effective? Why?

8.	Close the VI and quit. Do not save any changes.

End of Activity 37. Use the Curve Fitting VIs


Activity 38. Use the General LS Linear Fit VI

For this activity, your objective is to learn how to set up the input parameters and use the General LS Linear Fit VI.

This activity demonstrates how to use the General LS Linear Fit VI to obtain the set of least square coefficients a and the fitted values, and also how to set up the input parameters to the VI.

The purpose is to find the set of least square coefficients a that best represent the set of data points (x[i], y[i]). As an example, suppose that we have a physical process that generates data using the relationship

          (38-8)

where

and noise is a random value. Also, assume you have some idea of the general form of the relationship between x and y, but are not quite sure of the coefficient values. So, you may think that the relationship between x and y is of the form

          (38-9)

where

Equations 38-8 and 38-9 respectively correspond to the actual physical process and to your guess of this process. The coefficients you choose in your guess may be close to the actual values, or may be far away from them. Your objective now is to accurately determine the coefficients a.

Building the Observation Matrix

To obtain the coefficients a, you must supply the set of (x[i], y[i]) points in the arrays H and Y Values (where the matrix H is a 2D array) to the General LS Linear Fit VI. The x[i] and y[i] points are the values observed in your experiment. A simple way to build the matrix H is to use the Formula Node as shown in the following block diagram.

You can edit the Formula Node to change, add, or delete functions. At this point, you have all the necessary inputs to use the General LS Linear Fit VI to solve for a. To obtain equation (1) from equation (2), you need to multiply f0(x) by 0.0, f1(x) by 2.0, f2(x) by 1.0, f3(x) by 4.0, and f4(x) by 0.0. Thus, looking at equations (1) and (2), note that the expected set of coefficients are

a = {0.0, 2.0, 1.0, 4.0, 0.0}

The block diagram below demonstrates how to set up the General LS Linear Fit VI to obtain the coefficients and a new set of y values.

 The subVI labeled Data Create generates the X and Y arrays. You can replace this icon with one that actually collects the data in your experiments. The icon labeled H(X,i) generates the 2D matrix H.

The last portion of the block diagram overlays the original and the estimated data points and produces a visual record of the General LS Linear Fit. Executing the General LS Linear Fit VI with the values of X, Y, and H returns the following set of coefficients.

The resulting equation is thus

The following graph displays the results.

You will now see the VI in which this particular example has been implemented.

1.	Open the General LS Fit Example VI from the library Examples\analysis\regressn.llb.

2.	Examine the block diagram. Make sure you understand it.

3.	Examine the front panel.

noise amplitude—can change the amplitude of the noise added to the data points. The larger this value, the more the spread of the data points.

NumData—the number of data points that you want to generate.

algorithm—provides a choice of six different algorithms to obtain the set of coefficients and the fitted values. In this particular example, there is no significant difference among different algorithms. You can select different algorithms from the front panel to see the results. In some cases, different algorithms may have significant differences, depending on your observed data set.

MSE—gives the mean squared error. The smaller the MSE, the better the fit.

error—gives the error code in case of any errors. If error code = 0, it indicates no error. For a list of error codes, see Error Codes.

Coefficients—displays the calculated values of the coefficients (a0, a1, a2, a3, and a4) of the model.

4.	Run the VI with progressively larger values of the noise amplitude. What happens to the observed data plotted on the graph? What about the MSE?

5.	For a fixed value of noise amplitude, run the VI by choosing different algorithms from the algorithm control. Do you find that any one algorithm is better than the other? Which one gives you the lowest MSE?

6.	When you finish, close the VI. Do not save any changes.

End of Activity 38. Use the General LS Linear Fit VI


Activity 39. Use the Nonlinear Lev-Mar Fit VI

For this activity, your objective is to create a general exponential signal a*exp(b*x) + c + noise, and then use the Nonlinear Lev-Mar Fit VI to fit the data and get the best guess coefficients a, b, and c of the general exponential signal.

In this activity, you will see how to use the Nonlinear Lev-Mar Fit VI to determine the coefficients a, b, and c, of a nonlinear function given by a*exp(b*x) + c.

Front Panel

1.	Open the Nonlinear Lev-Mar Exponential Fit VI from the library Examples\analysis\regressn.llb. The front panel is shown in the following illustration.

The a, b, and c controls determine the actual values of the coefficients a, b, and c. The Initial Coefficients control is your educated guess as to the actual values of a, b, and c. Finally, the Best Guess Coef indicator gives you the values of a, b, and c calculated by the Nonlinear Lev-Mar Fit VI. To simulate a more practical example, we also add noise to this equation, thus making it of the form:

a*exp(b*x) + c + noise

The noise level control adjusts the noise level. Note that the actual values of a, b, and c being chosen are +1.0, –0.1 and 2.0. In the Initial Coefficients control, the default guess for these is a = 2.0, b = 0, and c = 4.0.

Block Diagram

2.	Examine the block diagram.

  The data samples of the exponential function are simulated using the Exponential VI (Numeric»Logarithmic subpalette), and uniform white noise is added to the samples with the help of the Uniform White Noise VI (Analysis»Signal Generation subpalette).

3.	From the Project menu, select Unopened SubVIs»Target Fnc and Deriv NonLin VI. The front panel of the Target Fnc and Deriv NonLin VI opens, as shown below.

4.	Switch to the block diagram.

Observe the Formula Node at the bottom. It has the form of the function whose parameters (a0, a1, and a2) you are trying to evaluate.

5.	Close the front panel and the block diagram of the Target Fnc and Deriv NonLin VI.

6.	Run the NonLinear Lev-Mar Exponential Fit VI. Note that the values of the coefficients returned in Best Guess Coef are very close to the actual values entered in the Initial Coefficients control. Also note the value of the mse.

7.	Increase the noise level from 0.1 to 0.5. What happens to the mse and the coefficient values in Best Guess Coef? Why?

8.	Change the noise level back to 0.1 and the Initial Coefficients to 5.0, –2.0, and 10.0, and run the VI. Note the values returned in the Best Guess Coef and the mse indicators.

9.	With the noise level still at 0.1, change your guess of the Initial Coefficients to 5.0, 8.0, and 10.0, and run the VI. This time, your guess is further away than the one you chose in Step 4. Notice the error. This illustrates how important it is to have a reasonably educated guess for the coefficients.

10.	When you finish, close the VI. Do not save any changes.

End of Activity 39. Use the Nonlinear Lev-Mar Fit VI


Activity 40. Compute the Inverse of a Matrix

Your objective is to compute the inverse of a matrix.

You will build a VI that will compute the inverse of a matrix A. Further, you will compute a matrix B which is similar to matrix A. A matrix B is similar to a matrix A if there is a nonsingular matrix T such that [image] so that A and B have the same eigenvalues. You will verify this definition of similar matrices.

Front Panel

1.	Build the front panel as shown below. Matrix A is a  2 x 2  real matrix. Matrix T is a  2 x 2  nonsingular matrix that will be used to construct the similar matrix B.

Block Diagram

2.	Open the block diagram and modify it as shown in the following illustration.

 Inverse Matrix VI (Analysis»Linear Algebra subpalette). In this activity, this function computes the inverse of the input matrix A.

 AxB VI (Analysis»Linear Algebra subpalette). In this activity, this function multiplies two two-dimensional input matrices.

 EigenValues and Vectors VI (Analysis»Linear Algebra subpalette). In this activity, this VI computes the eigenvalues and eigenvectors of the input matrix.

3.	Save the VI as Matrix Inverse.vi in the LabVIEW\Activity directory.

4.	Return to the front panel and run the VI. Check if the eigenvalues of A and the similar matrix B are the same.

End of Activity 40. Compute the Inverse of a Matrix


Activity 41. Solve a System of Linear Equations

Your objective is to solve a system of linear equations.

Many practical applications require you to solve a system of linear equations. A very important area of application is related to military defense. This includes analysis of electromagnetic scattering and radiation from large targets, performance analysis of large radomes, and design of aerospace vehicles having low radar cross sections (the Stealth Technology). A second area of application is in the design and modeling of wireless communication systems such as hand-held cellular phones. This list of applications goes on and on, and therefore it is very important for you to properly understand how to use the VIs in the Analysis Library to solve a linear system of equations.

1.	Use the Solve Linear Equations VI in the Analysis»Linear Algebra subpalette to solve the system of equations  Ax = b  where the Input Matrix A and the Known Vector b are

Choose matrix type equal to general.

2.	Use the A x Vector VI to multiply the matrix A and the vector x (output of the above operation) and check if the result is equal to the vector b above.

3.	Save the VI as Linear System.vi in the LabVIEW\Activity directory.

End of Activity 41. Solve a System of Linear Equations


Activity 42. Use the Normal Distribution VI

Your objective is to understand key probability concepts.

In this activity, you will first generate a data sample with standard normal distribution and then use the Normal Distribution VI to check the probability of a random variable x.

Front Panel

1.	Build the front panel as shown in the following figure. Noise Plot is a waveform graph, whereas Noise Histogram is an XY graph.

Block Diagram

2.	Build the block diagram as shown in the following illustration. The Gaussian White Noise VI generates a Gaussian-distributed pattern with mean value equal to 0 and standard deviation set by the user using the Standard Deviation input. Number of Samples is the number of samples of the Gaussian Noise Pattern. Seed is the seed value used to generate the random noise. Connect the Gaussian Noise Pattern to the waveform graph Noise Plot.

 Gaussian White Noise function (Analysis»Signal Generation subpalette). In this activity, this function generates a Gaussian White Noise pattern.

 Histogram function (Analysis»Probability and Statistics subpalette). In this activity, this function computes the histogram of the Gaussian Noise Pattern.

 Normal Distribution function (Analysis»Probability and Statistics subpalette). In this activity, this function computes the one-sided probability of the normally distributed Random Variable.

3.	You will compute the histogram of the Gaussian Noise Pattern using the Histogram VI used in the previous activity.

4.	As discussed earlier, do some postprocessing to plot the histogram in a different way. Select the PostProcessing VI from the LabVIEW\Activity directory.

5.	Bundle the output of this VI and connect it to the Noise Histogram.

6.	Select the Normal Distribution VI. Connect the Random Variable control to the input terminal and connect the output to the probability indicator.

7.	Return to the front panel. Set the Number of Samples to 2,048, Standard Deviation to 1, Seed to 2 and Number of intervals to 10. Run the VI.

8.	You will see the Gaussian white noise on the Noise Plot graph. It is difficult to tell much from this plot. However, the histogram plot for the same noise pattern provides a lot of information. It shows that most of the samples are centered around the mean value of zero. From this histogram, you can approximate this noise pattern by a Normal Distribution function (Gaussian distribution). Because the mean value is zero and you set the standard deviation equal to one, the Probability Density function is actually a standard normal distribution.

Note	It is very important that you carefully choose the proper type of distribution function to approximate your data. In this example, you actually plotted the histogram to make this decision. Many times, you can make an intelligent decision based solely on prior knowledge of the behavior and characteristics of the data sample.

9.	Return to the front panel and enter a value for Random Variable. This VI will compute the one-sided probability of this normally distributed random variable. Remember, you have assumed that the variable is normally distributed by looking at the histogram.

10.	 Save the VI as Probability.vi in the LabVIEW\Activity directory.

End of Activity 42. Use the Normal Distribution VI


Activity 16. Use the Formula Node

Your objective is to build a VI that uses the Formula Node to calculate the following equations.

y1 = x3 - x2 + 5

y2 = m * x + b

where x ranges from 0 to 10.

You will use only one Formula Node for both equations, and you will graph the results on the same graph. For more information on graphs, see Arrays, Clusters, and Graphs.

Front Panel

1.	Open a new front panel and build the front panel shown in following illustration. The waveform graph indicator displays the plots of the equation. The VI uses the two digital controls to input the values for m and b.

2.	Create the graph legend shown in the following illustration by selecting Show»Legend. Use the Resizing cursor [image] to drag the legend downward so it displays two plots. Use the Labeling tool [image] to rename the plots. You can define the line style for each plot using the legend pop-up menu. You also can color each plot by using the Color tool [image] on the plots legend.

Block Diagram

3.	Build the block diagram shown in the following illustration.

 Formula Node (Functions»Structures). With this node, you can enter formulas directly. Create the three input terminals by popping up on the border and choosing Add Input. You create the output terminal by choosing Add Output from the pop-up menu.

When you create an input or output terminal, you must give it a variable name. The variable name must match the one you use in the formula exactly. The names are case sensitive. That is, if you use a lowercase a in naming the terminal, you must use a lowercase a in the formula. You can enter the variable names and formula with the Labeling tool.

Note	Although variable names are not limited in length, be aware that long names take up considerable diagram space. A semicolon ( ; ) terminates the formula statement.

 Numeric Constant (Functions»Numeric). You also can pop up on the count terminal and select Create Constant to create and wire the numeric constant automatically. The numeric constant specifies the number of For Loop iterations. If x range is 0 to 10 including 10, you must wire 11 to the count terminal.

 Because the iteration terminal counts from 0 to 10, you use it to control the x value in the Formula Node.

 Build Array (Functions»Array) puts two array inputs into the form of a multiplot graph. Create the two input terminals by using the Resizing cursor to drag one of the corners. For more information on arrays, see Arrays, Clusters, and Graphs.

4.	Return to the front panel and run the VI with different values for m and b.

5.	Save the VI as Equations.vi in the LabVIEW/Activity directory.

End of Activity 16. Use the Formula Node


Glossary

Prefix	Meaning	Value

n-	nano-	10^-9

m-	micro-	10^-6

m-	milli-	10^-3

k-	kilo-	10^3

M-	mega-	10^6

Numbers/Symbols

1D	One-dimensional.

2D	Two-dimensional.

Infinity.

Pi.

Delta. Difference. Δx denotes the value by which x changes from one index to the next.

A

access level

ACK (Acknowledge)

API

application software

Application Programming Interface

array

Attribute Node

B

block diagram

Boolean control

breakpoint

BridgeVIEW

broken VI

C

Case Structure

CIN

cluster

coercion dot

connector

connector pane

constant

control

D

data flow

deadband

DDE

device

E

Engineering Unit (EU)

error message

event

event driven programming

F

For Loop

Formula Node

frame

free label

front panel

G

G

H

Help window

I

IAC

icon

icon pane

IP

L

LabVIEW

M

MB

O

object

OLE

OPC

Operating tool

operator

P

palette

panel window

PID

PLC

polling

pop up

pop-up menu

Positioning tool

PPC

Programmable Logic Control

Proportional Integral Derivative Control

pseudocode

R

range

reentrant execution

representation

resizing handle

S

sampling period

sensor

sequence local

Sequence Structure

shift register

string tag

structure

subVI

supervisory control

system developer

T

tag attribute

TCP

terminal

top-level VI

U

UDP

universal constant

user

user-defined constant

V

VI

VI library

virtual instrument (VI)

W

While Loop

wire

Wiring tool


array

Ordered, indexed set of data elements of the same type.


ASCII

American Standard Code for Information Interchange.


block diagram

Pictorial description or representation of a program or algorithm. In G, the block diagram, which consists of executable icons called nodes and wires that carry data between the nodes, is the source code for the virtual instrument.


Boolean control

Front panel object used to manipulate and display or input and indicators output Boolean (True or False) data. Several styles are available, such as switches, buttons and LEDs.


breakpoint

Mode that halts execution when a subVI is called. You set a breakpoint by clicking on the toolbar and then on a node.


broken VI

VI that cannot be compiled or run; signified by a Run button with a broken arrow.


Case Structure

Conditional branching control structure, which executes one and only one of its subdiagrams based on its input. It is the combination of the IF THEN ELSE and CASE statements in control flow languages.


CIN

Code interface node.


cluster

A set of ordered, unindexed data elements of any data type including numeric, Boolean, string, array, or cluster. The elements must be all controls or all indicators.


coercion dot

A gray dot on a terminal to indicate that one of two terminals wired together has been converted to match the datatype representation of the other.


connector

Part of the VI or function node that contains its input and output terminals, through which data passes to and from the node.


connector pane

Region in the upper right corner of a front panel window that displays the VI's connector. It underlies the Icon pane.


control

Front panel object for entering data to a VI interactively or to a subVI programmatically.


constant

See universal and user-defined constants.


data flow

Programming system consisting of executable nodes in which nodes execute only when they have received all required input data and produce output automatically when they have executed. G is a dataflow system.


DDE

Dynamic Data Exchange.


device

An instrument or controller that is addressable as a single entity and controls or monitors real-world I/O points. A device is often connected to the host computer through some type of communication network, or can be a plug-in device.

For data acquisition (DAQ) applications, a DAQ device is inside your computer or attached directly to your computer through a parallel port. Plug-in boards, PCMCIA cards, and devices such as the DAQPad-1200, which connects to your computer's parallel port, are all examples of DAQ devices. SCXI modules are distinct from devices, with the exception of the SCXI-1200, which is a hybrid.


event

The condition or state of an analog or digital signal.

Something that happens to a tag in the LabVIEW system. Events include tags going into or out of alarm state and the user setting a tag value.


external trigger

A voltage pulse from an external source that triggers an event such as A/D conversion.


For Loop

Iterative loop structure that executes its subdiagram a set number of times. Equivalent to conventional code: For i=0 to n-1, do É .


Formula Node

Node that executes formulas that you enter as text. This node is especially useful for lengthy formulas that would be cumbersome to build in block diagram form.


frame

Subdiagram of a Sequence Structure.


free label

Label on the front panel or block diagram that does not belong to any other object.


front panel

The interactive user interface of a VI. Modeled from the front panel of physical instruments, it is composed of switches, slides, meters, graphs, charts, gauges, LEDs, and other controls and indicators.


Help window

Special window that displays the names and locations of the terminals for a function or subVI, the description of controls and indicators, the values of universal constants, and descriptions and data types of control attributes.


IAC

Interapplication communication.


icon

Graphical representation of a node on a block diagram.


icon pane

Region in the upper right-hand corner of the front panel and block diagram windows that displays the VI icon.


indicator

Front panel object that displays output.


IP

Internet protocol.


LabVIEW

Laboratory Virtual Instrument Engineering Workbench. A program development application used commonly for test and measurement purposes.


MB

Megabyte of memory.


object

Generic term for any item on the front panel or block diagram, including controls, nodes, wires, and imported pictures.


OLE

Object Linking and Embedding.


OPC

OLE for Process Control. A COM-based standard defined by the OPC foundation that specifies how to interact with device servers. COM is a Microsoft 32-bit Windows technology.


Operating tool

Tool used to enter data into controls as well as operate them. Resembles a pointing finger.


palette

Menu that displays a palette of pictures that represent possible options.


panel window

VI window that contains the front panel, the toolbar, and the icon/connector pane.


pop up

To call up a special menu by clicking on an object with the right mouse button (Windows, Sun and HP-UX) or holding down the <command> key while clicking (Macintosh).


pop-up menu

Menu accessed by popping up on an object. Menu options pertain to that object specifically.


Positioning tool

Tool used to move and resize objects. Resembles an arrow.


PPC

Program-to-program communication.


pseudocode

Simplified language-independent representation of programming code.


representation

Subtype of the numeric data type, of which there are signed and unsigned byte, word, and long integers, as well as single-, double-, and extended-precision floating-point numbers.


resizing handle

Angled handle on the corners of objects that indicate resizing points.


sequence local

Terminal used to pass data between the frames of a Sequence Structure.


Sequence Structure

Program control structure that executes its subdiagrams in numeric order. Commonly used to force nodes that are not data dependent to execute in a desired order.


shift register

Optional mechanism in loop structures used to pass a variable's value from one iteration of a loop to a subsequent iteration.


structure

Program control element, such as a Sequence, Case, For Loop, or While Loop.


subVI

VI used in the block diagram of another VI; comparable to a subroutine.


terminal

Object or region on a node through which data passes.


top-level VI

VI at the top of the VI hierarchy. This term is used to distinguish the VI from its subVIs.


UDP

User Datagram Protocol.


universal constant

Uneditable block diagram object that emits a particular ASCII character or standard numeric constant, for example, pi.


user-defined constant

Block diagram object that emits a value you set.


VI

See virtual instrument.


virtual instrument (VI)

A program in the graphical programming language G; so-called because it models the appearance and function of a physical instrument.


While Loop

Post-iterative-test loop structure that repeats a section of code until a condition is met. Comparable to a Do loop or a Repeat-Until loop in conventional programming languages.


wire

Data path between nodes.


Wiring tool

Tool used to define data paths between source and sink terminals.


access level

Determines which access privileges a user has for certain LabVIEW utilities. Access level values are between 0 and 255.


ACK (Acknowledge)

The sequence action that indicates recognition of a new alarm.


API

See Application Programming Interface.


Application Programming Interface

A specification of a set of software functions and their input and return parameters.


Attribute Node

A special block diagram node you can use to control the appearance and functionality of controls and indicators.


bit array tag

A multibit value representation of a connection to a real-world I/O point or memory variable. In LabVIEW, this type of tag can be comprised of up to 32 discrete values.


deadband

In process instrumentation, the range through which an input signal can vary, upon reversal of direction, without initiating an observable change in output signal. Deadband is usually expressed in percent of range.


Engineering Unit (EU)

Term of data measurement, as degrees Celsius, pounds, grams and so on.


error message

An indication of a software or hardware malfunction, or an unacceptable data entry attempt.


event driven programming

A method of programming whereby the program waits on an event occurring before executing one or more functions.


G

Graphical programming language used to develop BridgeVIEW and LabVIEW applications.


operator

The person who initiates and monitors the operation of a process.


PID

See Proportional Integral Derivative Control.


PLC

See Programmable Logic Control.


polling

A method of sequentially observing each I/O point or user interface control to determine if it is ready to receive data or request computer action.


Programmable Logic Control (PLC)

A device with multiple inputs and outputs that contains a program you can alter. LabVIEW Device Servers establish communication with PLCs.


Proportional Integral Derivative (PID) Control

A combination of proportional, integral and derivative control actions.  Refers to a control method in which the controller output is proportional to the error, its time history, and the rate at which it is changing. The error is the difference between the observed and desired values of a variable that is under control action.


range

The region between the limits within which a quantity is measured, received, or transmitted expressed by stating the lower and upper range values.


sampling period

The time interval between observations in a periodic sampling control system.


sensor

A device that produces a voltage or current output representative of some physical property being measured, such as speed, temperature, or flow.


string tag

An ASCII character representation of a connection to a real-world I/O point.


supervisory control

Control in which the control loops operate independently subject to intermittent corrective action.


tag attribute

Parameter pertaining to a tag, like its alarm, limits, or Engineering Units. Tag attributes are configured in the Tag Configuration Editor but can be changed dynamically using the Tag Attributes VIs.


TCP

Transmission Control Protocol.


user

See operator.


VI Library

Special file that contains a collection of related VIs for a specific use.


application software

The application created using the LabVIEW Development System and executed in the LabVIEW Run-Time System environment.


BridgeVIEW

A program development application for real-time process monitoring and control. BridgeVIEW uses the graphical development environment called G.


BridgeVIEW Run-Time System

An execution environment for applications created using the BridgeVIEW Development System.


reentrant execution

Mode in which calls to multiple instances of a subVI can execute in parallel with distinct and separate data storage.


system developer

The creator of the application software to be executed in the LabVIEW Run-Time System.


Charts and Graphs

How do I wire data to a graph or chart?

What is the basic difference between graphs and charts?

How do I flip the scales on my graph or chart?

How do I make a graph or chart display information in a time format?

How do I make the x-axis of a chart display real time?

How do I clear a chart programmatically?

How do I avoid the flashing from the graph each time it is updated?

How do I update a graph without clearing it?

How can I create a bar graph?

How can I create polar plots and Smith charts?

How can I make a label for the y-axis that is rotated 90 degrees?

How do I place a text label on a cursor?

After I have added a cursor to my graph, how do I remove it?


How do I wire data to a graph or chart?

Show the Help window and move the Wiring tool across a graph terminal in the block diagram to see a brief description of how to wire basic graph types. There are excellent examples on graphs and charts in the general\graphs directory.


What is the basic difference between graphs and charts?

Graphs and charts differ in the way they display and update data. VIs with graphs usually collect the data in an array and then plot it on the graph, similar to a spreadsheet that first stores the data then generates a plot of it. In contrast, a chart appends new data points to those already in the display. In this manner, you can see the current reading or measurement in context with data previously acquired. The length of the chart history buffer can be set by a pop-up option on the chart. Of course, it is possible to implement a history buffer with the graph indicators as well; however, this needs to be done in the block diagram. These features are already built into the chart.


How do I flip the scales on my graph or chart?

To flip the scales for the x-axis or y-axis, use the attribute X Flipped or Y Flipped. If the X Flipped attribute is set to TRUE, then the minimum of the x-axis scale is set to the right and the maximum to the left. Similarly, if the Y Flipped attribute is set to TRUE, the minimum of the y-axis scale is at the top and the maximum is at the bottom.


How do I make a graph or chart display information in a time format?

Graphs and charts can display numeric information in a relative or absolute time format. Use the X Scale»Formatting… or Y Scale»Formatting… popup option to set the x-axis or y-axis scale format to Relative Time.


How do I make the x-axis of a chart display real time?

See the example VI called Real-Time Chart.vi, located in examples\general\graphs\charts.llb. It unbundles the date time cluster from the Seconds to Date/Time function into hours, minutes, and seconds. It then converts these numbers into the number of seconds elapsed since midnight. Finally, this number is used as an input to the Xo and delta X attribute of a chart with its x-scale formatting set to Relative Time. Or you can use the Absolute Time Format & Precision option.


How do I clear a chart programmatically?

Wire an empty array to the History Data attribute. The data type of this empty array is the same as the data type wired to the chart. An excellent example illustrating this technique is found in examples\general\graphs\charts.llb\How to Clear Charts & Graphs.vi.


 How do I avoid the flashing from the graph each time it is updated?

Use the Smooth Updates option to keep graphs from flashing. This option is located in the Data Operations submenu of the graph popup menu. Smooth Updates redraws the graph to an off-screen buffer before copying the image to the display. While producing a smoother update to the indicators, this option is generally slower and requires more memory.

Smooth Updates can be set globally through the Edit»Preferences»Front Panel dialog box. It can be turned on or off for individual graphs from their popup menus..


How do I update a graph without clearing it?

All the graphs (waveform, XY, and intensity) always clear before writing new data; however, it is a simple procedure to keep track of the data previously written to the graph and append new data with each write. The examples\general\arrays.llb\Separate Array Values.vi demonstrates the technique of using the Build Array function to append new values to an array. If you are a LabVIEW user, refer to the Array and Cluster Controls and Indicators topic.


How can I create a bar graph?

The legend menu item, Common Plots lists bar plots as one style. The other plot attributes allow for a different baseline and for horizontal bar plots. Also, see examples\general\graphs\bargraph.llb. This VI library contains an example bar graph and two VIs to create bar graphs out of an array input. The G Picture Control Toolkit also can create bar graphs.


How can I make a label for the y-axis that is rotated 90 degrees?

BridgeVIEW and LabVIEW do not rotate text. To use rotated text, first create it in an application with this capability, Windows Paintbrush for example, and save it in a suitable format (see the Customizing Controls Using Imported Graphics topic for more information on importing graphics into G). You then can import this graphic and place it on the y-axis of the graph or chart.


How can I create polar plots and Smith charts?

The G Picture Control Toolkit contains examples with routines to create polar plots and Smith charts. The toolkit is a versatile graphics package for creating arbitrary front panel displays. The Picture VI Library, which ships with the toolkit, implements a common set of two-dimensional drawing commands for building graphic images.


How do I place a text label on a cursor?
How do I place a text label on a graph cursor?

For programmatic access you first use the Cursor Name Visible attribute to display the cursor name. You then use the Cursor Name attribute to assign a name to the cursor. For interactive use, the cursor style menu permits control of the name in the cursor display of the graph.


After I have added a cursor to my graph, how do I remove it?

You must empty the array that contains the clusters holding the information of each cursor. Select Data Operations»Empty Array from the pop-up menu of the cursor display, or write an empty array to the Cursor List Attribute Node programmatically.


Error Messages and Crashes

All Platforms

While running LabVIEW or BridgeVIEW, what should I do if I receive a failure message which includes a source code file and line number?

Windows Only

(Windows) What do I do if LabVIEW or BridgeVIEW crashes when printing?

(Windows) What should I do if LabVIEW or BridgeVIEW tends to crash randomly?

(Windows) What should I do if I receive a memory parity error, followed by a General Protection Fault?


What do I do when a dialog box appears stating that my application is out of memory?

LabVIEW and BridgeVIEW allocate memory as needed, but arrays and strings must be stored in a contiguous block of memory. If your LabVIEW or BridgeVIEW application is unable to find a block of unused memory (physical or virtual) large enough for the string or array, a dialog box appears to indicate it was not able to allocate the required memory.

If you want to save changes to your VIs after the application runs out of memory, you might save your VIs to another location or make sure you have a backup copy. After you restart the software with more memory, you can load these VIs into memory, check to see if the save was successful, and proceed in your VI development.


What do I do if LabVIEW or BridgeVIEW crashes when printing? (Windows)

This crash might be related to the video driver or printer driver. See the question below concerning random crashes on Windows for information on how to proceed.


While running LabVIEW or BridgeVIEW, what do I do if I receive a failure message which includes a source code file and line
While running LabVIEW or BridgeVIEW, what do I do if I receive a failure message which includes a source code file and line number?

This indicates an error has occurred and the application cannot proceed. Please notify National Instruments of this message and explain what action triggered the message.


What do I do if LabVIEW or BridgeVIEW tends to crash randomly? (Windows)

The crashes might be general protection faults or failure messages which include a source code file and line number. Often random crashes involve problems with the video driver on the computer. To help determine if this is the case, use standard VGA as the video driver. To change video drivers, select VGA from the list of video drivers in Windows Setup. LabVIEW and BridgeVIEW use the standard Windows API for its graphical calls; however, many video drivers do not fully conform to this standard. If the crashes do not occur with the standard VGA driver, then it is a good idea to get an update to your video driver. You probably can obtain the latest release of the video driver software from both the manufacturer of your PC and the manufacturer of the video card.

If the situation is not resolved by updating the video driver, please contact National Instruments.


What do I do if I receive a memory parity error, followed by a General Protection Fault? (Windows)
(Windows) What do I do if I receive a memory parity error, followed by a General Protection Fault?

Memory parity errors are the result of bad memory in your machine. This memory might be virtual memory, indicating a problem on your hard disk, or physical memory, indicating a bad SIMM. To check for problems with your hard disk, use a standard disk utility package such as Norton Utilities. To check for problems with physical RAM, physically rotate the SIMMs in your machine, rebooting the PC after each rotation. When the bad SIMM is placed in the lowest bank of memory, the machine does not boot at all. It is a good idea to replace the SIMM.


Miscellaneous

All Platforms

What is Info-Labview and how do I subscribe?

How can I dynamically load and run VIs?

How do I replace a subVI with another VI that has the same name?

Loading two VIs that call two distinct subVIs with the same name causes problems.

How does priority affect the execution of VIs?

When loading and executing multiple VIs, how is the priority of execution assigned to the VIs?

How can G service interrupts without using polling?

With nested While Loops, how do I stop both loops without anything in the outer loop executing after the inner loop stops?

What is Panel Order?

How can I get my G development environment to launch a particular VI automatically?

How do I change the entries of an enumerated type programmatically?

How can I hide the menu bars of a VI?

How do I disable mouse interrupts to improve performance?


What is Info-Labview and how do I subscribe?

Info-labview is a user-sponsored and supported network of LabVIEW and users. Users can post information to a specific e-mail address (see below); the posting is then broadcast to all users subscribing to the list. Other users then can respond back to the group or perhaps directly to the individual who wrote the post.

Several power users, as well as some National Instruments employees, subscribe to the list and respond to various issues. Overall the Info LabVIEW group has been received extremely well. Although the group is not connected with National Instruments, official responses are made on occasion to the group. Most of the time the conversations take place strictly between users.

Users who want to subscribe to the list should send e-mail to this address:

info-labview-request@pica.army.mil

There are two ways for users to receive the postings — the standard format and digest format. Standard format means you receive the postings as they occur. Digest format means you receive one package at the end of each day containing all postings for the day. Subscribers should specify digest format in the e-mail messages they send to info-labview-request if they wish to receive one bulk message daily.

After you subscribe to the list, you will receive postings from other subscribers. Traffic in the group is fairly active, from 10 to 30 postings per day. To post information to the list, send e-mail to this address:

info-labview@pica.army.mil


How can I dynamically load and run VIs?

When a subVI exists in the block diagram of another VI, the subVI loads into memory as soon as the calling VI loads into memory. For memory considerations, you might want to load and unload VIs dynamically from memory during the execution of your program. You can use the VI Server feature to do this. For more information on these VIs, see the VI Server topic.

(Macintosh) In addition to the platform-independent VI Server, you can use Apple Events on the Macintosh to dynamically load and run VIs. The VIs are located in the palette Functions» Communication»AppleEvent or its subpalette LabVIEW Specific Apple Events, and are called:

•	AESend Finder Open

•	AESend Open, Run, Close VI

•	AESend Run VI

•	AESend Close VI


How do I replace a subVI with another VI that has the same name?

Your G development environment references all VIs by name, and thus never loads two VIs with the same name, regardless of the paths to those VIs. This includes subVIs. When you select Replace on a subVI and ask your G development environment to replace it with a VI of the same name, your G development environment recognizes that it already has a copy of the VI in memory, and substitutes the VI with itself.

To load the new copy of the subVI, you must first remove the old copy from memory. The VIs currently are listed in the Windows menu. The easiest way to remove the subVI from memory is to close the subVI and any other VIs that call the subVI. Open the new copy of the subVI into memory, check File»Show VI Info... to confirm that this is the version you want, and then re-open the main VI. When your G development environment tries to link in the subVI, it finds a copy in memory (the new version) and will use it rather than search for the previous version.

The solution to many of these problems is always to give subVIs unique names.


Loading two VIs that call two distinct subVIs with the same name causes problems.

For example, main1.vi and main2.vi both call distinct subVIs which are both named subVI.vi.

2.	1.	main1.vi is loaded into memory, subVI.vi is loaded in because it is called by main1.vi.

3.	2.	main2.vi is loaded into memory, linker information signals LabVIEW or BridgeVIEW to load subVI.vi. The application recognizes it already has subVI.vi loaded into memory, tries to link main2.vi with this subVI.vi. If the connector pane is exactly the same, it probably makes the link (but the behavior might be very peculiar). If the connector pane is different, you receive a bad linkage error.

Solution: Always give subVIs unique names.


How does priority affect the execution of VIs?

The G execution system can execute multiple VIs or subdiagrams in parallel. VIs might be assigned one of five priorities: background (lowest), normal, above normal, high and time critical (highest). Another priority, subroutine, forces a VI to run until completion without sharing its execution system thread with other VIs. Each execution system has a queue of sections of code from the VIs in the system. The queue is ordered by priority such that higher priority VIs run before lower priority VIs. As long as high priority items are on the queue, lower priority items can not work their way to the head of the queue and can not execute. This means that starvation of low priority VIs is possible if higher priority VIs run continuously without pausing for a timeout or other asynchronous activity. Because of this, take care when elevating the priority of a VI.

The G execution queue has entry points for each of the five priorities. There is no entry point for subroutine priority. A subroutine priority VI begins running when called from a VI, and dominates its execution system thread until it returns to the caller VI of another priority. It might call other subroutine priority VIs, but not VIs of the other priorities. Subroutine VIs do not update their indicators, cannot perform Waits or other asynchronous operations and therefore can never be put on a queue. In this sense, once they begin running, they are the highest priority VI in an execution system.

In multithreaded systems, there are several execution systems each with a run queue and one or more threads. The threads are set to run at priorities such that the operating system can preempt a low priority thread when a higher priority thread is ready to run. The VI priority is used to select which execution system queue it is best placed upon. A subroutine VI called in a multithreaded system dominates the thread in which it is called but cannot prevent other VIs in other threads from running. This means you cannot use subroutine VIs to block out all other execution of VIs on systems with other threads at equal or higher priority.

On multithreaded systems, the user interface is a thread at normal priority. On some systems, it can be starved by VIs running at higher priority which never pause for a timeout or perform other asynchronous activity. It might not be possible to change a control to stop a high priority VI which never permits the user interface to notice the control. Because of this, take care when elevating the priority of a VI.


When loading and executing multiple VIs, how is the priority of execution assigned to the VIs?

You can use the G execution system to execute multiple VIs or subdiagrams in parallel and assign priorities to VIs. Priorities range from 0 (low) to 3 (high), with an additional, highest, level of subroutine. At any one time only one section of code executes; other sections wait on an execution queue. If the code does not complete in a given time period, G puts it back on the queue, and the front-most queue element starts running. In this fashion, execution passes round-robin between VIs or subdiagrams.

You can alter the priority of a VI through the dialog box in VI Setup. Notice that a VI with high priority automatically bumps its subVIs to the same level of priority. For example, if main.vi has priority 3 (high) and subVI.vi has priority 1 (not as high), then when main.vi calls subVI.vi, subVI.vi has priority 3.

With priorities, the G internal execution queue has multiple entry points. The queue is always ordered via priority, as in this example:

sss322211111

If a new item with priority 3 is placed on the queue, then the queue would look like the following:

sss3322211111

Notice that the new “3” item gets placed behind all s items (compiled as subroutines) and other priority 3 items.

A potential danger in using VI priority is that low priority items will never execute if higher level tasks are always available to run. Also, priority does not specify which of two items in parallel gets executed first. If something with high priority is put on the queue, it will execute as soon as the currently executing lower priority node checks the queue.


How can G service interrupts without using polling?

Occurrences are a method for G to make a section of code wait for a particular event. For example, you can write a CIN that spawns a process (in Windows through a DLL, for example) that generates an occurrence when an event takes place in the DLL. A particular section of diagram code is executing, and another section or VI is waiting for the event. When the event happens, it logs the occurrence in LabVIEW or BridgeVIEW, and the appropriate code begins to execute as soon as its turn on the queue comes up.

Internally, LabVIEW and BridgeVIEW look at the queue when it finishes a block of atomic code. This means if something else is executing it must complete before the occurrence, and hence the interrupt, is handled.

Note	There is no definite time limit on how long this might be, particularly if the VI contains CINs, which might take a very long time to complete execution.


With nested While Loops, how do I stop both loops without anything in the outer loop executing after the inner loop stops?

Put the code you do not want to execute on the last iteration into a Case Structure. The condition terminal of the inner loop should be connected to the selection terminal of the Case Structure.


What is Panel Order?

Edit»Panel Order determines the order of the objects on the front panel. In other words, if you were using <Tab> on the keyboard to move between objects, the key focus changes from object to object in the order determined by the panel order. Only controls can receive key focus; the <Tab> key does not switch focus to indicators. By default, the panel order is the order in which you create objects on the front panel.

With front panel data logging, the panel order determines the order in which the different objects are compacted into a cluster within the file.


How can I LabVIEW or BridgeVIEW to launch a particular VI automatically?
How can I instruct LabVIEW or BridgeVIEW to launch a particular VI automatically?

By default, LabVIEW and BridgeVIEW launch and create an Untitled1.vi. You might want your application to launch a particular VI automatically. You also can set the VI to run when loaded, so launching LabVIEW or BridgeVIEW not only opens your VI but also starts running it. Set the appropriate Execution Options in VI Setup… to make a VI run when opened. If you specify a library (.llb) to be opened when your application is launched, it opens all VIs marked as Top Level. Use File»Edit VI Library… to mark VIs with Top Level. Finally, if you specify a library and no VIs are marked Top Level, when launched, a file dialog box prompts the user to select a VI within the specified .llb.

To tell LabVIEW or BridgeVIEW to launch a particular VI, follow the instructions below for the relevant platform.

(Windows) Select the LabVIEW or BridgeVIEW icon, select File»Properties (in Program Manager), and change the pathname in Command Line to point towards your VI. For example, to make LabVIEW load test.vi automatically, set the Command Line to:

c:\labview\labview.exe test.vi

If test.vi is inside a library called test.llb, then:

c:\labview\labview.exe “test.llb\test.vi”

It might be necessary to specify the full path to the VI.

If you want to launch a VI from the command line (Start»Run...), the syntax for this is

c:\labview\labview.exe <path to VI relative to the labview directory>

For example to launch the Readme.vi inside the c:\labview\examples directory, the command is

c:\labview\labview.exe examples\readme.vi

If the VI is located in a different path, you need to specify the full path to the VI:

c:\labview\labview.exe c:\coolapp\mycool.vi

If a directory in the path contains spaces, you must enclose the path in quotes:

c:\labview\labview.exe "c:\cool application\mycool.vi"

If the VI is within an LLB, you can do one of the following:

1.	1.	Specify the full path in quotes:

c:\labview\labview.exe "c:\coolapp\eagle.llb\mycool.vi"

or

2.	2.	Change the VI Setup for the VI to Run When Opened. Then, select File»Edit VI Library... and mark the VI as Top Level.

In this case, you only need to specify the path to the llb:

c:\labview\labview.exe "c:\coolapp\eagle.llb"

If you want LabVIEW to automatically launch a VI, modify the Shortcut properties and specify the path in Target as shown above.

(Macintosh) There is no way to instruct the LabVIEW application to launch a particular VI on the Macintosh automatically; however, you can launch a VI by double-clicking its icon in the Finder. If you have multiple copies of LabVIEW installed on your machine, the Finder determines which copy launches when you double-click the VI (you cannot control which copy is launched). For example, the Finder might launch the Run-Time System if both the Run-Time System and Full Development System are installed. If you are running System 7 or later, you can use Drag & Drop to launch one or more VIs, or VI libraries.

(UNIX) LabVIEW responds to command-line options to launch a particular VI when opened. Therefore, you can type:

labview /usr/home/test.vi

or

labview /usr/home/test.llb/test.vi

to launch the Test VI, depending on the correct path. You can use a simple script to make a command that launches LabVIEW with a particular VI.


How do I change the entries of an enumerated type programmatically?
How do I programmatically change the entries of an enumerated type?

You cannot programmatically change the type (the strings) of an enumerated data type, just as you cannot programmatically change an integer control into a double or a string control into a path control. The strings in an Enum are a part of its data type and thus can only be changed during edit time. It is possible to read the strings of the Enum through an Attribute Node, but you cannot write them using an Attribute Node.

If you want to programmatically change the text values in the Enum, use a text ring control instead. You can use the ring control to programmatically read and write the strings through the Strings[] attribute.


How do I hide the menu bars of a VI?

All VI attributes, including whether the menu bar and the toolbar are displayed, are set through the dialog box in VI Setup.... To access the VI Setup... dialog box pop up on the VI icon in the upper-right corner of the front panel and select VI Setup…. See Setting up VIs and SubVIs, for more details.


How do I disable mouse interrupts to improve performance?

Interrupts caused by moving the mouse or clicking it on an item take CPU time. In some extremely time-critical applications, this interrupt activity can result in a loss of data or some other problem with the application. Other than unplugging the mouse, there is no recommended method for disabling mouse interrupts. By making sure the mouse does not move during the time-critical portions of your application you can minimize its effects.


Platform Issues and Compatibilities

What is required to transfer VIs between platforms?

When a VI file is brought to another platform, no conversion is necessary for LabVIEW or BridgeVIEW to read it. When a VI is opened, it is recompiled for the new platform. This means you must include the block diagram of a VI if you want to take it to another platform. For VIs containing CINs, you must recompile the CINs on the new platform and then relink them to the ported VI. Eliminate platform-specific functions (for example, Apple Events for Macintosh, DDE for Windows, and so on) before you port a VI to another platform.

You can move VIs between platforms using networks, modems, and disks. VIs are saved in the same file format on all platforms. If you transfer VIs across a network using ftp or modem, make sure you specify a binary transfer.

If disks are the method of transfer, disk conversion utilities are required to read the disks from other platforms. Conversion utilities change the format of files stored on disk because each platform (Macintosh, Windows, Sun) saves files to disk in a different format. Most file conversion utilities not only read files from another platform, but also write files in the disk format of that platform. For example, there are utilities such as MacDisk and TransferPro available for the PC that transfer Macintosh disks to the PC format and vice versa. On the Macintosh, DOS Mounter and Apple File Exchange are two utilities that convert files on DOS-formatted disks to the Macintosh format and vice versa. For the Sun and HP, there is PC File System (PCFS) that helps SunOS and HPUX to read and write DOS-formatted disks.

To ease porting between platforms, you can save your VIs into a VI library. To facilitate saving all your VIs into a library, you can select the Development Distribution option from the Save with Options dialog box. In this way, you can save all non-vi.lib VIs, controls, and external subroutines to a single library.


Printing

All Platforms

When using automatic (programmatic) printing while executing a VI, why is the information not printed until the VI stops executing?

How do I print a single control from the front panel (for example, a graph)?

How can I print a string?

How do I print all of the data on a Waveform Chart?

Why does my G development environment crash when printing?

How do I use PostScript printing in my G development environment?

When I select PostScript printing, why does my printout yield a pile-up of printed text at the top of the page?

What should I do if the text on labels and front panel controls is clipped when the VI prints?

Windows Only

How do I select bitmap printing?


When using automatic (programmatic) printing while executing a VI, why is the information not printed until the VI
When using automatic (programmatic) printing while executing a VI, why is the information not printed until the VI stops executing?

Programmatic printing by design does not print a VI or subVI until it stops execution. For printing during execution, use a) File»Print Window to print the front panel manually, or b) a call to a subVI that accepts the input data to its controls (the front panel might be identical to that of the executing VI) and prints its “results” with programmatic printing. For more details, see the topic Programmatic Printing.


How do I print a single control from the front panel (for example, a graph)?

To print only a graph from the front panel, create a subVI with a graph on its front panel.

1.	Change the graph from an indicator to a control.

2.	Open the subVI and select Operate»Print at Completion.

3.	Assign the subVI a connector and pass the data from the graph on the main VI to the graph on the subVI.

Every time your main VI calls the subVI, it automatically prints the graph.


How can I print a string?

Use the Serial Port Init.vi in VI.lib\Instr\ SERIAL.llb to initialize the port where the printer is connected (LPT1, LPT2, and so on, on the PC, or the printer port on the Mac) and then the Serial Port Write.vi to write the string to the initialized port. The printer sees the data at the port and print it. Doing this generally requires some knowledge of the command language of the printer, but has worked well for a number of applications developed by LabVIEW and BridgeVIEW users. If you are a LabVIEW user, see the Serial I/O Common Questions topic as well as the Serial Port VIs topics for more details.

(Windows and UNIX) Use the System Exec VI to print a file through a command line function. The VI is located in Functions»Communication»AppleEvent. For example, under Windows NT/95, if you want to print a text document, use the System Exec VI with the following command:

notepad /p <document name>

Notepad has a limit of 32K. For larger documents us a different text editor.

(Macintosh) You can use the AESend Print Document VI to direct the other application to print a document. The VI is located in Functions»Communication»AppleEvent. For more details, see the topic Using Alternative Printing Methods. You can also use the programmatic print option.


How do I print all of the data on a Waveform Chart?

The Waveform Chart will only print the data that is displayed when the front panel is printed. To print all of data in a chart, including that in the history buffer, first autoscale the x-axis of the chart by popping up on the chart, showing the chart palette and locking the x-axis, or setting the x-axis programmatically through a chart Attribute Node.


Why does my G development environment crash when printing?

On Windows, this crash might be related to the video driver or printer driver.

See the question concerning random crashes on your platform in the topic Error Messages and Crashes for information on how to proceed.


How do I use PostScript printing in my G development environment?

If your printer works with PostScript language, first install and select the PostScript printer driver for your printer. In LabVIEW or BridgeVIEW go to Edit»Preferences»Printing and select PostScript printing.

If you have a PostScript printer, you can take advantage of the following benefits:

•	PostScript printouts reproduce the image of the screen more accurately.

•	PostScript reproduces patterns and line styles more accurately.


What should I do if the text on labels and front panel controls is clipped when the VI prints?

This occurs when the size of the font for the printer does not match the size of the font on the monitor.

•	If your printer supports PostScript language, use the PostScript printer driver for your printer and you will get higher quality printouts. See the question above for more information on PostScript printing.

•	Enlarge the labels and front panel controls so that, when the text expands because of a font mismatch, the text still fits in the control or label boundary.

•	Find a font which is the same size on both the monitor and the printer. Many printer drivers have font substitution algorithms to assist this process.

•	(Windows) Use bitmap printing, which will make the printout exactly match what you see on the monitor.


When I select PostScript printing, why does my printout yield a pile-up of printed text at the top of the page?

Printing translates the VI print data into PostScript (.PS) format and sends it to the Windows printer driver as PostScript text. If your printer driver does not support PostScript printing, the printout will be the actual text of the PostScript file instead of a graphics image. See the How do I use PostScript printing in my G development environment? topic for more information.


(Windows) How do I select bitmap printing?

Go to Edit»Preferences and select Printing. The last option on the screen is Bitmap printing.