LabVIEW Basics II Course Manual 6 (1) .0
LabVIEW Basics II Course Manual 6 (1) .0
Course Manual
Copyright
Copyright 1993, 2000 by National Instruments Corporation,11500 North Mopac Expressway, Austin, Texas 78759-3504.
Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including
photocopying, recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written consent
of National Instruments Corporation.
Trademarks
LabVIEW, National Instruments, and ni.com are trademarks of National Instruments Corporation.
Product and company names mentioned herein are trademarks or trade names of their respective companies.
Worldwide Offices
Australia 03 9879 5166, Austria 0662 45 79 90 0, Belgium 02 757 00 20, Brazil 011 284 5011, Canada (Calgary) 403 274 9391,
Canada (Ontario) 905 785 0085, Canada (Qubec) 514 694 8521, China 0755 3904939, Denmark 45 76 26 00,
Finland 09 725 725 11, France 01 48 14 24 24, Greece 30 1 42 96 427, Germany 089 741 31 30, Hong Kong 2645 3186,
India 91805275406, Israel 03 6120092, Italy 02 413091, Japan 03 5472 2970, Korea 02 596 7456, Mexico (D.F.) 5 280 7625,
Mexico (Monterrey) 8 357 7695, Netherlands 0348 433466, New Zealand 09 914 0488, Norway 32 27 73 00,
Poland 0 22 528 94 06, Portugal 351 1 726 9011, Singapore 2265886, Spain 91 640 0085, Sweden 08 587 895 00,
Switzerland 056 200 51 51, Taiwan 02 2528 7227, United Kingdom 01635 523545
Contents
Student Guide
A.
B.
C.
D.
E.
F.
Lesson 1
Planning LabVIEW Applications
A. The Planning and Design Process......................................................................... 1-2
B. The Implementation Process................................................................................ 1-3
C. Error Handling Techniques................................................................................... 1-4
D. LabVIEW Programming Architectures ................................................................ 1-10
E. VI Templates ........................................................................................................ 1-21
Summary, Tips, and Tricks......................................................................................... 1-24
Lesson 2
Designing Front Panels
A. Basic User Interface Issues................................................................................... 2-2
B. Using Boolean Clusters as Menus ........................................................................ 2-14
C. Property Nodes ..................................................................................................... 2-24
Common Properties .................................................................................................... 2-27
D. Graph and Chart Properties .................................................................................. 2-37
E. Control References ............................................................................................... 2-46
F. LabVIEW Run-Time Menus (Optional)............................................................... 2-51
G. Intensity Plots ....................................................................................................... 2-60
Summary, Tips, and Tricks......................................................................................... 2-64
Additional Exercises................................................................................................... 2-65
iii
Contents
Lesson 3
Data Management Techniques
A. Data Management Techniques in LabVIEW........................................................3-2
B. Local Variables .....................................................................................................3-4
C. Global Variables ...................................................................................................3-14
D. Important Advice about Local and Global Variables ...........................................3-23
E. DataSocket ............................................................................................................3-26
Summary, Tips, and Tricks.........................................................................................3-35
Additional Exercises ...................................................................................................3-36
Lesson 4
Advanced File I/O Techniques
A. Working with Byte Stream Files ..........................................................................4-2
B. LabVIEW Datalog Files .......................................................................................4-13
C. Streaming Data to Disk.........................................................................................4-20
Summary, Tips, and Tricks.........................................................................................4-21
Additional Exercises ...................................................................................................4-22
Lesson 5
Developing Larger Projects in LabVIEW
A. Assembling a LabVIEW Application ...................................................................5-2
B. LabVIEW Features for Project Development.......................................................5-13
C. LabVIEW Tools for Project Management............................................................5-21
Summary, Tips, and Tricks.........................................................................................5-35
Additional Exercises ...................................................................................................5-36
Lesson 6
Performance Issues
A. LabVIEW Multithreading and Multitasking Overview........................................6-2
B. The Profile Window..............................................................................................6-6
C. Speeding Up Your VIs..........................................................................................6-12
D. System Memory Issues .........................................................................................6-25
E. Optimizing VI Memory Use .................................................................................6-28
Summary, Tips, and Tricks.........................................................................................6-46
Appendix
A.
B.
C.
D.
E.
Polymorphic SubVIs.............................................................................................A-2
Custom Graphics in LabVIEW.............................................................................A-7
The LabVIEW Web Server...................................................................................A-14
Additional Information .........................................................................................A-20
ASCII Character Code Equivalents Table ............................................................A-22
iv
ni.com
Student Guide
Thank you for purchasing the LabVIEW Basics II course kit. You can begin
developing an application soon after you complete the exercises in this
manual. This course manual and the accompanying software are used in the
two-day, hands-on LabVIEW Basics II course. You can apply the full
purchase of this course kit towards the corresponding course registration fee
if you register within 90 days of purchasing the kit. Visit the Customer
Education section of ni.com for online course schedules, syllabi, training
centers, and class registration.
An introduction that describes the purpose of the lesson and what you
will learn
SG-1
Student Guide
Front Panel
Block Diagram
SG-2
ni.com
Student Guide
Description
LVB2SW.exe
LVB2Sol.exe
LVB2Read.txt
SG-3
Student Guide
Windows
1. Run the program called LVB2SW.exe. The course files will be extracted
to the c:\exercises\LV Basics 2 directory:
Basics2.llb will be installed in the LabVIEW\user.lib directory.
Macintosh
1. As shown in steps 1 and 2 of the Windows installation, use a
Windows-based PC to extract the files and transfer them to your
Macintosh. If you do not have access to a PC, contact National
Instruments for uncompressed files.
2. Copy the files to your hard disk using the directory structure described
in the Windows section.
UNIX
1. As shown in steps 1 and 2 of the Windows installation, use a
Windows-based PC to extract the files and transfer them to your
workstation. If you do not have access to a PC, contact National
Instruments for uncompressed files.
2. Mount the PC disk you are using to transfer the files. The course
assumes the directory structure described in the Windows section.
Copy all files to the appropriate location.
SG-4
ni.com
Student Guide
If the user is not correctly logged in, other features are disabled.
The user can analyze a subset of data and save the results to a file.
The user can load and view analysis results previously saved to disk.
The following course map contains notes about the parts of the project you
will develop in various sections of the course. Exercises within the lessons
also remind you when you are working on a VI used in a later exercise.
This course does not describe any of the following:
Programming theory
SG-5
Student Guide
E. Course Map
Planning
LabVIEW
Applications
Data Management
Techniques
Creating Larger
Projects
Performance
Issues
SG-6
ni.com
Student Guide
F. Course Conventions
The following conventions appear in this course manual:
The symbol leads you through nested menu items and dialog box options
to a final action. The sequence FilePage SetupOptions directs you to pull
down the File menu, select the Page Setup item, and select Options from
the last dialog box.
This icon denotes a note, which alerts you to important information.
This icon indicates that an exercise requires a plug-in DAQ device.
bold
Bold text denotes items that you must select or click in the software, such as
menu items and dialog box options. Bold text also denotes parameter names,
controls and buttons on the front panel, dialog boxes, sections of dialog
boxes, menu names, and palette names.
italic
monospace
Text in this font denotes text or characters that you should enter from the
keyboard, sections of code, programming examples, and syntax examples.
This font is also used for the proper names of disk drives, paths, directories,
programs, subprograms, subroutines, device names, functions, operations,
variables, filenames and extensions, and code excerpts.
Platform
Text in this font denotes a specific platform and indicates that the text
following it applies only to that platform.
right-click
right-click.
SG-7
Lesson 1
Planning LabVIEW
Applications
This lesson describes some of the issues involved when developing
LabVIEW applications, including the design process, the organization of
subVI components, and the process of combining those components to
create a complete application. This lesson also describes common
LabVIEW programming architectures along with some tools to help you
build VIs.
1-1
Process
Customer
Feedback
Define Project
Design
Flowchart
Integrate SubVIs
into Project
Implement
Nodes as VIs
Test SubVIs
Top-Down
Bottom-Up
LabVIEW Project Development Process
Designing a flow diagram can help you visualize how your application
should operate and set up the overall hierarchy of your project. Because
LabVIEW is a data flow programming language and its block diagrams are
similar to typical flowcharts, it is important to carefully plan this chart. You
can directly implement many nodes of the flowchart as LabVIEW subVIs.
By carefully planning the flowchart before implementing your LabVIEW
application, you can save development time later.
Also, keep in mind the following development guidelines:
1-2
ni.com
Lesson 1
1-3
The previous example illustrates a typical usage of the error in/error out
approach. That is, the File I/O VIs and functions use error clusters to pass
information from one operation to the next. You can then use the error
handling VIs from the bottom row of the Time & Dialog palette to notify
the user of any error conditions that occur.
The General Error Handler VI also accepts the error in cluster or the error
code value and a dialog box of the type specified appears when an error
occurs. However, in addition, you can set up error exception lists so that
specified errors are cleared or set when they occur. You also can use the
General Error Handler VI to add errors to the internal error description table.
The error description table describes all errors for LabVIEW and its
1-4
ni.com
Lesson 1
associated I/O operations. Therefore, you can add your own error codes and
descriptions to the error handler VIs. Refer to the LabVIEW Help for
information about how to modify your error handler VIs.
When an error occurs, the Simple Error Handler and General Error Handler
VIs open a dialog box that displays the information contained in the error
cluster and possible reasons for that error as listed in the internal error
description table.
Sometimes you have separate lines of operations that run in parallel in
LabVIEW and each operation maintains their own error clusters. You can
use the Merge Errors VI to combine several error clusters into one.
The Merge Errors VI looks at the incoming error clusters or the array of
error clusters and outputs the first error found. If no errors occur, LabVIEW
returns the first warning message, error code is a positive value. Otherwise,
LabVIEW returns a no error condition.
1-5
As shown in the previous example, you place the code you wish to run in the
No Error case and then define the error out value for that case depending
upon what is occurring in that case.
In the next exercise you will build a VI that generates data, analyzes those
data, and presents the data to the front panel while using error clusters
appropriately.
1-6
ni.com
Lesson 1
Exercise 1-1
Objective:
To build a VI that generates, analyzes, and displays data while using error handling
techniques.
You will build a VI that generates a noisy sine waveform, computes the
frequency response of those data, and plots the time and frequency
waveforms in waveform graphs. You will use the error clusters and the error
handling VIs to properly monitor error conditions.
Note
Front Panel
1-7
Block Diagram
3. Open and build the block diagram using the following components.
a. Place a While Loop located on the FunctionsStructures palette on
the block diagram. This structures the VI to continue to generate and
analyze data until the user clicks the Stop button. Right-click the
Conditional terminal and select Stop If True.
b.
1-8
ni.com
Lesson 1
1-9
Simple VI Architecture
When doing calculations or making quick lab measurements, you do not
need a complicated architecture. Your program might consist of a single VI
that takes a measurement, performs calculations, and either displays the
results or records them to disk. The Simple VI architecture usually does not
require a specific start or stop action from the user and can be initiated when
the user clicks the run arrow. In addition to being commonly used for simple
applications, this architecture is used for functional components within
larger applications. You can convert these simple VIs into subVIs that are
used as building blocks for larger applications.
1-10
ni.com
Lesson 1
The previous front panel and block diagram example is the Convert C to
F VI built in the LabVIEW Basics I course. This VI performs the single task
of converting a value in degrees Celsius to degrees Fahrenheit. You can use
this simple VI in other applications that need this conversion function
without needing to remember the equation.
General VI Architecture
In designing an application, you generally have up to three main phases:
Startup
Main Application
Shutdown
The following block diagram shows this general architecture. For simple
applications, the main application loop can be fairly straightforward. When
you have complicated user interfaces or multiple events, such as, user
action, I/O triggers, and so on, this section can get more complicated. The
next few illustrations show design strategies you can use to design larger
applications.
Notice in the previous block diagram that the error cluster wires control the
execution order of the three sections. The While Loop cannot begin running
until the Startup VI is finished running and returns the error cluster.
Consequently, the Shutdown VI cannot run until the main program in the
While Loop is finished and the error cluster is passed out of the loop.
Another thing to notice in the previous block diagram is the wait function.
A wait function is required in most loops, especially if that loop is
1-11
monitoring user input on the front panel. Without the wait function, the loop
might run continuously so that it uses all of the computer's system resources.
The wait function forces the loop to run asynchronously even if the wait
period is specified as zero milliseconds. If the operations inside the main
loop react to user inputs, then the wait period can be increased to a level
acceptable for reaction times. A wait of 100200 ms is usually good as most
users will not detect that amount of delay between pushing a button on the
front panel and the subsequent event executing.
This structure is straightforward and appropriate for some simple menu type
VIs where a user is expected to select from one of several buttons that lead
to different actions. This VI architecture also has an advantage over other
techniques in that taking care of one event does not prevent you from
responding to additional events. For example, if a user selects a button that
causes a dialog box to appear, parallel loops can continue to respond to I/O
events. Therefore, the main advantage of the Parallel Loops VI architecture
is its ability to handle simultaneous multiple independent processes.
The main disadvantages of the parallel loop VI architecture lie in
coordinating and communicating between different loops. The Stop button
1-12
ni.com
Lesson 1
for the second loop in the previous block diagram is a local variable. You
cannot use wires to pass data between loops, because that would prevent
the loops from running in parallel. Instead, you have to use some global
technique for passing information between processes. This can lead to race
conditions where multiple tasks attempt to read and modify the same data
simultaneously resulting in inconsistent results and are difficult to debug.
Refer to Lesson 3, Data Management Techniques, of this course for more
information about global variables, local variables, and race conditions.
Note
An advantage of this VI architecture is that you can use wires to pass data.
This helps improve readability. This also reduces the need for using global
data, and consequently makes it less likely that you will encounter race
conditions. You can use shift registers on the loop border to remember
values from one iteration to the next to pass data as well.
Several disadvantages exist to the multiple case structure VI architecture.
First, you can end up with block diagrams that are very large and
consequently are hard to read, edit, and debug. In addition, because all event
handlers are in the same loop, each one is handled serially. Consequently, if
an event takes a long time, your loop cannot handle other events. A related
problem is that events are handled at the same rate because no event can
repeat until all objects in the While Loop complete. In some applications,
you might want to set the priority of user interface events to be fairly low
compared to I/O events.
1-13
1-14
ni.com
Lesson 1
In this architecture, you design the list of possible events, or states, and then
map that to each case. For the VI in the previous block diagram, the possible
states are startup, idle, event 1, event 2, and shutdown. These states above
are stored in an enumerated constant. Each state has its own case where you
place the appropriate nodes. While a case is running, the next state is
determined based on the current outcome. The next state to run is stored in
the shift register. If an error occurs an any of the states, the shutdown case is
called.
The advantage of the State Machine VI architecture is that the block
diagram can become much smaller, making it easier to read and debug.
One drawback of the Sequence structure is that it cannot skip or break out
of a frame. The State Machine architecture solves that problem because each
case determines what the next state will be as it runs.
A disadvantage to the State Machine VI architecture is that with the
approach in the previous block diagram, you can lose events. If two events
occur at the same time, this model handles only the first one, and the second
one is lost. This can lead to errors that are difficult to debug because they
can occur only occasionally. More complex versions of the State Machine
VI architecture contain extra code that builds a queue of events, states,
so that you do not miss any events.
1-15
1-16
ni.com
Lesson 1
Exercise 1-2
Objective:
Verify Information VI
Note
Front Panel
1. Open a new VI and build the previous front panel. Modify the string
controls as described in the labels by right-clicking the control. The
Table control located on the ControlsList & Table palette is a
two-dimensional array of strings where the first cell is at element 0,0.
2. Enter the information shown in the previous front panel in the Table and
save those values as default by right-clicking the Table and selecting
Data OperationsMake Current Value Default from the shortcut
menu.
1-17
Block Diagram
3. Open and build the previous block diagram using the following
components.
a. Place a While Loop located on the FunctionsStructures palette on
the block diagram. This structures the VI to continue checking for a
match until a name match occurs or there are no more rows in the
table. Notice that indexing is enabled on the names array but not on
the other two items entering the While Loop. Enable the indexing by
right-clicking the tunnel and selecting Enable Indexing from the
shortcut menu.
b. Place a Case structure located on the FunctionsStructures palette
on the block diagram. If the Name input matches a listing in the first
column of the table, the Passwords are also checked. If the Name
does not match the current table entry, the loop continues to the next
iteration.
To create the Boolean constant in the False case, wait until the True
case is completely wired. Then select the False case and right-click
the green outlined tunnel and select CreateConstant from the
shortcut menu.
c. Place the Index Array function located on the FunctionsArray
palette on the block diagram. This function is used to pull the names
1-18
ni.com
Lesson 1
array out of the table. When you wire the table to the array input of
this function, two indicesrows and columns appear. Right-click
the bottom index, columns, and select CreateConstant from the
shortcut menu. You will use two of these functions, so make a copy
of the Index Array function and place it into the True Case.
d. Place the Array Size function located on the FunctionsArray
palette on the block diagram. This function returns the size of the
names array.
e. Place the Decrement function located on the FunctionsNumeric
palette on the block diagram. This function decreases the number of
names in the array by one so that it can control the While Loop
which starts indexing at 0.
f. Place the Equal? function located on the FunctionsComparison
palette on the block diagram. You will use two of these functions to
check if the Name input matches a table entry and if the Password
also matches the table entry.
g. Place the Less Than? function located on the Functions
Comparison palette on the block diagram. This function controls
the While Loop conditional. The loop continues to run while the
current iteration number is less than the number of rows in the table.
h. Place the Not Or function located on the FunctionsBoolean palette
on the block diagram. This function also controls the conditional of
the While Loop so that the loop continues until a match is found or
there are no more rows in the table.
i. Place the Empty String constant located on the FunctionsString
palette on the block diagram. You will use two of these functions,
one in the True case and one in the False case. If the names match
but not the passwords or if neither match, then an empty string is
returned in the Name Confirmed indicator.
j. Place the Select function located on the FunctionsComparison
palette on the block diagram. This function is used along with the
password matching. If the password matches, the current name is
sent to the Name Confirmed indicator; otherwise, the Empty String
is sent.
4. Save this VI as Verify Information.vi.
5. Go to the front panel and make sure you have some namesthe names
do not have to be the same ones used in the course manualand
passwords in the table control. If you have not already done so,
right-click the table and select Data OperationsMake Current
Values Default so that the names and passwords are permanently stored
in the table.
1-19
6. Enter values into the Name and Password controls and run the VI.
If the Name and Password match one of the rows in the table, the name
is returned in the Name Confirmed indicator and the Verified LED is
lit. Otherwise, an empty string is returned and the Verified LED is off.
Be sure to try various combinations of names and passwords to make
sure that this VI shows the correct behavior.
7. Create an icon for this VI because you will use this VI as a subVI in a
later exercise. To create the icon, right-click the icon in the top right
corner of either the front panel or the block diagram and select Edit Icon
from the menu. Design an icon similar to the one shown here.
8. Create the connector pane for this VI by right-clicking the icon in the
front panel and selecting Show Connector from the shortcut menu.
Select a pattern and connect the front panel objects to the terminals as
shown in the following connector pane.
1-20
ni.com
Lesson 1
E. VI Templates
In the last section, you learned about some of the common programming
architectures for VIs. So that you do not have to start building each new VI
from an empty front panel and block diagram, a number of templates are
included with the LabVIEW package. These VI templates can be found in
the LabVIEW 6\Templates directory and contain the file extension .vit.
LabVIEW provides some basic templates, however, not all of the VI
architectures described are available as templates.
You can save a VI you create as a template by using the FileSave with
Options option as shown in the following dialog box.
1-21
Exercise 1-3
Objective:
Front Panel
1. Open the Timed While Loop with Stop.vit from the LabVIEW
6\Templates directory. The front panel only contains the Stop button.
Block Diagram
1-22
ni.com
Lesson 1
Block Diagram
1-23
After you design a flowchart, you can develop VIs to accomplish the
various steps in your flowchart. It is a good idea to modularize your
application into logical subtasks when possible. By working with small
modules, you can debug an application by testing each module
individually. This approach also makes it much easier to modify the
application in the future.
Error clusters are a powerful method of error handling used with nearly
all of the I/O VIs and functions in LabVIEW. These clusters pass error
information from one VI to the next.
An error handler at the end of the data flow can receive the error cluster
and display error information in a dialog box.
The most common VI architectures are the Simple, the General, the
Parallel Loops, the Multiple Case Structures, and the State Machine.
Each of these architectures has advantages and disadvantages depending
upon what you want your application to do.
The State Machine VI architecture is very useful for user interface VIs
and it generates clean, simple code.
Several template VIs ship with the LabVIEW package so you do not
need to start VI development from empty front panels and block
diagrams each time.
1-24
ni.com
Lesson 1
Notes
1-25
Notes
1-26
ni.com
Lesson 2
Designing Front Panels
This lesson introduces how you can design and build the user interface to
your VIs. First, an overview and list of things to consider while building the
front panel. The next few sections describe some common methods and
tools for customizing panels. The last few sections describe additional items
and panel objects used for developing user interfaces.
2-1
The next example shows the same subVI after the front panel has been
resized and the menu bar, scrollbars, and toolbar have been removed with
the VI PropertiesWindow AppearanceDialog option.
2-2
ni.com
Lesson 2
Using Color
Proper use of color can improve the appearance and functionality of your
front panel. Using too many colors, however, can result in color clashes that
cause the front panels to look too busy and distracting. Here are some color
matching tips:
Start with a gray schemeselect one or two shades of gray and highlight
colors that have good contrast with the background.
Add highlight colors sparinglyon plots, abort buttons, and perhaps the
slider thumbs for important settings. Small objects need brighter colors
and more contrast than larger objects.
2-3
2-4
ni.com
Lesson 2
Dialog Controls
A common user interface technique is to have dialog boxes appear at
appropriate times to interact with the user. You can make a VI behave like a
dialog box by checking that option in the FileVI PropertiesWindow
Appearance dialog box. The ControlsDialog Controls palette contains
the same kinds of objects available in system dialog boxes.
You should use these dialog controls to build system-like dialogs. Dialog
controls change appearance according to the operating system and Window
Appearance settings and they typically ignore all color clicks except
transparent. If you are integrating a graph or non-dialog controls into the
front panel, try to make them match by hiding some borders or selecting
colors similar to the system.
Tab Controls
Physical instruments usually have good user interfaces. Borrow heavily
from them, but move to smaller or more efficient controls, such as rings,
or tab controls where this makes sense. Tab Controls are found in the
ControlsDialog Controls palette or the ControlsArray & Cluster
palette and offer a convenient way to group front panel objects together.
The way you use a Tab Control is to place it on the front panel as shown
previously. You add tabs by right-clicking an existing tab and selecting Add
Page After, Add Page Before, or Duplicate Page from the menu. You
relabel the tabs with the Labeling tool, and you place other front panel
objects into the appropriate pages. The terminals for these objects are
available in the block diagram as are terminals for any other front panel
object.
2-5
The Tab Control wires directly to a Case structure as shown previously and
the page name shows up as the name of the case. You can then wire the data
to and from the other terminals as needed.
Decorations
One of the easiest and often overlooked methods of grouping or separating
objects is to use an item from the ControlsDecorations palette. You can
select to use various types of boxes, arrows, and lines from this palette as
follows:
2-6
ni.com
Lesson 2
Menus
Menus are a good way to present most of a front panels functionality in an
orderly way and in a relatively small space. This leaves room on the front
panel for actions that are needed in an emergency, items for beginners, items
needed for productivity, and items that do not fit well into menus. Also be
sure to add menu shortcut keys for the frequently accessed items. Later in
this lesson you will learn how to create your own menus in a VI.
2-7
Exercise 2-1
Objective:
Scope Panel.vi
To logically arrange and separate front panel objects to make the user interface of
a VI easier to read and use.
You will resize, reorganize, and rearrange the objects on the front panel to
make the user interface easier to use. You will also setup the graph to resize
along with the front panel.
Front Panel
Remember to use the Align Objects and Distribute Objects features in the tool bar.
3. After making groups out of the controls, use the Raised Box decoration
on the ControlsDecorations palette to make visible separations
2-8
ni.com
Lesson 2
between the groups. And resize your window so the front panel fits
inside the window, as shown in the following example.
You need to use the Reorder button in the tool bar on the decorations to Move to
Back, so that the controls are visible and on top of the raised boxes.
Tip
2-9
Exercise 2-2
Objective:
Acquire Data.vi
To modify a VI to use the Tab Control along with proper user-interface design
techniques.
You will modify the Generate & Analyze VI so that it uses the tab control.
One page of the tab will be for the generation of data as before and a second
page will be for acquiring the data from a DAQ device.
Note
Front Panel
1. Open the Generate & Analyze VI you built in Exercise 1-1. Resize the
front panel to make room on the left of the other front panel objects as
you will be adding the tab control.
2. Place a Tab Control located on the ControlsArray & Cluster palette
on the front panel as shown previously. Select the Sine Frequency, Sine
Amplitude, Sampling Info, and Noise Amplitude controls and place
them into the first page of the Tab Control.
2-10
ni.com
Lesson 2
3. Name the two pages of the tab control Simulate and DAQ respectively.
Click the DAQ page and add the objects as follows:
2-11
Block Diagram
7. Open and modify the block diagram as shown previously using the
following components:
a. Place a Case structure located on the FunctionsStructures palette
on the block diagram. When used with the tab controlone case
handles the Simulate page and the other case is for the DAQ page.
b. Place the AI Acquire Waveform VI located on the FunctionsData
AcquisitionAnalog Input palette on the block diagram. This VI
acquires data from an analog input channel on the DAQ device.
Note If you do not have a DAQ device or a DAQ Signal Accessory, use the Demo
Acquire Waveform VI located on the FunctionsUser LibrariesBasics 2 Course
palette on the block diagram in place of the AI Acquire Waveform VI. The Demo Acquire
Waveform VI simulates acquiring data from an analog input channel at a specified
sampling rate and returning the specified number of samples.
2-12
ni.com
Lesson 2
2-13
2-14
ni.com
Lesson 2
Cluster Conversion
You can convert a cluster to an array if all cluster components have the same
data type (for example, all are Boolean data types or all are numeric). With
this conversion, you can use array functions to process components within
the cluster.
The Cluster to Array function FunctionsCluster and FunctionsArray
palettes converts a cluster of identically typed components to a 1D array of
the same data type.
2-15
Front Panel
Cluster Panel
Block Diagram
You must right-click the function icon to set the number of components in the
cluster. The default number of components in the output cluster is nine.
Note
You can combine the concept of a state machine with a Boolean menu
cluster to provide a powerful system for menus. For example, perhaps you
need to provide the following application, which can be divided into a series
of states.
State Value
State Name
Description
Next State
1, Default
No Event
Monitor Boolean
menu to determine
the next state
Depends on the
Boolean button
pressed. If no button
is pressed, next state
is No Event.
Login
Log in user
No Event (0)
Configure
Configure
acquisition
Acquire (2)
Acquire
Acquire data
No Event (0)
2-16
ni.com
Lesson 2
The front panel consists of a Boolean button cluster, with each button
triggering a state in the state machine. In state 1 (the No Event state), the
Boolean button cluster is checked to see if a button has been pressed. The
Search 1D Array function returns the index of the button pressed (or 1 if
no button is pressed) to determine the next state to execute. That state value
is loaded into the shift register, so that on the next iteration of the while loop
the selected state will execute.
In each of the other states, the shift register is loaded with the next state to
execute using a numeric constant. Normally this is state 1, so that the
Boolean menu will be checked again, but in state 1 (Configure) the
subsequent state is state 2 (Acquire).
2-17
Exercise 2-3
Objective:
Menu.vi
State Name
Description
Next State
1, Default
No Event
Monitor Boolean
menu to determine
the next state
Depends on the
Boolean button
pressed. If no button
is pressed, next state
is No Event.
Login
Log in user
No Event
Acquire
Acquire data
No Event
Analyze
Analyze data,
possibly save to file
No Event
View
No Event
Stop
Stop VI
No Event
In this exercise, you will build the state machine to be used in this
application and observe its operation.
Note
2-18
ni.com
Lesson 2
Front Panel
2-19
Block Diagram
2-20
ni.com
Lesson 2
2-21
Exercise 2-4
Objective:
Front Panel
2-22
ni.com
Lesson 2
Block Diagram
False case is empty except for passing the cluster from the left shift register
to the right shift register.
1. Open and examine the block diagram.
2. Run the VI. Click a button. The corresponding digital indicator should
increment each time you click a button.
3. Close the VI. Do not save any changes.
2-23
C. Property Nodes
In some applications, you might want to programmatically modify the
appearance of front panel objects in response to certain inputs. For example,
if a user enters an invalid password, you might want to cause a red LED to
start blinking. Another example would be changing the color of a trace on a
chart. When data points are above a certain threshold, you might want to
show a red trace instead of a green one. Resizing front panel objects, hiding
parts of the front panel, and adding cursors to graphs also can be done
programmatically using Property Nodes.
Property Nodes in LabVIEW are very powerful and have many uses. This
course only covers one use for Property Nodes to change the appearance and
functional characteristics of front panel objects programmatically. You can
set properties such as display colors, visibility, position, size, blinking,
menu strings, graph or chart scales, graph cursors, and many more. Refer to
the HelpContents and Index in LabVIEW for more information about the
Property Node.
2-24
ni.com
Lesson 2
Property Node receives the data. Wiring a TRUE causes the control to
reappear.
You can read the current state of a property by right-clicking the Property
Node terminal and selecting Change To Read. When the Property Node is
called, it will output a Boolean TRUE if the control is visible or a Boolean
FALSE if it is invisible.
Operating
tool
Positioning
tool
From the terminal on the Property Node, you can select properties by
clicking the node with the Operating tool, shown at left, and selecting the
desired property from the shortcut menu.
You can read or set more than one property with the same node by enlarging
the Property Node. Using the Positioning tool, shown at left, click the lower
corner of the Property Node and drag the corner down to enlarge the node.
As you enlarge the node, you add more terminals. You can then associate
each Property Node terminal with a property from its shortcut menu.
2-25
To access bundled properties, select the All Elements option from the
propertys shortcut menu. For example, you can access all the elements in
the Position property by selecting PositionAll Elements or you can access
a single element from that bundle.
Execution
Order
2-26
ni.com
Lesson 2
Common Properties
There are many properties available for the various front panel objects in
LabVIEW. This section describes the Visible, Disable, Key Focus, Blink,
Position, Bounds, and Value properties, which are common to all front panel
objects. It also introduces some Property Nodes for specific kinds of
controls and indicators.
Visible Property
The Visible property, shown at left, sets or reads the visibility of a front
panel object. The associated object is visible when TRUE, hidden when
FALSE.
Wiring ExampleSet the digital control to an invisible state. A Boolean
TRUE value makes the control visible, as shown.
Block Diagram
Front Panel
Disabled Property
The Disabled property, shown at left, sets or reads the user access status
of an object. A value of 0 enables an object so that the user can operate it.
A value of 1 disables the object, preventing operation. A value of 2 disables
and greys out the object.
Wiring ExampleDisable user access to the digital control. The control
does not change appearance when disabled.
2-27
Wiring ExampleDisable user access to the digital control and grey it out.
Blinking Property
The Blinking property, shown at left, reads or sets the blink status of an
object. By setting this property to TRUE, an object will begin to blink. You
can set the blink rate and colors by selecting ToolsOptions and selecting
Front Panel and Colors from the top pull-down menu. When this property is
set to FALSE, the object stops blinking.
Wiring ExampleEnable blinking for the digital control.
1
1
Block Diagram
2
2
Value Property
The Value property, shown at left, reads or sets the current value of an object.
When you set the Value property to write, it writes the wired value to object
whether it is a control or indicator. When you set the Value property to read,
it reads the current value in either a control or indicator. The example
2-28
ni.com
Lesson 2
Position Property
The Position property, shown at left, sets or reads the position of an objects
upper left corner on the front panel. The position is determined in units of
pixels relative to the upper left corner of the front panel. This property
consists of a cluster of two unsigned long integers. The first item in the
cluster (Left) is the location of the left edge of the control relative to the left
edge of the front panel, and the second item in the cluster (Top) is the
location of the top edge of the control relative to the top edge of the front
panel.
Wiring ExampleMake the digital control change its location on the front
panel.
2-29
Bounds Property
The Bounds property, shown at left, reads the boundary of an object on the
front panel in units of pixels. The value includes the control and all of its
parts, including the label, legend, scale, and so on. This property consists of
a cluster of two unsigned long integers. The first item in the cluster (Width)
is the width of object in pixels, and the second item in the cluster (Height)
is the height of the object in pixels. This is a read-only property. It does not
resize a control or indicator on the front panel. Some objects have other
properties for resizing, such as the Plot Area Size property for graphs and
charts.
Wiring ExampleDetermine the bounds of the digital control.
2-30
ni.com
Lesson 2
2-31
Wiring ExampleShow the text in the string control in the three other
modes.
2-32
ni.com
Lesson 2
Exercise 2-5
Objective:
Front Panel
Block Diagram
2-33
2. Open and build the block diagram shown previously using the following
components:
a. Place the While Loop located on the FunctionsStructures palette
on the block diagram. This structures the VI to continue running
until the user presses the Stop button. Right-click the Conditional
terminal and select Stop If True.
b. Place the Wait Until Next ms Multiple function located on the
FunctionsTime & Dialog palette on the block diagram. This
function causes the While Loop to execute once a second. Create
the constant by right-clicking the input terminal and selecting
CreateConstant.
c. Place the Random Number (0-1) function located on the
FunctionsNumeric palette on the block diagram. Creates a
random number between zero and one.
d. Place the Multiply function located on the FunctionsNumeric
palette on the block diagram. Multiplies two numbers together and
is used here to scale the random number to be between zero and 10.
e. Place the Greater? function located on the FunctionsComparison
palette on the block diagram. Compares two values, in this case the
random value and the limit value, and returns a True if the random
value is greater than the limit. Otherwise it returns a False.
f. Place the Select function located on the FunctionsComparison
palette on the block diagram. You will use two of these functions.
This function takes a Boolean input and outputs the top value if the
Boolean object is True and the bottom value if the Boolean object is
False.
g. Place the Color Box Constant located on the FunctionsNumeric
Additional Numeric Constants palette on the block diagram. This
constant is used to color the panel objects through their Property
Node. You will need two of these constants. Use the operating tool
to select the color and make one red and the other blue.
h. Create the Tank Property Node on the block diagram. To create this
node, right-click the Tank terminal and select CreateProperty
Node from the shortcut menu. Resize this node by dragging the
corner with the positioning tool to show three terminals. Select the
properties shown by right-clicking each terminal and selecting the
item from the Properties menu. Right-click this node and select
Change All To Write from the menu.
i. Place the Bundle function located on the FunctionsCluster palette
on the block diagram. This function clusters together the left and top
positions into the Position property for the tank.
2-34
ni.com
Lesson 2
2-35
7. The Disable switch controls whether you can change the values. Flip the
Disable switch to True and all the panel objects except the Disable
switch and the Stop button are grayed out and you cannot change their
values.
8. Stop and close this VI when you are finished.
2-36
ni.com
Lesson 2
You have many scale options for graphs and charts. With Property Nodes,
you can set or read scale information for the X and Y scales. For each axis,
the VI can read or set the minimum, maximum, and increment values.
You also can use Property Nodes to programmatically read or set the plot
and background colors, and the X and Y grid colors. You can use this
capability to set plot or background colors depending on program conditions
such as out-of-range or error values.
To change the size of a graph or chart, use the Plot AreaSize property.
Thus, if you want to have a particular plot appear in a small window during
part of your application, but appear larger later, you can use this property in
conjunction with other properties that change the size of a VIs panel.
Using Property Nodes, you have access to the information that cursors
provide on graphs. You use cursors to move a graphic selector on the plot.
A cursor can be locked to the plot or can float on the plotting surface. Values
from each cursor are returned to an optional display on the front panel.
Property Nodes present a means to programmatically set or read cursor
position on the graph, allowing user input from cursors in the VI.
2-37
2-38
ni.com
Lesson 2
2-39
Exercise 2-6
Objective:
Temperature Limit.vi
To create a VI that uses Property Nodes to clear a waveform chart and notify the user
if the data exceed a limit.
You will finish building a VI that uses Property Nodes to perform the
following tasks:
Set the delta X value of the chart to the sample rate in seconds.
Front Panel
2-40
ni.com
Lesson 2
Block Diagram
1. Modify the VI so that it sets the delta X value to the sample rate and
clears the Temperature chart before starting. While the VI acquires data,
it should turn the High Limit line red when the temperature exceeds
the limit value, and the Out of Range LED should blink.
a. In the Sequence structure, create a Property Node for the
Temperature chart that has two terminals. One terminal should be
the multiplier property, X ScaleOffset and MultiplierMultiplier,
and the other terminal should be the History Data property. To clear
a waveform chart from the block diagram, send an empty array of
data to the History Data property. To do this, right-click the property
and select CreateConstant. Make sure that the array constant is
empty.
b. In the Case structure inside the While Loop, create a Property Node
for the Temperature chart that has two terminals. The top terminal
should be the Active Plot property, and the bottom terminal should
be the Plot Color property, PlotPlot Color. You will need these
properties in both cases of the Case structure. The High Limit plot is
plot 1, so set the Active Plot property to one before setting the Plot
Color property. If the data are greater than the High Limit, set the
plot color to red. Otherwise, it should be yellow. Use a Color Box
constant to send the color value to this property.
c. Right-click the Out of Range indicator to create the Blink Property
Node. The indicator should blink when the temperature is greater
than the High Limit.
2-41
2-42
ni.com
Lesson 2
Exercise 2-7
Objective:
Note
Front Panel
2-43
Block Diagram
2-44
ni.com
Lesson 2
2-45
E. Control References
In the previous two sections you used Property Nodes to programmatically
change the characteristics of panel objects. If you are building a large VI that
contains many Property Nodes or if you are using the same property for
many different controls and indicators, you might want to consider placing
the Property Node in a subVI and using Control References to access that
node. A Control Reference is a refnum to a specific control. This section
shows only one way to use these versatile objects. Refer to the LabVIEW
manuals for more information about control references.
Property Nodes use error clusters like many of the I/O functions in
LabVIEW so you can use the error handlers to keep track of the error
conditions. The VI that calls this subVI can use it to change the properties
of any type of control. The following example shows the subVI disabling a
numeric and setting a Boolean object to be the key focus.
2-46
ni.com
Lesson 2
Next you will build a subVI that changes the disabled property for an array
of controls using the controls references.
2-47
Exercise 2-8
Objective:
To build a VI that uses control references to access Property Nodes from a subVI.
You will start with the Property Node Exercise VI you built in Exercise 2-5.
You will make a subVI that accesses an array of control references and
assigns the Disabled property. Then you will modify the Property Node
Exercise VI to use the subVI rather than the original Property Nodes.
Note
Front Panel
Block Diagram
2. Open and build the block diagram shown previously using the following
components:
a. Place a For Loop located on the FunctionsStructures palette on
the block diagram. The For Loop is used to auto-index through the
array of control refnums so that each refnum and property is handled
separately.
b. Place a Property Node located on the FunctionsApplication
Control palette on the block diagram. You will use this Property
Node as a generic control type. When you wire the Refnum Array to
the refnum input terminal, the function changes slightly as in the
following example:
2-48
ni.com
Lesson 2
5. Save and close this VI. You will now make a calling VI for this subVI.
6. Open the Property Node Exercise VI you built in Exercise 2-5. You will
not modify the panel.
7. Select FileSave As and rename this VI Control Refs
Exercise.vi.
2-49
2-50
ni.com
Lesson 2
Static Menus
Static menus are stored in RTM files. You can enable, create, or edit an RTM
file for a VI by selecting EditRun-Time Menu. The Menu Editor dialog
box appears.
On the left side of this dialog box is an overall organization of the menu
items. Menu items are classified into three types: User Item, Application
Item, or Separator.
A User Item can be handled programmatically in the block diagram. It has
a name, which is the string that appears in the actual menu, and a tag, which
is a unique case-insensitive string identifier. A tag identifies a User Item in
the block diagram. For ease in editing, when you enter the name, it is copied
to the tag. However, you can always edit the tag to make it different from the
2-51
name. For a menu item to be valid, its tag should not be empty. Invalid menu
items appear as ???.
An Application Item is one that LabVIEW provides. These items are part
of the default LabVIEW menu. To select a particular LabVIEW item, click
the arrow button next to the Item Name. You can add individual items or
entire submenus by using this process. Application Items are handled
implicitly by LabVIEW. These item tags do not appear in block diagrams.
You cannot alter the name, tag, or other properties of an Application Item.
LabVIEW reserves tags starting with APP_ for Application Items.
A Separator inserts a separation line in the menu. You cannot set any of the
properties for a Separator item.
The Menu Editor ensures that the tag is unique to a given menu
hierarchy by appending numbers when necessary. A User Item can be
enabled/disabled or checked/unchecked by setting the respective properties.
You can set a shortcut (accelerator) for a User Item by selecting an
appropriate key combination.
The Menu Editor allows you to insert, delete, or reorder menu items in the
menu hierarchy. Clicking the + button adds a new menu item. You also can
change the type of a menu item by selecting from the Item Type ring. In
addition, you can reorder the menu items and create submenus using the
arrow buttons. Finally, clicking the Delete Item button deletes the selected
menu item.
The Preview portion of the Menu Editor provides an up-to-date view of the
run-time menu. On the Menu Editor pull-down menu, the Open, New,
Save, and Save As buttons allow you to load and save RTM files. Once you
close the Menu Editor, you will have the option of updating the VIs
run-time menu with the menu you edited.
Dynamic Menus
While a VI executes, you can change items in the VI menu bar by using the
menu management functions described in the following sections. All of
these functions are located under FunctionsApplication ControlMenu.
All of these functions operate on a refnum for the menu retrieved using the
Current VIs Menu function.
2-52
ni.com
Lesson 2
Inserts a menu item (or an array of menu items) identified by item names
or item tags into a menu (menu bar or submenu). The position of the item
is specified either through the after item parameter or through a
combination of the menu tag and after item pair.
Deletes a menu item (or an array of menu items) identified by items from
a menu identified by menu tag (from the menu bar, if menu tag is not
specified). Items can be a tag, array of tags, position number, or an array
of position numbers.
Returns properties of the menu item specified through item tag (or the
menubar if the item tag is unspecified). Item properties include item
name, enabled, checked, and shortcut. If the item has a submenu attached,
its item tags are returned in submenu tags.
2-53
Sets properties of the menu item specified through item tag. Item properties
include item name, enabled, checked, and shortcut. Unwired properties
remain unchanged.
Returns the menubar refnum of the current VI. This function must be
executed before the other menu handling functions are invoked.
2-54
ni.com
Lesson 2
Returns the item tag of the last selected menu item, optionally waiting for
a period of time specified by timeout. Item path is a string describing the
position of the item in the menu hierarchy. Menu selection is blocked after
an item is read if block menu is set to TRUE.
2-55
Exercise 2-9
Objective:
The current run-time menu for the application is the LabVIEW default
menu. In the next several steps, you will replace that menu with a
custom list of selections.
3. Change the top ring control in the Menu Editor from Default to
Custom. The menu listed on the left portion of the dialog box should be
replaced with a ???, representing a single unnamed item.
4. In the Item Type ring control, select Application ItemOperate
Entire Menu. The LabVIEW Operate menu should be added to the
custom menu. Default LabVIEW options, as well as selections you
create, can be added to a custom menu.
Take a moment to navigate the Operate menu in the editor. Notice that
you can select various items and collapse submenus using the triangle
icons. As you select individual items in the menu, their Item Name and
Item Tag appear in the Item Properties box of the editor. When finished,
collapse the Operate menu by clicking the triangle next to the Operate
option. You should now see only the Operate item in the menu list.
2-56
ni.com
Lesson 2
5. Click the + button in the Menu Editor toolbar. A new unnamed item,
???, appears in the menu list. With this item highlighted, enter Test into
the Item Name property. This menu item now has an item name and tag
of Test.
6. Click the + button again to add another entry under the Test item. Click
the right arrow button on the toolbar, and this unnamed option becomes
a subitem under the Test menu. Type in the Item Name Test 1 for this
new item.
7. Add two more subitems under the Test submenu called Test 2 and
Test 3. The Menu Editor dialog box should now resemble the
following:
In the Preview area of the Menu Editor, you can see how the custom
menu will behave during run time.
8. Select FileSave from the Menu Editor dialog box. Save the run-time
menu as Menu Exercise.rtm in the c:\exercises\LV Basics 2
directory. Then close the Menu Editor dialog box. When LabVIEW
asks if you want to change the run-time menu to Menu Exercise.rtm,
select Yes. You have configured a custom pull-down menu which will
be invoked while the VI executes.
2-57
Block Diagram
2-58
ni.com
Lesson 2
do not show up in the Item Tag stringonly User items are returned
from the Get Menu Selection option.
To observe the flow of the VI, you might want to turn on execution
highlighting and single-stepping and examine the block diagram. Click
Stop on the VIs front panel to halt program execution.
11. Using the Menu Editor, you can assign shortcut keys to User items you
create. Assign the keyboard shortcuts to the test options according to the
following table:
Menu Item
Windows Keyboard
Shortcut
Macintosh Keyboard
Shortcut
Test 1
<Ctrl-1>
<option-1>
Test 2
<Ctrl-2>
<option-2>
Test 3
<Ctrl-3>
<option-3>
2-59
G. Intensity Plots
Intensity plots are extremely useful for displaying patterned data. For
example, the plots work well for displaying terrain, where the magnitude
represents altitude. Also, you can demonstrate temperature patterns with
intensity plots. Like the waveform graph and chart, the intensity chart
features a scrolling display while the intensity graph features a fixed display.
These displays accept a block of data and map each value to an associated
color, with a maximum of 256 accessible colors.
To change the color associated with a specific intensity value, right-click the
marker appearing next to the color ramp and select Marker Color from the
menu. The color palette appears, from which you select a color to associate
with that particular numeric value. To add more values to the color ramp,
right-click it and select Add Marker. You can drag the tick mark that
appears to the appropriate location on the color ramp, or select the text next
to the tick mark with the Labeling tool and type in the location of the marker.
After you have placed the marker at the appropriate location on the ramp,
right-click it and select Marker Color.
2-60
ni.com
Lesson 2
2-61
2. Change the Plot switch on the front panel to User Data and enter values
between 0.0 and 10.0 in the User Data array control. Run the VI. Notice
how the magnitude of each element is mapped to the intensity graph.
2-62
ni.com
Lesson 2
2-63
When you are designing user interfaces, keep the following things in
mind: the number of objects in the panel, color, spacing and alignment
of objects, and the text and fonts used.
You can convert a cluster containing components of the same data type
to an array and then use the array functions to process the cluster
components. The Cluster To Array function (FunctionsCluster or
FunctionsArray palette) converts a cluster to a 1D array.
You create Property Nodes from the Create shortcut menu of a control
or indicator (or a terminal for a control or indicator on the block
diagram).
You can create several Property Node terminals for a single front panel
object, so you can configure properties from several locations in the
block diagram.
You can set or read properties such as user access (enable, disable, gray
out), colors, visibility, location, and blinking.
Use the Context Help window to learn more about individual properties.
You can use Control References and refnums to access Property Nodes
inside subVIs.
You can programmatically create and read run-time menus with the
functions in the FunctionsApplication ControlMenu palette.
You can use intensity charts and graphs to plot three-dimensional data.
The third dimension is represented by different colors corresponding to
a color mapping that you define. Intensity charts and graphs are
commonly used in conjunction with spectrum analysis, temperature
display, and image processing.
2-64
ni.com
Lesson 2
Additional Exercises
2-11
2-12
2-13
Open the Analyze & Present Data VI you developed in Exercise 2-7
and modify the VI so that if the number of data points in the subset
is one point or less, the Log Results to File button is grayed out.
2-65
Notes
2-66
ni.com
Lesson 3
Data Management Techniques
This lesson describes how you can organize the block diagrams of your VIs
based upon how you transfer data from one place to another. First, you will
be reminded of how LabVIEW runs a VI. Then you will learn how to use
local and global data to pass data within and between VIs and tips for using
those data objects efficiently. Last, you will learn how to use DataSocket to
pass data between VIs and computers.
3-1
A node executes only when data is available at all its input terminals.
Therefore, a block diagram does not execute top to bottom or left to right,
but according to data flow rules. This contrasts with the control flow method
of executing a conventional program in which instructions execute in the
sequence in which you write them.
Wires are the key to understanding how data flow works in LabVIEW.
When wires directly connect one node to the next, the order of execution
is defined. If no wire connects two nodes, then those nodes can run
concurrently. If you require those two nodes to run in order, then you either
use a sequence structure or, if the nodes are subVIs, program data
dependencies such as the error clusters to control program execution.
3-2
ni.com
Lesson 3
This approach does not work if you need to exchange data between block
diagrams that run in parallel. Parallel block diagrams can be in two parallel
loops on the same block diagram or in two VIs that are called without any
data flow dependency. Consider the following block diagram.
This block diagram does not run the two loops in parallel because of the wire
passing between the two subVIs. The wire creates a data dependency where
the second loop does not start until the first loop is finished and passes
the data through its tunnel. The only way to make the two loops run
concurrently is to remove the wire connection. However, then the subVIs
cannot pass data between each other unless you use another technique of
data management. This lesson describes local variables, global variables,
and DataSocket as methods to pass data between parts of the same block
diagram and between different block diagrams.
3-3
B. Local Variables
Up until now, you have read data from or updated a front panel object using
its terminal on the block diagram. However, a front panel object has only
one terminal on the block diagram, and you might need to update or read a
front panel object from several locations on the block diagram. Using local
variables, you can access front panel objects in several places and pass data
between structures that cannot be connected by a wire.
Local variable
node
Local variable
icon with
number in
selected
You also can select Local Variable from the Structures palette. A local
variable node, shown at left, appears on the block diagram. You can select
the front panel object you want to access by right-clicking the variable node
and selecting an object from the Select Item menu. This menu lists the
owned labels for the front panel controls and indicators. Thus, always label
your front panel controls and indicators with descriptive names, using
owned labels.
For example, if the first object you create on the front panel is labeled
number in, the local variable icon appears as shown at left. After you place
the local variable on the block diagram, you can select the appropriate front
panel object by either clicking the variable using the Operating tool, or
right-clicking it and selecting the front panel object from the Select Item
menu.
3-4
ni.com
Lesson 3
3-5
Write Local
Method 1 (Incorrect)
As a first attempt, we place the Loop Control terminal outside of both loops
and wire it to each conditional terminal. In this case, the Loop Control
terminal is read only once, before either While Loop begins executing.
Recall that this happens because LabVIEW is a dataflow language, and the
status of the Boolean control is a data input to both loops. If a TRUE is
passed into the loops, the While Loops run indefinitely. Turning off the
switch does not stop the VI because the switch is not read during the
iteration of either loop. This solution does not work.
Method 2 (Incorrect)
Now we move the Loop Control terminal inside Loop 1 so that it is read in
each iteration of Loop 1. Although Loop 1 terminates properly, there is a
problem with this approach. Loop 2 does not execute until it receives all its
data inputs. Remember that Loop 1 does not pass data out of the loop until
the loop stops. Thus, Loop 2 must wait for the final value of the Loop
3-6
ni.com
Lesson 3
Control, available only after Loop 1 finishes. Therefore, the loops do not
execute in parallel. Also, Loop 2 executes for only one iteration because its
conditional terminal receives a FALSE value from the Loop Control switch
in Loop 1.
Method 3 (Correct)
In this example, Loop 1 is again controlled by the Loop Control switch, but
this time, Loop 2 reads a local variable associated with the switch. When
you set the switch to FALSE on the front panel, the switch terminal in Loop
1 writes a FALSE value to the conditional terminal in Loop 1. Loop 2 reads
the Loop Control local variable and writes a FALSE to Loop 2s conditional
terminal. Thus, the While Loops run in parallel and terminate
simultaneously when the single front panel switch is turned off.
3-7
You cannot do this with standard controls and indicators. Using local
variables, you can overcome this limitation. You can update a control from
the block diagram. Also, you can have any number of local variable
references for a given front panel control, with some in write mode and
others in read mode. With a local variable reference, you can access a front
panel object as both an input and an output.
To understand this concept, we will look at an example that shows another
use of local variables. Below is a single string indicator. Suppose you want
to update that indicator to display the loop that is currently executing.
Without a local variable, there is no way to accomplish this task. You can
place the indicator terminal in only one loop.
However, using a local variable, you can access the same front panel
indicator from more than one location on the block diagram, so that a single
indicator displays the loop that is executing. The Which Loop? indicator is
placed in Loop 1 and a local variable instance of that indicator is placed in
Loop 2. Although this example is simple, it shows how an indicator can be
updated from two separate locations on the block diagram.
3-8
ni.com
Lesson 3
Exercise 3-1
Objective:
Login VI
Note
Front Panel
Block Diagram
1. Complete the block diagram. Notice that the local variables are enclosed
in a single-frame Sequence structure, and that the empty string constant
is wired to the border of the While Loop. This setup ensures that both
local variables are updated before the While Loop starts.
a. Login Name local variable set to write localResets the login name
to an empty string. To create this local variable, right-click the Login
Name terminal and select CreateLocal Variable from the pop-up
menu.
b. Password local variable set to write localResets the password
string to an empty string. To create this local variable, right-click the
Password terminal and select CreateLocal Variable from the
pop-up menu.
3-9
3-10
ni.com
Lesson 3
Exercise 3-2
Objective:
To use local variables to modify both indicators and controls on the front panel.
Front Panel
3-11
Block Diagram
3-12
ni.com
Lesson 3
3-13
C. Global Variables
Recall that you can use local variables to access front panel objects at
various locations in the block diagram. Those local variables are accessible
only in that single VI. Suppose that you need to pass data between several
VIs that run concurrently, or whose subVI icons cannot be connected by
wires in the block diagram. You can use a global variable to accomplish this.
Global variables are similar to local variables, but instead of being limited
to use in a single VI, global variables can pass values between several VIs.
Consider the following example. Suppose you have two VIs running
simultaneously. Each VI writes a data point to a waveform chart. The first
VI also contains a Boolean to terminate both VIs. Remember that when both
loops were on a single block diagram, you needed to use a local variable to
terminate the loops. Now that each loop is in a separate VI, you must use a
global variable to terminate the loops.
3-14
ni.com
Lesson 3
Global variable
node
You must label each control or indicator with an owned label because a global
variable refers to an item by its name.
Note
The following example shows a global variable front panel with three
objectsa numeric, a string, and a cluster containing a digital and a
Boolean control. Notice that the toolbar in the window does not show the
same items as a normal front panel.
After you finish placing objects on the global variables front panel, save the
global variable and return to the block diagram of the original VI. Select the
specific object in the global variable VI that you want to access. To select a
specific object, right-click the global variable node and select the object
from the Select Item menu. This menu lists the owned labels for all the
objects on the panel. Notice that you also can open the front panel
containing the objects in the global variable from this pop-up menu.
3-15
You also can click the node with the Operating tool and select the global
variable you want to access.
Global variable
node
Global variable
node displaying
a numeric
After you select the specific global variable object that you want to access,
the node changes from the figure shown at left to display the object you have
chosen, such as a numeric.
You might want to use this global variable in other VIs. Because a global
variable is a special kind of VI, you can place it in other VIs using the Select
a VI option in the Functions palette. Then, right-click the node to select the
specific object in the global variable you want to access, as described above.
Note A global variable front panel can contain references to many individual objects
that are globally accessible. You do not need to create a separate global variable VI for
each item you need to globally access.
3-16
Write Global
ni.com
Lesson 3
Exercise 3-3
Objective:
Data to Global VI
Block Diagram
3-17
Global variable
node
f. Using the Operating tool, click the global variable node and select
Stop Button. You can change the variable to be readable or writable
by right-clicking it.
g. Make enough copies of the My Global.vi variable. Use the
Operating tool to select the correct item you need from the global
variable.
Initialize the Stop Button global variable inside the Sequence structure
by writing a FALSE to it. The constant is wired to the loop border to
force the global to initialize before the loop begins executing. This
prevents the While Loop from reading an uninitialized global variable,
or one that has an unknown value.
4. Save the VI as Data to Global.vi. Keep it open so you can run it in
the next exercise.
3-18
ni.com
Lesson 3
Exercise 3-4
Objective:
Front Panel
Block Diagram
3-19
Global variable
node
3-20
ni.com
Lesson 3
The Time Delay control determines how often the global variable is
read. Notice how the Time Delay affects the values plotted on the
waveform chart. If you set the Time Delay to 0, the same Data Value
value is read from the global variable several times, appearing to
decrease the frequency of the sine wave generated in Data to Global.
If you set the Time Delay to a value greater than 50 ms, Display Global
Data may never read some values generated in Data to Global, and the
frequency of the sine wave appears to increase. If you set the Time
Delay to 50 ms, the same rate used in the While Loop in Data to Global,
Display Global Data reads and displays each point of the Data Value
global only once.
Note When using globals, if you are not careful, you may read values more than once,
or you may not read them at all. If you must process every single update, take special care
to ensure that a new value is not written to a global variable until the previous one has
been read, and that after a global has been read, it is not read again until another value
has been written to the global.
7. Press the STOP button on the Display Global Data front panel to stop
the VI. Notice that both Display Global Data and Data to Global stop.
The VI continually writes the value of the STOP button to the Stop
Button global variable object. That value is then read in Data to Global
3-21
and passed to the conditional terminal to control its loop as well. When
you press the STOP button, a TRUE passes through the global variable
to Data to Global, where that TRUE value is read to stop that VI as well.
8. Close both VIs.
3-22
ni.com
Lesson 3
Race Conditions
Local and global variables in LabVIEW do not behave like local and global
variables in text-based programming languages. Recall that LabVIEW is a
dataflow language, not a sequential programming language. Overusing local
and global variables can lead to unexpected behavior in your program,
because functions might not execute in the order you expect. Consider the
simple local variable example below. The LabVIEW code appears next to
the equivalent code of a sequential programming language.
LabVIEW Code
Sequential Code
x=x *5
x=x+2
or
x=x+2
x=x *5
When you execute the sequential code, the solution for a given value of x is
clear because the statements execute from top to bottom. However, the
LabVIEW code does not follow such a convention because LabVIEW is a
dataflow language. Each node executes when all of its data is available.
There are no data dependencies to guarantee the desired order of execution
in the above block diagram. In fact, there are several possible solutions,
depending on how the VI compiles. You cannot assume that the code located
at the bottom of the block diagram executed after the code above it.
The above example illustrates what is known as a race condition. The result
of your program depends on the order in which its instructions execute, and
the code might not execute in the order you assume. If you use local and
global variables, you might have a race condition if you notice that your
code executes correctly only some times, or that it executes correctly during
execution highlighting but not during normal execution.
3-23
3-24
ni.com
Lesson 3
This three-frame sequence structure performs the usual tasks for all VIs.
Frame 0 reads the controls on the panel for configuring the test system,
Frame 1 uses the local variables for the controls to acquire data, and Frame 2
uses the locals to write the data to file. Although there is nothing inherently
wrong with using the sequence structure and the local variables in this way,
it is not the most efficient method of using dataflow programming. When
you look at one of the frames, it is not obvious where the values for the
locals are coming from and where they were last updated.
The block diagram shown above eliminates the use of local variables by
putting the original control terminals outside the sequence structure so that
each frame of the sequence now has access to the values. The data are passed
between frames of the sequence through a sequence local.
The block diagram shown above removes the sequence structure and uses
dataflow to define how the program works. The error clusters define the
execution order of the subVIs and also maintain the error conditions which
are checked at the end with the error handler VI. This is the most efficient
way to build a program and manage data in LabVIEW. Not only is the block
diagram smaller and easier to read, but passing data through wires is the
most efficient method for memory use.
3-25
E. DataSocket
So far in this lesson you learned three main things:
The most efficient way to manage data in the block diagram is through
a direct wire connection.
Global variables can be used to pass data between separate VIs without
using a wire.
There are many other ways to manage data in LabVIEW. This lesson covers
one other method, DataSocket. DataSocket is an Internet programming
technology based on TCP/IP that simplifies data exchange between
computers and applications. With DataSocket, you can efficiently pass data
over the Internet and respond to multiple users without the complexity of
low-level TCP programming.
Therefore, you can use DataSocket to pass live data not only between VIs
running on the same machine but also between VIs running on separate
computers that are connected through a network. You also can use
DataSocket to communicate between LabVIEW and any other
programming language that contains support for TCP/IP, such as Excel,
Visual Basic, C, and so on.
DataSocket API
DataSocket is a single, unified, end-user API based on URLs for
connecting to measurement and automation data located anywhere, be it
on a local computer or on the Internet. It is a protocol-independent,
language-independent, and OS-independent API designed to simplify
binary data publishing. The DataSocket API is implemented so you can use
it in any programming environment and on any operating system.
The DataSocket API automatically converts your measurement data into a
stream of bytes that is sent across the network. The subscribing DataSocket
application automatically converts the stream of bytes back into its original
form. This automatic conversion eliminates network complexity, which
accounts for a substantial amount of code that you must write when using
TCP/IP libraries.
3-26
ni.com
Lesson 3
DataSocket Server
The DataSocket Server is a lightweight, stand-alone component with which
programs using the DataSocket API can broadcast live measurement data at
high rates across the Internet to several remote clients concurrently.
The DataSocket Server simplifies network TCP programming by
automatically managing connections to clients. Access the DataSocket
Server by selecting StartProgramsNational Instruments
DataSocketDataSocket Server. When you select the DataSocket Server,
it opens the following window and begins running.
As shown above, the DataSocket Server keeps track of the number of clients
connected to it as well as how many packets of data have been exchanged.
You can select to have the DataSocket Server run hidden by selecting
Hide DataSocket Server from the Server menu.
Broadcasting data with the DataSocket Server requires three actorsa
publisher, the DataSocket Server, and a subscriber. A publishing application
uses the DataSocket API to write data to the server. A subscribing
application uses the DataSocket API to read data from the server. Both the
publishing and the subscribing applications are clients of the DataSocket
Server. The three actors can reside on the same machine, but more often the
three actors run on different machines. The ability to run the DataSocket
Server on another machine improves performance and provides security by
isolating network connections from your measurement application. The
DataSocket Server restricts access to data by administering security and
permissions. With DataSocket, you can share confidential measurement
data over the Internet while preventing access by unauthorized viewers.
3-27
transfer protocol, to connect to the machine named ni.com and to fetch the
web page named datasocket.
The URL is different from the names used by most I/O technologies in that
it not only defines what you are interested in but also indicates how to get it.
The how encoded in the first part of the URL is called the access method of
protocol. Web browsers typically use several access methods, such as HTTP,
HTTPS (encrypted HTTP), FTP (file transfer protocol), and FILE (for
reading files on your local machine). DataSocket takes the same approach
for measurement data. For example, DataSocket can use the following URL
to connect to a data item: dstp://mytestmachine/wave1. The dstp in
the front tells DataSocket to open a data socket transfer protocol connection
to the test machine and fetch a signal called wave1. Had the URL started
with file, the data would have been fetched from a file instead of the
DataSocket server.
The DataSocket Write function writes the data input to the specified URL.
The data can be in any format or LabVIEW data type. The error in and
error out clusters maintain the error conditions.
The DataSocket Read function reads the data type specified by type from the
specified URL. The ms timeout value has a default of 10 seconds and you
can specify a different timeout value. The timed out Boolean indicates a
TRUE if this function timed out. The error in and error out clusters
maintain the error conditions.
3-28
ni.com
Lesson 3
The DataSocket Select URL VI is only used when you do not know the URL
for an object and you want to search for a data source or target from a dialog
box.
If the rectangle is gray, there is no connection to the server at that time. If the
rectangle is red, the connection has an error.
Now build two VIs that transfer data using DataSocket.
3-29
Exercise 3-5
Objective:
Front Panel
1. Open a new VI and build the front panel shown above. The URL object
is a string control.
Block Diagram
2. Open and build the block diagram shown above using the following
components:
a. While Loop, available on the FunctionsStructures
paletteStructures the VI to continue running until you press the
Stop button. Right-click the Conditional terminal and select Stop If
True.
b. Wait Until Next ms Multiple function, available on the Functions
Time & Dialog paletteCauses the While Loop to execute once per
second. Create the constant by right-clicking the input terminal and
selecting CreateConstant.
3-30
ni.com
Lesson 3
Front Panel
1. Open a new VI and build the front panel shown above. The URL object
is a string control. To show the scale on the slide indicator, right-click
the slide and select ScaleStyle.
Block Diagram
2. Open and build the block diagram shown above using the following
components:
a. While Loop, available on the FunctionsStructures
paletteStructures the VI to continue running until you press the
3-31
6. Return to the two VI front panels and make sure that the URLs have been
entered the same for both VIs.
3-32
ni.com
Lesson 3
8. Stop both VIs when you are finished. Now modify the VIs to use the
automatic publish and subscribe capabilities of front panel objects.
Front Panel
11. Click the Attach button and a little gray rectangle appears to the top
right side of the digital indicator. This indicates that the DataSocket
connection is not active.
12. Run the DS Generate Data and DS Read Data VIs again.
The rectangle next to the Random Number indicator turns green, and the
value matches the values shown in the meter and the slide.
Note If your computer is on a network with the other computers used in class, you can
type in URLs for other machines on the network and transfer the values between
classroom computers. Remember that you can use any programming language or
operating system with DataSocket connections. Go to the National Instruments
DataSocket web page, at ni.com/datasocket, for more information.
3-33
13. Stop and close both VIs and the DataSocket Server when you are
finished.
3-34
ni.com
Lesson 3
You can have any control or indicator publish and/or subscribe data
through the DataSocket Server by right-clicking that front panel object
and using the Data OperationsDataSocket Connection window.
You can use global and local variables to access a given set of values
throughout your LabVIEW application. These variables pass
information between places in your application that cannot be connected
by a wire.
Local variables access front panel objects of the VI in which you placed
the local variable.
When you write to a local variable, you update its corresponding front
panel control or indicator.
When you read from a local variable, you read the current value of its
corresponding front panel control or indicator.
Global variables are built-in LabVIEW objects that pass data between
VIs. They have front panels in which they store their data.
Always write a value to a global variable before reading from it, so that
it has a known initial value when you access it.
Write to local and global variables at locations separate from where you
read them to avoid race conditions.
Use local and global variables only when necessary. Overuse can cause
slower execution and inefficient memory usage in your application.
Local and global variables do not use dataflow, so if you use them too
frequently, they can make your block diagrams difficult for others to
understand. Use locals and globals wisely.
3-35
Additional Exercises
3-6
Open the In Range VI. Examine the block diagram. This simple VI
generates five random numbers and turns on an LED if the last
number generated is between 0.1 and 0.9. Run the VI several times
until the LED turns on. Notice that if the LED turns on during one
run of the VI, it remains on during the second run until the For Loop
completes and the last number is passed to the In Range? function,
available on the FunctionsComparison palette. Modify the VI
using a local variable so that the LED is turned off when the VI starts
execution. Save your VI after you have finished.
3-7
Challenge
3-8
Open the Select and Plot Waveform VI from Exercise 3-2. Use the
information at the end of Section D to rewrite this VI to no longer
use the sequence structure and local variables.
Use a state machine architecture and pass data using shift registers or direct wire
connections.
Tip
3-36
ni.com
Lesson 3
Notes
3-37
Notes
3-38
ni.com
Lesson 4
Advanced File I/O Techniques
When implementing subVIs for file I/O, you might need to account for
different file formats. For example, if a third-party application needs to read
data acquired by LabVIEW, you should save that data in text format because
most applications have support for text files. On the other hand, if only
LabVIEW will access the data, and file size is critical, binary files are a
better choice. Advanced File I/O techniques and the built-in file I/O
functions allow this flexibility.
4-1
The File Dialog function on the File I/OAdvanced File Functions palette
displays a file dialog box for file selection. You can select new or existing
files or directories from this dialog box. We will describe the use of the
datalog type input later in this lesson.
File Dialog
The Open File function on the File I/OAdvanced File Functions palette
opens an existing file. You must wire a valid path to the file path input. This
function is not capable of creating or replacing files. It opens only existing
files. The datalog type input is used only when opening LabVIEW datalog
files.
Open File
4-2
ni.com
Lesson 4
New File
The Write File function on the FunctionsFile I/O palette writes data to an
open file. The behavior of this function varies slightly depending on whether
you are writing data to a byte stream file or to a LabVIEW datalog file.
Write File
The Read File function on the FunctionsFile I/O palette reads data from
an open file. When reading byte stream files, you can use the byte stream
type input to indicate how LabVIEW should interpret data in the file. We
will describe this concept later in this lesson.
Read File
The Close File function on the FunctionsFile I/O palette closes the file
associated with refnum.
Close File
4-3
4-4
ni.com
Lesson 4
any information about the number of rows or columns in the array into
the file. Even if you know that the data were originally single-precision
floating-point numbers, you cannot successfully reconstruct the
two-dimensional array. If the file contains 24 bytes of data, and knowing
that single-precision floating-point numbers use four bytes of memory each,
you can figure out that the array contained six values (24/4 = 6). However,
the original data might have been stored in a one-dimensional array of six
elements, a two-dimensional array with one row and six columns, or a table
with three columns and two rows.
You also can generate the same file using the header input of the Write File
function. If you wire a Boolean value of TRUE to the header input of the
Write File function, it writes the same data to the file as if you had manually
written a header. The following example shows how to use the Write File
function to create a binary file with a header.
4-5
Notice that the byte stream type input of the Read File function has a
two-dimensional array of single-precision numbers wired to it. The Read
File function uses only the data type of this input to read the data in the file,
assuming that it has the correct header information for that data type.
4-6
ni.com
Lesson 4
In the previous block diagram example, the pos mode input of the Read File
function is set to start, which means that the function begins reading data
at pos offset bytes from the beginning of the file. The first byte in the file
has an offset of zero. So, the location of the nth element in an array of
single-precision floating-point numbers stored in this file is 4 n bytes from
the beginning of the file. A single-precision floating-point constant, wired
to the byte stream type input, tells the Read File function to read
single-precision floating-point values from the file. The # values to read
control, connected to the count input of the Read File function, tells the
function how many single-precision elements to read from the file. Notice
that when the count input is wired, LabVIEW places the output data in an
array, because LabVIEW reads more than one value from the file.
The following points are important to remember about random access
operations:
When performing text and binary file I/O, remember that values for the
pos offset terminal are measured in bytes.
The count input in the Read File function controls how many bytes of
information are read from the file when the byte stream type input is
unwired. The data read from the file is returned in a string.
If the byte stream type input is wired, the data output of the Read File
function is of the same data type as the byte stream type input when the
count input is unwired.
If the byte stream type input is wired and the count input has data
connected to it, then the Read File function returns an array containing
count elements of the same data type as the byte stream type input.
Refer to the LabVIEW Help and the LabVIEW User Manual for more
information about random access operations and byte stream files.
4-7
Exercise 4-1
Objective:
To build a VI that writes data to a binary file with a simple data formatting scheme.
This VI saves data to a binary file using a simple formatting scheme in
which the files header is a long word integer (I32) containing the number
of data points in the file. In the next exercise, build a VI that reads the binary
file.
Front Panel
1. Open a new VI.
2. Build the following front panel. When you create the menu ring, recall
that a shortcut for adding a new item to the list of options is to press
<Shift-Enter> after entering the text for an item in the list. Enter Zero
for item 0 in the list, Sine for item one, and so on. To view the numeric
value of the menu ring, right-click the control and select Visible
ItemsDigital Display.
Macintosh, <Shift-Return>; Sun, <Shift-Return>; HP-UX, <Shift-Enter>; and
Linux, <Shift-Enter>
Note
The appearance of the menu ring control varies from one platform to the next.
4-8
ni.com
Lesson 4
Block Diagram
4. Build the following block diagram.
4-9
4-10
ni.com
Lesson 4
Exercise 4-2
Objective:
To build a VI that reads the binary file created in the last exercise.
Front Panel
1. Open a new VI and build the following front panel.
Block Diagram
3. Build the following block diagram.
4-11
elements in the array stored in the file. The second instance reads the
array of data from the file.
c. Place the Close File function located on the FunctionsFile I/O
palette on the block diagram. In this exercise, this function closes the
binary file after data has been read from it.
d. Place the Simple Error Handler VI located on the FunctionsTime
& Dialog palette on the block diagram. In the event of an error, this
VI displays a dialog box with information about the error and where
it occurred.
e. Place the Numeric constant located on the FunctionsNumeric
palette on the block diagram. You must create an I32 constant so the
Read File function knows what data type to expect. I32 is the default
data type for numeric constants.
f. Place the Numeric constant located on the FunctionsNumeric
palette on the block diagram. Create a double-precision constant so
the Read File function knows what data type to expect. Because the
default data type for numeric constants is I32, right-click the
constant and select RepresentationDouble Precision.
4. Return to the front panel. Save the VI as Binary File Reader.vi.
5. Run the VI. Open the data.bin file created in Exercise 4-1.
After the file opens, the Read File function uses the byte stream type
input, which has a long integer, four bytes, wired to it, to read the first
four bytes from the file. The function displays the number in the Number
of Data Points indicator, which shows how many numbers were stored
in the file. Recall that this header was created by the Write File function
in the Binary File Writer VI in Exercise 4-1.
The second Read File function reads the array of data points from the
file using the byte stream type input, which has a double-precision
floating-point value wired to it. The count input specifies how many
values should be read from the file.
6. Close the VI.
4-12
ni.com
Lesson 4
Use the same file I/O functions to work with datalog files that you use for
byte stream files. However, you use the data type input differently for
datalog files. To create a new datalog file, wire a cluster matching the data
record cluster to the datalog type terminal of the New File function. This
cluster specifies how the data is written to the file. Then wire the actual data
record to the data terminal of the Write File function. The datalog type
cluster wired to New File need not be an actual data recordyou need it
only to establish the type of data that you can store in the file. The following
example shows how to create a new datalog file.
4-13
To read the record of information from the datalog file, you must wire an
input to the datalog type of the Open File function that exactly matches the
data type of the records stored in the file. The following example shows how
to open and read an existing datalog file.
Note The cluster wired to the datalog type input of the Open File function must be
identical to the cluster used to create the file and write data to it, including numeric data
types and cluster order.
When the count input of the Read File function remains unwired, the
function reads a single record from the datalog file. If you wire an input to
the count terminal, Read File returns an array of records.
4-14
ni.com
Lesson 4
Exercise 4-3
Objective:
Note Completing this VI enables the Log Results to File option in the Analyze and
Present Data VI from Exercise 2-7. Recall that you will use Exercise 4-3 in the project in
Lesson 5.
In the application being developed, you need to save a mixed data set to
disk. This data set contains simple numerics, arrays of numerics, and string
data. In addition, this data is used only in LabVIEW. Because of these
requirements, you will use datalog files to save the applications data subsets
to disk.
Front Panel
1. Open the Save Data to File VI in exercises\Basics2 directory.
The front panel is already built.
The two controls on the front panel are used to pass application data to
this VI, which functions as a subVI in the finished project. The Data
Cluster will contain the subset of analyzed data to save to disk, and the
Employee Name string will contain the Operator name to save to
the file.
4-15
Block Diagram
3. Complete the Case structures for the following block diagram. The cases
that are not shown are already built.
4-16
ni.com
Lesson 4
4-17
Exercise 4-4
Objective:
To study a VI that reads data files created by the Save Data to File VI from
Exercise 4-3.
This VI reads and displays the data stored by the Save Data to File VI.
Note
Front Panel
1. Open the View Analysis File VI in exercises\Basics2 directory.
This VI has already been built.
4-18
ni.com
Lesson 4
Block Diagram
3. Examine the behavior of the VI. If the user cancels the file dialog box,
nothing happens.
Notice that the datalog type input of the File Dialog function is wired
to a dummy cluster of the same data type to be read. This connection
causes the LabVIEW file dialog to display only directories and files of
the appropriate data type. Once the file is selected, the file is opened as
a datalog file and a single data record is read. Finally, notice the use of
error checking in this application.
4. After you run the VI and test it, close it. Do not save any changes.
4-19
Disk streaming is especially important when you use the high-level VIs,
such as Write To Spreadsheet File and Write Characters To File. These VIs
open, write, and close the file each time they run. Thus, if you call one of
these VIs in a loop, you perform unnecessary Open File and Close File
operations during every iteration of the loop.
4-20
ni.com
Lesson 4
Text Files
Text files are files in which all data is stored as readable text characters. Text
files are useful because almost all software applications and operating
systems can read them. However, text files can be larger than necessary and
therefore slower to access. It is also very difficult to perform random access
file I/O with text files. You typically use text files when:
You do not need random access reading or writing in the data file.
Binary Files
Binary data files are files in which data is stored in binary format without
any conversion to text representation. Binary data files are generally smaller
and thus faster to access. Random access file I/O presents no major
difficulties. However, there is no industry-standard format for binary files.
Thus, you must keep precise records of the exact data types and header
information used in binary files. We recommend you use binary data files
when:
You need to perform random access file I/O in the data file.
Datalog Files
Datalog files are a special type of binary file for saving and retrieving
complex data structures in LabVIEW. Like binary files, they have no
industry-standard format. We recommend using datalog files when:
Users who write VIs to access the data know the datalog structure.
4-21
Additional Exercises
4-5
Write a VI that uses the Advanced file I/O functions to create a new
file. Then, write to that file a single string composed of a string input
by the user concatenated with a number converted to a text string
using the Format Into String function. Name the VI File
Writer.vi.
4-6
Write a VI that uses the Advanced File I/O functions to read the file
created in Exercise 4-5. Name the VI File Reader.vi.
Use the EOF function located on the File I/OAdvanced File Functions palette to
obtain the length of the written file.
Tip
4-22
ni.com
Lesson 4
Notes
4-23
Notes
4-24
ni.com
Lesson 5
Developing Larger
Projects in LabVIEW
This lesson describes some of the issues involved when building larger
LabVIEW projects, including the design process, the organization of subVI
components, and the process of combining those components to create a
complete application.
5-1
Process
Customer
Feedback
Define Project
Design
Flowchart
Integrate SubVIs
into Project
Implement
Nodes as VIs
Test SubVIs
Top-Down
Bottom-Up
If the user is not correctly loged in, other features are disabled.
As soon as the data have been acquired, and any time the user selects
thereafter, the user can select a subset of the acquired data, analyze it,
and save the analysis results to a file.
Allows the user to load and view analysis results previously saved to
disk.
5-2
ni.com
Lesson 5
Teamwork
Business management experts stress the importance of teamwork in
designing solutions for large, complex tasks. When using LabVIEW,
teamwork is a powerful tool for increasing your productivity in graphical
programming. When several people work together to develop a project in
LabVIEW, it is essential that all team members agree on a method of source
code control and organization.
5-3
You can use names up to 255 characters in length for your VIs.
5-4
ni.com
Lesson 5
Loading and saving time for applications that use a large number of
subVIs stored in LLBs is generally slower than if the subVIs are stored
directly on disk using directories.
When LLB files become large, that is, up to several megabytes, saving
edits to a VI stored in a LLB takes longer.
Recall that the operating system views an LLB as a single file, so when
you save a VI in an LLB, LabVIEW and the operating system must
manipulate a very large file. When working with such large files, you
run a higher risk of running out of memory or disk space when
manipulating the file, increasing the likelihood of corrupting the library
and losing work.
You cannot use your operating systems file searching tools to locate VIs
stored in a LLB.
As a rule of thumb, try to limit the size of your LLB to roughly 1 MB.
Whether you store your VIs in an LLB or directly on disk can depend on file
naming restrictions in your operating system or how you select to organize
your files.
Refer to the LabVIEW Development Guidelines manual, available at
ni.com, for more information about designing, building, and testing
applications in LabVIEW complete with a style guide, checklists, and
references.
5-5
Exercise 5-1
Objective:
Front Panel
1. Open the Menu VI in the exercises\Basics2 directory. You created
this VI in Exercise 2-3.
Note If you did not complete Exercise 2-3, locate Menu VI in the course solutions stored
on your computer.
5-6
ni.com
Lesson 5
Block Diagram
1. Modify the following VI. Only modify the While Loop and Cases -1 and
0. The Login VI is called when the user presses the Login button on the
front panel (Case 0 of the Case structure). Remember to delete the One
Button Dialog function that you placed in Case 0 in Exercise 2-3.
If you did not complete Exercise 3-1, locate Login VI in the course solutions
stored on your computer.
Note
5-7
By using the shift registers, notice that only Case 0, in which the Login VI
runs, can change the Operator and Access Granted values.
The loop verifies that the value stored in the Boolean shift register, which is
the Access Granted status, is TRUE, or if the user pressed the Login button
(component 0 in the menu cluster) or Stop button (component 4) to
determine which case to execute. If all of these conditions are FALSE, then
Case -1 executes.
3. Run the VI and test it to make sure it behaves properly. Use the
LabVIEW debugging toolsexecution highlighting, single-stepping,
probes, and breakpointsto determine the dataflow of the VI.
4. Save the VI as Application Exercise(5-1).vi. Do not close
the VI.
5-8
ni.com
Lesson 5
Exercise 5-2
Objective:
Block Diagram
1. Make sure that the Application Exercise (5-1) VI is open. You will not
modify the front panel in this exercise. Open the block diagram.
2. Show Case 1 of the Case structure and delete the One Button Dialog
function. Add Acquire Data VI, which you built in Exercise 2-2. If you
did not finish that exercise, use the VI from the solutions located on your
computer.
3. Add a shift register to the border of the While Loop. Connect the Time
Waveform output of the Acquire Data VI to the right side of the shift
register.
4. You must initialize the new shift register you created.
a. Right-click the left side of the shift register that contains the
configuration cluster and select CreateControl from the shortcut
menu. This creates an empty waveform control on the front panel.
b. Hide this Time Waveform control by right-clicking the terminal and
selecting Hide Control fromt he shortcut menu. This makes the
waveform control invisible so it does not confuse users.
5-9
5-10
ni.com
Lesson 5
Exercise 5-3
Objective:
To finish the Application Exercise VI by adding the subVIs for the Analyze & Present
Data and View Analysis File buttons.
You will add the Analyze & Present Data VI from Exercise 2-7 and the View
Analysis File VI, which you studied in Exercise 4-4.
Block Diagram
1. Make sure that the Application Exercise(5-2) VI is open. You will not
modify the front panel in this exercise. Open the block diagram.
5-11
2. Delete the One Button Dialog function in Case 2 of the Case structure.
Add the Analyze & Present Data VI to this case. You completed this VI
in Exercise 2-7.
a. Connect the string containing the operator name to the Operator
input.
b. Connect the waveform containing the collected data to the Data
input.
3. Show Case 3 of the Case structure and delete the One Button Dialog
function. Add the View Analysis File VI. You do not need to make any
connections to it.
4. Save the VI as Application Exercise(5-3).vi and run it. You
should now be able to perform all of the options available in the menu
after you log in with a valid name and password.
You must select a subset of the acquired data when you select Analyze & Present
Data. After you select the data subset, click the Analyze button and then select the button
to save the data to file. Otherwise, the file does not contain any waveform data.
Note
5-12
ni.com
Lesson 5
After typing your comments into the Comment area of the Revision History
window, click Add to add them to the VIs history. The VI Revision History
window also keeps track of revision numbers. Each time you save the VI,
the revision number for the VI increments by one.
In addition to the revision number and the date and time at which a comment
is added to a VIs history, the current users name appears in the User field.
You can configure the LabVIEW preferences to prompt for a user name at
launch time, by selecting Revision History from the top pull-down menu in
the ToolsOptions dialog box, or you can change the user name by
selecting ToolsUser Name.
5-13
VI Hierarchy
One of the most important advantages of breaking your main application
into subVIs is that you save memory. In addition, the responsiveness of
the LabVIEW editor improves because smaller VIs are easier to handle.
Hierarchical applications are easier to develop, read, document, and modify.
Therefore, as a general rule, it is recommended that you keep the block
diagram for your top-level VI under 500 KB in size. In general, your subVIs
should be significantly smaller. To check the size of a block diagram, select
Memory Usage from the top pull-down menu in the FileVI Properties
dialog box. Typically, you should consider breaking a VI into several subVIs
if the block diagram for your VI is too large to fit entirely on the screen.
If you find that the block diagram for a VI is getting too large, you can
convert part of it into a subVI by using EditCreate SubVI. This capability
gives you a fast and easy method to create your applications VI hierarchy
as you develop the source code.
The VI Hierarchy window is also a valuable tool for locating subVIs and
viewing the overall layout of the project as your application grows. To view
the Hierarchy window, select BrowseShow VI Hierarchy. A new window
appears showing the hierarchies of all top-level VIs in memory.
You can use the options available in the toolbar at the top of the Hierarchy
window to show or hide various categories of objects used in the hierarchy,
such as global variables or VIs shipped with LabVIEW, as well as whether
the hierarchy expands horizontally or vertically. Clicking the small arrow
appearing next to a VI expands or collapses the view of that VIs hierarchy.
Thus, you can expand different branches of the overall hierarchy.
LabVIEW Basics II Course Manual
5-14
ni.com
Lesson 5
Horizontal Layout
Include VI Library
Include Globals
Include Type Def
As you move the cursor over the icons shown in the Hierarchy window, the
name of the VI follows the VI. You can double-click an icon to open the VI.
You can also locate a VI in the hierarchy by typing in the name of a VI while
in the Hierarchy window. As you type the name, the Hierarchy window
scrolls to the appropriate VI. You can also use the Find feature to search the
Hierarchy window for a VI.
The Hierarchy window can also be used a development tool when planning
or implementing your project. For example, after developing a flowchart of
the VIs required for an application, you can create, from the bottom of the
hierarchy up, each of these VIs so that they have all necessary inputs and
outputs on their front panel, and the subVIs they call on their block
diagrams. This will build the basic application hierarchy, which will now
appear in the Hierarchy window. You can then begin to develop each subVI,
5-15
perhaps color-coding their icons, which will also be colored in the Hierarchy
window, to reflect their status. For example, white icons could represent
untouched VIs, red icons could represent subVIs in development, and blue
icons could represent completed VIs. While this is only one example of
using the Hierarchy window as a development tool, it demonstrates the
usefulness of this window for organizing a project.
With this function, you can control whether the Context Help window is
visible, and where it will appear when shown.
You can also use the Control Online Help function to access the LabVIEW
Help or custom help files that you compile using third-party tools. The type
of online reference development tools you can use to develop this type of
help file depend on the platform on which your application will run.
Windows
Macintosh
QuickView
Sun/HP-UX
HyperHelp
5-16
ni.com
Lesson 5
With this function, you manipulate an online help file. You can list the
contents of the help file, jump to keywords in the file, or close the online
help file.
Providing online help and reference materials for your application makes it
easier to use and gives it a more polished, professional look.
VI Comparison
The LabVIEW Professional Development System includes a utility to
determine the differences between two VIs loaded into the memory. From
the LabVIEW pull-down menu, select ToolsCompareCompare VIs to
display the Compare VIs dialog box.
From this dialog box, you can select the VIs you want to compare, as well
as the characteristics of the VIs to check. When you compare the VIs, both
VIs will be displayed, along with a Differences window that lists all
differences between the two VIs. In this window, you can select various
differences and details to view, which can be circled for clarity.
5-17
Exercise 5-4
Objective:
5-18
ni.com
Lesson 5
10. Using the Select option, make sure that the two Application Exercises
are listed in the VIs to Compare box, and that the Compare options are
set as in the previous example.
11. Click Compare to display the Differences window and tile the two VIs.
Place a checkmark in the Circle Differences checkbox in the
Differences window. Then, select a difference from the Differences
listbox, select a detail from the Details listbox, and then click Show
Detail. The difference between the two VIs is highlighted. Examine the
various differences between the two VIs and then close the Differences
window.
5-19
5-20
ni.com
Lesson 5
5-21
5-22
ni.com
Lesson 5
5-23
From the Target tab, you can specify if you want to create a stand-alone
executable or a shared library, the name of your application and the
directory in which to create it. Optionally, you can choose to write
subVIs to an external file if you want to keep the main application small.
From the Source Files tab, you can define the VIs that make up your
application. When you click Add Top Level VI, you add the main VI(s)
for your application. You need to select only the top-level VI, and
LabVIEW automatically includes all subVIs and related files (such as
menu files or DLLs). If your VI dynamically calls any subVIs using the
VI Server, LabVIEW cannot detect them automatically, so you must add
them by clicking the Add Dynamic VI button. If you want to include
any data files with your application, click the Add Support File button,
and the data files automatically copy over to your application directory.
From the Application Settings tab, you can customize the features in
your application. You can choose to specify the memory size for the
Macintosh, or customize icons and ActiveX server features on
Windows.
From the Installer Settings tab (Windows only), you create an installer.
The installer is written to the directory that contains your application.
5-24
ni.com
Lesson 5
The first section of this lesson describes the architecture of your application
and has you build the application in the exercises. Your application is a
single top-level VI that runs when you launch the application and calls front
panels from several subVIs when called. This is the most common and
easiest architecture for building a stand-alone application.
Programming Issues
You should consider several programming issues when you are building VIs
that end up as built applications. The first issue is to know what outside code
is used for the application. For example, are you calling any system or
custom DLLs or shared libraries? Are you going to process command line
arguments? These are advanced examples that are beyond the scope of this
course, but you need to consider them for the application.
A second issue is with the path names used in the VI. One example is when
you use the VI Server capability to dynamically load and run VIs (this is
described in the LabVIEW Advanced I course). Once an application is built,
the VIs are embedded in the executable. Suppose you have a VI named
test.vi inside an application named test.exe. A Current VIs path
primitive in test.vi returns test.exe\test.vi prepended with the full
path of test.exe. Being aware of these issues will help you to build more
robust applications in the future.
A last issue that will affect the application you have currently built is that the
top-level VI does not quit LabVIEW or close the VIs front panel when it is
finished executing. To completely quit and close the top-level VI, you must
call the Quit LabVIEW function located on the FunctionsApplication
Control palette on the block diagram of the top-level VI.
5-25
5-26
ni.com
Lesson 5
You will learn about each of the steps and options of the Application Builder
when you build an application in the next exercise. After defining your build
specifications using the LabVIEW Application Builder, you will save those
settings to disk in the form of a build script (.bld) file.
5-27
Exercise 5-5
Objective:
My Application executable
Note You must have the Application Builder properly installed to run this example.
To determine whether it is installed, select the Tools menu. If the option Build
Application or Shared Library (DLL) appears in the Tools menu, then the Application
Builder is properly installed.
Front Panel
1. Open the Application Exercise(5-3) VI you created in Exercise 5-3.
Modify the following front panel to remove the comments.
Block Diagram
4. Open the block diagram and use the following components.
a. Place the not function located on the FunctionsBoolean palette on
the block diagram. This function inverts the value being sent to the
While Conditional terminal. When the loop ends, this value is a
False, so a True value is actually sent through the loop boundary to
the Quit LabVIEW function.
5-28
ni.com
Lesson 5
5-29
5-30
ni.com
Lesson 5
9. Click the Source Files tab and select the Add Top-Level VI button.
Add Application Exercise.vi as shown.
5-31
10. Click the VI Settings tab. Leave these settings at their default
valuesthe top-level VI runs when opened and the block diagrams and
front panels are only saved if they are necessary. Examine these settings;
they should resemble the following examples.
11. Click the Application Settings tab. This is where you would enable
ActiveX settings or give your application a custom icon. Leave the icon
as the default LabVIEW icon. Do not change any of these settings.
5-32
ni.com
Lesson 5
12. Click the Installer Settings tab. Build a distribution kit for your
application that installs into the C:\Program Files\
Myapplication directory. Configure the Installer tab as shown.
13. Click the Build button. The files associated with the installer are
then compressed into setup diskettes, which are stored in the
C:\myapp\installer\disks directory. A Setup.exe file is
created as well, which can be used to install the diskette images. All of
these files could be copied to diskettes to transfer the application to
another system. The LabVIEW Run-Time DLL installer is included by
default. The executable for your application is also built and is called
myApplication.exe, as defined on the Target tab.
14. Select Done from the Build Application window to close that utility. It
asks you to save a script so you can build this application again. Select
Yes and name the script myapp.bld. Now if you make changes to the
original application and want to rebuild an executable and installer with
the same settings, you can open this script file using the Load button.
15. Run myApplication.exe from the C:\myapp directory. Application
Exercise should open its front panel and run automatically. Operate the
VI to make sure all the settings you chose are working. Close the
application when you are finished.
5-33
5-34
ni.com
Lesson 5
5-35
Additional Exercises
5-6
5-7
Use a Property Node to set the button text. The mechanical action of the button
should be Latch When Released. Use a shift register to retain the status of the Context
Help windows visibility, and use the Control Help Window function to show and hide
the Context Help window.
Note
5-36
ni.com
Lesson 5
Notes
5-37
Notes
5-38
ni.com
Lesson 6
Performance Issues
This lesson describes how to maximize the performance of your VIs,
including how to improve run-time speed and memory use.
6-1
6-2
ni.com
Lesson 6
Performance Issues
Benefits
One important benefit of multithreaded LabVIEW is the separation of the
user interface from block diagram execution. Any activities conducted in the
user interface, such as drawing on the front panel, responding to mouse
clicks, and so on, operate in their own thread. This prevents the user
interface from robbing the block diagram code of execution time. So,
displaying a lot of information about a graph does not prevent the block
diagram code from executing. Likewise, executing a long computational
routine does not prevent the user interface from responding to mouse clicks
or keyboard strikes.
Computers with multiple processors benefit even more from multithreading.
On a single-processor system, the operating system preempts the threads
and distributes time to each thread on the processor. On a multiprocessor
computer, threads can run on the multiple processors simultaneously, so
more than one activity can occur at the same time.
6-3
Using Multithreading
When an existing LabVIEW application runs, it takes advantage of the
multithreaded system automatically without any modification to the
application. However, when working with multiple VIs, there are different
classifications of threads, called execution systems, available to organize
your application. There are six execution systems available to run VIs:
User Interface
Standard
Instrument I/O
Data Acquisition
Other 1
Other 2
6-4
ni.com
Lesson 6
Performance Issues
The Preferred Execution System list box lists the available categories of
execution systems. You also can prioritize parallel tasks in a multithreaded
environment by setting the Priority of the VI. Within each thread category,
you can specify the priority of executionnormal, above normal, high, time
critical, subroutine, and background. Normal priority is the same as level 0
priority in previous versions of LabVIEW, above normal priority is the same
as level 1 priority, and so on. If there are multiple VIs, the VIs are placed
into an execution queue. VIs with higher priority, except the subroutine
priority, still execute before lower priority VIs. However, VIs with a
subroutine priority level behave differently than VIs with other priority
levels. When a VI runs at subroutine priority, it runs in the thread category
of its caller, and no other VI can run in that thread until that VI or its subVIs
complete. Subroutine priority VIs can call other subroutine priority VIs
only. Use subroutine priority VIs only when you want to run a simple
computation with no interactive elements. You can skip the execution of a
subroutine priority subVI when it is busy by right-clicking the subVI and
selecting Skip Subroutine Call if Busy. Use this option when you are
calling a shared subroutine from a high-priority VI but you do not want to
wait for the subroutine VI to become available.
Exercise caution when setting the priority levels for VIs. Using priorities to
control execution order might not produce the results you expect. For
example, if you use the priority setting incorrectly, lower priority tasks
might never execute. As you will see later in this lesson, strategic use of
Wait functions within VIs also can be a very effective way of optimizing
your LabVIEW code. Refer to the LabVIEW Help for more information
about how to use Wait functions.
6-5
Notice that you must select the Profile Memory Usage option before
starting a profiling session. Collecting information about VI memory use
adds a significant amount of overhead to VI execution, which affects the
accuracy of any timing statistics you gather during the profiling session.
Therefore, you should perform memory profiling separate from time
profiling.
Many of the options in the Profile window are available only after you begin
a profiling session. During a profiling session, you can grab a snapshot of
the available data and save the data to an ASCII spreadsheet file. The timing
measurements accumulate each time you run a VI.
All statistics measured in a profiling session are collected for a complete run of
a VI, not a partial run of a VI.
Note
6-6
ni.com
Lesson 6
Performance Issues
Memory Statistics
To collect memory statistics with the Profile window, select the Profile
Memory Usage option before starting the profiling session. You also can
select the Profile Memory Usage option after starting the Profiler to collect
additional memory information.
The Profile window displays two sets of memory use data. One set of data
shows the number of bytes of memory used, and the other shows the blocks
of memory. LabVIEW stores data such as arrays, strings, and paths in
contiguous blocks of memory. If a VI uses a large number of blocks of
memory, the memory can fragment, which degrades LabVIEW
performance in general, not VI execution.
The Average Bytes statistic column shows the average number of bytes of
memory used by a VIs data space during its execution. Min Bytes and Max
Bytes represent the least and greatest amount of memory used by a VI
during an individual run. Average Blocks indicates how many blocks of
memory a VI needs on average, while the Min Blocks and Max Blocks
show the fewest and greatest number of blocks of memory used by a VI
during an individual run.
6-7
Exercise 6-1
Objective:
To use the Profile window to get information about how your application VI runs.
The Profile window is a powerful tool for analyzing how your application
uses execution time as well as memory. With this information, you can
identify the areas of your VI that you need to optimize. In this exercise,
examine the project just completed using the Profile window.
1. Open your final project, called CD Application Exercise VI.
If you did not complete this final project, you can open the solution.
6-8
ni.com
Lesson 6
Performance Issues
You are now capturing timing information about the VIs in memory.
6-9
Note Collecting information about VI memory usage requires overhead which can
create misleading timing statistics.
6-10
ni.com
Lesson 6
Performance Issues
6-11
Other factors, such as execution overhead and subVI call overhead, usually
have minimal effects on execution speed.
Input/Output
Input/Output (I/O) calls generally take much more time than a
computational operation. For example, a simple serial port read operation
can have an associated overhead of several milliseconds. This overhead is
present not only in LabVIEW, but also in other applications. The reason for
this overhead is that an I/O call involves transferring information through
several layers of an operating system.
The best method of reducing this I/O overhead is to minimize the number of
I/O calls you make in your application. Structure your application so that
you transfer larger amounts of data with each call, instead of making several
I/O calls that transfer a small amount of data.
For example, consider creating a data acquisition (DAQ) application that
acquires 100 points of data. For faster execution, use a multi-point data
transfer function such as the AI Acquire Waveform VI, instead of using a
single-point data transfer function such as the AI Sample Channel VI. To
acquire 100 points, use the AI Acquire Waveform VI with an input
specifying that you want 100 points. This is faster than using the AI Sample
Channel VI in a loop with a wait function to establish the timing.
6-12
ni.com
Lesson 6
Performance Issues
Screen Display
Updating controls on a front panel is another time-consuming task in an
application. While multithreading helps to reduce the effect that display
updates have on overall execution time, complicated displays, such as
graphs and charts, can adversely affect execution speed. This effect can
become significant on the LabVIEW platforms that do not support
multithreading. Although most indicators do not redraw when they receive
data values that are the same as the old data, graphs and charts always
redraw. To minimize this overhead, keep front panel displays simple, and try
to reduce the number of front panel objects. Disabling autoscaling, scale
markers, and grids on graphs and charts improves their efficiency.
The design of subVIs also can reduce display overhead. If subVIs have front
panels that remain closed during execution, none of the controls on the front
panel can affect the overall VI execution speed.
As shown in the following block diagram, you can reduce display overhead
by minimizing the number of times your VI updates the display. Drawing
data on the screen is an I/O operation, similar to accessing a file or GPIB
instrument. For example, you can update a waveform chart one point at a
time, or several points at a time. You get much higher data display rates if
you collect your chart data into arrays so that you can display several points
at a time. This way, you reduce the amount of I/O overhead required to
update the indicator.
6-13
Single-Update Charting
(Slower Method)
Multiple-Update Charting
(Faster Method)
Other Issues
SubVI Overhead
Each call to a subVI involves a certain amount of overhead. This overhead
is fairly small, on the order of tens of microseconds, especially in
comparison to I/O overhead and display overhead, which can range from
milliseconds to tens of milliseconds. However, if you make 10,000 calls to
a subVI in a loop, the overhead could significantly affect your execution
speed. In this case, you might consider embedding the loop in the subVI.
Another way to minimize subVI overhead is to turn your subVIs into
subroutines by selecting Execution from the top pull-down menu in the
FileVI Properties dialog box. However, there are some trade-offs.
Subroutines cannot display front panel data, call timing or dialog box
functions, or multitask with other VIs. Subroutines are generally most
appropriate for VIs that do not require user interaction and are short,
frequently executed tasks.
6-14
ni.com
Lesson 6
Performance Issues
Also, avoid accessing local and global variables unnecessarily in loops. For
example, the following first block diagram wastes time by reading from the
global variable and writing to the global variable during each iteration of the
loop. If you know that the global variable is not read from or written to by
another block diagram during the loop, consider using shift registers to store
the data, as shown in the second block diagram.
Notice that you need the shift registers to pass the new value from the subVI
to the next iteration of the loop. Beginning LabVIEW users commonly omit
these shift registers. Without using a shift register, the results from the subVI
are never passed back to the subVI as the new input value, as shown in the
following block diagram.
In the previous block diagram, the global variable is read once before the
loop begins, and the same value is passed to the function 10,000 times. The
result of the loop is the same as if you had written the code as shown in the
following block diagram.
6-15
Parallel Diagrams
When several loops run in parallel on a block diagram, LabVIEW changes
between the loops periodically. If some of these loops are less important
than others, you should use the Wait (ms) function to ensure that the less
important loops use less time. For example, consider the following block
diagram.
The two loops run in parallel. One of the loops acquires data and must
execute as frequently as possible. The other loop monitors user input.
Currently, both loops get equal time. The loop monitoring the user input can
execute several hundred times per second. In reality, this loop needs to
execute only a few times per second, because the user cannot make changes
to the interface very quickly. As shown in the following block diagram, you
can call the Wait (ms) function in the user interface loop to give significantly
more execution time to the other loop.
6-16
ni.com
Lesson 6
Exercise 6-2
Objective:
Performance Issues
Front Panels
6-17
4. Move the window so that it does not overlap any of the VI front panels.
5. Click the Start button in the Profile window. You see the VI Time,
SubVIs Time, and Total Time statistics in the table.
6. Run the Charting Benchmark Example VI. The VI does nothing until
you click the Run SubVIs button. Run the subVIs at least three or four
times. Then click the Quit button to stop the Charting Benchmark
Example VI.
7. After running the subVIs several times, click the Snapshot button in the
Profile window. Locate Charting Benchmark Example VI in the Profile
window and double-click it to display its subVIs. Notice the VI
execution times for the two subVIs. Recall that these are cumulative
times, not the amount of time needed to execute the subVIs once. Notice
that updating the chart one point at a time is the slowest method, and that
updating the chart several points at a time is the fastest method.
6-18
ni.com
Lesson 6
Performance Issues
8. Select the Timing Statistics option to view the average execution time
for the subVIs. Then select the Timing Details option and examine the
Display and Draw statistics. Notice that the Display statistic is largest
for the Update Chart 1 Point at a Time subVI and is very low for the
Update Chart 50 Points at a Time VI. Record the average execution time
in the following table.
Refer to the LabVIEW Help or the LabVIEW User Manual for more
information about these statistics.
9. Click the Stop button in the Profile window to stop the profiling session.
Then close the Profile window.
10. Close all open VIs and do not save any changes.
11. If you are running LabVIEW on a multithreading operating system,
place a checkmark in the Run with multiple threads checkbox on the
Execution page in the FileVI Properties dialog box and restart
LabVIEW. Repeat steps 3 through 10, noting in the table how much
faster the VIs execute when the display is running under its own
execution subsystem.
Table 6-1. Record of Execution Times
Multithreading On
Percent Faster
Charting Benchmark
Example VI
6-19
Exercise 6-3
Objective:
Front Panel
1. If you are running LabVIEW on an operating system that supports
multithreading (Windows, Solaris2, or Concurrent PowerMAX), complete
steps a though c. If you are on a system that does not support
multithreading, skip to step 2.
a. Configure LabVIEW so that it does not use multithreading when it
runs VIs. Select ToolsOptions to display the Options dialog box.
b. From the top pull-down menu of the Options dialog box, select
Performance and Disk. In the Performance and Disk section,
remove the checkmark from the Run with multiple threads
checkbox. Click OK.
c. Exit and restart LabVIEW so that the updated preferences take
effect. LabVIEW is now configured to run VIs under a single thread,
using co-operative multitasking.
2. Open the Dialog & SubVI Demo VI. The VI is already built for you. The
front panel contains a strip chart and several option buttons. This chart
shows two pieces of data, the running average of a simulated
temperature and a red plot showing how quickly these averages are
calculated.
6-20
ni.com
Lesson 6
Performance Issues
3. Open the block diagram and examine it. Two While Loops run in
parallel. One loop handles data collection and analysis while the other
handles the user interface.
4. Run the VI. Notice the plot speed and the averages/second being
calculated.
Notice that the Averages/Sec value is periodic and dips very low. The
block diagram contains two While Loops running in parallel. The Plot
Loop (top) is the one generating the temperature average and the number
of averages per second. The dips in performance happen when the Menu
Loop executes and checks the values of the buttons on the front panel.
Performance increases when the Plot Loop runs.
5. Click the Show Dialog button. Notice the effect on the plot speed and
the Averages/Sec value. Recall that a loop cannot begin its next iteration
until the entire block diagram inside it finishes executing. In the Menu
Loop, the values from the buttons are read to determine which case
should be executed. If you click the Show Dialog button, Case 0 is
executed. The case does not complete until you click the OK button in
6-21
the dialog box. Thus, while the dialog box is displayed, the Plot Loop
does not need to share the processor with the Menu Loop.
6. Click the Pop-Up VI button. The Pop-up 2nd Process VI opens its front
panel and runs. Notice the effect on the first VIs Averages/Sec value. As
in the situation when you clicked the Show Dialog button, the Menu
Loop no longer executes until the Pop-up 2nd Process VI ends.
However, LabVIEW runs the second VI at the same time as the original
VI. The dips in performance appear when the second VI runs. Therefore,
LabVIEW executes multiple VIs in the same way it executes parallel
loopseach process gets an equal time-slice.
7. Click the Stop button.
8. Modify the Menu Loop so it includes a Wait (ms) function. Wire a
constant value of 300 to the input of the function. Notice how the speed
of the Plot Loop changes.
9. Close the VI and do not save any changes.
10. If you are running LabVIEW on a multithreaded operating system, place
a checkmark in the Run with Multiple Threads checkbox on the
Execution page in the FileVI Properties dialog box. Exit and restart
LabVIEW. Repeat steps 2 through 9 and notice how multithreading
affects the execution speed of the Dialog & SubVI Demo VI.
If you want to magnify the results of this exercise, move windows with your
cursor while the Dialog & SubVI Demo VI runs. This increases the
processor workload creating more drastic results.
6-22
ni.com
Lesson 6
Exercise 6-4
Objective:
Performance Issues
Front Panel
6-23
5. After running the subVIs several times, stop the VI and click the
Snapshot button in the Profile window. Locate the Computation and
Global Benchmark VI in the Profile window and double-click it to
display its subVIs if they are not already displayed.
Notice the amount of time spent in each subVI. Specifically, compare
the amount of time spent executing Update Globals Inside Loop VI
versus Globals Outside of Loop VI and the time spent executing
Unnecessary Loop Computations VI versus Unnecessary Computations
Removed VI. Is this the behavior you expected? How would you apply
what you have learned in this exercise to your programming?
6. Click the Stop button in the Profile window to stop the profiling session.
Then close the Profile window.
7. Close the VI. Do not save any changes.
6-24
ni.com
Lesson 6
Performance Issues
LabVIEW Memory
Windows, Sun, and HP-UXLabVIEW allocates memory dynamically,
out of which all subsequent allocations are performed. When you load a VI,
its components are loaded into this block of memory. Likewise, when you
run a VI, all the memory that it manipulates is allocated from this block.
On the Macintosh, you configure the amount of memory that LabVIEW
allocates at launch time by selecting the Get Info option from the File menu
in the Finder. Note that if LabVIEW runs out of memory, it cannot increase
the size of this memory pool. Therefore, you should set this parameter as
large as possible. Make sure to leave enough memory for any other
applications that you want to run at the same time as LabVIEW.
6-25
Virtual Memory
When using Windows or Macintosh, you can use virtual memory to increase
the amount of memory available for your applications. Virtual memory uses
available disk space for RAM storage. If you allocate a large amount of
virtual memory, applications perceive this as memory that is available for
storage.
On the Macintosh, you allocate virtual memory using the Memory device in
the Control Panel folder. Windows, Sun, and HP-UX automatically manage
virtual memory allocation.
LabVIEW does not differentiate between RAM and virtual memory. The
operating system hides the fact that the memory is virtual. However,
accessing data stored in virtual memory is much slower than accessing data
stored in physical RAM. With virtual memory, you might occasionally
notice more sluggish performance because data are swapped to and from the
hard disk by the operating system. Virtual memory can help run larger
applications, but it is probably not appropriate for applications that have
critical time constraints.
VI Components
VIs have the following major components:
Front Panel
Block Diagram
When you load a VI, LabVIEW loads the front panel, the code, if it matches
the platform, and the data for the VI into memory. If the VI needs to be
recompiled because of a change in platform or in the interface to a subVI,
LabVIEW also loads the block diagram into memory.
LabVIEW also loads the code and data space of subVIs into memory. Under
certain circumstances, LabVIEW also loads the front panel of some subVIs
into memory. For example, if the subVI uses Property Nodes, LabVIEW
must load the front panel because Property Nodes manipulate the
characteristics of front panel controls.
As shown in the following example, you can save memory by converting
some of your VI components into subVIs. If you create a single, large VI
with no subVIs, the front panel, code, and data for that top-level VI end up
in memory. If the VI is broken into subVIs, the code for the top-level VI is
smaller, and only the code and data of the subVIs is in memory. In some
cases, you might actually see lower run-time memory use.
6-26
ni.com
Lesson 6
Performance Issues
front panel
block
diagram
front panel
block
diagram
front panel
block
diagram
code
data space
code
data space
code
data space
Top-Level VI
SubVI
SubVI
always resident
resident when necessary
6-27
You also can use the Profile window to monitor the memory used by all VIs
in memory.
Note When monitoring VI memory use, be sure to save the VI before examining its
memory requirements. The LabVIEW Undo feature makes temporary copies of objects
and data, which can increase the reported memory requirements of a VI. Saving the VI
purges the copies generated by Undo, resulting in accurate reports of memory
information.
6-28
ni.com
Lesson 6
Performance Issues
On open front panels, display large arrays and strings only when
necessary. Indicators on open front panels retain a copy of the data that
they display.
If the front panel of a subVI will not be displayed, do not leave unused
Property Nodes on the subVI. Property Nodes cause the front panel of a
subVI to remain in memory, which increases memory use.
When designing block diagrams, watch for places where the size of an
input is different from the size of an output. For example, if you
frequently increase the size of an array or string using the Build Array
or Concatenate Strings function, you generate copies of data, increasing
the number of memory allocations LabVIEW must perform. These
operations can fragment memory.
Use consistent data types for arrays and watch for coercion dots when
passing data to subVIs and functions. When LabVIEW changes data
types, the output is a new buffer.
6-29
cannot predetermine the space requirements you will need. LabVIEW might
need to relocate the entire buffer as the array grows in size, perhaps several
times. The time needed for relocation increases with the size of the array.
Therefore, you should use For Loops to assemble arrays when possible,
rather than using While Loops or concatenating arrays with the Build Array
function.
For Loop
vs.
While Loop
Inplaceness
When possible, LabVIEWs compiler reuses a functions input buffers to
store its output. This buffer sharing is called inplaceness. In the following
example, the Multiply function output uses the same buffer as the top input.
The array at the right is said to be inplace to array A.
6-30
ni.com
Lesson 6
Performance Issues
A function output reuses an input buffer if the output and the input have the
same data type, representation, and, in arrays, strings, and clusters, the same
structure and number of elements. Functions capable of inplaceness include
Trigonometric and Logarithmic functions, most Numeric functions, and
some string and array functions such as To Upper Case and Replace Array
Element. A function that shifts or swaps elements of an array, such as
Replace Array Element, can reuse buffers. Some functions such as Array
Subset and String Subset might not copy data but might pass pointers to the
subarrays or substrings. In the following illustration, A, B, C, and D identify
individual buffers. Build Array and Concatenate Strings are special
functions. They operate inplace when they can, but sometimes they must
allocate new buffers.
6-31
6-32
ni.com
Lesson 6
Performance Issues
Method 1 (Incorrect)
Method 1 might be your first attempt to save data space memory. You might
think changing the representation of the array on the front panel (FP) to SGL
can save space memory. However, this method does not affect the amount of
memory needed by the VI, because the function creates a separate buffer to
hold the converted data. The coercion dot on the SGL array terminal
indicates the function created a separate buffer to hold the converted data.
6-33
Method 2 (Incorrect)
6-34
ni.com
Lesson 6
Performance Issues
Method 3 (Correct)
Method 3 reduces the size of the data space considerably, from 24.8 KB to
12.8 KB. This method converts the Random Number (0-1) function output
to SGL before the array is created; therefore, this method creates two SGL
arrays at the border of a For Loop rather than two DBL arrays.
6-35
6-36
ni.com
Lesson 6
Performance Issues
Now, consider what you need to do to change an element in the Test Data
array. First, you must index an element of the overall Tests array. For that
element, which is a cluster, you must unbundle the elements to get to the
array. You then replace an element of the array and store the resulting array
in the cluster. Finally, you store the resulting cluster in the original array. An
example of this is shown in the following illustration.
6-37
6-38
ni.com
Lesson 6
Exercise 6-5
Objective:
Performance Issues
Assembling Arrays VI
Front Panel
6-39
The Initialize Array function is slightly faster than an Auto Indexing For
Loop. In both instances, the array size is known and LabVIEW can allocate
the correct amount of memory only once. Recall that resizing requires more
execution time. Therefore the Initialize Array function or an Auto Indexing
For Loop are the best ways to create arrays.
If you can predetermine the maximum size of the array to be built, then you
can initialize this array and pass it into the While Loop. Once inside the
While Loop, each element can be updated or replaced as needed. This is
somewhat efficient, because the array does not need to be reallocated once
it is passed into the While Loop. This is still not as efficient as the For Loop
or Initialize Array function.
6-40
ni.com
Lesson 6
Performance Issues
Avoid using the Build Array function inside a loop. Every time a new value
is appended to the array, LabVIEW must reallocate the buffer and copy the
entire array to the new location. Thus execution times for the Build Array
function are the slowest.
6. Close the Profile window. Close the VI and do not save changes.
6-41
Exercise 6-6
Objective:
Performance Enhancements VI
Runs faster.
Is better documented.
Use the tips in this lesson, information from other chapters in this
course, and the following tips to get started:
6-42
ni.com
Lesson 6
Performance Issues
Flat data types are more memory efficient than complex data
structures.
6-43
Exercise 6-7
Objective:
6-44
ni.com
Lesson 6
Performance Issues
You only need to meet the requirements of the application described previously.
How you choose to implement this application is up to you.
Tip
6-45
Reduce the number of I/O calls you make by reducing the amount of
data you acquire, or by acquiring more data in fewer calls.
Reduce the number of controls and indicators you have on the front
panel.
Update graphs and charts with several points at a time, not one point at
a time.
Force less important parallel tasks to wait, using the Wait (ms) function,
so more crucial ones have more processor time.
6-46
ni.com
Lesson 6
Performance Issues
6-47
Notes
6-48
ni.com
Appendix
This appendix contains the following sections of useful information for
LabVIEW users:
A. Polymorphic subVIs
B. Custom Graphics in LabVIEW
C. The LabVIEW Web Server
D. Additional Information
E. ASCII Character Code Equivalents Table
A-1
Appendix
A. Polymorphic SubVIs
LabVIEW built-in functions can handle different types of data for the same
terminal, a capability called polymorphism. An example of polymorphism
is the Add function.
It is also possible to create your own polymorphic VIs, which can handle
more than one type of data for the same terminal. These polymorphic VIs
can then be used as polymorphic subVIs.
Using polymorphic VIs allows you to present a much simpler interface to
the users of your VIs. Consider the case of a polymorphic VI that can sort
either 1D or 2D arrays. Instead of having one VI for sorting 1D arrays and
another subVI for sorting 2D arrays, one VI called Sort Array handles both
types of inputs.
A-2
ni.com
Appendix
3. Add each of the set of VIs to the polymorphic VI using the Add VI
button.
4. You can create an icon for the polymorphic VI using the Edit Icon
button. You also can create context help for the polymorphic VI by
selecting Documentation from the top pull-down menu in the FileVI
Properties dialog box.
Note Context help for the polymorphic VI is not associated with context help for the VIs
that compose the polymorphic VI. Therefore, you must create new context help by using
the Documentation page in the FileVI Properties dialog box.
A-3
Appendix
Exercise A-1
Objective:
Instead of having one VI for sorting 1D arrays and another subVI for sorting
2D arrays, one VI called Sort Array handles both types of inputs. In this
exercise, create this VI.
1. Create a VI that sorts a 1D array. This VI should also include an option
to sort in ascending or descending order and pass out an error Boolean
object. The following example is a suggested front panel. You need to
create the front panel and block diagram and test the code you write.
Use the same icon connector pane for the Sort 2D Array instance. Otherwise the
polymorphic VI produces broken wires.
Note
A-4
ni.com
Appendix
A-5
Appendix
8. Add the Sort 1D Array+ and Sort 2D Array+ VIs using the Add VI
button. You might need to browse to the directories where you saved
these VIs.
9. Create an icon for this new polymorphic VI by selecting the Edit Icon
button.
10. Create context help for this VI by selecting Documentation from the
top pull-down menu in the FileVI Properties dialog box.
11. Save your VI as Sort Poly Array.vi.
12. Use this VI as a subVI in another VI to test the functionality. Notice the
help screen. Also notice what happens when you double-click the
polymorphic VI. What happens if you select a particular context by
right-clicking and selecting Select Type?
A-6
ni.com
Appendix
Decorations
One of the most straightforward methods to enhance a user interface is to
apply the LabVIEW Decorations to a front panel as you did in Lesson 2,
Designing Front Panels. Through careful use of the decorations, you can
increase the readability of the front panels.
Importing Graphics
You can import graphics from other VIs for use as background pictures,
items in ring controls, or parts of other controls. However, before you can
use a picture in LabVIEW, you need to load it into the LabVIEW Clipboard.
There are one or two ways to do this, depending on your platform.
MacintoshIf you copy from a paint program to the Clipboard and then
UNIXYou can use the Import Picture from File option from the
Custom Controls
You can customize LabVIEW controls and indicators to change their
appearance on the front panel. You also can save these controls for use in
other VIs. Programmatically, they function the same as standard LabVIEW
controls.
A-7
Appendix
Control Editor
Launch the Control Editor by selecting a control on the front panel and
selecting EditCustomize Control. The Control Editor appears with the
selected front panel object in its window. The Control Editor has two modes,
edit mode and customize mode.
Edit Mode
In edit mode, you can right-click the control and manipulate its settings as
you would in the LabVIEW programming environment.
Edit Mode
Type Def.
Status
Text
Align
Distribute
Objects Objects
Reorder
Objects
Customize Mode
In customize mode, you can move the individual components of the control
around with respect to each other. For a listing of what you can manipulate
in customize mode, select WindowShow Parts Window.
Customize
Mode
Type Def.
Status
Text
Align
Distribute Reorder
Objects Objects
Objects
One way to customize a control is to change its type definition status. You
can save a control as a control, a type definition, or a strict type definition,
depending on the selection showing in the Type Def. Status ring. The
control option is the same as a control you would select from the Controls
palette. You can modify it in any way you need to, and each copy you make
and change retains its individual properties.
A Type Definition control is a master copy of a custom control. All copies
of this kind of custom control must be of the same data type. For example,
if you create a Type Definition custom control having a numeric
representation of Long, you cannot make a copy of it and change its
representation to Unsigned Long. Use a Type Definition when you want to
place a control of the same data type in many places. If you change the data
type of the Type Definition in the Control Editor, the data type updates
automatically in all VIs using the custom control. However, you can still
individually customize the appearance of each copy of a Type Definition
control.
A-8
ni.com
Appendix
Saving Controls
After creating a custom control, you can save it for use later. By default,
controls saved on disk has a .ctl extension. You also can place controls in
the Controls palette using the same method as that you used to add subVIs
to the Functions palette.
You also can use the Control Editor to save controls with your own default
settings. For example, you can use the Control Editor to modify the defaults
of a waveform graph, save it, and later recall it in other VIs.
A-9
Appendix
Exercise A-2
Objective:
A-10
ni.com
Appendix
6. Close the Control Editor by selecting Close from the File menu. Save
the control as Custom Slider.ctl, then click Yes to replace the
existing one. The modified slider is shown on the front panel.
Note You can save controls that you create like you save VIs. You can load saved
controls using Select a Control from the Controls palette. Controls have a .ctl
extension.
7. Manipulate the slider and watch the meter track its data value.
8. Close the VI. Do not save changes.
A-11
Appendix
Exercise A-3
Objective:
Front Panel
A-12
ni.com
Appendix
c. Change to the front panel by clicking it. Using the Positioning tool,
select the graphic of the flask that shows the contents of the flask not
boiling, and select EditCut. Change to the Control Editor window
by clicking it.
d. Right-click the boiling flask and select Import PictureFalse. This
custom picture now represents the FALSE state.
e. Select Apply Changes from the File menu, and close the Control
Editor. Do not save the custom control.
3. Right-click an open area and select Square LED from the
ControlsClassic ControlsBoolean shortcut menu. Label the LED
Flame.
4. Using the previous steps, make the LED look like a Bunsen burner. The
TRUE state should show the burner on; the FALSE state should show
the burner off.
5. Hide the labels of both Boolean indicators by right-clicking them and
selecting Visible ItemsLabel. Select both Boolean indicators and
align them on horizontal centers using the Align Objects tool.
Block Diagram
6. Complete the following block diagram.
A-13
Appendix
A-14
ni.com
Appendix
Click the Instructions button to display information about how to add a title
to your HTML file and how to add text before and after your VI front panel.
Enter a VI name in the VI Name field or select Browse from the VI Name
pull-down menu and navigate to a VI.
Note To display VI front panels on the Web, the VIs must be in memory on your
computer.
You can preview the document in your default browser by clicking the
Start Web Server button and then clicking the Preview in Browser button.
If the Start Web Server button is dimmed, the Web Server is already
running. When you click the Save to Disk button, the title, text, and VI front
panel image are saved in an HTML document. If you want to view the
document from a remote computer, save the HTML document in the Web
Server root directory, usually labview\www. The Document URL dialog
box appears with the URL for your HTML document.
A-15
Appendix
Exercise A-4
Objective:
To use the LabVIEW Web Server tools to display a front panel in a web browser.
Open the VI you built in Exercise 1-1, the Generate & Analyze Data VI,
and save its front panel into an HTML document.
Front Panel
A-16
ni.com
Appendix
8. Click the Preview in Browser button to open and display the front panel
in a web browser. A window similar to the one shown in the next figure
appears.
A-17
Appendix
The Animated option only works with Netscape Navigator. You can only view
static images using Internet Explorer.
Note
9. Return to the Web Publishing Tool window and click the Save to Disk
button to save the title, text, and VI front panel image in an HTML
document. Save the document as Generate & Analyze Data.htm
in the LV Basics 2 directory. A warning message appears, telling you
where to install the file if you want other machines to view it.
10. Click the Done button to exit the Web Publishing Tool.
11. Go back to the Browser application and type the following URL into the
address: http://127.0.0.1. This specifies the local machine. The
following window appears.
A-18
ni.com
Appendix
12. Read the information and close the browser when you are finished.
13. Turn off the Web Server by selecting ToolsOptions to display the
Options dialog box.
14. Select Web Server: Configuration from the top pull-down menu of the
Options dialog box and remove the checkmark from the Enable Web
Server checkbox.
15. Click the OK button to close the Options dialog box.
16. Close the Generate & Analyze Data VI.
A-19
Appendix
D. Additional Information
This section describes how you can receive more information regarding
LabVIEW, instrument drivers, and other topics related to this course.
A-20
ni.com
Appendix
LabVIEW Publications
LabVIEW Technical Resource (LTR) Newsletter
Subscribe to LabVIEW Technical Resource to discover power tips and
techniques for developing LabVIEW applications. This quarterly
publication offers detailed technical information for novice users as well
as advanced users. In addition, every issue contains a disk of LabVIEW
VIs and utilities that implement methods covered in that issue. To order
LabVIEW Technical Resource, call LTR publishing at (214) 706-0587
or visit ltrpub.com
LabVIEW Books
Many books have been written about LabVIEW programming and
applications. The National Instruments Web site contains a list of all the
LabVIEW books and links to places to purchase these books. Publisher
information is also included so you can directly contact the publisher for
more information on the contents and ordering information for LabVIEW
and related computer-based measurement and automation books.
discuss LabVIEW issues. The people on this list can answer questions about
building LabVIEW systems for particular applications, where to get
instrument drivers or help with a device, and problems that appear.
Send subscription messages to the info-labview list processor at:
[email protected]
The archives contain a large set of donated VIs for doing a wide variety of
tasks.
A-21
Appendix
Octal
Decimal
ASCII
Hex
Octal
Decimal
ASCII
00
000
NUL
20
040
32
SP
01
001
SOH
21
041
33
02
002
STX
22
042
34
"
03
003
ETX
23
043
35
04
004
EOT
24
044
36
05
005
ENQ
25
045
37
06
006
ACK
26
046
38
&
07
007
BEL
27
047
39
'
08
010
BS
28
050
40
09
011
HT
29
051
41
0A
012
10
LF
2A
052
42
0B
013
11
VT
2B
053
43
0C
014
12
FF
2C
054
44
0D
015
13
CR
2D
055
45
0E
016
14
SO
2E
056
46
0F
017
15
SI
2F
057
47
10
020
16
DLE
30
060
48
11
021
17
DC1
31
061
49
12
022
18
DC2
32
062
50
13
023
19
DC3
33
063
51
14
024
20
DC4
34
064
52
15
025
21
NAK
35
065
53
16
026
22
SYN
36
066
54
17
027
23
ETB
37
067
55
A-22
ni.com
Appendix
Hex
Octal
Decimal
ASCII
Hex
Octal
Decimal
ASCII
18
030
24
CAN
38
070
56
19
031
25
EM
39
071
57
1A
032
26
SUB
3A
072
58
1B
033
27
ESC
3B
073
59
1C
034
28
FS
3C
074
60
<
1D
035
29
GS
3D
075
61
1E
036
30
RS
3E
076
62
>
1F
037
31
US
3F
077
63
40
100
64
60
140
96
41
101
65
61
141
97
42
102
66
62
142
98
43
103
67
63
143
99
44
104
68
64
144
100
45
105
69
65
145
101
46
106
70
66
146
102
47
107
71
67
147
103
48
110
72
68
150
104
49
111
73
69
151
105
4A
112
74
6A
152
106
4B
113
75
6B
153
107
4C
114
76
6C
154
108
4D
115
77
6D
155
109
4E
116
78
6E
156
110
4F
117
79
6F
157
111
50
120
80
70
160
112
51
121
81
71
161
113
52
122
82
72
162
114
A-23
Appendix
Hex
Octal
Decimal
ASCII
Hex
Octal
Decimal
ASCII
53
123
83
73
163
115
54
124
84
74
164
116
55
125
85
75
165
117
56
126
86
76
166
118
57
127
87
77
167
119
58
130
88
78
170
120
59
131
89
79
171
121
5A
132
90
7A
172
122
5B
133
91
7B
173
123
5C
134
92
7C
174
124
5D
135
93
7D
175
125
5E
136
94
7E
176
126
5F
137
95
7F
177
127
DEL
A-24
ni.com
Title:
Edition Date:
September 2000
Part Number:
320629G-01
Fax to:
Customer Education
National Instruments Corporation
512 683 6837
Course Evaluation
Course _______________________________________________________________________________________
Location _____________________________________________________________________________________
Instructor _________________________________________
Date ____________________________________
Company _________________________________________
Instructor
Please evaluate the instructor by checking the appropriate circle.
Unsatisfactory Poor
Satisfactory Good
Excellent
Course
Too long
Yes
No
Just right
Too short
Too much
Yes
Yes
Just right
No
Not enough
Sometimes
No
Co-worker
Other _____________________________________________________________
Title _____________________________________
Company _________________________________________
State/Province ____________
Telephone ________________________________________
Country ______________
Zip ______________
Fax ______________________________________
E-Mail _______________________________________________________________________________________
Date _____________________________________________
Pharmaceutical
Test, measurement,
and instrumentation
Computer
Medical
Aero/avionics
Telecommunications
Consumer products
Military/space
Semiconductor
University/education
Electronics
Paper/pulp
ATE/automated test
Graphics
Petrochemical/plastics
Other ______________
If you are currently a customer of National Instruments, please check the products you use:
LabVIEW
HiQ
DAQ
Fieldbus
LabWindows/CVI
ComponentWorks
SCXI
IMAQ Vision
BridgeVIEW
VirtualBench
GPIB
Serial
Lookout
Measure
VXI
Motion control
HP-UX
Windows 3.1
Mac OS
Windows 95
Sun
Concurrent PowerMax
PCI
PCMCIA
VME
Macintosh
DEC
HiQ
DAQ
Fieldbus
LabWindows/CVI
ComponentWorks
SCXI
IMAQ Vision
BridgeVIEW
VirtualBench
GPIB
Serial
Lookout
Measure
VXI
Motion control
System(s) integrator
consultant
Which statements best describe your role in the purchase of instrumentation or data acquisition products?
I set company standards.
Calibration
Government/legal
Production test
Manufacturing/
automation
Engineering
management
Research/R&D/grad
student
Systems integrator/
hardware
Reseller/sales
Purchasing/contracts
Software developer
Software consultant
Service/repair
Student/co-op
Design
Compliance testing
Third-Party Solution CD
Academic Catalogue
Instrumentation Newsletter
Industry-specific Literature
Aerospace
Semiconductor
Analytical chemistry
Industrial automation
Telecommunications
Vibration/acoustics
Education
Laboratory automation
Automotive
Physiology
Analysis
GPIB
PXI
ComponentWorks
HIQ
IMAQ
TestStand
Measure
HS488
Customer education
LabVIEW Add-On
Toolkit pack
LabVIEW
productivity study
Virtual instrumentation
software
Computer-based
instruments
BridgeVIEW
DAQ
VXI
Lookout
Low-cost DAQ
VME
SCXI signal
conditioning
Additional Literature
NI Global Services
340812C-01