National Instruments LabVIEW Application Note

User Manual

LabVIEW User Manual

January 1998 Edition
Part Number 320999B-01

Internet Support

E-mail: support@natinst.com FTP Site: ftp.natinst.com Web Address: http://www.natinst.com
BBS United States: 51 2 794 5422 BBS United Kingd om: 01635 551422 BBS France: 01 48 65 15 59

Fax-on-Demand Support

512 418 1111

Telephone Support (USA)

Tel: 512 795 8248 Fax: 512 794 5678

International Offices

Australia 03 9879 5166, Austria 0662 45 79 90 0, Belgium 02 7 57 00 20, Brazil 011 288 3336, Canada (Ontario) 905 785 0085, Canada (Québec) 514 694 8521, Denmark 45 76 26 00, Finland 09 725 725 11, France 01 48 14 24 24, Germany 089 741 31 30, Hong Kong 2645 3186, Israel 03 6120092, Italy 02 413091, Japan 03 5472 2970, Kore a 02 596 7456, Mexico 5 520 2635, Netherlands 0348 433466, Norway 32 84 84 00, Singapore 2265886, Spain 91 640 0085, Sweden 08 730 49 70, Switzerland 056 200 51 51, Taiwan 02 377 1200, United Kingdom 01635 523545

National Instruments Corporate Headquarters

6504 Bridge Point Parkway Austin, Texas 78730 -5039 USA Tel: 512 794 0100
© Copyright 1992, 1998 National Instruments Corporation. All rights reserved.

Important Information

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 accept ed for warranty work. National Instru ments will pay the shippi ng costs of returning to the owner parts which are covered by warranty.
National Instruments believes that the informatio n in this manual is accurate. The docume nt has been ca refully review ed for technical accurac y. In th e even t that te ch nical o r typograp hic al errors exis t, Nation al Inst ruments rese rves th e 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.
XCEPT AS SPECIFIED HEREIN
E
ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE BY FAULT OR NEGLIGENCE ON THE PART OF NATIONAL INSTRUMENTS SHALL BE LIMITED TO THE AMOUNT THERETOFORE PAID BY THE CUSTOME R OR INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY THEREOF
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.
ATIONAL INSTRUMENTS WILL NOT BE LIABLE FOR DAMAGES RESULTING FROM LOSS OF DATA, PROFITS, USE OF PRODUCTS
. N
ATIONAL INSTRUMENTS MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AND SPECIFICALLY DISCLAIMS
, N

Copyright

Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including photocopyi ng, recordi ng, st oring in an info rmation ret riev al syste m, or translating , in whole or in part, wit hout the prior written consent of National Instruments Corporation.
USTOMER’S RIGHT TO RECOVER DAMAGES CAUSED
. C
. This limitation of the liability of
,

Trademarks

CVI™, LabVIEW™, National Instruments™, natinst.com™, NI-488™, NI-488.2™, NI-DAQ™, NI-VISA™, NI-VXI™,
, and VXI pc™, are trademarks of National Instruments Corporation.
SCXI Product and company names listed 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 des igner. Any us e or ap plica tion of Na tiona l Instrum ents pr oducts for or inv olving m edi cal or clin ica l treatment must be performed by properly trai ned and qualifi ed medic al pe rsonne l, and al l tra ditiona l medic al safegu ards, equipment, and procedu res that are appropriate in the particula r situation to prevent serious injury or dea th should al ways continue to be used when Natio nal Instrume nts products are being use d. National In struments prod ucts are N OT intended to be a substitute for any form of establis hed process, procedure, or e quipment us ed to monit or or safeguard human heal th and safety in medical or clinical treatment.

Contents

About This Manual
Organization of This Manual................................................ ...... .....................................xxiii
Part I, Introduction to G Programming..............................................................xxiii
Part II, I/O Interfaces.........................................................................................xxiv
Part III, Analysis................................................................................................xxiv
Part IV, Network and Interapplication Communication....................................xxv
Part V, Advanced G Programming....................................................................xxvi
Appendices, Glossary, and Index......................................................................xxvi
Conventions Used in This Manual...................................................................................xxvii
Related Documentation....................................................................................................xxviii
Customer Communication...............................................................................................xxviii
Chapter 1 Introduction
What Is LabVIEW? .........................................................................................................1-1
How Does LabVIEW Work?................................................ ...... ..... ................................1-1
G Programming.................................................................................................1-2
Organization of the LabVIEW System (Windows).........................................................1-4
Startup Screen on Windows..............................................................................1-5
Organization of the LabVIEW System (Macintosh).......................................................1-6
Organization of the LabVIEW System (UNIX)..............................................................1-7
Toolkit Support................................................................................................................1-9
Where Should I Start?......................................................................................................1-9
P
I
ART
Introduction to G Programming
Chapter 2 Creating VIs
What is a Virtual Instrument?..........................................................................................2-1
How Do You Build a VI?................................................................................................2-1
VI Hierarchy..................................... ....................................... ..........................2-1
Controls, Constants, and Indicators...................................................................2-2
Terminals...........................................................................................................2-3
©
National Instruments Corporation v LabVIEW User Manual
Contents
Wires.................................................................................................................2-4
VI Documentation............................................................ ..... ...... ......................2-10
What is a SubVI?.............................................................................................................2-12
Hierarchy Window............................................................................................2-12
Icon and Connector...........................................................................................2-14
Opening, Operating, and Changing SubVIs......................................................2-19
Front Panel........................................................................................................2-19
Block Diagram..................................................................................................2-20
How Do You Debug a VI?.............................................................................................. 2-21
Chapter 3 Loops and Charts
What is a Structure?.........................................................................................................3-1
Charts...............................................................................................................................3-2
Chart Modes......................................................................................................3-2
Faster Chart Updates.........................................................................................3-3
Overlaid Versus Stacked Plots.......................................................................... 3-3
While Loops ....................................................................................................................3-4
Front Panel........................................................................................................3-5
Block Diagram..................................................................................................3-6
Mechanical Action of Boolean Switches..........................................................3-8
Timing...............................................................................................................3-10
Preventing Code Execution in the First Iteration..............................................3-12
Shift Registers .................................................................................................................3-13
Front Panel........................................................................................................3-15
Block Diagram..................................................................................................3-15
Using Uninitialized Shift Registers...................................................................3-17
Front Panel........................................................................................................3-19
Block Diagram..................................................................................................3-20
For Loops.........................................................................................................................3-22
Numeric Conversion.........................................................................................3-24
Front Panel........................................................................................................3-25
Block Diagram..................................................................................................3-26
Tip Strips ............................................................................................2-4
Wire Stretching...................................................................................2-5
Selecting and Deleting Wires.............................................................2-5
Bad Wires...........................................................................................2-6
Search Hierarchy ................................................................................2-14
LabVIEW User Manual vi
©
National Instruments Corporation
Chapter 4 Case and Sequence Structures and the Formula Node
Case Structure...................................................... ...... ...... ................................................4-2
Front Panel.........................................................................................................4-2
Block Diagram...................................................................................................4-3
VI Logic................................ ...... ....................................... ................................4-4
Sequence Structures.........................................................................................................4-5
Front Panel.........................................................................................................4-5
Modifying the Numeric Format..........................................................4-6
Setting the Data Range........................................................................4-7
Block Diagram...................................................................................................4-7
Formula Node.................................................................................................................. 4-11
Front Panel.........................................................................................................4-14
Block Diagram...................................................................................................4-14
Artificial Data Dependency.............................................................................................4-15
Chapter 5 Arrays, Clusters, and Graphs
Arrays...............................................................................................................................5-1
How Do You Create and Initialize Arrays? ......................................................5-1
Array Controls, Constants, and Indicators..........................................5-2
Auto-Indexing....................................................................................................5-2
Front Panel.........................................................................................................5-3
Block Diagram...................................................................................................5-4
Multiplot Graphs ...............................................................................................5-7
Using Auto-Indexing to Set the For Loop Count..............................................5-10
Using Array Functions ......................................................................................5-10
Build Array .........................................................................................5-10
Initialize Array....................................................................................5-11
Array Size ...........................................................................................5-12
Array Subset........................................................................................5-13
Index Array.........................................................................................5-14
Front Panel.........................................................................................................5-17
Block Diagram...................................................................................................5-18
Efficient Memory Usage: Minimizing Data Copies..........................................5-18
What is Polymorphism?...................................................................................................5-19
Clusters ............................................................................................................................ 5-20
Contents
©
National Instruments Corporation vii LabVIEW User Manual
Contents
Graphs..............................................................................................................................5-20
Customizing Graphs..........................................................................................5-20
Data Acquisition Arrays....................................................................................5-22
Front Panel........................................................................................................5-22
Block Diagram..................................................................................................5-23
Intensity Plots..................................................................................................................5-25
Chapter 6 Strings and File I/O
Strings.............................................................................................................................. 6-1
Creating String Controls and Indicators............................................................6-1
Strings and File I/O........................................................................................... 6-2
Front Panel........................................................................................................6-2
Block Diagram..................................................................................................6-3
Front Panel........................................................................................................6-4
Block Diagram..................................................................................................6-4
Front Panel........................................................................................................6-7
Block Diagram..................................................................................................6-8
File I/O.............................................................................................................................6-9
File I/O Functions .............................................................................................6-9
Writing to a Spreadsheet File..........................................................................................6-11
Front Panel........................................................................................................6-12
Block Diagram..................................................................................................6-12
Front Panel........................................................................................................6-14
Block Diagram..................................................................................................6-15
Front Panel........................................................................................................6-16
Block Diagram..................................................................................................6-17
Using the File I/O Functions...........................................................................................6-18
Specifying a File ................................................... ..... ...... .................................6-18
Paths and Refnums............................................................................................ 6-19
File I/O Examples .............................................................................................6-19
Datalog Files....................................................................................................................6-20
Graph Cursors.....................................................................................5-21
Graph Axes.........................................................................................5-22
LabVIEW User Manual viii
©
National Instruments Corporation
P
II
ART
I/O Interfaces
Chapter 7 Getting Started with a LabVIEW Instrument Driver
What is a LabVIEW Instrument Driver?.........................................................................7-1
Where Can I Get Instrument Drivers?.............................................................................7-2
Where Should I Install My LabVIEW Instrument Driver? .............................................7-2
How Do I Access the Instrument Driver VIs?.................................................................7-3
Instrument Driver Structure........................................................ .....................................7-4
Obtaining Help for Your Instrument Driver VIs .............................................................7-6
Running the Getting Started VI Interactively
(Selecting the GPIB Address, Serial Port, and Logical Address).................................7-7
Interactively Testing Component VIs..............................................................................7-8
Building Your Application ..............................................................................................7-9
Related Topics .................................................................................................................7-10
Open VISA Session Monitor VI........................................................................7-10
Error Handling...................................................................................................7-11
Testing Communication with Your Instrument.................................................7-11
Developing a Quick and Simple LabVIEW Instrument Driver.......................................7-12
Modifying an Existing Driver ...........................................................................7-12
Developing a Simple Driver..............................................................................7-13
Developing a Full-Featured Driver ...................................................................7-17
Using LabVIEW with IVI Instrument Drivers..................................................7-17
Contents
Chapter 8 LabVIEW VISA Tutorial
What is VISA?.................................................................................................................8-1
Supported Platforms and Environments............................................................ 8-1
Why Use VISA? ........................................................ ...... ..... ...........................................8-2
VISA Is the Standard.........................................................................................8-2
Interface Independence...................................... ....................................... .........8-2
Platform Independence......................................................................................8-2
Easily Adapted to the Future.............................................................................8-2
Basic VISA Concepts ......................................................................................................8-3
Default Resource Manager, Session, and Instrument Descriptors....................8-3
How Do I Search for Resources?......................................................................8-4
What is a VISA Class?......................................................................................8-5
Popping Up on a VISA Control..........................................................8-6
Opening a Session ............................................. ..... ........................................ ...8-6
©
National Instruments Corporation ix LabVIEW User Manual
Contents
How Do the Default Resource Manager, Instrument Descriptors,
and Sessions Relate?......................................................................................8-7
Closing a Session..............................................................................................8-8
When Is It a Good Idea to Leave a Session Open?.............................8-8
Error Handling with VISA................................................................................8-9
Easy VISA VIs.................................. ..... ...... ...... ....................................... ......................8-11
Message-Based Communication.....................................................................................8-11
How Do I Write To and Read From a Message-Based Device?......................8-12
Register-Based Communication (VXI only)...................................................................8-12
Basic Register Access.......................................................................................8-14
Basic Register Move.........................................................................................8-15
Low-Level Access Functions............................................................................8-15
Using VISA to Perform Low-Level Register Accesses ..................... 8-15
Bus Errors........................................................................................... 8-17
Comparison of High-Level and Low-Level Access ......................................... 8-17
Speed .................................................................................................. 8-17
Ease of Use.........................................................................................8-18
Accessing Multiple Address Spaces...................................................8-18
VISA Properties...............................................................................................................8-18
Serial .................................................................................................................8-20
GPIB.................................................................................................................. 8-21
VXI....................................................................................................................8-21
VISA Property Examples..................................................................................8-22
Serial Write and Read.........................................................................8-22
How Do I Set a Termination Character for a Read Operation?.......... 8-22
VXI Properties.................................................................................... 8-23
Events..............................................................................................................................8-24
GPIB SRQ Events.............................................................................................8-24
Trigger Events...................................................................................................8-25
Interrupt Events.................................................................................................8-25
Locking............................................................................................................................8-26
Shared Locking.................................................................................................8-28
Platform-Specific Issues..................................................................................................8-28
Programming Considerations............................................................................8-29
Multiple Applications Using the NI-VISA Driver............................. 8-29
Multiple Interface Support Issues.....................................................................8-29
VXI and GPIB Platforms....................................................................8-29
Multiple GPIB-VXI Support .................................. ...... ...... ................8-30
Serial Port Support..............................................................................8-30
VME Support...................................................................................... 8-30
Debugging A VISA Program..........................................................................................8-31
Debugging Tool for Windows 95/NT...............................................................8-32
VISAIC............................................................................................................................8-32
LabVIEW User Manual x
©
National Instruments Corporation
Chapter 9 Introduction to LabVIEW GPIB Functions
Types of Messages...........................................................................................................9-1
The Controller-In-Charge and System Controller...........................................................9-3
Compatible GPIB Hardware............................................................................................9-3
LabVIEW for Windows 95 and Windows 95-Japanese....................................9-3
LabVIEW for Windows NT............. ..... ...... ....................................... ...............9-3
LabVIEW for Windows 3.1 .................................................... ..........................9-4
LabVIEW for Mac OS....................................... ..... ........................................ ...9-4
LabVIEW for HP-UX.................................................................... ....................9-4
LabVIEW for Sun............................. ....................................... ..........................9-5
LabVIEW for Concurrent PowerMAX........................ .....................................9-5
Chapter 10 Serial Port VIs
Handshaking Modes ........................................................................................................10-2
Software Handshaking—XON/XOFF...............................................................10-2
Error Codes......................................................................................................................10-2
Port Number.................................................... ..... ........................................ ....................10-3
Windows 95 and 3.x..........................................................................................10-3
Macintosh..........................................................................................................10-3
UNIX.................................................................................................................10-3
Contents
P
III
ART
Analysis
Chapter 11 Introduction to Analysis in LabVIEW
The Importance of Data Analysis....................................................................................11-1
Full Development System................................................................................................11-3
Analysis VI Overview .....................................................................................................11-3
Notation and Naming Conventions..................................................................................11-6
Data Sampling.................................................................................................................. 11-9
Sampling Signals...............................................................................................11-9
Sampling Considerations...................................................................................11-10
Why Do You Need Anti-Aliasing Filters?........................................................11-13
Why Use Decibels? ................................................ ...........................................11-14
©
National Instruments Corporation xi LabVIEW User Manual
Contents
Chapter 12 Signal Generation
Normalized Frequency....................................................................................................12-1
Front Panel........................................................................................................12-5
Block Diagram..................................................................................................12-6
Wave and Pattern VIs......................................................................................................12-7
Phase Control.................................................................................................... 12-7
Front Panel........................................................................................................12-8
Block Diagram..................................................................................................12-9
Front Panel........................................................................................................12-11
Block Diagram..................................................................................................12-12
Chapter 13 Digital Signal Processing
The Fast Fourier Transform (FFT)..................................................................................13-1
DFT Calculation Example ................................................................................13-2
Magnitude and Phase Information....................................................................13-4
Frequency Spacing between DFT/FFT Samples.............................................................13-5
Fast Fourier Transforms....................................................................................13-7
Zero Padding.....................................................................................................13-8
FFT VIs in the Analysis Library.......................................................................13-9
Front Panel........................................................................................................13-10
Block Diagram..................................................................................................13-11
Two-Sided FFT.................................................................................................13-12
One-Sided FFT..................................................................................................13-12
The Power Spectrum .......................................................................................................13-14
Loss of Phase Information................................................................................13-14
Frequency Spacing between Samples...............................................................13-14
Summary..........................................................................................................................13-15
Chapter 14 Smoothing Windows
Introduction to Smoothing Windows..............................................................................14-1
About Spectral Leakage and Smoothing Windows.........................................................14-2
Windowing Applications.................................................................................................14-7
Characteristics of Different Types of Window Functions...............................................14-7
Rectangular (None)...........................................................................................14-7
Hanning.............................................................................................................14-8
Hamming...........................................................................................................14-9
Kaiser-Bessel ....................................................................................................14-10
Triangle.............................................................................................................14-11
LabVIEW User Manual xii
©
National Instruments Corporation
Flattop................................................................................................................14-11
Exponential........................................................................................................14-12
Windows for Spectral Analysis Versus Windows for Coefficient Design......................14-13
What Type of Window Do I Use?.....................................................................14-16
Front Panel.........................................................................................................14-17
Block Diagram...................................................................................................14-18
Chapter 15 Spectrum Analysis and Measurement
Introduction to Measurement VIs....................................................................................15-1
You Will Learn................................................................................................................15-4
Spectrum Analysis...........................................................................................................15-4
Calculating the Amplitude and Phase Spectrum of a Signal.............................15-4
Front Panel.........................................................................................................15-5
Block Diagram...................................................................................................15-6
Calculating the Frequency Response of a System.............................................15-7
Front Panel.........................................................................................................15-8
Block Diagram...................................................................................................15-9
Harmonic Distortion........................................................................................................15-10
Total Harmonic Distortion ................................................................................15-11
Using the Harmonic Analyzer VI......................................................................15-12
Block Diagram...................................................................................................15-14
Front Panel.........................................................................................................15-15
Summary..........................................................................................................................15-16
Contents
Chapter 16 Filtering
Introduction to Digital Filtering Functions ......................................................................16-1
Ideal Filters ......................................................................................................................16-3
Practical (Nonideal) Filters..............................................................................................16-4
The Transition Band.......................................................................................... 16-4
Passband Ripple and Stopband Attenuation......................................................16-5
IIR and FIR Filters...........................................................................................................16-6
Filter Coefficients..............................................................................................16-8
Infinite Impulse Response Filters....................................................................................16-8
Cascade Form IIR Filtering...............................................................................16-10
Butterworth Filters.............................................................................................16-12
Chebyshev Filters..............................................................................................16-12
Chebyshev II or Inverse Chebyshev Filters.......................................................16-13
Elliptic (or Cauer) Filters...................................................................................16-14
Bessel Filters .....................................................................................................16-15
©
National Instruments Corporation xiii LabVIEW User Manual
Contents
Finite Impulse Response Filters......................................................................................16-16
Nonlinear Filters..............................................................................................................16-20
How Do I Decide Which Filter to Use?..........................................................................16-20
Summary..........................................................................................................................16-24
Chapter 17 Curve Fitting
Introduction to Curve Fitting...........................................................................................17-1
General LS Linear Fit Theory.........................................................................................17-6
How to Use the General LS Linear Fit VI........................................... ............................17-11
Nonlinear Lev-Mar Fit Theory........................................................................................17-18
Using the Nonlinear Lev-Mar Fit VI...............................................................................17-19
Designing FIR Filters by Windowing...............................................................16-17
Designing Optimum FIR Filters Using the Parks-McClellan Algorithm.........16-18
Designing Narrowband FIR Filters...................................................................16-18
Windowed FIR Filters....................................................................................... 16-19
Optimum FIR Filters.........................................................................................16-19
FIR Narrowband Filters....................................................................................16-19
Front Panel........................................................................................................16-22
Block Diagram..................................................................................................16-23
Applications of Curve Fitting ...........................................................................17-3
Front Panel........................................................................................................17-4
Block Diagram..................................................................................................17-5
Building the Observation Matrix......................................................................17-15
Front Panel........................................................................................................17-21
Block Diagram..................................................................................................17-22
Chapter 18 Linear Algebra
Linear Systems and Matrix Analysis...............................................................................18-1
Types of Matrices..............................................................................................18-1
Determinant of a Matrix....................................................................................18-2
Transpose of a Matrix.......................................................................................18-3
Can You Obtain One Vector as a Linear Combination
of Other Vectors? (Linear Independence).......................................18-3
How Can You Determine Linear Independence? (Matrix Rank).......18-4
“Magnitude” (Norms) of Matrices....................................................................18-5
Determining Singularity (Condition Number)..................................................18-7
Basic Matrix Operations and Eigenvalues-Eigenvector Problems..................................18-9
Dot Product and Outer Product............................................. ...... ......................18-10
Eigenvalues and Eigenvectors ..........................................................................18-12
LabVIEW User Manual xiv
©
National Instruments Corporation
Matrix Inverse and Solving Systems of Linear Equations ..............................................18-14
Solutions of Systems of Linear Equations.........................................................18-15
Front Panel.........................................................................................................18-17
Block Diagram...................................................................................................18-18
Matrix Factorization ........................................................................................................18-20
Pseudoinverse....................................................................................................18-21
Summary..........................................................................................................................18-21
Chapter 19 Probability and Statistics
Probability and Statistics .................................................................................................19-1
Statistics...........................................................................................................................19-3
Mean..................................................................................................................19-3
Median...............................................................................................................19-3
Sample Variance.......................................... ...... ..... ........................................ ...19-4
Standard Deviation............................................................................................19-5
Mode..................................................................................................................19-6
Moment About Mean ........................................................................................19-6
Histogram..........................................................................................................19-7
Mean Square Error (MSE).................................................................................19-10
Root Mean Square (RMS).................................................................................19-11
Probability........................................................................................................................19-12
Random Variables.............................................................................................19-12
Normal Distribution...........................................................................................19-15
Front Panel.........................................................................................................19-17
Block Diagram...................................................................................................19-18
Summary..........................................................................................................................19-20
Contents
P
IV
ART
Network and Interapplication Communication
Chapter 20 Introduction to Communication
LabVIEW Communication Overview............................. ..... ........................................ ...20-1
Introduction to Communication Protocols.......................................................................20-1
File Sharing Versus Communication Protocols...............................................................20-2
Client/Server Model.........................................................................................................20-3
A General Model for a Client............................................................................20-3
A General Model for a Server...........................................................................20-4
©
National Instruments Corporation xv LabVIEW User Manual
Contents
Chapter 21 TCP and UDP
Overview .........................................................................................................................21-1
Internet Protocol (IP) .......................................................................................................21-2
User Datagram Protocol (UDP).......................................................................................21-3
Transmission Control Protocol (TCP).............................................................................21-4
LabVIEW and TCP/IP .................................... ..................................................21-2
Internet Addresses............................................................................................. 21-2
Using UDP........................................................................................................21-3
Using TCP.........................................................................................................21-4
TCP Versus UDP................................................................................21-5
TCP Client Example...........................................................................21-5
Timeouts and Errors ...........................................................................21-6
TCP Server Example..........................................................................21-6
TCP Server with Multiple Connections..............................................21-7
Setup..................................................................................................................21-7
UNIX ..................................................................................................21-7
Macintosh ...........................................................................................21-8
Windows 3.x.......................................................................................21-8
Windows 95 and Windows NT ..........................................................21-8
Chapter 22 ActiveX Support
ActiveX Automation Server Functionality......................................................................22-2
ActiveX Server Properties and Methods.........................................................................22-3
ActiveX Automation Client Functionality...................................................................... 22-3
ActiveX Client Examples................................................................................................22-4
Converting ActiveX Variant Data to G Data....................................................22-4
Adding a Workbook to Microsoft Excel from LabVIEW ................................22-5
Chapter 23 Using DDE
DDE Overview................................................................................................................23-1
Services, Topics, and Data Items......................................................................23-2
Examples of Client Communication with Excel...............................................23-2
LabVIEW VIs as DDE Servers.........................................................................23-4
Requesting Data Versus Advising Data................................ ...... ...... ................23-6
Synchronization of Data......................................................................... ...........23-7
LabVIEW User Manual xvi
©
National Instruments Corporation
Networked DDE................................................................................................23-8
Using NetDDE....................................................................................23-10
Server Machine.....................................................................23-10
Client Machine .....................................................................23-12
Chapter 24 AppleEvents
AppleEvents .....................................................................................................................24-1
Sending AppleEvents........................................................................................24-2
Client Server Model ..........................................................................................24-2
AppleEvent Client Examples ............................................................................24-3
Launching Other Applications............................................................24-3
Sending Events to Other Applications................................................24-3
Dynamically Loading and Running a VI............................................24-4
Chapter 25 Program-to-Program Communication
Introduction to PPC .........................................................................................................25-1
Ports, Target IDs, and Sessions.........................................................................25-2
PPC Client Example..........................................................................................25-3
PPC Server Example .........................................................................................25-4
PPC Server with Multiple Connections.............................................................25-5
Contents
P
V
ART
Advanced G Programming
Chapter 26 Customizing VIs
How Do You Customize a VI?........................................................................................26-1
Set Window Options..........................................................................................26-1
SubVI Node Setup.............................................................................................26-2
Front Panel.........................................................................................................26-2
Block Diagram...................................................................................................26-3
Front Panel.........................................................................................................26-6
Block Diagram...................................................................................................26-7
©
National Instruments Corporation xvii LabVIEW User Manual
Contents
Chapter 27 Front Panel Object Attributes
Front Panel........................................................................................................27-3
Block Diagram..................................................................................................27-3
Chapter 28 Program Design
Use Top-Down Design....................................................................................................28-1
Make a List of User Requirements ...................................................................28-1
Design the VI Hierarchy...................................................................................28-1
Create the Program............................................................................................28-3
Plan Ahead with Connector Panes .................................................................................. 28-3
SubVIs with Required Inputs........................................... ..... ............................28-4
Good Diagram Style........................................................................................................28-4
Watch for Common Operations........................................................................28-5
Use Left-to-Right Layouts................................................................................28-5
Check for Errors................................................................................................28-6
Watch Out for Missing Dependencies..............................................................28-7
Avoid Overuse of Sequence Structures............................................................28-8
Study the Examples...........................................................................................28-9
Chapter 29 Where to Go from Here
Other Useful Resources...................................................................................................29-1
Solution Wizard and Search Examples............................................................. 29-1
Data Acquisition Applications..........................................................................29-1
G Programming Techniques.............................................................................29-1
Function and VI Reference...............................................................................29-2
Resources for Advanced Topics......................................................................................29-2
Attribute Nodes.................................................................................................29-2
VI Setup and Preferences..................................................................................29-2
Local and Global Variables...............................................................................29-3
Creating SubVIs........................................ ........................................ ................29-3
VI Profiles....................................................... ...... ....................................... .....29-3
Control Editor ...................................................................................................29-4
List and Ring Controls......................................................................................29-4
Call Library Function.................................................................. ......................29-4
Code Interface Nodes............................................................ ...... ......................29-4
LabVIEW User Manual xviii
©
National Instruments Corporation
Appendices, Glossary, and Index
Appendix A Analysis References
Appendix B Common Questions
Appendix C Customer Communication
Glossary
Index
Figures, Tables, and Activities

Figures

Figure 11-1. Analog Signal and Corresponding Sampled Version..............................11-9
Figure 11-2. Aliasing Effects of an Improper Sampling Rate.....................................11-10
Figure 11-3. Actual Signal Frequency Components....................................................11-11
Figure 11-4. Signal Frequency Components and Aliases............................................11-12
Figure 11-5. Effects of Sampling at Different Rates....................................................11-13
Contents
Figure 14-1. Periodic Waveform Created from Sampled Period.................................14-2
Figure 14-2. Sine Wave and Corresponding Fourier Transform .................................14-3
Figure 14-3. Spectral Representation When Sampling a Nonintegral Number
of Samples............................................................................................14-4
Figure 14-4. Time Signal Windowed Using a Hamming Window..............................14-6
Figure 22-1. Preferences Dialog Box, Server Configuration.......................................22-2
Figure 22-2. Block Diagram Displaying ActiveX Variant Data to G Data.................22-4
Figure 22-3. Adding a Workbook to Microsoft Excel.................................................22-5
Figure 25-1. PPC VI Execution Order (Used by Permission
of Apple Computer, Inc.)......................................................................25-5
©
National Instruments Corporation xix LabVIEW User Manual
Contents

Tables

Table 22-1. Functions for ActiveX Automation Client Support................................ 22-3
Table 23-1. Values to Add in Place of Default..........................................................23-11

Activities

Activity 2-1. Create a VI..............................................................................................2-7
Activity 2-2. Document a VI........................................................................................2-10
Activity 2-3. Create an Icon and Connector.................................................................2-17
Activity 2-4. Call a SubVI............................................................................................2-19
Activity 2-5. Debug a VI in LabVIEW........................................................................2-22
Activity 3-1. Experiment with Chart Modes................................................................3-3
Activity 3-2. Use a While Loop and a Chart................................................................3-5
Activity 3-3. Change the Mechanical Action of a Boolean Switch.............................3-9
Activity 3-4. Control Loop Timing..............................................................................3-10
Activity 3-5. Use a Shift Register ................................................................................3-15
Activity 3-6. Create a Multiplot Chart .........................................................................3-19
Activity 3-7. Use a For Loop........................................................................................3-25
Activity 4-1. Use the Case Structure............................................................................4-2
Activity 4-2. Use a Sequence Structure........................................................................ 4-5
Activity 4-3. Use the Formula Node............................................................................4-13
Activity 5-1. Create an Array with Auto-Indexing ......................................................5-3
Activity 5-2. Use Auto-Indexing on Input Arrays .......................................................5-8
Activity 5-3. Use the Build Array Function.................................................................5-17
Activity 5-4. Use the Graph and Analysis VIs.............................................................5-22
Activity 6-1. Concatenate a String...............................................................................6-2
Activity 6-2. Use Format Strings .................................................................................6-4
Activity 6-3. String Subsets and Number Extraction...................................................6-7
Activity 6-4. Write to a Spreadsheet File.....................................................................6-12
Activity 6-5. Append Data to a File.............................................................................6-14
Activity 6-6. Read Data from a File.............................................................................6-16
Activity 12-1. Learn More about Normalized Frequency..............................................12-5
Activity 12-2. Use the Sine Wave and Sine Pattern VIs................................................12-8
Activity 12-3. Build a Function Generator.....................................................................12-11
LabVIEW User Manual xx
©
National Instruments Corporation
Contents
Activity 13-1. Use the Real FFT VI ...............................................................................13-10
Activity 14-1. Compare a Windowed and Nonwindowed Signal ..................................14-17
Activity 15-1. Use the Amplitude and Phase Spectrum VI............................................15-5
Activity 15-2. Compute the Frequency and Impulse Response......................................15-8
Activity 15-3. Calculate Harmonic Distortion................................................................15-14
Activity 16-1. Extract a Sine Wave................................................................................16-22
Activity 17-1. Use the Curve Fitting VIs........................................................................17-4
Activity 17-2. Use the General LS Linear Fit VI ...........................................................17-14
Activity 17-3. Use the Nonlinear Lev-Mar Fit VI..........................................................17-20
Activity 18-1. Compute the Inverse of a Matrix.............................................................18-17
Activity 18-2. Solve a System of Linear Equations........................................................18-19
Activity 19-1. Use the Normal Distribution VI..............................................................19-17
Activity 26-1. Use Setup Options for a SubVI...............................................................26-2
Activity 27-1. Use an Attribute Node.............................................................................27-3
©
National Instruments Corporation xxi LabVIEW User Manual

About This Manual

The LabVIEW User Manual provides information about creating virtual instruments (VIs). This manual also includes information about the interfaces to which you can input and output data, using LabVIEW VIs to perform analysis operations, and how LabVIEW handles network and interapplication communication. Please read the LabVIEW Release Notes before you use the LabVIEW User Manual.

Organization of This Manual

The LabVIEW User Manual is organized as follows.
Chapter 1, Introduction, introduces the unique LabVIEW approa ch to programming. It also e xplains ho w to start us ing LabVIEW to de v elop programs.

Part I, Introduction to G Programming

This section contains basic information ab out creating virtual instruments (VIs), using VIs in other VIs, programming structures such as loops, and data structures such as arrays and strings.
Part I, Introduction to G Programming, contains the following chapters.
Chapter 2, Creating VIs, explains how to create a VI including the front panel, which is the user interface, and the block diagram, which is the source code. Once you create a VI, you can use it in other VIs.
Chapter 3, Loops and Charts, shows you how to rep eat portio ns of the block diagram using a While Loop and a For Loop. This chapter also explains how to display graphically multiple points, one at a time, on a chart.
Chapter 4, Case and Sequence Structures and the Formula Node, explains how to use the Case structure, which is a conditional structure, the Sequence structure, which aids in establishing ex ecution order , and the Formula Node, which aids in executing mathematical formulas.
Chapter 5, Arrays, Cl usters, and Gr aphs, shows how to display a group or array of data points on a graph. You can pass scale parameters as well as an array of data points to a graph by creating a cluster, which is a group of data different data types.
Chapter 6, Strings and File I/O, introduces string controls and indicators and file i npu t and out pu t operat io ns .
©
National Instruments Corporation xxiii LabVIEW User Manual
About This Manual

Part II, I/O Interfaces

This section contains basic information on the interfaces to which you can input and output data, which are data acquisition, GPIB, serial, and VXI. Refer to the Data Acquisition Basics Manual for basic information on real-time data acquisition. VISA (Virtual Instrument Software Architecture) is a single software library that interfaces with GPIB, serial, and VXI instruments. LabVIEW applications developed especially for a specific instrument are called instrument drivers. National Instruments provides several instrument drivers using the VISA library , but you can also build your own instrument drivers.
Part II, I/O Interfaces, contains the following chapters.
Chapter 7, Getting Started with a LabVIEW Instrument Driver,
Chapter 8, LabVIEW VISA Tutorial, shows you how to implement
Chapter 9, Introduction to LabVIEW GPIB Functions, explains how
Chapter10, Serial Port VIs, explains the important factors that affect
explains how to create and use National Instruments instrument drivers.
common VISA applications using message-based and register-based communication as well as events and locking.
the GPIB operates and the difference between the IEEE 488 and IEEE 488.2 interface.
serial communication.

Part III, Analysis

This section contains basic information on analysis of data, signal processing, signal generation, linear algebra, curve fitting, probability, and statistics.
Part III, Analysis, contains the following chapters.
Chapter11, Introduction to Analysis in LabVIEW, introduces concepts that apply to all analysis applications, including supported functionality, notation and naming conventions, and sampling signal methods.
Chapter12, Signal Generation, explains how to produce signals using the normalized frequency and how to build a simulated function generator.
Chapter13, Digital Signal Processing, shows the difference between the Fast Fourier Transform (FFT) and the Discrete Fourier Transform (DFT).
LabVIEW User Manual xxiv
©
National Instruments Corporation
Chapter14, Smoothing Wind ow s, explains how using windows prevents spectral leakage and improves the analysis of acquired signals.
Chapter15, Spectrum Analysis and Measurement, shows how to determine the amplitude and phase sp ectrum, develop a spectrum analyzer, and determine the total harmonic distortion (THD).
Chapter16, Filtering, explains how to filter unnecessary frequencies from signals using infinite impulse response filters (IIR), finite impulse response filters (FIR), and nonlinear filters.
Chapter17, Curve Fitting, shows how to extract information from a data set to create a data trend description.
Chapter18, Linear Algebra, explains how to perform matrix computation and analysis.
Chapter19, Probability and Statistics, explains some fundamental concepts of probability and statistics, and shows how to use these concepts in solving real-world problems.
Part IV, Network and Interapplication Communication
This section contai ns basic inform ation abou t network an d interapp lication communication.
About This Manual
Part IV, Network and Interapplication Communication, contains the following chapters.
Chapter20, Introduction to Communication, introduces the way LabVIEW handles networking and interapplication communication.
Chapter21, TCP and UDP, explains basic concepts of Transmission Control Protocol (TCP), Internet Protocol (IP ), and internet addres ses.
Chapter22, Acti veX Support, shows how LabVIEW can be an ActiveX server and client. ActiveX is the same as OLE Automation communication.
Chapter23, Using DDE, explains ho w to use Dynamic Data Exchange (DDE) to communicate between Windows applications. DDE can be used in a client, a server, and across a network.
Chapter24, AppleEvents, shows how AppleEvents are used to communicate between LabVIEW and other Macintosh applications. LabVIEW can be an AppleEvents server and client.
Chapter25, Program-to-Program Communication, explains how LabVIEW can communicate to other Macintosh applications using Program-to-Program Communication (PPC).
©
National Instruments Corporation xxv LabVIEW User Manual
About This Manual

Part V, Advanced G Programming

This section contains information on VI customization; programmatic control of front panel objects, VIs, and LabVIEW; and tips on how to design complex applications.
Part V, Advanced G Programming, contains the following chapters.
Chapter26, Customizing VIs, shows how to use VI Setup… and VI Node Setup… to customize the appearance and execution behavior of a VI when it is running.
Chapter27, Front Panel Object Attributes, describes objects called attribute nodes, which are special block diagram nodes that control the appearance and functional characteristics of controls and indicators.
Chapter28, Program Design, explains techniques to use when creating programs and offers programming-style guidelines.
Chapter29, Where to Go from Here, provides information about resources you can use to create your applications successfully.

Appendices, Glossary, and Index

•AppendixA, Analysis References, lists the reference material used to produce the Analysis VIs in LabVIEW . These references contain more information on the theories and algorithms implemented in the analysis library.
•AppendixB, Common Questions, answers common questions about LabVIEW networking communications and Instrument I/O , specifically GPIB and serial I/O.
•AppendixC, Customer Communication, contains forms to help you gather the information necessary to help us solve your technical problems and a form you can use to comment on the product documentation.
•The Glossary contains an alphabetical list of terms used in this manual, including abbreviations, acronyms, metric prefixes, mnemonics, and symbols.
•The Index contains an alphabetical list of key terms and topics in this manual, including the page where you can find each one.
LabVIEW User Manual xxvi
©
National Instruments Corporation
About This Manual

Conventions Used in This Manual

The following conventions are used in this manual:
< > Angle brackets enclose the name of a key on the keyboard—for example,
<shift>. Angle brackets containing numbers separated by an ellipsis represent a range of values associated with a bit or signal name— for example, DBIO<3..0>.
- A hyphen between two or more key names enclosed in angle brackets denotes that you should simultaneously press the named keys— for example, <Control-Alt-Delete>.
» The » symb ol leads you throu gh nested menu ite ms and dialog box op tions
to a final action. The sequence File»Page Setup»Options» Substitute Fonts directs you to pull down the File menu, select the Page Setup item, select Options, and finally select the Substitute Fonts options from the last dialog box.
This icon to the left of bold te xt denotes the be ginning of an acti vity, which contains step-by-step instructions you can follow to learn more about LabVIEW.
This icon to the left of bold text denotes the end of an activity, which contains step-by-step instructions you can follow to learn more about LabVIEW.
This icon to the left of bold italicized text denotes a note, which alerts you to important information.
!
bold Bold text denotes the names of menus, menu items, parameters, dialo g
bold italic Bold italic text denotes an activity objective, note, caution, or warning.
bold monospace Bold monospace text denotes messages and responses that the computer
italic Italic text denotes variables, emphasis, a cross reference, or an introduction
©
National Instruments Corporation xxvii LabVIEW User Manual
This icon to the left of bold italicized text denotes a caution, which advises you of precautions to take to avoid injury, data loss, or a system crash.
boxes, dialog box buttons or options, icons, windows, Windows 95 tabs, or LEDs.
automatically prints to the screen.
to a key concept. This font also denotes text from which you supply the appropriate word or value, as in Windows 3.x.
About This Manual
monospace Text in this font denotes text or characters that you should literally enter
from the keyboard, sections of code, programming examples, and syntax examples. This font is also used for the proper n ames of disk d ri ves, p aths, directories, progr ams, su bprog rams, s ubrouti nes, d e vice n ames, functio ns, operations, variables, filenames and extensions, and for statements and comments taken from programs.
paths Paths in this manual are denoted using backslashes (\) to separate drive
names, director i es, fol ders, and files.
Platform Text in this font denotes information related to a specific platform.

Related Documentation

G Programming Reference Manual
LabVIEW Data Acquisition Basics Manual
LabVIEW Function and VI Reference Manual
LabVIEW QuickStart Guide
LabVIEW Online Reference, available by selecting
Help»Online Reference
LabVIEW Online Tutorial LabVIEW dialog box
G Programming Quick Reference Card
LabVIEW Getting Starte d Card
LabVIEW Release Notes
LabVIEW Upgrade Notes
(Windows only), which you launch f rom t he

Customer Communication

National Instruments wants to receive your comments on our products and manuals. We are interested in the applications you develop with our products, and we want to help if you have problems with them. To make it easy for you to contact us, this manual contains comment and configuration forms for you to complete. These forms are in Appendix C, Customer
Communication, at the end of this manual.
LabVIEW User Manual xxviii
©
National Instruments Corporation
Introduction
This chapter introduces the unique LabVIEW approach to programming. It also explains how to start using LabVIEW to develop programs. The chapter refers you to other chapters or manuals for more information.

What Is LabVIEW?

LabVIEW is a program development enviro nment, much like modern C or BASIC development environments, and National Instr uments LabWindows/CVI. 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 for any programming task. LabVIEW includes 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.
1

How Does LabVIEW Work?

LabVIEW is a general-purpose programming system, but it also includes libraries of functions and devel opment tool s designed specifically fo r data acquisition and instrument control. LabVIEW programs are called virtual instruments (VIs) because their appearance and operation can imitate actual instruments. However, VIs are similar to the functions of conventional language programs.
A VI consists of an interactive user interface, a dataflow diagram that serves as the source code, and icon connections that allow the VI to be
©
National Instruments Corporation 1-1 LabVIEW User Manual
Chapter 1 Introduction
called from higher level VIs. More specifically, VIs are structured as follows:
The interactive user interface of a VI is called the front panel, because it simulates the pane l o f a physica l instru ment. T he fr ont panel can contain knobs, push buttons, graphs, and othe r controls and indicators. Yo u ente r data using a m ouse and k eyboa rd , and then view th e re su lt s o n t h e co mpu ter sc re en .
The VI receives instructions from a block diagram, which you construct in G. The block diagram is a pictorial solution to a programming problem. The block diagram is also the sourc e code for the VI.
VIs are hierarchical and modular. You can use them as top-level programs, or as sub pro gram s within o the r p rogra ms. A VI w ithin another VI is called a su bVI. The icon and connector of a VI work like a graphical parameter list so that other VIs can pass data to a subVI.
With these features, LabVIEW promotes and adheres to the concept of modular programming. You divide an application into a series of tasks, which you can divide again until a complicated application becomes a series of simple subtasks. You build a VI to accomplish each subtask and then combine those VIs on another block diagram to accomplish the larger task. Finally, your top-level VI contains a collection of subVIs that represent application functions.
Because you can execute each subVI by itself, apart from the rest of the application, debugging is much easier. Furthermore, many low-level subVIs often perform tas ks common to sev eral applications, s o that you can develop a specialized set of subVIs well-suited to applications you are likely to construct.

G Programming

G is the easy to use graphical data flow programming language on which LabVIEW is based. G simplifies scientific computation , process monitoring and control, and test and measurement applications, and you also can use it for a wide variety of other applications.
Part I, Introduction to G Programming, covers the functionality of G that
you need to get started with most LabVIEW applications . For a more extensive explanation of LabVIEW functionality, see the G Programming Reference Manual.
LabVIEW User Manual 1-2
©
National Instruments Corporation
Chapter 1 Introduction
The basic concepts of G that are covered in this manual are described in the following list.
VIs—Virtual instruments (VIs) have three main parts: the front panel, the block diagram, and the icon/connector. The front panel specifies the user interface of the VI. The block diagram consists of the executable code that you create using nodes, terminals, and wires. With the icon/connector, you can use a VI as a subVI in the block diagram of another VI. For more information about VIs, refer to Chapter 2, Creating VIs and Chapter 26, Customizing VIs.
Loops and Charts—G has two structures to repeat execution of a sub-diagram—the While Loop and the For Loop. Both structures are resizable boxes. You place the subdiagram to be repeated inside the border of the loop structure. The While Loop executes as long as the value at the conditional terminal is TRUE. The For Loop executes a set number of times. Charts are used to d isplay real-time trend information to the operator. For more information about loops and charts, refer to Chapter 3, Loops and Charts.
Case and Sequence Structures—The Case structure is a co nditional branching control structure, which executes a subdiagram based on certain input. A Sequence structure is a program control structure that executes its subdiagrams in numeric order. For more information about Case or Sequence structures, refer to Chapter 4, Case and Sequence
Structures and the Formula Node.
Attribute Nodes—Attribute nodes are special block diagra m nodes that you can use to control the appearance and functional characteristics of controls and indicators. For mor e info rmation abo ut attribute nodes, refer to Chapter 27, Front Panel Object Attributes.
Arrays, Clusters and Graphs—An array is a resizable collection of data elements of the same type. A cluster is a statically sized collection of data elements of the same or different types. Graphs commo nly are used to display data. For more informa tion about arrays, clusters, and graphs, refer to Chapter 5, Arrays, Clusters, and Graphs.
©
National Instruments Corporation 1-3 LabVIEW User Manual
Chapter 1 Introduction

Organization of the LabVIEW System (Windows)

After you have completed the installation, as described in th e LabVIEW Release Notes that come with your software, your LabVIEW directory
should contain the following files.
LABVIEW.EXE—This is the LabVI EW program. Launch this progr am
to start LabVIEW .
vi.lib directory—Contains libraries of VIs that are included with
LabVIEW , including GPIB, analysis, and data acquisition (DAQ) VIs. Most of these are available from the Functions palette.
examples directory—Contains numerous subdirectories of e xamples.
This directory also contains a VI called guide to the examples.
serpdrv and daqdrv—These files serve as part of LabVIEW’s
interface to the serial port, and DAQ communication, respectively. These files must be in the same directory as
resource directory
labview.rsc, lvstring.rsc, and lvicon.rsc—Data files
used by the LabVIEW application
(Windows 3.1)
lvdevice.dll—This file provides timing services to LabVIEW and must be in the same directory as LabVIEW to run.
(Windows 3.1)
lvimage.dll
images created using a variety of graphics programs.
labview50
.tlb
—This file is a type library to enable LabVIEW
to act as an ActiveX server.
ole_container.dll—This file enables LabVIEW to display
and update ActiveX containers.
lvwutil32.dll—This file is used by the Solution Wizard,
which builds DAQ and Instrument I/O examples based on your criteria.
lvjpeg.dll and lvpng.dll—These files provide support to
display JPEG and PNG graphics in HTML files when you print VI documentation to an HTML file.
Cintools directory—Contains files necessary to build Code Inter face
Nodes (CINs), which are a means to link C code to LabVIEW VIs.
visarc file—Serves as part of LabVIEW’s interface to VISA (V irtual
Instrument Software Architecture). VISA provides a single interface library for controlling VXI, GPIB, and Serial instruments.
readme.vi that serves as a
vi.lib.
—This file allows LabVIEW to load
vi.lib for
LabVIEW User Manual 1-4
©
National Instruments Corporation
Chapter 1 Introduction
labview.ini—Contains the configuration options for LabVIEW.
Project directory—Contains files which become items in the
LabVIEW Project menu.
menus directory—Contains files used to configure the structur e of the
Controls and Functions palettes.
Instr.lib directory—Contains instrument drivers used to control
VXI, GPIB, and Serial instruments. When you install National Instruments instrument drivers, place them in this directory because they will be added to the Functions palette.
Help directory—Contains complete online documentation as well as
• the Search Examples help file, which aids in locating examples common to your application.
Tutorial directory—Contains files that are necessary to run the
online tutorial, an interactive tutorial co vering the basic concepts of the LabVIEW environment.
Activity directory—Is a location where you can save the VIs you
create while completing the activities in this manual.
User.lib directory—Is a location where you can save commonly
used VIs that you have created. The VIs in this directory will be displayed in the Functions palett e.
Wizard directory—This directory creates the Solution Wizard option
in the File menu. You can use this directory to add items to the File menu.
LabVIEW installs driver software for GPIB, data acquisition, and VXI driver hardware. For configuration information, see Chapter 2, Installing
and Configuring Your Data Acquisition Hardwar e, in th e LabVIEW Data Acquisition Basics Manual, the VXI VI Reference Manual, and Chapter 8,
LabVIEW VISA Tutorial, of this manual.

Startup Screen on Windows

When you launch LabVIEW, you are greeted with a navigation dialog box where introductory material, common commands, and Quick Tips are easily accessible. If you prefer to bypass the navigation dialog, you can disable it using a checkbox at the bottom of the dialog box. To reenable it, use the Preferences dialog box.
When all VIs are closed, a similar dialog box appears. The Small Dialog button switches to a simpler version of the dialog box—with only New, Open, and Exit buttons.
©
National Instruments Corporation 1-5 LabVIEW User Manual
Chapter 1 Introduction

Organization of the LabVIEW System (Macintosh)

After you have completed the installation, as described in th e LabVIEW Release Notes that come with your software, your LabVIEW directory
should contain the following files.
LabVIEW—This is the LabVIEW program. Launch this program to
start LabVIEW.
vi.lib folder—Contains libraries of VIs that are included with
LabVIEW , including GPIB, analysis, and data acquisition (DAQ) VIs. Most of these are available from the Functions palette.
examples folder—Contains numerous su bfolders of examples. This
folder also contains a VI called the examples.
resource folder
lvstring.rsrc and lvicon.rsrc—Data files used by the
LabVIEW application.
lvjpeg.lib and lvpng.lib—These files provide support to
display JPEG and PNG graphics in HTML files when you print VI documentation to an HTML file.
cintools folder—C ontains files necessary to build Code Interface
Nodes (CINs), which are a means to link C code to LabVIEW VIs.
visarc file—Serves as part of LabVIEW’s interface to VISA, V irtual
Instrument Software Architecture. VISA provides a single interface library for controlling VXI, GPIB, and Serial instruments.
Project folder—Contains files which become items in the LabVIEW
Project menu.
menus folder—C ontains files used to configure the structure of the
Controls and Functions palettes.
instr.lib folder—Contains instrument driers used to control VXI,
GPIB, and Serial instruments. When you install National Instruments instrument drivers, place them in this directory because they will be added to the Functions palette.
help folder—Contains complete online documentation as well as the
• Search Examples help file, which aids in locating examples common to your application.
activity folder—Is a location where you can save the VIs you create
while completing the activities in this manual.
readme.vi that serves as a guide to
LabVIEW User Manual 1-6
©
National Instruments Corporation
Chapter 1 Introduction
user.lib folder—Is a location where you can save commonly used VIs that you have created. The VIs in this directory will be displayed in the Functions palette.
Wizard folder—This directory creates the Solution Wizard opt ion in
the File menu (
PCI Macintosh only). You can use this directory to add
items to the File menu.
In addition, the LabVIEW installation utility installs several driver files so that you can use GPIB and/or DAQ plug-in boards.
System Folder:Control Panels:NI-488 INIT—This control
• panel contains the drivers for your GPIB boards. You can use it to configure your boards, but you rarely need to change any settings.
System Folder:Control Panels:NI-DAQ—Thi s control panel
loads DAQ drivers into memory. You can use it to configure the location and behavior of your DAQ boards and SCXI modules.
System Folder:Extensions:NI-DMA/DSP—Both the GPIB and
DAQ drivers use this e xtension. It provides support for direct memory access (DMA) transfer of data, which provides higher data transfer rates. This extension also provides support for NI-DSP boards.
LabVIEW installs driv er software for GPIB an d data acquisition hardw are. For configuration information, see Chapter 2, Installing and Configuring
Your Data Acquisition Hardware, in the LabVIEW Data Acquisition Basics Manual.

Organization of the LabVIEW System (UNIX)

After you have completed the installation, as described in th e LabVIEW Release Notes that come with your software, your LabVIEW directory
should contain the following files.
labview—This is the LabVIEW program. Launch this program to
start LabVIEW.
vi.lib directory—Contains libraries of VIs that are included with
LabVIEW , including GPIB, analysis, and data acquisition (DAQ) VIs. Most of these are available from the Functions palette.
examples directory—Contains numerous subdirectories of e xamples.
This directory also contains a VI called guide to the examples.
serpdrv—This file serves as part of LabVIEW's interface to
serial port communication. This file must be in the same directory
vi.lib.
as
©
National Instruments Corporation 1-7 LabVIEW User Manual
readme.vi that serves as a
Chapter 1 Introduction
resource directory –
labview.rsc, lvstring.rsc, and lvicon.rsc—Data files
used by the LabVIEW application
lvjpeg.lib and lvpng.lib—These files provide support to
display JPEG and PNG graphics in HTML files when you print VI documentation to an HTML file.
cintools directory—Contains files necessary to build Code
Interface Nodes (CINs), which are a means to link C code to LabVIEW VIs.
visarc file—Serves as part of LabVIEW’s interface to VISA,
Virtual Instrument Software Architecture. VISA provides a single interface library for controlling VXI, GPIB, and Serial instruments.
Project directory—Contains the files which become items in the
LabVIEW Project menu.
menus directory—Contains files used to configure the structure of the
Controls and Functions palettes.
instr.lib directory—Contains instrument drivers used to control
VXI, GPIB, and Serial instruments. When you install National Instruments instrument drivers, place them in this directory because they will be added to the Functions palette.
help directory—Contains complete online documentation as well as
• the Search Examples help file, which aids in locating examples common to your application.
activity directory—Is a location where you can save the VIs you
create while completing the activities in this manual.
user.lib directory—Is a location where you can save commonly
used VIs that you have created. The VIs in this directory will be displayed in the Functions palett e.
Wizard directory—This directory creates the Solution Wizard
option in the File menu. You can use this directory to add items to the File menu.
acrobat directory—Contains online documentation in Acrobat
.pdf) format.
(
acroread directory—Contains Adobe Acrobat reader files.
LabVIEW User Manual 1-8
©
National Instruments Corporation

Toolkit Support

Files that are installed in vi.lib\addons automatically show up at the top level of the Controls and Functions palettes. This feature can be used by new toolkits to make them more accessible after installation. If you already have toolkits that installed files elsewhere, you can move them to the
addons directory for easier access. If you want to add yo ur own VIs to the
palettes, we recommend placing them in user.lib or adding them to a custom palette set.

Where Should I Start?

This manual provides basic information on how to build an application in LabVIEW. To become familiar with the LabVIEW environment, go through the LabVIEW Online Tutorial LabVIEW QuickStart Guide, and Part I, Introduction to G Programming in this manual.
Most LabVIEW applications are divided into the following tasks: I/O interface to sensors or instrumen ts, data display on the fron t panel, data analysis, data storage, and data transfer across a network. To learn more about each of these tasks, refer to Part II, I/O Interfaces, Part III, Analysis, and Part IV, Network and Interapplication Communication. For advanced G programming techniques, refer to Part V, Advanced G Programming, in this manual.
Chapter 1 Introduction
(Windows only)
, the
To generate or find examples similar to your application, refer to the Solution Wizard online help file startup dialog.
For information on individual functions and VIs, refer to the LabVIEW Function and VI Reference Manual and online help.
©
National Instruments Corporation 1-9 LabVIEW User Manual
(Windows and PCI Macintosh only)
(Windows only)
, which you can access from the LabVIEW
or Search Examples
Introduction to G Programming
This section contains basic information ab out creating virtual instruments (VIs), using VIs in other VIs, programming structures such as loops, and data structures such as arrays and strings.
Part I, Introduction to G Programming, contains the following chapters.
Chapter 2, Creating VIs, explains how to create a VI including the front panel, which is the user interface, and the block diagram, which is the source code. Once you create a VI, you can use it in other VIs.
Chapter 3, Loops and Charts, shows you how to repeat por tions of the block diagram using a While Loop and a For Loop. This chapter also explains how to display multiple points graphically, one at a time, on achart.
Chapter 4, Case and Sequence Structures and the Formula Node, explains how to use the Case structure, which is a conditional structure, the Sequence structure, which aids in establishing ex ecution order , and the Formula Node, which aids in executing mathematical formulas.
Chapter 5, Arrays, Clusters, an d G raphs, shows how to display a group or array of data points on a graph. You can pass scale parameters as well as an array of data points to a graph by creating a cluster, which is a group of different data types.
Chapter 6, Strings and File I/O, explains how to manipulate strings and write those strings to an ASCII file.
Part I
Note (Windows 3.1)
VI libraries allow you to use file name s that are longer than 8 characters. Also, the VIs needed for the activities in Part I are located in the VI library
LabVIEW\Activity\Activity.llb. Refer to the Saving VIs section in
Chapter 2, Editi ng VIs, of the G Programming Reference Manual for more information on VI Libraries.
You must save the VIs you create in Part I in VI libraries.
Creating VIs
This chapter introduces the basic concepts of virtual instruments and provides activities that explain the following:
How to create the icon and connector
How to use a VI as a subVI

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 panel s or block di agrams as VIs do. Fu nction 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.
2

VI Hierarchy

When you create an application, you start at the top-level VI and define the inputs and outpu ts 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 n umber of icons, grou p 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.
©
National Instruments Corporation 2-1 LabVIEW User Manual
Chapter 2 Creating VIs
If you are using Windows3.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. F or a list of the advantages and disadvan tages of using VI libraries and individual files, see the section Saving VIs in Chapter 2, Editing VIs, of the G Programming Reference Manual.
VI libraries have the same load, save, and open capabilities as other directories. VI libraries, howev er, 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 manual, you will save your VIs in the activities are provided in the
LabVIEW\Activity directory. Solutions to these
LabVIEW\Activity\Solution directory.

Controls, Constants, and Indicators

A control is an object you place on your front panel f or 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 indicato rs in G are similar to input and output parameters, respectively, in traditional programming languages. An alternative to placing 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 dir ectly 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.
LabVIEW User Manual 2-2
©
National Instruments Corporation
Chapter 2 Creating VIs
Y o u can create an indicator and wire it to an output terminal by popping up on the terminal and selecting Create Indicator. As an alternati ve to placing constants on th e bl o ck d iag ram and wi ri n g 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 impor tan t 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 or VI and select Show»Terminals again.
©
National Instruments Corporation 2-3 LabVIEW User Manual
Chapter 2 Creating VIs

Wires

Hot Spot
A wire is a data path between nodes. Wires are colored according to the kind of data each wire carries. Blue wires carry integers, o range 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 Refere nce 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 Wiring tool is the tip of the unwound wiring segment.
1
symbol shows where to click and the number printed on the ar row 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. Y ou can ben d a wire once by movin g the mouse perpendicular to the curr ent 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.
In the wiring illustrations in this section, the arrow at the end of this mouse
1 1
Tip Strips
When you move the Wiring to ol over the termi nal of a node, a tip strip for that terminal pops up. Tip strips consist of small, yellow text banners that display the name of eac h term inal . These tip strip s sh ould hel p yo u to wi re the terminals. The following illustration displays the tip strip that appears when you place the Wiring tool over an output of the Simple Error Handler VI.
LabVIEW User Manual 2-4
©
National Instruments Corporation
Chapter 2 Creating VIs
VI
Wiring Tool Tip Strip
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 th e Pos itioning tool.
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.
©
National Instruments Corporation 2-5 LabVIEW User Manual
Chapter 2 Creating VIs
Segment
Junction
Bend
Note
Segment
1 2 3
Selects a Segment Selects a Branch Selects an Entire Wire
Bad Wires
A dashed wire represents a bad wire. You can get a bad wire fo r a n umb er 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 and pressing <Delete>. Choosing Edit»Remove Bad Wires or <Ctrl-B> deletes all bad wires in the block diagram. This is a useful qui ck fix to try i f your VI refuse s to run or retu rns
Signal has Loose Ends error message.
the
Do not confuse a blac k, da shed wi re with a dotted wire. A d otted wi re represent s a Boolean data type, as the following illustration shows.
Dashed Wire (bad)
LabVIEW User Manual 2-6
Dotted Wire (good)
©
National Instruments Corporation

Activity 2-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 simulate the temperature and volume measurements in volts. Y ou will write a VI to scale these measurements to degrees fahrenheit and liters, respectively.
1. Open a new front panel by selecting File»New. If you have closed all VIs, select New VI from the LabVIEW dialog box.
Chapter 2 Creating VIs
LabVIEW\Activity directory to
Note
Note
If the Controls palette is not visible, select Windows»Show Cont rols Palette to display the palette. You also can access the Controls palette by popping up in an open area of the front p anel. T o pop u p, right-click on you r mouse (<Option>-clic k for Macintosh).
2. Select Tank from Controls»Numeric, and place it on the front panel.
3. Type
Volume in the label text box and click anywhere on the front
panel.
If you click outside the text box without entering text, the la bel 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. Usi ng the Labeling t ool, double-c lick 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.
©
National Instruments Corporation 2-7 LabVIEW User Manual
Chapter 2 Creating VIs
6. Your front panel should look like the following illustration.
7. Open the block di agram 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 visi ble, se lect Windows»Show Functions Palette to
display the palette. Y ou also can access the Functions palette by popping u p 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 acti vity, you need two of these. Drop on e 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 Anoth e r way to create a constant is to pop up on the terminal of a function or VI
using the W iring to ol. Select Create Constant from the floating menu. A constant of the appropriate data type appears.
©
LabVIEW User Manual 2-8
National Instruments Corporation
Chapter 2 Creating VIs
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, wire the objects as shown.
Note To mo v e ob jects ar ound on the blo ck di agra m, clic k on t he Positioni ng tool in th e
Tools palette.
11. Select File»Save and save the VI as
LabVIEW\Activity directory.
Temp & Vol.vi in the
12. From the front panel, run the VI b y clicking on the Run button. Notice values for Volume and Temperature are displayed on the front panel.
13. Close th e VI by selecting File»Close.
End of Activity 2-1.
©
National Instruments Corporation 2-9 LabVIEW User Manual
Chapter 2 Creating VIs

VI Documentation

You can document a VI by choosin g 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 respectiv e terminals on the bl ock diagram) by poppi ng 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 you 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-2. Document a VI

Yo ur objective is to document a VI that you have created.
1. Open the
LabVIEW\Activity directory.
2. Select Windows»Show VI Info…. Type the des cription for the VI, as shown in the following illustration, and click on OK.
Temp & Vol.vi created in Activity 2-1 from the
LabVIEW User Manual 2-10
©
National Instruments Corporation
Chapter 2 Creating VIs
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.
©
National Instruments Corporation 2-11 LabVIEW User Manual
Chapter 2 Creating VIs
4. Pop up on the thermometer and choose Data Operations»
5. Select Show Help from the Help menu. Place the cursor on Volume
6. Save and close the VI.
End of Activity 2-2.

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 conn ector , 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.
Description…. Type in the description:
temperature (deg F) measurement.
and then on Temp. You can see the descriptions you typed in appear in the help window.
Displays simulated
Click on OK.
A subVI is analogous to a subroutine. A subVI node 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

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.
LabVIEW User Manual 2-12
©
National Instruments Corporation
Chapter 2 Creating VIs
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 the following options. For more information about the Hierarchy window see the
Using the Hierarchy Window section in Chapter 3, Using SubVIs, of the G Programming Reference Manua l.
Redraw—Rearranges nodes after successi ve operations on hierarch y 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 th e nodes from top-to-bo ttom, 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 g raph to include or exclude global variables. Global variables store data used by several VIs.
Include/Exclude typede fs—Toggles the hierarchy graph to include or exclude typedefs. A typedef is a master cop y of a custom control, which can be used by severa l VIs.
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 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 nod e. <Shift>-cli ck on a VI or subVIs 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.
©
National Instruments Corporation 2-13 LabVIEW User Manual
Chapter 2 Creating VIs
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 displays 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 hidi ng subVIs, opening the VI or subVI fro nt panel, editing th e VI icon, and so on.
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 p ress <Enter> to search for the next node that matches the search string, or you can press <Shift-En ter> to f ind the previous node that matches the search string.

Icon and Connector

Every VI has a default icon di splayed in the upper -right corner of the Front Panel and Diagram windows. For VIs, th e default is the LabVIEW VI ico n 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 activ ate the Icon Editor, p op 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 at left 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.
LabVIEW User Manual 2-14
©
National Instruments Corporation
Chapter 2 Creating VIs
The tools to the left of the editing area perform the following functions: 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 backgro und 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 p alette from which you can choose new colors.
©
National Instruments Corporation 2-15 LabVIEW User Manual
Chapter 2 Creating VIs
The buttons at the right of the editing screen perform the following functions:
Undo—Cancels the last operation you performed.
OK—Saves your drawing as the VI icon and retur ns to the front panel.
Cancel—Returns to the front panel without saving any changes.
Depending on the type of mon itor yo u are using, yo u can design a s eparate icon for monochrome , 16-color, and 256-c olor m ode. You design and sav e 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 wh ite 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 terminal s on the connector pane. You define connections by choosing the number of terminals yo u want for the VI and ass igning 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 corn er of the P anel window. LabVIEW selects a terminal pattern appropriate for your VI with terminals for 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 term inal area, and you can use the rectangles either for input or output from the VI. If necessary , yo u can select a different terminal pattern for your VI. To do this, pop up on the icon, select Show Connect o r, pop up again, and select Patterns.
LabVIEW User Manual 2-16
©
National Instruments Corporation
Chapter 2 Creating VIs

Activity 2-3. Create an Icon and Connector

Your objective is to make an icon and connector for a VI.
T o 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 i n the block diag ram of other VIs. It can be a pictorial representation of the purpose of the VI, or a textual description of the VI.
1. Open
2. From the front panel, pop up on the icon in the top right corner and
Temp & Vol.vi in the LabVIEW\Activity directory.
select Edit Icon…. You also can double click on the icon t o in v oke the icon editor.
Note
Yo u only can acces s the icon/connector for a VI from the front panel.
3. Erase the default icon. With the Select tool, which appears as a dotted rectangle, 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.
5. Create the text with the Te x t tool. T o chan ge the font, double-click on the Text tool. Your icon should look similar to the following illustration.
©
National Instruments Corporation 2-17 LabVIEW User Manual
Chapter 2 Creating VIs
6. Close the Icon Editor by click ing on OK. Th e ne w 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, as shown at left.
8. Pop up on the connector pane and select Rotate 90 Degrees.
Notice how the connector pane changes, as shown at left.
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, 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.
c. Repeat steps a and b to associate the bottom terminal with the
Volume indicator.
d. 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.
LabVIEW User Manual 2-18
©
National Instruments Corporation
Chapter 2 Creating VIs
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 2-3.

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 2-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 in Activity 2-1 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
Gallons by using the Labeling tool.
and
3. Select a meter from Controls»Numeric and place it on the front panel.
Label it
©
National Instruments Corporation 2-19 LabVIEW User Manual
Tank Volume.
Chapter 2 Creating VIs
Block Diagram
4. Change the range of the meter to accommodate values ranging between 0.0 and 1000.0. With the Operating tool, 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.
5. G o to the block diagr am 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 dire ctory. Click on
Open in the dialog box. LabVIEW places the Temp & Vol VI on the block diagra m.
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 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.
LabVIEW User Manual 2-20
3.785 to the constant by using the
©
National Instruments Corporation
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 on the Run button in the toolbar.
The meter shows the value in liters.
10. Click on the switch to select The meter shows the value in gallons.
11. Save the VI as directory.
End of Activity 2-4.

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 Wir es from the Edit menu. Often, this fixes a broken VI.
Chapter 2 Creating VIs
Gallons and click on the Run button.
Using Temp & Vol.vi in the LabVIEW\Activity
When your VI is not executable, a br oken arrow ap pears 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 debuggi n g pu rpo ses , yo u mi gh t wan t to e xecute a block diagram no de by node. This is kno wn 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 execu te the subVI and proceed to the next node b ut cannot see how the subVI nodes e xecute. To single step thro ugh a structure or subVI, select the Step Into button.
©
National Instruments Corporation 2-21 LabVIEW User Manual
Chapter 2 Creating VIs

Activity 2-5. Debug a VI in LabVIEW

Click on the Step Out button to finish execution of t he block diagram nodes and/or complete single stepping. For more information about debugging, see Chapter 4, Executing and Debugging VIs and SubVIs, in the G Programming Reference Manua l.
Your objective is to use the probe tool and the probe window and to examine data flo w in the bloc k diagram using t he execution h ighlighting feature.
1. Open
Using Temp & Vol.vi from the LabVIEW\Activity
directory.
2. Select Windows»Show Di agram.
3. If the Tool s palette is not open , select Windows»Show Tools Palette.
4. Select the Probe tool from the Tools palette. Click with the Probe tool
on the wire coming out of the Di vi de fu ncti on. A Prob e 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.
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
LabVIEW User Manual 2-22
Tank Volume displays the value in liters.
©
National Instruments Corporation
Chapter 2 Creating VIs
Note The volume values that appear on your screen may be different than what is
shown in this illustration. Refer to the Numeric Conversion section in Chapter 3,
Loops and Charts, 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.
7. Return to the block diagram of the VI.
8. Begin execution highli ghting b y clicki ng on the Highlight Execution button, in the toolbar. The Highlight Execution button changes to an illuminated light bulb.
9. Click on the Run button to run the VI, and notice that execution highlighting animates the VI block diagram execution. Moving bubbles represent the flow o f 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 on the Step Over button, in the toolbar.
11. Step into the Temp & Vol subVI by clicking on the Step Into button, in the toolbar. Clicking o n thi s button opens the front pan e l and block diagram of your Temp & Vol subVI. Click on the Step Over button until the VI finishes executing.
12. Finish executing the block diagram by clicking on the Step Out butt on, in the toolbar. Clicking on this button completes all remaining sequences in the block diagram.
End of Activity 2-5.
©
National Instruments Corporation 2-23 LabVIEW User Manual
Loops and Charts
This chapter introduces structures and explains the basic concepts of charts, the While Loop, and the For Loop. This chapter 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?

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 chapter 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 Chapter 4, Case and Sequence Structures and the
Formula Node.
3
While and For Loops are basic str uctures for progr amming with G, so you can find them in most of the G examples as well as the activities in this manual. You also can find more information on loops in Chapter 19, Structures, in the G Programming Reference Manual.
For examples of structures, see For examples of charts, see
©
National Instruments Corporation 3-1 LabVIEW User Manual
Examples\General\structs.llb.
Examples\General\Graphs\charts.llb.
Chapter 3 Loops and Charts

Charts

Chart Modes

A chart is a numeric plotting indicator which 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 Chapter 15, Graph and Chart Controls and Indicators, in your G Programming Reference Manual.
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.
LabVIEW User Manual 3-2
©
National Instruments Corporation

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 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
Graphs\charts.llb.
charts.vi example located in Examples\General\

Activity 3-1. Experiment with Chart Modes

Y our objective is to view a chart as your VI runs in strip chart mode, scope chart mode, and sweep chart mode.
1. Open
2. Run the VI.
Charts.vi, located in the following directory:
LabVIEW\Examples\General\Graphs\charts.11b.
Chapter 3 Loops and Charts
charts.vi example
The strip chart mode has a scaling display similar to a pa per tape strip chart recorder. As each new value is recei ved, 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 receiv es each n ew 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 th e difference between the various charts and modes.
4. Stop and close the VI.
End of Activity 3-1.
©
National Instruments Corporation 3-3 LabVIEW User Manual
Chapter 3 Loops and Charts

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. Ho we v er, the iteration count always starts at zero, so if the loop runs once, the iteration terminal outputs 0.
Iteration
Terminal
Conditional
Terminal
The While Loop is equivalent to the following pseudocode:
Do Execute Diagram Inside the Loop (which sets the
condition) While Condition is TRUE
LabVIEW User Manual 3-4
©
National Instruments Corporation
Front Panel
Chapter 3 Loops and Charts

Activity 3-2. 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 ti me.
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.
1. Open a new front panel by selecting File»New.
2. Place a Vertical Switch (Controls»Boolean) on the front panel. Label the switch
3. Use the Labeling tool to create free labels for Labeling tool, and type in the label text. With the Color tool, shown at left, 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 (Controls»Graph) on the front panel. Label the chart in real time.
Note
©
National Instruments Corporation 3-5 LabVIEW User Manual
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.
Enable.
ON and OFF. Select the
Random Signal. The chart displays rando m data
Chapter 3 Loops and Charts
Block Diagram
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 high limit of
10.0 with 1.0.
0.0 to 1.0. Use the Labeling tool to replace the
7. Place a knob (Controls»Numeric) on the front panel. Label the kno b
Loop Delay (sec). This knob controls the timing of the While
Loop. Pop up on the knob and deselect Show»Digital Dis play to hide the digital display.
8. Rescale the knob. Using the Labeling tool, double-click on scale around the knob, and replace it with
2.0.
10.0 in the
9. Open the block diagram and create the diagram in the following illustration.
a. Place the While Loop 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.
LabVIEW User Manual 3-6
©
National Instruments Corporation
Chapter 3 Loops and Charts
b. Select the Random Number (0–1) function from Functions»
Numeric.
c. Wire the diagram as shown in the Block Diagr am, 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 by clicking on it with the Operating tool.
11. Save the VI as 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. Sto p the VI by clicking on the vertical switch. Turning the switch off sen ds the value FALSE to the loop conditional terminal and sto ps 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 u p on the chart and choosing Data Oper ation s»Cl ear Chart.
Random Signal.vi in the LabVIEW\Activity
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 3-2.
©
National Instruments Corporation 3-7 LabVIEW User Manual
Chapter 3 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 the Run button in the toolbar. With G, yo u 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 Un til 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 simi lar 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.
LabVIEW User Manual 3-8
©
National Instruments Corporation
Chapter 3 Loops and Charts
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 th is act ion high lig hts the button, and releasi ng 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 3-3. Change the Mechanical Action
of a Boolean Switch
Your objective is to experiment with the different mechanical actions of Boolean switches.
Note
1. Open 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
c. Pop up on the switch and choose Mechanical Action»Latch
3. Run the VI. Click on the The switch moves to the OFF position momentarily and is reset back to the ON position.
4. Save the VI.
For your reference, LabVIEW contains an example that demonstrates these behaviors, called
Examples\General\Controls\booleans.llb.
Random Signal.vi, as saved in Activity 3-2, from the
Current Value Default. This makes the ON position the default value.
When Pressed.
Enable switch to stop the acquisition.
Mechanical Action of Booleans.vi. It is located in
End of Activity 3-3.
©
National Instruments Corporation 3-9 LabVIEW User Manual
Chapter 3 Loops and Charts

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 it erate 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 1ms.
The timer has a resolution of 1 ms.
(UNIX)

Activity 3-4. Control Loop Timing

Your objective is to control loop timing a nd ensure that no iteration is shorter than the specified number of milliseconds.
1. Open
2. Modify the VI to generate a new random number at a time interval
LabVIEW User Manual 3-10
Random Signal.vi, as modified and saved in Activity 3-3,
from the
LabVIEW\Activity directory.
specified by the knob, as shown in the following illustration.
©
National Instruments Corporation
Chapter 3 Loops and Charts
Wait Until Next ms Multiple function (Function s»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 1000 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 1000 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
Signal
4. Save the VI as
LabVIEW\Activity directory. Close the VI.
display.
Random Signal with Delay.vi in the
End of Activity 3-4.
Random
©
National Instruments Corporation 3-11 LabVIEW User Manual
Chapter 3 Loops and Charts

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 inclu ding 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 Chapter 4, 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
LabVIEW User Manual 3-12
©
National Instruments Corporation

Shift Registers

Chapter 3 Loops and Charts
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.
©
National Instruments Corporation 3-13 LabVIEW User Manual
Chapter 3 Loops and Charts
Before Loop Begins First Iteration
Inital
Value
Subsequent Iterations Last Iteration
Previous
Value
New
Value
Inital
Value
Previous
Value
New
Value
New
Value
Value
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.
New
Contains i–1 Contains i–2 Contains i–3
Pop up on left terminal to add new elements or use Positioning tool to resize the left terminal to expose more elements.
LabVIEW User Manual 3-14
Previous values are available at the left terminal.
Latest value passes to the right terminal.
Pop up on border for new shift register.
©
National Instruments Corporation
Front Panel
Chapter 3 Loops and Charts

Activity 3-5. Use a Shift Register

Your objective is to build a VI that displays a runnin g averag e on a chart.
1. Open a new front panel and create the objects as 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. Bu ild the block diagram shown in the following illustration.
©
National Instruments Corporation 3-15 LabVIEW User Manual
Chapter 3 Loops and Charts
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 arithmet ic function returns the sum of random numb ers 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 re gister. 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.
W ait 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»L abel, the label Wait Until Next ms Multiple appears.
6. Po p 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. 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.
LabVIEW User Manual 3-16
©
National Instruments Corporation
Chapter 3 Loops and Charts
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 pr evious run and the first fe w averages are meaningless.
8. Run the VI and observe the operation.
9. Save this VI as directory .
Note Remember to initialize shift registers to avoid incorporating old or default data
into your current data measurements
Random Average.vi in the LabVIEW\Activity
End of Activity 3-5.

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.
©
National Instruments Corporation 3-17 LabVIEW User Manual
Chapter 3 Loops and Charts
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 v alues 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 condition 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 shift registers between calls.
When the Running Average 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.
LabVIEW User Manual 3-18
©
National Instruments Corporation
Front Panel
Chapter 3 Loops and Charts

Activity 3-6. Create a Multiplot Chart

Your objective is to create a chart that can accommodate more than one plot.
1. Open the Random Average.vi you created in Activity 3-5.
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 displa y by po pping up on t he chart, and choo sing
Show»Digital Display. Move the legend if necessary.
c. Rename Plot 0 to
label with the Labeling tool and typing in the new text. You can resize the label area by dragging either of the left corners with the Positioning tool. Rena me Plot 1 to same way.
d. For th e
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.
©
National Instruments Corporation 3-19 LabVIEW User Manual
Current Value plot, change the interpolation to
Current Value by double-clicking on the
Running Avg in the
Chapter 3 Loops and Charts
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 (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 v ertical 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 b uttons 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 to the left of each button to lock on autoscaling.
LabVIEW User Manual 3-20
©
National Instruments Corporation
Chapter 3 Loops and Charts
Y o u can use the other buttons to modify the axis text precision or to control the operation mode for the ch art. Experimen t with th ese b uttons 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 s tarting 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 th e chart smaller.
©
National Instruments Corporation 3-21 LabVIEW User Manual
Chapter 3 Loops and Charts
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 select OK.
9. Run the VI.
10. Save the VI as
LabVIEW\Activity directory.
Multiple Random Plot.vi in the
End of Activity 3-6.

For Loops

A For Loop executes a section of code a defined number of times. It is resizable, and, like the While Loop, is not dropped on the blo c k diagram immediately. Instead, a small icon representing the Fo r Loop appears in the block diagram, and you hav e the o pportunity 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, d rag out a rectangle that en compasses 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.
LabVIEW User Manual 3-22
©
National Instruments Corporation
Chapter 3 Loops and Charts
Loop Count Numerical Input
Numerical Output
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 coun t 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.
©
National Instruments Corporation 3-23 LabVIEW User Manual
Chapter 3 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. 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.
Gray Dot
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 inte ger . F or exampl e, the VI rounds 6.5 to 6, b ut rounds 7.5 to 8. This is an IEEE standard method for rounding numbers. See the IEEE Standard 754 for details.
LabVIEW User Manual 3-24
©
National Instruments Corporation
Front Panel
Chapter 3 Loops and Charts

Activity 3-7. 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.
1. Open a new front panel and add the objects shown in the following illustration.
a. Place a digital indicator on the front panel and label it
Value
.
b. Place a waveform chart on the front panel and label it
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.
Maximum
Random
©
National Instruments Corporation 3-25 LabVIEW User Manual
Chapter 3 Loops and Charts
Block Diagram
2. Op en th e block diagram and modify it as shown in the following illustration.
3. Place a For Loop (Functions»Structures) on the block diagram .
4. Ad d the shift register 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 v alue 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. F or example, if you initialize the shift register to 1.0, then that value is already greater than all the e xpected 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.
LabVIEW User Manual 3-26
©
National Instruments Corporation
Chapter 3 Loops and Charts
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 igno re 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 directory.
Calculate Max.vi in the LabVIEW\Activity
End of Activity 3-7.
©
National Instruments Corporation 3-27 LabVIEW User Manual
Case and Sequence Structures and the Formula Node
This chapter 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 a Formula Node is and how to use it
Both Case and Sequence structures can have multiple subdiagrams, configured like a deck of card s, 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 structu res, 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.
4
Increment/Decrement
Buttons
Diagram Identifier
Case Structure 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 f rom th e first subdiagram displays the last. For more information about Case and Sequence structures, refer to Chapter 19, Structures, in the G Programming Reference Manual.
©
National Instruments Corporation 4-1 LabVIEW User Manual
Chapter 4 Case and Sequence Structures and the Formula Node

Case Structure

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 an 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
Front Panel
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 4-1. 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.
1. Open a new front panel and create the objects as shown in the following illustration.
Number control supplies the number. The Square Root Value
The indicator displays the square root of the number. The free label acts as a note to the user.
LabVIEW User Manual 4-2
©
National Instruments Corporation
Block Diagram
Chapter 4 Case and Sequence Structures and the Formula Node
2. Bu ild the diagram as shown in the following illustration.
Selection
Terminal
3. Place a Case structure 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 hav e 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.
©
National Instruments Corporation 4-3 LabVIEW User Manual
Chapter 4 Case and Sequence Structures and the Formula Node
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 TR UE 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
Note You must define the output tunnel for each case. When you create an output
Error...Negative Number.
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. Tr y a number greater than zero and a number less than zero b y changing the value in the digital control you labeled
Number. Notice that when you change the digital control
to a negati ve number , LabVI EW displays th e 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 4-1.
LabVIEW User Manual 4-4
©
National Instruments Corporation

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.
Chapter 4 Case and Sequence Structures and the Formula Node
Front Panel

Activity 4-2. Use a 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.
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.
©
National Instruments Corporation 4-5 LabVIEW User Manual
Chapter 4 Case and Sequence Structures and the Formula Node
The Number to Match control contains the number you want to match.
Current Number indicator displays the current random number.
The
# of iterations indicator displays the number of iterations before
The 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 decima l 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 windo w 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.
LabVIEW User Manual 4-6
©
National Instruments Corporation
Chapter 4 Case and Sequence Structures and the Formula Node

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 r ange, or suspend execution. The range error symbol 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.
©
National Instruments Corporation 4-7 LabVIEW User Manual
Chapter 4 Case and Sequence Structures and the Formula Node
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.
LabVIEW User Manual 4-8
©
National Instruments Corporation
Chapter 4 Case and Sequence Structures and the Formula Node
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. Fin ish 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 hav e elapse d 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 th is 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.
©
National Instruments Corporation 4-9 LabVIEW User Manual
Chapter 4 Case and Sequence Structures and the Formula Node
Round to Nearest function (Functions»Numeric)—In this activity, the function rounds the random n umber 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 (Fu nctions»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 specifi ed does not match the number that the Rando m 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
Match
control and run the VI.
16. Save the VI as
Time to Match.vi in the LabVIEW\Activity
directory.
Number to
End of Activity 4-2.
LabVIEW User Manual 4-10
©
National Instruments Corporation

Formula Node

Chapter 4 Case and Sequence Structures and the 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 us ing regular G arithmetic functions, the block diagram looks like the one in the following illustration.
You can implement the same eq uation u sing 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 di agram 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 choo sin g 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 ( ; ).
©
National Instruments Corporation 4-11 LabVIEW User Manual
Chapter 4 Case and Sequence Structures and the Formula Node
The operators and functions av ailable 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 Formu la Node.
Consider the following code fragment th at computes the square root o f
x is positive, and assigns the result to y. If x is negative, the code assigns
y.
-99 to
if (x >= 0) then y = sqrt(x) else y = -99 end if
x if
You can implement the co de fr agmen t using a Formula Node, as shown in the following illustration.
LabVIEW User Manual 4-12
©
National Instruments Corporation
Chapter 4 Case and Sequence Structures and the Formula Node
Conditional
Operator
Condition
Condition
False
Condition
True

Activity 4-3. Use the Formula Node

Y our objective is to build a VI that uses the F ormula 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 Chapter 5, Arrays, Clusters, and Graphs.
©
National Instruments Corporation 4-13 LabVIEW User Manual
Chapter 4 Case and Sequence Structures and the Formula Node
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 th e graph legend shown in the following illustration by selecting Show»Legend. Use the Resizing cursor to drag the legend downward so it displays two plots. Use the Labeling tool 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 on the plots legend.
Block Diagram
3. Bu ild 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. Yo u create the output terminal by choosing Add Output from the pop-up menu.
LabVIEW User Manual 4-14
©
National Instruments Corporation
Loading...