Web Interface Network

hotdogrelishnoseΛογισμικό & κατασκευή λογ/κού

4 Νοε 2013 (πριν από 3 χρόνια και 8 μήνες)

187 εμφανίσεις

Web Interface Network


In this training module, we will cover what the Web Interface Framework, or WIF, is and
why we would want to use it. We will then discuss the basics behind how the WIF
works. Next we will talk about what we need to set up the WIF in

order to get started
before ending with examples of using the WIF to configure and monitor our devices.
The toolbar you see to the right represents the various settings you can access through
the WIF.





First let’s talk about what the Web Interface Fra
mework is, and even more importantly
why we have it.


Prior to the release of the Web Interface Framework, the only way to configure and
monitor your remote real
-
time targets was through NI Measurement and Automation
Explorer, which had to reside on a host

machine. Only the host had direct access to the
setup of and communication with a real
-
time target.


However, with the Web Interface Framework, you can now configure and control your
real
-
time targets through any web browser. You no longer need to install

driver software
on your host in order to interact with your real
-
time targets. The Web Interface
Framework provides you with a rich, interactive web application client built on Microsoft
Silverlight that exposes device
-
specific information.




You can co
mpare the interaction between your real
-
time targets and the Web Interface
Framework to the configuration of your router at home. Almost all routers provide a
web
-
client interface that can be accessed through a web
-
browser. Through the browser
you can conf
igure parameters such as the encryption key and security. The router itself
has an on
-
board web
-
service that deploys this HTML interface.


Similarly, our real
-
time targets running LabVIEW Real
-
Time 2010 will run a small
embedded web
-
service to which you ca
n connect using a standard web
-
browser on the
host machine. The browser communicates with the web
-
service through a standard
request/response protocol, allowing you to see the status of your device as well as
affect changes to its configuration.


Previousl
y, all configuration and monitoring of remote targets could only be done
through NI Measurement and Automation Explorer. Now with the Web Interface
Framework, we can configure and monitor our real
-
time targets by simply pointing to
their IP addresses throu
gh any standard browser.




In order to make use of the Web Interface Framework on your remote targets, you will
need to have a host computer with LabVIEW 2010 and the LabVIEW Real
-
Time 2010
Module installed. Through NI Measurement and Automation Explore
r, you will have to
install LabVIEW Real
-
Time 2010 on your target device from the host. Upon installing
LabVIEW Real
-
Time 2010 on the target, you will automatically install the NI Web
Configuration and Monitoring application, which provides the browser
-
sid
e interface to
your devices. After rebooting the target device, you will be able to make use of the Web
Interface Framework by simply opening up a browser and pointing it to the IP address of
your target device.





After directing your browser to the IP
address of your target device, you will first come
across the Web Configuration and Monitoring homepage which is built upon the Web
Interface Framework. You will see several Web Configuration and Monitoring icons on
the left
-
hand side of the page, which al
low you to access or configure various settings
for your device. At the top of the page, you will notice the buttons that give you the
ability to Reboot the real
-
time target, Login to it, or access the Help documentation for
each setting. Clicking on the H
elp button will open another page in your browser that
provides detailed documentation for the current setting you are trying to configure. In
this case, we are looking at the System Settings Page.


From the Systems Settings page you can set device setting
s such as the device name
and its comments, and you can view but not edit settings such as the device’s IP
Address, model, and serial number.





The next page for the Web Configuration and Monitoring page is the Network
Configuration. This page is respon
sible for viewing and configuring network settings for
your LabVIEW Real
-
Time target. This page lists all the Ethernet adapters detected in
the system. The first adapter in the list is the default adapter, but it may not be the
primary adapter. For static
IPv4 addresses, you can set the IP address and subnet
mask through this page.





The Security Configuration page enables you to set security permissions for users to
monitor and configure a remote or local system. You can use this page to change the
defa
ult administrator password, create new user accounts, and grant permissions to
users and groups. To create a new user, click on the New User button, set the User
Name, Password, and determine what groups they are a part of and what permissions
they have.






Use Time Configuration page to view and set time settings such as the date, current
time, time zone, and daylight savings time on your LabVIEW Real
-
Time target. You can
also use this page to set time synchronization sources for your system if it supp
orts this
feature.




The Remote File Browser page gives you access to the files stored on your real
-
time
target. With the Remote File Browser, you can transfer files to and from a real
-
time
target. You can also create, delete, and rename files on the tar
get, as well as edit text
files in
-
place.




With the Web Server Configuration page you can enable the Application Web Server,
which hosts LabVIEW web services. You can also enable Secure Sockets Layer (SSL)
encryption on both the System Web Server and th
e Application Web Server.





You can configure more device
-
specific parameters. For example, for a Wireless
Sensor Network (WSN), you can use the WSN Configuration page to view and set NI
WSN gateway settings, add and remove nodes, update firmware, and
change network
modes.





Using the Installed Configuration Tools page, you can enable and disable the Web
Configuration and Monitoring pages installed on the remote device. The Control Name
displays the name of each Web Configuration and Monitoring page.

Check the Is
Enabled? component to specify which pages are enabled from all the installed Web
Configuration and Monitoring pages. The Description lists the functionality of each page.



























Source
:

Getting Started with NI LabVIEW Student Training
-

Developer Zone
-

National Instruments

(15 March 2011
11:09 PM)



Getting Started with NI LabVIEW Student Training


The LabVIEW Environment





Launching LabVIEW


click

National Instruments LabVIEW 8.5.1.


If you do not have a shortcut for

National Instruments LabVIEW 8.5.1
, navigate through the programs list and find
the

National Instruments

program directory. A menu appears that shows all Natio
nal Instruments software
installed on your computer. Navigate to

LabVIEW 8.5.1

and select the

LabVIEW

icon. This launches LabVIEW and
opens the

Getting Started

window.


clipboard.htm

When you launch LabVIEW, the LabVIEW splash screen opens. It may take a few moments for LabVIEW to launch
depending on your system configuration and the number of LabVIEW modules you have installed.



The Getting Started Window

The

Getting Started

window is divided in half from left to right. On the left is the

Files

section and on the right is
the

Resources

section. In the

Files

section under

New
, you can create a blank virtual instrument (VI), project, or
module
-
specific project, o
r you can select the

More

folder to start from one of the may LabVIEW templates.
Under

Open
, see a list of recently opened LabVIEW files such as VIs and projects. In the

Resources

section, find
additional getting started tools ranging from online discussio
n forums to a comprehensive library of example
programs that are shipped with LabVIEW.


Note:

If you do not want to see the

Getting Started

window every time you launch LabVIEW, you can configure
LabVIEW to open a new, blank VI on launch instead. Select

T
ools»Options
.


clipboard.htm

In the Options dialog box, select

Environment

from the

Category

list and place a checkmark in
Skip Getting
Started window on launch

check
box.


clipboard.htm

Click

OK

to save and apply your changes. The many other options in the

Getting Started

window vary depending
on which version of LabVIEW and whic
h toolkits you have installed.

It is essential to know how to change the options and preferences for LabVIEW. The
Getting

Started

windows have
many important resources on it that are very useful. Make sure that you are familiar with all of the different
res
ources that are available on the

Getting

Started
window






Front Panel


This tutorial explores the Front Panel and its relationship with the Block Diagram. Learn about the different types of
Front Panel objects as well as how to find them on the Controls
palette and place them on the Front Panel.

This video explores the Front Panel and its relationship with the Block Diagram. Learn about the different types of
Front Panel objects as well as how to find them on the Controls palette and place them on the Fro
nt Panel.This
video explores the Front Panel and its relationship with the Block Diagram. Learn about the different types of Front
Panel objects as well as how to find them on the Controls palette and place them on the Front Panel.This video
explores the F
ront Panel and its relationship with the Block Diagram. Learn about the different types of Front Panel
objects as well as how to find them on the Controls palette and place them on the Front Panel.

The front panel window is the user interface for the VI. T
he front panel has controls and indicators, which are the
interactive input and output terminals, respectively, of the VI. Controls and indicators placed on the front panel are
automatically placed on the block diagram. Refer to the “Block Diagram” tutoria
l for more information on block
diagram terminals.

Front Panel Window

When you open a new or existing VI, the front panel window of the VI appears and functions as the graphical user
interface or GUI of a VI. You can find the source code that runs the fron
t panel on the block diagram. The front
panel window contains a toolbar across the top and a

Controls
palette that you can access by right
-
clicking
anywhere on the front panel.

After opening the

Controls

palette, use it to place controls and indicators on t
he front panel.


Note:

Use the thumb tack to pin the

Controls

palette to the front panel and then select
View»Change Visible
Categories
.



In the

Change Visible Categories

dialog box, click

Select All

and then

OK

to make all available controls and
indicat
ors visible on the front panel.

Controls and Indicators

Controls


knobs, push buttons, dials, and other input devices


are the interactive input terminals, while indicators


graphs, LEDs, and other displays


are the interactive output terminals of the
VI. Controls simulate instrument
input devices and supply data to the block diagram of the VI. Indicators simulate instrument output devices and
display data the block diagram acquires or generates.

The figure above has two controls


Number of Measurement
s

and

Delay (sec)



and one indicator, a waveform
graph named

Temperature Graph
. The user can change the input value for the

Number of
Measurements

and

Delay (sec)

controls. The user can see the value generated by the VI on the

Temperature
Graph

indicator.

The VI generates the values for the indicators based on the code created on the block diagram. To
learn more about the block diagram, see the “Block Diagram” tutorial.

Every control and indicator has a data type associated with it. For example, the

Delay
(sec)
horizontal slide is a
numeric data type. Double
-
click the

Delay (sec)

control to make LabVIEW jump to the terminal location on the
block diagram. Notice the color of the terminal. Orange terminals signify a data type called double (DBL), which is a
ty
pe of numeric data.

The most commonly used data types are numeric, Boolean value, and string. Learn more about data types in the
“Data Types” tutorial.

Numeric Controls and Indicators

The numeric data type can represent various types of numbers, such as in
teger or real. The two common numeric
objects are the numeric control and the numeric indicator. Objects such as meters and dials also represent numeric
data. Use the

Controls

palette to place a numeric control on the front panel and then use the increment

and
decrement buttons to adjust its values.

Follow steps 1
-
3 to create a numeric control and change its value.


1.


Right
-
click the front panel to open the

Controls

palette, and from the

Numeric

subpalette drag and drop
a

Numeric Control

onto the fr
ont panel.


2.


Label the control

Input

by double
-
clicking on the label and typing the word “Input.”

3.


Now change the value of the control by clicking the increment or decrement button. Alternatively, you can
double
-
click the number with eithe
r the Labeling tool or the Operating tool, enter a new number, and press
the

<Enter>

key.

Boolean Controls and Indicators

The Boolean data type represents data that has only two parts, such as TRUE and FALSE or ON and OFF. Use
Boolean controls and indicato
rs to enter and display Boolean values. Boolean objects simulate switches, push
buttons, and LEDs. The vertical toggle switch and the round LED Boolean objects are shown below. You can find
them in the

Boolean

subpalette in the

Controls
palette (see below).


String Controls and Indicators

The string data type is a sequence of ASCII characters. Use string controls to receive text from the user, such as a
password or user name, and use string indicators to display text to the user. The most common string objec
ts are
tables and text entry boxes as shown below. You can find string controls and indicators in the

String and
Path

subpalette or the

Lists and Tables

subpalette. Some common string indicators are shown below.

Shortcut Menus and Property Dialog Boxes

All

LabVIEW objects have associated shortcut menus and property dialog boxes. As you create a VI, use the
shortcut menu items and/or the properties dialog box to change the appearance and/or behavior of front panel and
block diagram objects. To access the sho
rtcut menu, right
-
click the object you want to modify. To access the
Properties dialog box, select

Properties

from the shortcut menu.

Follow steps 1 and 2 to create a string control and then use the Properties dialog box to add a scroll bar. Start with
a b
lank VI.

1.


From the

String & Path

subpalette, select a

String Control

and place it on the front panel.

2.


Right
-
click the string indicator to open the shortcut menu and select

Properties
.





3.


From the Properties dialog box, put a chec
k in the

Show vertical scroll bar

checkbox and click

OK
.



4.


The resulting string control

has a scroll bar so the user can scroll up and down to view all of the text. This
allows the use of a small string control to display a large amount of text.

Front Panel Window Toolbar

Each window has a toolbar associated with it. Use the front panel window toolbar buttons to run and edit the VI.
The following toolbar appears on the front panel window.


Click the

Run

button to run your VI. You do not need

to compile your code; LabVIEW compiles it automatically. You can run a VI if the

Run

button appears as a solid
white arrow, shown at left.


The

Run

button appears broken when the VI you are creating or editing contains
errors. If the Run button stil
l appears broken after you finish wiring the block diagram, the VI is broken and cannot
run. Click this button to display the

Error List

window, which lists all errors and warnings.


Click

Run
Continuously

to run the VI until you abort or pause exe
cution. You also can click the button again to disable
continuous running.



While the VI runs, the

Abort Execution

button appears. Click this button to stop the VI immediately if
there is no other way to stop the VI. If more than one running
top
-
level VI uses the VI, the button is dimmed.

Caution:

The

Abort Execution

button stops the VI immediately before it finishes the current iteration. Aborting a VI
that uses external resources, such as external hardware, might leave the resources in an un
known state by not
resetting or releasing them properly. Design VIs with a stop button to avoid this problem.



Click

Pause

to pause a running VI. When you click the

Pause

button, LabVIEW highlights on the block
diagram the location where you paused

execution, and the

Pause

button appears red. Click the

Pause

button
again to continue running the VI.


Select the

Text Settings

pull
-
down menu to change the font settings for the selected
portions of your VI, including size, style, and color.



Click

the

Align Objects

pull
-
down menu to align objects along axes, including vertical, edge, and left.




Click the

Distribute Objects

pull
-
down menu to resize multiple front panel objects to the same
size.


Click the

Resize Objects

pull
-
down menu to res
ize multiple front panel objects to the same size.



Click the

Reorder

pull
-
down menu when your objects overlap each other and you want to define which
one is in front or back of another. Select one of the objects with the Positioning tool and then sele
ct from

Move
Forward, Move Backward, Move To Front,

and

Move To Back
.




Click the

Show Context Help Window

button to toggle the display of the context help window.

Enter
Text

appears to remind you that a new value is available to replace an

old value. The

Enter Text

button disappears
when you click it, press the

<Enter>

key, or click the front panel or block diagram workspace.

Tip:

The

<Enter>

key on the numeric keypad ends a text entry, while the main

<Enter>

key adds a new line. To
modify
this behavior, select

Tools»Options
, choose

Environment

from the

Category
list, and place a checkmark
in the

End text entry with Enter key

option.

It is important for a VI to have an intuitive and easy
-
to
-
read front panel. The front panel is essentially the

gateway
for all user input and output of a VI. Therefore it is essential that the programmer has good grasp of how to
effectively program a front panel






Block Diagram


In this introduction to the Block Diagram, we examine the concept of this tool as w
ell as the Block Diagram’s
relationship with the Front Panel. We also explore how to open the Block Diagram, how to find objects in the
Functions palette and put them on the Block Diagram, and how to use different toolbar icons. In addition, we learn
how t
o build a simple block diagram to illustrate the important concepts of creating graphical code in NI LabVIEW
software.

The block diagram contains the graphical source code of a LabVIEW program. The concept of the block diagram is
to separate the graphical
source code from the user interface in a logical and simple manner. Front panel objects
appear as terminals on the block diagram. Terminals on the block diagram reflect the changes made to their
corresponding front panel objects and vice versa.


Block
Diagram Window

When you create or open a new VI, the front panel opens automatically. To bring up the block diagram,
select

Window»Show Block Diagram

from the menu bar. Additionally, you can toggle between the block diagram
and the front panel by pressing

<Ctrl
-
E>
.

Block Diagram Objects and Environment

Block diagram objects include terminals, subVIs, functions, constants, structures, and wires that transfer data
among other block diagram objects. You can use LabVIEW tools to create, modify, and debug a VI.
A tool is a
special operating mode of the mouse cursor, so the operating mode of the cursor corresponds to the icon of the tool
selected. LabVIEW chooses which tool to select based on the current location of the mouse. You can manually
choose the tool you
need by selecting it on the

Tools

palette (from the menu bar, select

View»Tools Palette
). Now
you can choose your desired tool, which remains selected until you choose another tool from the

Tools
palette.

To place objects on the block diagram, simply drag a
nd drop them from the

Functions

palette.
The

Functions

palette automatically appears when you right
-
click anywhere on the block diagram workspace. It
contains functions, constants, structures, and some subVIs.

Notice the two buttons on the top of the

Funct
ions

palette.


The

Thumb Tack

pins the

Functions

palette to
the block diagram.

The

Search

button opens a search dialog box that you can use to search for functions by
name.

Click the

Search

button to launch the functions search engine. It takes a
few moments to launch.

You can use this tool to search for a function by name if you are having trouble finding it.

Once you see the function you want, double
-
click on it and LabVIEW jumps to the place on the
Functions

palette
where you can find that funct
ion.

Note:

Complete the following steps to change the subpalettes visible on the

Functions

palette:

1.


Use the thumb tack to pin the

Functions

palette to the block diagram.



2.


Notice the

View

button appears when you pin the

Functions

palette
to the block diagram.

3.


Select

View

and, from the shortcut menu, select

Change Visible Categories
.

4.


In the

Change Visible Categories

dialog box, you can select the Palettes that you use the most or
click

Select All

to include all Palettes.

T
o change the appearance of the block diagram, select

Tools»Options

from the menu bar. In the
Options

dialog
box, select the

Block Diagram

category. Here you can customize the appearance of your block diagram. To save
space on the block diagram, deselect

Pla
ce front panel terminals as icons
.

Terminals

Terminals create the block diagram appearance of objects on the front panel. In addition, they are entry and exit
ports that exchange information between the front panel and block diagram. Analogous to parameter
s and
constants in text
-
based programming languages, terminals come in two types: control or indicator terminals and
node terminals. Control and indicator terminals belong to front panel controls and indicators.

[+] Enlarge Image

In the example above, data you enter in front panel controls

a

and

b

enter the block diagram through their
respective control terminals

a

and

b
. The data then enter the Add and Subtract functi
ons. When the Add and
Subtract functions complete their calculations, they produce new data values. The data values flow to the indicator
terminals, where they update the front panel indicators

a+b

and

a
-
b
.

Controls, Indicators, and Constants

Controls, ind
icators, and constants operate as the inputs and outputs of the block diagram algorithm. Controls
receive their values from the front panel and pass data to other block diagram objects. Indicators receive their
values from block diagram logic and pass data

from the block diagram to the front panel. Constants pass data to
the object to which they are wired. Consider an algorithm for computing the area of a triangle. You might have the
following front panel and corresponding block diagram.

The constant

Triang
ular Multiplier

does not necessarily appear on the front panel window except possibly as
documentation of the algorithm. It simply passes the value of

.5

into the multiply function. Notice that
the

Base(cm)

and

Height(cm)

block diagram terminals look diffe
rent from the
Area(cm^2)

terminal. There are two
distinguishing characteristics between a control and an indicator on the block diagram. The first is an arrow on the
terminal that indicates the direction of data flow. The controls have arrows showing the
data leaving the terminal,
whereas the indicator has an arrow showing the data entering the terminal. The second distinguishing characteristic
is the border around the terminal. Controls have a thick border and indicators have a thin border.

You can create

controls and indicators from either the block diagram or the front panel. This tutorial demonstrates
this in a later section.

Block Diagram Nodes

Nodes are objects on the block diagram that have inputs and/or outputs and perform operations when a VI runs.

They are analogous to statements, operators, functions, and subroutines in text
-
based programming languages.
Nodes can be functions, subVIs, or structures. Structures are process control elements, such as case structures,
for loops, or while loops, which
are covered in a later tutorial. The image below shows some examples of block
diagram nodes.





Functions

Functions are the fundamental operating elements of LabVIEW. Functions do not have front panel windows or
block diagram windows, but they do have inp
ut and output terminals for passing data in and out similarly to controls
and indicators. You can tell if a block diagram object is a function by the pale yellow background on its icon.
The

Functions

palette has functions arranged in groups based on the ty
pe of function they perform. Look in
the

Numeric

subpalette for functions that perform numeric operations.



There are many different types of functions. Remember that a function has a pale yellow background like the
functions shown below.


SubVIs

SubVIs

are VIs that you create to use inside another VI or that you access on the

Functions
palette. Any VI has the
potential to be used as a subVI. When you double
-
click a subVI that is on the block diagram, its front panel window
appears and you can access its
block diagram. Some examples of the subVIs you can find in the

Functions

palette
are shown below.

Structures

Structures, which include for loops, case structures, and while loops, are used for process control. They are
examined in a later tutorial. You can

open the

Structures

subpalette from the
Functions

palette
under

Programming
.

Below are some examples of different structures and how they look on the block diagram.

[
+] Enlarge Image

Now create the block diagram shown below by following these steps:


1.


Open a blank VI from the toolbar. Select

File»New VI
.

2.


Put two multiply functions on the block diagram by dragging them onto the block diagram from
the

N
umeric

subpalette under

Programming
. Repeat to put a second multiply function on the block diagram.


Tip:

To copy an object on the block diagram, hold down

<ctr>

while you click and drag the object.

3.


Hover your mouse over the left
-
most multiply fu
nction to make the input and output terminals appear. If you
hold your mouse over one of the terminals, the wire spool appears along with the name of the terminal you are
hovering over.


To create a control for the

y

terminal, simply hover your mouse over

it and right
-
click.


Do the same for the

x

terminal on the left
-
most multiply function so that you have a control for each input terminal.

4.


Wire the output terminal of the left multiply function to the x input of the right multiply function by
hovering
your mouse over the output terminal. When it turns into the wiring spool, click and hold while you drag the wire to
the desired input.


5.


Create the Triangular Multiplier constant .5 by right
-
clicking on the y input terminal of the
right
-
most multiply
function and selecting

Create»Constant
. You can change the value of a constant by double
-
clicking it to highlight
the text and typing in the new value. Type in .5 and press
<enter>
.




6.


Now right
-
click the output of the right
multiply function and select

Create»Indicator

to create an indicator that
passes the value of the block diagram logic to the front panel.

Tip:

You can make comments on the block diagram or the front panel by double
-
clicking the block diagram and
typing you
r comment into the automatically created text box.


You can change the name of indicators, controls, and constants by double
-
clicking the label and typing in the
desired name. If there is no label showing, right
-
click the desired object and select
Visible
Items»Label
.


7.


Now look at the front panel that was generated from your work on the block diagram by pressing

<ctr
-
E>

or
selecting

Window»Show Front Panel
. Notice that the two controls Base(cm) and Height(cm) and the indicator
Area(cm^2) were auto
matically generated and placed on the front panel. You will run this program after learning
about the toolbar icons.





Block Diagram Window Toolbar

When you run a VI, the following toolbar appears on the block diagram. You can use some of the buttons o
n the
block diagram toolbar to debug the VI. Those buttons are covered in a later tutorial.


[+] Enlarge Image



Click the

Run

button to run your VI. You do n
ot need to compile your code; LabVIEW compiles it
automatically. You can run a VI if the

Run

button appears as a solid white arrow, shown at left.



The

Run

button appears broken when the VI you are creating or editing contains errors. If the Run
button
still appears broken after you finish wiring the block diagram, the VI is broken and cannot run. Click this button to
display the

Error List

window, which lists all errors and warnings.




Click

Run Continuously

to run the VI until you abort

or pause execution. You also can click the button
again to disable continuous running.



While the VI runs, the

Abort Execution

button appears. Click this button to stop the VI immediately if
there is no other way to stop the VI. If more than one r
unning top
-
level VI uses the VI, the button is dimmed.

Caution:

The

Abort Execution

button stops the VI immediately before it finishes the current iteration. Aborting a VI
that uses external resources, such as external hardware, might leave the resources i
n an unknown state by not
resetting or releasing them properly. Design VIs with a stop button to avoid this problem.



Click

Pause

to pause a running VI. When you click the

Pause

button, LabVIEW highlights on the block
diagram the location where you

paused execution, and the

Pause

button appears red. Click the

Pause

button
again to continue running the VI.


Select the

Text Settings

pull
-
down menu to change the font settings for the selected
portions of your VI, including size, style, and color.




Click the

Align Objects

pull
-
down menu to align objects along axes, including vertical, edge, and left.




Click the

Distribute Objects

pull
-
down menu to resize multiple front panel objects to the same size.



Click the

Reorder

pull
-
down menu when

your objects overlap each other and you want to define which
one is in front or back of another. Select one of the objects with the Positioning tool and then select from

Move
Forward, Move Backward, Move To Front,

and

Move To Back
.




Click the

Show Context Help Window

button to toggle the display of the context help window.


Enter Text

appears to remind you that a new value is available to replace an old value. The

Enter
Text

button disappears when you click it, press the

<Enter>

key, or

click the front panel or block diagram
workspace.

Running a VI from the Block Diagram

Finally, click the

Run Continuously

button on the VI you just created and change the values on the front panel.
Watch how changing the control values of

a

and

b

updates
the indicator value of

a*b
.



Values put into the controls on the front are passed to the block diagram, and the result that is computed by the
block diagram logic is passed back to the front panel indicator.

Click the

Abort Execution

button to stop the V
I. Save and close the VI by selecting

File»Save

from the menu bar
and then clicking the

Close

button in the top right corner of the front panel window.

The block diagram is the most fundamental aspect of any virtual instrument. It controls everything from
data flow to
passing data in and out of the front panel.

It is essential for a LabVIEW programmer to have a clear and solid
understanding of how the block diagram works.






User Interface


This tutorial examines how to use NI LabVIEW tools to build user

interfaces. Learn how to design controls and
indicators, use labels and captions, set default values for user interface objects, and apply color to enhance the
appearance of your user interface. Also get some basic tips and tools to help you create elegan
t and functional user
interfaces like the one below.

Concept

A user interface gives users a way to interact with the source code. It allows the user to change the values passed
to the source code and see the data that the source code computes. In LabVIEW,
the user interface is the front
panel. It is important to identify the inputs and outputs of a software development problem during the design phase
of the development method. This identification leads directly to the design of the front panel window.

You c
an acquire the inputs of the problem using the following methods:

1.


Acquiring from a device such as a data acquisition device or multimeter

2.


Reading directly from a file

3.


Manipulating controls

You can display the outputs of the
problem with indicators such as graphs, charts, or LEDs, or you can log the
outputs to a file. You can also output data to a device using signal generation.

Designing Controls and Indicators

When choosing controls and indicators, make sure that they are ap
propriate for the task you want to perform. For
example, when you want to determine the frequency of a sine wave, choose a dial control, and when you want to
display temperature, choose a thermometer indicator.

Labels and Captions

Make sure to label contro
ls and indicators clearly. These labels help users identify the purpose of each control and
indicator. Also, clear labeling helps you document your code on the block diagram. Control and indicator labels
correspond to the names of terminals on the block di
agram.

Captions help you describe a front panel control. They do not appear on the block diagram. With captions, you can
document the user interface without cluttering the block diagram with additional text. Open a blank VI and make a
label and a caption f
or a thermometer indicator.

1.


Put the thermometer indicator on the block diagram.

2.


By default, only the label is visible. To change the label, double
-
click it and type in a new label that is short
but descriptive.

3.


Right
-
click the th
ermometer indicator and select

Properties
.


In the Properties dialog box, put a check in the

Visible

checkbox under the

Caption

section of the
Appearance

tab.
Type

Indoor Temperature

in the

Caption text box
. Click

OK

to save the changes and exit the dialog

box. You can
also change the label from the Properties dialog box.

4.


Notice that the caption now appears on the front panel above the indicator. Switch to the block diagram and
note that only the label appears.



Control and Indicator Options

The f
ront panel offers many options for controls and indicators that you can view by right
-
clicking on the
thermometer indicator and browsing through the shortcut menu and submenus. Complete the following steps to
create a temperature control and set the defaul
t value.


1.


Put a numeric control on the front panel beneath the thermometer indicator. Make a caption for it that
says

“Indoor Temperature Control.”

2.



Enter the desired value.

3.



Right
-
click the control and select

Data Operations»Ma
ke Current Value Default

from the shortcut menu.

[+] Enlarge Image

4.


Because you have a good caption for the temperature control, hide the label by
right
-
clicking the control and
selecting

Visible Items»Label

from the shortcut menu. Do the same for the thermometer indicator.

Using Color

The proper use of color can improve the appearance and functionality of your user interface. Using too many
colors,
however, can result in color clashes that cause the user interface to look too busy and distracting. LabVIEW
provides a color picker that can help with determining the appropriate colors. Select the Coloring tool from the tools
palette and right
-
click an o
bject or workspace to display the color picker. With the color picker open, you can move
your cursor to different colors and watch the objects or workspace change as you move over different colors.


[+] Enlarge Image

The top of the color picker contains a grayscale spectrum and a box you can use to create transparent objects. The
second spectrum contains muted colors that are well
-
suited for backgrounds and front pane
l objects. The third
spectrum contains colors that are well
-
suited for highlights. Moving your cursor vertically from the background
colors to the highlight colors helps you select appropriate highlight colors for a specific background color.

[+] Enlarge Image



Spacing and Alignment

White space and alignment are probably the most important techniques for grouping and separation; the more
items that your eye can find
on a line, the cleaner and more cohesive the organization seems. When items are on a
line, the eye follows the line from left to right or top to bottom. This is related to the script direction. Although some
cultures view items right to left, almost all fo
llow top to bottom. When you design the front panel, consider how
users interact logically with the VI and group controls and indicators. If several controls are related, add a
decorative border around them or put them in a cluster.

Centered items are less

orderly than items aligned to the left or right. A band of white space on one side acts as a
very strong means of alignment. Centered items typically have ragged edges, and users cannot determine the
order as easily.

Placing front panel objects too close
together can be problematic. Leave some blank space between objects to
make the front panel easier to read. Blank space also prevents users from accidentally clicking the wrong control or
button.

In general, use common sense and develop your own style of d
esign for your user interfaces. Also refer to these
guidelines to help you successfully create user
-
friendly front panels. Notice the difference between the following two
simple user interfaces. Proper labeling, alignment, and spacing can make a big differ
ence.

[+] Enlarge Image

[+] Enlarge Image

User Interface Tips and Tools

Some

of the built
-
in LabVIEW tools for creating user
-
friendly front panel windows include tab controls and
decorations.

Tab Controls

Physical instruments usually have effective user interfaces. Borrow heavily from their design principles but use
smaller or mor
e efficient controls, such as ring controls or tab controls, where appropriate. Use tab controls to
overlap front panel controls and indicators in a smaller area.

To add more pages to a tab control, right
-
click a tab and select

Add Page Before

or

Add Page
After

from the
shortcut menu. Relabel the tabs with the Labeling tool and place front panel objects on the appropriate pages. The
terminals for these objects are available on the block diagram, as are terminals for any other front panel object
(except deco
rations). Complete the following steps to create a tab control with a thermometer indicator,
temperature control, fan speed control, and sector alarm for a building with three sectors. Start with a new VI.

1.


Create a new VI by selecting

File»New VI

from the menu bar.

2.


Add one round LED and label it Sector 1 Alarm, add one thermometer indicator and label it Sector
Temperature, and add one dial control and label it Fan Speed Control. Your front panel should look like this. (This
tutorial does n
ot include examples featuring block diagrams.)

[+] Enlarge Image

3.


Add a tab control from the

Controls

palette as shown.

[+] Enlarge Image

4.


Expand the tab control and add one additional tab after the second tab by right
-
clicking the tab and
selecting

Add Page After
. Label each tab

appropriately by double
-
clicking and typing a label for each of the three
sectors of the building.

[+] Enlarge Image

5.


Add the various controls and indicators

to each tab. Remember you can hold

<Ctr>

while you click and drag
an object to copy it. Arrange the objects logically and rescale them if needed. Your VI may look something like this.

[+] Enlarge Image

Decorations

Use the decorations located on the

Decorations

subpalette to group or separate objects on a front panel with
boxes, lines, or arrows. The objects on the

Decorations

palette do not display data or show up on
the block
diagram. Try adding some decorations to the front panel you just made.

[+] Enlarge Image


[+] Enlarge Image



It is important to create visually appealing and organized user interfaces.

Since the user interface is generally what
the end user will be working with, it is very important to make it as straight forward and
intuitive as possible






Module Exercise


This exercise will go over the components of the LabVIEW Environment. You will be able to see how the Front
Panel interacts with the Block Diagram. You will walk through a series of instructions that will
introduce you to
changing properties of LabVIEW as well as controls, indicators, and functions.

Goal

Understand the basic components of the LabVIEW environment and learn the elementary concepts of graphical
programming.

Description

This exercise consists o
f a series of tasks in which will walk you through launching the LabVIEW environment,
changing various options, creating a simple virtual instrument, running the virtual instrument, and using the example
finder found in LabVIEW.

Introduction to the LabVIEW

Environment

1. Launch LabVIEW.



From the start menu, click the

Labview 8.5

program to launch LabVIEW.

2. Wait for the splash screen to occur and the

Getting Started

menu to be displayed.

3. Create a blank VI.





Click

New»Blank VI

4. Display both the

front panel and the block diagram.



In the window labeled

Untitled 1 Front Panel
, navigate to and select

Tile Up and Down

to concurrently
display both the front panel and block diagram on the screen.

5. Customize the options in LabVIEW.



Navigate to and select

Tools»Options

to bring up the Options window for LabVIEW.





Click on the

Environment

submenu. In this menu, there are going to be


a few settings of interest:



Maximum undo steps per VI



This option sets the maximum amount of “
undo” steps the user can make
for each individual vi. This number can be increased if the user desires and the physical memory on the
system allows it.



Automatic Saving Settings



This option sets how LabVIEW auto saves the current project. This can be
adjusted to your preferences.







Next click on the

Block Diagram

submenu on the left. In this options menu, one useful option to note is
the

Place front panel terminal as icons
. Many people prefer this option to be disabled as it cleans up the
block dia
gram and makes front panel elements easier to read on the block diagram.





Close the options menu by clicking

OK
.

6. Create a

Numeric Control

on the front panel.



Right click anywhere within the front panel. This brings up the controls palette with all
of the available
controls.



Select

Modern»Numeric»Numeric Control

from the controls palette and then click on an empty space on
the front panel. Notice how an element also appears on the block diagram that corresponds to the control.

7. Use the

Search

fea
ture to place an

Add

function on the block diagram.



Right click anywhere on the block diagram. This brings up the functions palette with all of the available
functions.

To place a function on the block diagram click the function on the functions palette

and then click on
an empty space on the block diagram.





To search for a specific function within the functions palette, click the

Search

button on the functions
palette.


This brings up the search window. In the search field type “Add”.



Place the

Add


<<Numeric>>

function on the block diagram. This can be done by dragging the search result
directly from the search window to the block diagram.


8. Create a constant input for the

Add

function with representation

I32




Right click the first input of
the

Add

function and select

Create»Constant.



Give the constant a value of

10
.



Move the control to a different part of the block diagram by clicking and holding it, and then dragging it to a
different location.




Right click the constant and select

Representation»I32.

This changes the numeric representation of the
constant to a 32
-
bit integer, also known as a

long
.

9. Create a control for the second input of the

Add

function.



Right click the second input of the

Add

function and select

Create»Contro
l.



Move the control to a different position of the block diagram by clicking and holding it, and then moving the
mouse to an unused spot in the block diagram.

10. Create an indicator output for the

Add

function.



Right click the output of the

Add

functi
on and select

Create»Indicator
. Notice how the representation of the
output matches that of the input terminals.

11. Left align the elements on the front panel



Move the

Numeric Indicator

below the

Numeric Control

as seen below by clicking and holding
the

Numeric Indicator

and dragging it below the

Numeric Control
.





Highlight both elements and then select

Left Edges

from the

Align Objects

menu.

12. Rename the control and indicator on the front panel.



Double click the "y" text label of the numeric cont
rol to select the text.



With the keyboard, type "Original Number" to change the name of the control.




Repeat this process for the

Numeric Indicator.

Name the indicator "Number + 10".


13. Give a value of

100

to the

Original Number

control.



On the front panel, double click the number box of the

Original Number

control and type in a value of

100
.


14. Run the VI.



Click the

Run

button on the toolbar of the front panel.




Observe how the VI takes the number from the

Original Number

control

and add the constant's value
of

10

to it. It then displays the result in the

Number + 10

indicator.



15. Use the

Example Finder

to find a simple pulse train example.



To access the NI Example Finder, navigate to

Help»Find Examples...

of either the block

diagram or the
front panel.




This brings up the

Example Finder
. The example finder contains a database of example VIs written by
National Instruments. Click on the

Search

tab. In the search field type “Pulse Train Demo”. Double click the first
result t
o bring up the example VI.






On the front panel of the example that opens click the run panel to start the VI.




Observe how a waveform graph is generated based off of the options on the front panel.



Click the

STOP

button on the front panel.




Change the “pulse prototype” option to “Sine Pattern” by clicking the up arrow on the control.



Run the VI again and observe the generated Sine Wave.




16.

Close both VIs and do not save changes






















Source
:

Module 2: Passing Data, Debugging, and SubVIs
-

Developer Zone
-

National Instruments

(16 March 2011
12:00 AM)



Module 2: Passing Data, Debugging, and SubVIs





Wires


In text
-
based programming

languages, you store and access data with functions through the use of variables. In the
NI LabVIEW graphical programming language, wires implicitly handle all of the data storage and access that are
associated with variables in text
-
based languages. Thin
k of wires as a path for data to flow. Data comes into block
diagram objects through a wire and can leave only through a wire. In the figure below, wires connect the control
and indicator terminals to the Add and Subtract functions. As you can see, each wi
re has a single data source or
starting point. However, you can branch off one wire and wire it to many VIs and functions. By branching off the
main wire, you can send data to multiple destinations. Note that wires are different colors, styles, and thickne
sses.
Color, style, and thickness change depending on the type of data the wire is transmitting.



Broken wires (wires that are not connected properly) prevent your VI from running. A broken wire appears as a
dashed black line with a red X in the middle, a
s shown below.



Broken wires occur for a variety of reasons such as wiring two objects with different or incompatible data types. For
example, you cannot wire an array output to a numeric input. The data in the wire is an array and the input is
expecting
a single numeric, so the data types are not compatible. When connecting block diagram objects with
wires, you must connect a wire to one input and at least one output. For example, you cannot wire two indicators
together. The figure below shows the most co
mmon wire types. Notice the different colors and thicknesses of the
wires indicating the different data types.



Data Types

Every wire has a type based on the data that it is transmitting. The data type of a wire determines which object,
indicators, or fun
ctions you can connect a wire to. For example, if a switch has a green border, you can wire a
switch to any input with a green label on an Express VI or function. Note that the wire will also be green, reflecting
the Boolean data type. If a knob has an ora
nge border, you can wire a knob to any input with an orange label and
the wire will be orange. You cannot wire an orange knob to an input with a green label because the data types are
not compatible. Note that the wires are the same color as the terminal.
The figure below shows the correct wiring of
two controls to a subVI. Note that the color of the wire and control matches the color of the input terminal.




The figure below shows the incorrect wiring of two controls to a subVI. The data type of the
control does not match
the data type of the input terminal on the subVI. Hold your mouse over the broken wire to see the data types
required. Note that the source is a double and the sink, or input, is a Boolean. The wire is broken because the data
types a
re different.


Tip:

You can quickly delete all broken wires from your block diagram by pressing

<ctr
-
B>
.

Automatically Wiring Objects

You can use the LabVIEW auto wiring feature to connect objects on the block diagram faster. As you move a
selected object

close to other objects on the block diagram, LabVIEW draws temporary wires to show you valid
connections. When you release the mouse button to place the object on the block diagram, LabVIEW automatically
connects the wires. You can also automatically wire

objects already on the block diagram. LabVIEW connects only
the terminals that match. Toggle automatic wiring by pressing the spacebar while you move an object using the
Positioning tool.

You enable automatic wiring by default when you select an object fr
om the

Functions

palette or when you copy an
object already on the block diagram. You disable automatic wiring by default when you use the Positioning tool.
You can adjust these settings by selecting

Tools»Options

and selecting

Block Diagram

from the

Categ
ory

list.


You can enable or disable automatic wiring by checking or unchecking the checkbox as shown.


Manually Wiring Objects

Often you may want to manually wire the objects on the block diagram together. Note that when you pass the
Wiring tool over a te
rminal, a tip strip appears with the name of the terminal. Use this feature to ensure that you are
selecting the correct terminal before wiring.


To wire objects together, pass the Wiring tool over the first terminal and click and drag the cursor over to
the
second terminal (if the Tools palette is on auto
-
select, the wiring tool automatically appears when you hold the
mouse over a terminal). Click again on the destination terminal to terminate the wire.

After wiring, you may want to clean up the path of t
he wire. Simply right
-
click the wire and select
Clean Up
Wire

from the shortcut menu. LabVIEW automatically chooses a path for the wire.


To learn more about wiring by manually wiring several controls and indicators, follow the steps below:

1.


Create

a new VI and place a knob on the front panel by selecting it from the numeric subpalette in
the

Controls

palette.

2.


Place a tank indicator on the front panel to the right of the knob.

3.


Place a round LED on the front panel beneath the tank.

4.


Now switch to the block diagram. Note that all three front panel objects are on the block diagram.
Both

Knob

and

Tank

are orange and

Boolean

is green. Remember that the color represents the data
type.

Knob

and

Tank

are both a data type of DBL whil
e

Boolean

is a data type of Boolean. Hold the mouse over
the output terminal of

Knob

so that the wiring tool appears. Click and drag the wire to the input terminal of

Tank
.

[+] Enlarge Image

5.


Hold your mouse over the wire connecting

Knob

and

Tank

so that the wiring tool appears. Click and drag to
create a new wire coming off the existing wire. Try to connect the new wire to
Boolean
. Note that doing this causes
the wire to break. Because

Knob

is a data type of DBL and
Boolean

is a data type of Boolean, you cannot connect
them. Also notice that the

Run

arrow on the toolbar is broken. A broken wire prevents your VI from running.


6.


Delete the broken wires by

pressing

<ctr
-
B>

and reconnect

Knob

to

Tank
. Go to the front panel and
select

Run Continuously
. Use your mouse to move the

Knob

control to different values. Notice how it updates the
level in the tank. This happens because the value of the

Knob

control is

being passed by the wire on the block
diagram to the

Tank

indicator. Because there is no data wired to

Boolean
, it does not change value.

7.


Select

Abort Execution

to stop the VI. From the

Controls

palette, select a vertical toggle switch and place
it
next to the LED.

8.


Note that they are both labeled as Booleans. Switch to the block diagram and wire the output of the vertical
toggle switch (
Boolean2
) to the input of the LED (
Boolean
).

9.


Now select

Run Continuously

from the front panel.

Use your mouse to toggle the vertical toggle switch from
on to off. Observe how the LED changes from off to on.

10.


Close the block diagram and front panel without saving changes.


Wires are one of the most fundamental building blocks of a virtual inst
rument. They determine how the elements on
the block diagram interact with each other and determine the flow of the execution in general.






Data Types, Dataflow and Debugging


Just as in any other programming languages, it is important to have a basic
understanding of the different data
types in NI LabVIEW software and how to access them when composing a VI. When you are unsure of a wire’s
data type or of the inputs and outputs a certain VI accepts, the Context Help window is a very powerful tool for
fi
nding this information. Once you wire a VI, it is important to pay attention to the data flow of the VI to determine
the program’s sequence of events. When you are unsure of the exact sequence of events in a VI, you can use the
Highlight Debugging feature
to slow down the code and visually observe the data flow of the VI.

LabVIEW Data Types

1.


Open a blank VI from the toolbar by selecting

File»New VI
.

2.


Right
-
click on the front panel to open the

Controls

palette and select
Modern»Boolean»Vertical Toggle
Switch
, and place the switch on the front panel. This control is of the Boolean data type, which means it can take
on one of two values, TRUE or FALSE.




3.


Open the

Controls

palette and select

Modern»Boolean»Round LE
D
, and place the LED on the front panel.
This indicator is also a Boolean data type.





4.


Open the block diagram of the VI by selecting

Window»Show Block Diagram
, and notice that the Boolean
control and indicator are both represented by green
icons. This is the color for all Boolean data types in LabVIEW.


5.


Wire the output of the toggle switch control to the input of the LED indicator. Note that the wire connecting the
two icons is also green.


6.


Return to the front panel by se
lecting

Window»Show Front Panel
. Right
-
click on the toggle switch control
and hover your mouse over

Mechanical Action

to view the available switching actions for switch when pressed.
Leave the action as

Switch When Pressed
.


7.


Open the

Controls

pal
ette, select

Modern»String & Path»String Control
, and place a string control on the
front panel. The string data type is composed of a sequence of displayable or non
-
displayable ASCII characters.


8.


Open the

Controls

palette, select

Modern»Numeric»
Numeric Control
, and place a numeric control on the
front panel. The numeric data type is composed of numbers, and can take on several different representations.
Right
-
click on the numeric control and select
Representation»Long (I32)

to change the control t
o a 32
-
bit integer.





9.


From the

Controls

palette, select

Modern»Numeric»Numeric Indicator

and place the numeric indicator on
the front panel. Leave this indicator’s representation as the default double precision (DBL).


10.



Open the block d
iagram and observe the colors associated with each new control and indicator. The string
data type is pink, the long numeric data type is blue, and the double precision numeric data type is orange.


11.


Open the front panel and the

Controls

palette,
select

Modern»Ring & Enum»Enum
, and place the Enum
control on the front panel. The Enum control is an enumerated list of string values, where each string value has a
numeric value associated with it.


12.


Right
-
click on the Enum control and select

Edit
Items…

to open up the Edit Items tab under Enum Properties.
On the Edit Items tab, click on

Insert

and type in a string with the keyboard. Press the

<Enter>

key to create a new
item below the current item, or click on

Insert

to insert a new item above the
current item. Repeat the process until
you have at least a few items in the Enum.


13.


Click on the

OK

button when finished entering items into the Enum.

14.


Open up the block diagram, right
-
click on the output pin of the Enum control, and select
Creat
e»Indicator

to
create an indicator that is wired to the Enum control. Note that the indicator is also an Enum.


15.


In the block diagram of the VI from above, right
-
click on a blank space to open the

Functions
palette,
select

Programming»String»String
Length
, and place the function on the block diagram.


[+] Enlarge Image

16.


Open the

Functions

palette again, select

Programming»Numeric»Add,

and place an add func
tion on the
block diagram.


[+] Enlarge Image

17.


Wire the newly placed functions with the unconnected controls and indicators as seen in the figure below.




Usi
ng Context Help

The

Context Help

window displays basic information about LabVIEW objects when you hover your mouse over
each object.



1.


Open the

Context Help

window by selecting

Help»Show Context Help
, pressing the

<ctr
-
H>
keys on the
keyboard, or
by clicking on the

Show Context Help Window

button on the toolbar, as seen in the figure below.




2.


Hover your mouse over the different wires, controls, and indicators to see their data types in the

Context
Help

window. Hover your mouse over the f
unctions to see a brief explanation of their functions and the inputs and
outputs they accept.


[+] Enlarge Image

3.


Click on the

Detailed Help

link at the bot
tom of the

Context Help

window to get a more detailed description
of the function and its inputs and outputs.


Data Flow

As mentioned earlier, the concept of data flow is important to keep in mind when programming. Just as a line of
text
-
based code must w
ait for data to reach it before executing, a node (function or VI) must wait until data reaches
all of its input terminals before executing. Once that node finishes execution, it passes its output to the next node in
the execution sequence. In the VI that
you built, although one of the inputs to the add function is immediately
available, the node must wait for the string length function to execute first because its output is the other input to the
add function.

So data flow can sometimes determine the order

of execution of LabVIEW code. In this case, it forces the string
length function to execute before the add function, as seen in the figure above.

Debugging with Highlight Execution

When trying to visualize the data flow of a particular VI, a very useful
tool is highlight execution or execution
highlighting. Implement execution highlighting by clicking on the

Highlight Execution
button on the toolbar, as seen
in the figure below.


1.


Click on the

Highlight Execution

button on the toolbar. Note that
the light bulb on the button is now filled in.




2.


Run the VI by selecting

Operate»Run
, pressing the

<ctr
-
R>

keys on the keyboard, or by clicking on
the

Run

button on the toolbar.






3.


Observe the data flow of the VI on the block diagram
. Observe the sequence of execution of the nodes.


Note:

Not only does execution highlighting show the sequence of execution, but it also slows down the speed of
execution so that it is visible to the user. This execution speed impacts the overall perform
ance of the VI, and
should be turned off to return execution to normal speeds.



4.


Click on the

Highlight Execution

button to turn off execution highlighting. The light bulb on the button is no
longer filled in.


Note:

When an application appears t
o be running suspiciously slowly, it is always a good idea to check
the

Highlight Execution

button to see if execution highlighting is enabled









SubVIs


Modularity, by definition, means to use modules or smaller parts for the overall objective.
Within LabVIEW, program
modularity means creating smaller sections of code known as subVIs. SubVIs are the same as VIs. They contain
front panels and block diagrams, but you call them from within a VI. A subVI is similar to a subroutine in text
-
based
progr
amming languages.

When you create a subVI and use it, you see an icon within your block diagram that represents the subVI. You can
customize this icon, which is the same icon in the upper right corner of the subVI front panel and block diagram.
Learn how t
o customize icons in a later section of this tutorial.

The following figures demonstrate the difference when replacing a section of code with a subVI. You can see the
simplicity in the bottom figure.





You can create a subVI just like a VI and then use

it as a subVI, or you can create a subVI from code already within
another VI. Once you create a VI, you can:




Customize the icon for the subVI




Configure the terminals




Use it within other VIs repeatedly

Creating a SubVI from an Existing VI

You can simplify the block diagram of a VI by converting sections of the block diagram into subVIs.

1.

Create a new VI and construct the following block diagram.


2.

Select the section of the block diagram you want to convert.


3.

From the Tools menu,

select

Edit»Create SubVI
.




The selected section of the block diagram is replaced with an icon for the subVI. LabVIEW creates controls and
indicators for the new subVI, automatically configures the connector pane based on the number of control and
indic
ator terminals you selected, and wires the subVI to the existing wires.


The new subVI uses a default pattern for the connector pane and a default icon.

Creating an Icon

Create custom icons to replace the default icon by right
-
clicking the icon in the upp
er right corner of the front panel
or block diagram and selecting

Edit Icon.

You can also do this by double
-
clicking the icon in the upper right corner
of the front panel.






Once you open the Icon Editor, you have many tools for creating a custom icon
or importing an image.

You also can drag a graphic from anywhere in your file system and drop it in the upper right corner of the front
panel or block diagram. LabVIEW converts the graphic to a 32x32 pixel icon.

You can find a standard set of graphics to u
se as a VI icon at

ni.com/info

by entering the info code
expnr7
.

Use the tools on the left side of the

Icon Editor

dialog box to create the icon design in the editing area. The normal
size image of the icon appears in the appropriate box to the right of the

editing area, as shown in image of the front
panel above.

Use the

Edit menu

to cut, copy, and paste images from and to the icon. When you select a portion of the icon and
paste an image, LabVIEW resizes the image to fit into the selected area. You also
can drag a graphic from
anywhere in your file system and drop it in the upper right corner of the front panel window or block diagram
window. LabVIEW converts the graphic to an icon.

Use the

Copy from

option on the right side of the

Icon Editor

dialog box
to copy from a color icon to a black
-
and
-
white icon and vice versa. After you select the

Copy from

option, click the

OK

button to complete the change.

Use the

Icon Editor

tools to perform the following tasks:

The menu bar in the

Icon Editor

dialog box cont
ains more editing options under the

Edit

menu such
as

Undo
,

Redo
,

Cut
,

Copy
,

Paste
, and

Clear
.

Develop a simple icon for the subVI created:

1.

If the subVI is not open, double
-
click the placed icon on the block diagram.


2.

From the front panel or block

diagram of the subVI, double
-
click the icon in the upper right
-
hand corner.




3.

Double
-
click the filled rectangle tool,

, to create a blank icon with a border.




4.

Draw the icon you want to represent your subVI using the tools on the left.



5.

S
elect the

16 colors

icon on the right and click the

256 Colors

button under

Copy from
. Repeat for the

B &
W

icon.




6.

Click

OK

to save the icon.

Building the Connector Pane

You need to build a connector pane, shown as follows, to use the VI as a subVI.

The connector pane is a visual
representation of how inputs and outputs are connected to the subVI from the calling VI.

Setting Up the Connector Pane

Define connections by assigning a front panel control or indicator to each of the connector pane terminal
s.

1.

Right
-
click the icon in the upper right corner of the front panel.

2.

Select

Show Connector
.

3.

You can select a different pattern by right
-
clicking the connector pane and selecting

Patterns
.


Each rectangle on the connector pane represents a ter
minal. Use the rectangles to assign inputs and outputs.

The following front panel has four controls and one indicator, so LabVIEW displays four input terminals and one
output terminal on the connector pane.





Assigning Terminals to Controls and Indicator
s

After you select a pattern to use for the connector pane, you must assign a front panel control or indicator to each
of the connector pane terminals. It is generally good programming practice to organize the inputs to a subVI on the
left and the outputs
on the right.

To assign a terminal to a front panel control or indicator:

1.


Click a terminal of the connector pane.

2.


Click the front panel control or indicator you want to assign to that terminal.


Note that the terminal color changes to that

of the data type to which you have connected it. You also can select the
control or indicator first and then select the terminal.

3.


Click an open space on the front panel to deselect the control.

4.


Repeat these steps for all the controls and i
ndicators that you will use to pass data to and from the calling VI.

Using SubVIs

To place a subVI on the block diagram:

1.

Click the

Select a VI

button on the

Functions

palette.

2.

Navigate to the VI.


3.

Double
-
click to place it on the block diagram.

Opening and Editing SubVIs

To open the front panel of a subVI from the calling VI, double
-
click the subVI on the block diagram. To display the
block diagram of a subVI from the calling VI, press the

<Ctrl>
key and double
-
click the subVI on the block diagra
m.

You can edit and save a subVI, and the changes affect all calls to the subVI, not just the current instance.

Setting Required, Recommended, and Optional Inputs and Outputs

In the

Context Help

window, the labels of required terminals appear bold, recomme
nded terminals appear as plain
text, and optional terminals appear dimmed. The labels of optional terminals do not appear if you click the

Hide
Optional Terminals and Full Path

button in the
Context Help

window. Output terminals cannot be set as
Required.

T
o designate which inputs and outputs are required, recommended, and optional:

1.

Right
-
click a terminal in the connector pane.

2.

Select

This Connection Is

from the shortcut menu.

3.

Select

Required
,

Recommended
, or

Optional
.


You also can select

Tools
»Options»Front Panel

and put a checkmark in the

Connector pane terminals default
to required

checkbox. This option sets terminals on the connector pane to
Required

instead of

Recommended
.
This applies to connections made using the wiring tool and to subVIs
created using

Create SubVI
.


Inputs and outputs of VIs in vi.lib are already marked as

Required
,

Recommended
, or

Optional
. LabVIEW sets
the inputs and outputs of the VIs you create to

Recommended

by default. Set a terminal setting to

Required

only if
the
VI must have the input or output to run properly











Module Exercise


This exercise will go over dataflow within a VI. You will then go over debugging techniques and lastly how to turn
your program into a subVI that you can use in alternate programs.

Goal

Understand the basic behavior of data flow and debugging in the LabVIEW environment. Modular programming
using SubVIs is also explored.

Description

This exercise consists of a series of tasks in which will walk you through how data is passed from one

element to
another in the LabVIEW environment as well as how to debug using highlighted execution. Users will also learn
how to create a SubVI for modular programming.

Data Flow, Debugging, and SubVIs

1. Launch LabVIEW and open a blank VI.



Select
File»New VI

2. Open the front panel.

3. Place a numeric control on the front panel.



Select and place

Modern»Numeric»Numeric Control

on the front panel.



Double click the number box of the numeric control and give it a value of

5.



Right click the numeric control and navigate to

Data Operation»Make Current Value Default.

4. Place a numeric control on the front panel.



Select and place

Modern»Numeric»Numeric Control

on the front panel underneath the
Numeric

control.



Double click th
e number box of the numeric control and give it a value of

10.



Right click the numeric control and navigate to

Data Operation»Make Current Value Default.

5. Place a numeric control on the front panel.



Select and place

Modern»Numeric»Numeric Control

on
the front panel underneath the
Numer 2

control.



Double click the number box of the numeric control and give it a value of

8.



Right click the numeric control and navigate to

Data Operation»Make Current Value Default.

6. Place a numeric indicator to the r
ight of the numeric controls and name it “Result”.



Select and place

Modern»Numeric»Numeric Indicator

on the front panel to the right of the numeric
controls.



Right click the numeric control and navigate to

Data Operation»Make Current Value Default.


6
. Switch to the block diagram.



Select Window»Show Block Diagram.

7. Place an “Add” function



Select and place

Programming»Numeric»Add

from the functions palette on the Block Diagram.

8. Place an “Add” function



Select and place

Programming»Numeric»Subt
ract

from the functions palette on the Block Diagram.

9. Wire the block diagram as seen below.



Wire the output of the

Numeric

control to the first input of the

Add

function.



Wire the output of the

Numeric 2

control to the second input of the

Add

function.



Wire the output of the

Add

function to the first input of the

Subtract

function.



Wire the output of the

Numeric 3

control to the second input of the

Subtract

function.



Wire the output of the

Subtract

function to the input of the