You are on page 1of 25

Faculty of Computing,

Engineering and Technology

Real Time Systems 1


CE00345-3

TM

LabVIEW
8

© 2006 David D. Hodgkiss & Staffordshire University 1


Table of Contents

Chapter 1 - Introduction.

Introduction. 4
Tools Palette. 8
“Hello World” . 10
Editing the wiring. 19
Bad wires. 19
Manipulating the palettes. 19
Boolean operations. 20
Data types. 21
Nodes. 21
Changing the data representation. 21
Changing the value range. 21
Context sensitive help. 22
Creating SubVIs. 23
Adding the wiring terminals. 24
Using SubVIs. 24
Summary. 25
Chapter Exercises. 26

Chapter 2 - Select, Testing, Debugging and While Loops.

Select. 27
Debugging. 30
While Loops. 31
Data representation revisited. 34
Shift registers. 35
Summary. 36
Chapter Exercises. 37

Chapter 3 - For Loops, Case Structure and Sequences

For Loops. 38
Case Structure. 40
Case Example - Square Root Calculation. 40
Sequence Structures. 43
Summary. 48
Stopping the errant VI. 48
Chapter Exercises. 49
continued ........

© 2006 David D. Hodgkiss & Staffordshire University 2


Table of Contents (continued)

Chapter 4 - Formula Node, Arrays.

Formula Node 50
Arrays 52
Auto Indexing. 54
Initialising Arrays. 58
Array - Show Size. 59
Array Index. 60
Array Subset. 60
Summary. 61
Chapter Exercises. 62

Chapter 5 - String handling, File I/O & Feedback Node.

Format into String. 63


Extract from String. 66
File Input & Output. 70
Feedback Node. 72
Chapter Exercises. 74

Chapter 6 - Multithreading, Local & Global Variables and Bundles.

Multithreading. 75
Local Variables. 76
Global Variables. 78
Adding additional Global Variables. 81
Bundles. 82
Chapter Exercises. 83

Chapter 7 - Serial VIs, Properties & Designing with LabVIEW.

Serial Communications. 84
VISA Configure Serial Port. 86
Write. 86
Read. 86
Close. 86
Serial Cable Connections. 88
Object Properties. 89
Designing with LabView. 91
SubVI Terminals. 93
Testing. 93
Sequence Structures - a warning. 94
...... And finally. 94

Appendices.
Installing LabVIEW 7.1 Express. 96
Front Panel Common Controls. 101
Block Diagram Common Controls. 102

© 2006 David D. Hodgkiss & Staffordshire University 3


1. Introduction ___________________________________
LabVIEW™ is a graphical programming environment manufactured by the National Instruments
Corporation based in Austin, Texas, USA.

National Instruments started in much the same way as Hewlett Packard but in a garage instead of a
shed. The company first announced LabVIEW in 1986 with version 1.0 for DOS being released the
following year. Version 2.0 for Windows™ was released in 1990 with various upgrades following
every few years. The latest version being LabVIEW 8 that was released during October 2005.

For those of you that have had some experience using Microsoft Visual Basic™ will recognise some
similarities between the concept of a front screen for the user controls and a “back screen” that holds
the programmed functionality. The main difference, however, is that the programming in VB is car-
ried out using a textural based procedural language. LabVIEW uses a graphical event driven language
based upon data flow, the “code” looks like an electrical wiring diagram with the data “flowing”
along the connecting wires. An application / program built within LabVIEW is referred to as a
“Virtual Instrument” or “VI” the standard file extension is “.vi”

LabVIEW has, essentially, been developed to enable control of external scientific equipment such as
Oscilloscopes, Logic Analysers etc. You will find that a lot of the inbuilt functionality is intended pri-
marily for this type of work and will not be needed for the work that we will be covering during the
module. However, you may freely include any that is relevant and pertinent, indeed you are encour-
aged to explore the powers of LabVIEW beyond the features that will be covered within this manual.

For the Real Time Systems module, LabVIEW has been installed upon those computers within G1.
The computers in these three laboratories have been paired using a modified RS232 connecting cable
as some of the work will involve using such a link to communicate between separate applications.

To launch LabVIEW follow this path…….

Start Programs Programming Tools National Instruments LabVIEW 7.1 LabVIEW

Launching LabVIEW will initially generate a flash screen that is usually followed by the screen as
shown in Diagram 1, do not worry if it doesn’t it just indicates that the launch has been set so that it
does not present this screen.

The various links below


“Resources” will open a various
documents that you may find use-
ful.

To start a simple development,


simply select “Blank VI”

This pane shows VIs that have


been opened before.

Diagram 1 : Initial launch dialogue screen


© 2006 David D. Hodgkiss & Staffordshire University 4
If you have not already done so, open a blank VI.

Depending upon the local configuration, you should now see four windows as shown in diagram 4, do not
worry at this stage if you can only see the Front Panel and Block Diagram.
Controls Palette
Block Diagram Front Panel (for Front Panel)

Work Area

Functions Palette
(for Block Diagram)
Diagram 4 : Work Windows

Tools Palette
Front Panel

This is where you will place all of the control and output objects, e.g. Buttons, dials, LEDs, gauges,
graphs etc. These objects are virtual implementations of the sort of objects that you would find on any
device with which a user interacts e.g. Oscilloscope, Stereo, Mobile Phone, Power Station Control Panel
etc.

Block Diagram

This is where you will place all of the objects that are used to implement the actual functionality
(programming logic). As with the front panel, it will contain a virtual representation of the sort of devices
that would be present within those example devices mentioned above.

Controls Palette

Within this palette you will find all of the objects that can be placed upon the Front Panel.

This palette will only be visible when the Front Panel is selected, Clicking on the Block Panel will bring
it to the foreground, hide the Controls Palette and cause the Functions Palette to be visible.

© 2006 David D. Hodgkiss & Staffordshire University 5


Once you have started a VI you create or edit it using the Tools Palette and either the Controls Palette
or the Functions Palette.

Tools Palette
Automatic Tool Selection

Position / Size / Select Edit Text

Operate Value Object Shortcut Menu


Scroll Window
Connect Wire
Probe Data
Set / Clear Breakpoint
Get Colour

Set Colour

Diagram 5 : Tools Palette

Diagram 5 shows the “Tools Palette” that contains icons representing the various manipulation objects that
you will use when developing VIs. If this palette is not showing on the screen, select “Windows” menu from
the menu toolbar, then select “Show Tools Palette” from the drop down menu (you may have to expand this
menu to its full size using the double chevron at the bottom of the menu).

Auto Tool Selection

Whilst the green indicator is illuminated, LabVIEW™ will attempt to automatically select the correct
tool for the operation that you are attempting to implement.
You should experiment with this facility to determine if it suits your way of working.

Operate Value

Selecting this tool will allow you to change values of those objects placed upon the front panel before
the VI is running.

© 2006 David D. Hodgkiss & Staffordshire University 6


Position / Size / Select

This tool is used to place objects on either the front panel or block diagram, resize object or to simply
select them.

Edit Text

This icon represents the text-editing tool, it is used to rename objects, change range values and create
or edit free text labels.

Connect Wire.

This icon represents a virtual spool of connecting wire. The objects placed upon the block diagram are
interconnected using virtual wires.
Within LabVIEW™ the interconnecting wires carry the data that is then processed.

Object Shortcut Menu

Clicking on an object after selecting this tool will display a properties menu for that object. Right clicking
on the object will achieve the same result when working on a PC.

Scroll Window

This tool will allow you to move the front panel or block diagram around within the desktop window.
An alternative is to use the window scroll bars.

Set / Clear Break Points

This tool is used as a debugging aid and will place “stops” within the wiring of a block diagram that,
when encountered by the flowing data, will temporarily halt the VI execution.

© 2006 David D. Hodgkiss & Staffordshire University 7


Get Colour and Set Colour
These two tools will allow you to change the colour of both screen and object colours.
You should explore the functionality of these tools your self as you develop VIs.

Don’t worry too much if some of the above is not very clear, once you start developing VIs the
functionality of the various tools will become much clearer.

“Hello World”

As with most programming languages, it is always a good idea to start with a very simple application,
LabVIEW is no different.

This first application will demonstrate the four basic mathematical rules (“+”, “-”, “x” and “¸”).

If not already open, open a new blank Virtual Instrument and ensure that the Front Panel is on top -
holding focus.

Right click on the work area, the palette in diagram 6 will appear.

Diagram 6 : Controls

© 2006 David D. Hodgkiss & Staffordshire University 8


Now click on the icon labeled “Numeric”, the palette in diagram 7 will appear above the “Controls” palette.

Diagram 7 : Numeric Controls

Now click on the icon labeled “Numeric Control”, initially the cursor will change to a “no entry” symbol.
Now move the cursor so that it is above the Front Panel work area, the cursor will change to a small hand
and dotted boxes will appear underneath it. You will note that as the dotted box is moved around it will be
snapping to the layout grid.

© 2006 David D. Hodgkiss & Staffordshire University 9


Diagram 8 : Placing an object

Position the control towards the top left hand side of the work area and single click, the control will appear
on the front panel and be given a the default name “Numeric.” You will see that the default name has
automatically been placed into edit mode (white text on a black background), to change the name it is a
simple case of typing the replacement, for this control you should rename it “First Value.”

Should focus be lost from the default name it is a simple case of selecting the text edit tool from the tools
palette and editing in the usual manner. When editing in this manner you will see a “tick” icon appear on
the left hand side of the toolbar, just under “File”, clicking on this will instruct LabVIEW to accept the
amended text.

Once positioned and renamed the front panel should resemble diagram 9.

Diagram 9 : Naming and placing of first control object

© 2006 David D. Hodgkiss & Staffordshire University 10


Add a second numeric control and name it “Second Value”. Position it to the left hand side of the screen
below “First Value”, the exact position is not important at this stage.

You will have noted that the grid does help to align objects by aligning them to the grid. It is possible to
modify the grid properties by following these steps.

- Using the main menu tool bar at the top of the front panel, select Tools .. Options.

- Now, using the down arrow to display the options menu, select “Alignment Grid.”

- Here you will find various options for configuring the alignment grid, you will note that it is
possible to have grids on either of the two main screens.

- You should experiment with these controls as you develop the various LabVIEW applications
to find which settings are most suited to you or the particular application being developed.

Now add the four output objects....


Right click on the front panel work area, move the cursor to cover the “Num Inds” icon (Numeric
Indicators) and then select “Num Ind” from the sub palette. Position this object towards the top right
hand side of the front panel work area. As before the exact position is not important at this stage, rename
the object “Add.”

Now place three more numeric indicators onto the front panel work area, positioning them under the “Add”
indicator and rename them “Subtract”, “Multiply” and “Divide.”

The front panel should now resemble diagram 10.

Diagram 10 : Initial front panel

Whilst it would be quite acceptable to manually align and distribute the various objects on the front panel
so that they are suitably placed, tools are available within LabVIEW that can assist this operation.

From the tools palette, make sure that the “position / size / select” tool is selected.

Drag out a rectangle on the front panel work area that includes just “First Value” and “Second Value.”

© 2006 David D. Hodgkiss & Staffordshire University 11


Now click on the “Align Objects” button on the tool bar (see diagram 11) and select “Left Edges” from
the six options. The two controls will now rearrange themselves such that there left edges are aligned.

You should also explore the other layout tools as shown in diagram 11.

The “Order Objects” facility also offers a grouping function.

Align Objects
Distribute Objects
Resize Objects
Order Objects
Diagram 11 : Layout Tools

Do the same with the four numeric indicators so that you have a well structured front panel that resembles
diagram 12.

Diagram 12 : A well structured front panel

Having constructed the front panel you will now use the Block Diagram screen to program the functionality
that will make the VI operate as intended.

Switch to the Block Diagram by clicking on its window title bar, it should resemble diagram 13 on
the next page.

© 2006 David D. Hodgkiss & Staffordshire University 12


Diagram 13 : Initial block diagram

You will note that there are six objects (nodes), one for each of the six objects that were placed on the front
panel. You will also note that they are located in the same relative positions to the original placement of the
front panel objects, i.e. moving the objects around on the front panel does not move their nodes on the
block diagram, and visa versa.

As with this simple application it is appropriate to arrange the block diagram nodes in the same manner as
their front panel counterparts, you should use the layout tools as before. As VIs become more complex you
find that the front panel and block diagram node pairs will be in different relative locations and good layout
will be essential.

You will now add the functions to make the VI operable.

Right click on the block diagram work area (not on one of the nodes), this will activate a palette named
“Functions.” Now move the mouse cursor until it is above the icon “Numeric” to activate the next
palette, “Numeric.” Now select “Add” from this palette by clicking on it.

The cursor will change to a hand with a little yellow filled triangle underneath it. This triangle is the icon
that represents the “Add” function. Position the cursor so that it is to the right of the “Add” node and single
click to drop the item onto the work area. It should be noted that default setting for the alignment grid on
the block diagram is “off.”

Repeat the operation to introduce the “Subtract”, “Multiply” and “Divide” functions,
positioning each to the left of the corresponding nodes.

As before the layout tools can be used to position the function icons.

Your block diagram should now resemble diagram 14.

© 2006 David D. Hodgkiss & Staffordshire University 13


Diagram 14 : Block Diagram with functions added

In order to complete the programming you must now “wire” the nodes and function icons together.

On the tools palette select the connect wire tool, the cursor will change so that
it resembles a spool of wire.

Position the cursor so that it is above the “First Value” node, the node will start to flash and a connecting
terminal will appear on its right hand side. Click on the node and start to move the cursor to the left towards
the “Add” function and you will see a dotted line being drawn out of the node, this represents a connecting
wire. Now if you move the cursor up or down you will see that the dotted line has a turn within it, showing
that the wires can go around corners.

It is possible to add “way points” by clicking on the block diagram work area so that wires can be routed
wherever and however you like, however wires will only run horizontally or vertically.

Now, having added way points as necessary, place the cursor above the “Add” function, as with the “First
Value,” node it will respond by flashing and offering three connection points (“x”, “y” & “x + y”), you will
have to move the cursor around over the icon in order to see all of the connection points respond. Click on
the “x” connection terminal to complete this part of the wiring. To show that a valid wiring connection has
Been successfully completed the wire will become a solid orange wire as can be seen in diagram 15.

Diagram 15 : Detail of first wiring connection

© 2006 David D. Hodgkiss & Staffordshire University 14


Now connect a wire from “Second Value” to the “y” input of the “Add” function and then a wire from the
“x + y” output to the output node “Add.” Your Block Diagram should now resemble diagram 17.

Diagram 16 : Completed wiring for addition

In order to make the wiring of the remaining three functions tidier it is possible to connect new wires to
those that already exist.

Using the wiring spool, move it so that it is above an existing connecting wire, it will flash to indicate that
a connection can be made. Single clicking on the wire will allow you to draw out a new wire.

In this example, single click on the vertical section of wire that connects “Second Value” to the “y” input of
the “Add” function and draw out the wire, adding way points as necessary, and connect it to the “y” input
of the “Divide” function, ignoring “Subtract” and “Multiply” for now.

Now, using the same technique, connect a wire from the horizontal wire leading to the “y” input of the
“Add” function to the “y” input of the “Divide” function. Once that is connected, connect the output of the
divide function to the “divide” output node.

If you make any mistakes during this early wiring, use the “Undo” facility that can be found within the
“Edit” drop down menu. The keyboard short cut for undo is “Ctrl” + “Z”

Your Block diagram should now resemble diagram 17 on the following page.

© 2006 David D. Hodgkiss & Staffordshire University 15


Diagram 17 : Adding the Divide wiring

You will note that where wire connect a small blob has been added to enhance the wiring diagram. This
facility is an option within LabVIEW and can be toggled via the Options facility within the Tools drop
down menu. The check box to switch the “blobbing” on or off can be found within the “Block Diagram”
dialogue.

You should now complete the wiring by connecting the existing wires to the inputs of the “Subtract” and
“Multiply” functions as well as connecting their outputs to the appropriate output nodes so that it resembles
Diagram 18.

Diagram 18 : Completed wiring

That is the wiring completed, the instructions for running the application can be found on the next page.

© 2006 David D. Hodgkiss & Staffordshire University 16


Switch back to the front panel, at the left hand side of the tool bar you will see four icons.....

a single arrow
a double arrow
a (currently) greyed out red circle and
an icon with two vertical bars

Diagram 19 : Run controls

When pressed, the single arrow will cause the application to be run once (Run), whilst the double arrow will
cause the application to be run repeatedly (Run Continuously).

Once running the red circle will cease to be greyed out and when pressed will halt execution, the icon with
the two vertical bars is the pause execution feature (similar to VCRs etc.).

Click on the double arrow icon to run the application continuously, the cursor will change to the “Operate
Value” mode so that the input values (First and Second) can be modified using the little “up” and “down”
arrows to the left hand side of each of the two controls. The layout grid will also disappear.

Play time!

Now switch to the Block Diagram panel, you will see that the four above icon / buttons are repeated as it
is possible to run the application from the Block Diagram. You will also note that an additional button is
present. When pressed this button will place the application into “Highlight” mode (the button is used to
toggle this mode). Highlight mode is useful as it allows the user / developer to watch the data as it flows
through the application, it is a very useful basic debugging tool.

You should note that an application in highlight mode runs considerably slower than when in the normal
run mode.

An example of the application running in highlight mode can be seen in diagram 20 (can you spot the
deliberate programming error?)

Diagram 20 : “Hello World” running in highlight mode

© 2006 David D. Hodgkiss & Staffordshire University 17


Editing the wiring

Connecting wires can be easily edited to either move or remove them.

Before any editing can be carried out the wire(s) need to be highlighted using single, double or triple
clicking, the more clicks used corresponds to the amount of connecting wire highlighted.

Using the position / size / select tool single click on the wire between the “y” input of the “Add” function
and where the wire makes a right angle turn downwards, the result should resemble diagram 21.a.
Now, using the same tool double click on the same section of wire, the results should correspond to
diagram 21.b. Finally, triple click on the same section of wire to highlight it to its full extents, this
should resemble diagram 21.c.

Diagram 21.a : Single click Diagram 21.b : Double click Diagram 21.c : Triple click
wire selection wire selection wire selection

Once selected wires can be deleted by pressing the “Delete” key or can be moved by either dragging with
the position / size / select tool or by using the cursor keys (“up”, “down”, “right” or “left”). When using
the cursor keys alone the selected wire(s) will move by a very small amount, if the cursor keys are used in
conjunction with the “Shift” key the movement will be approximately eight times as great.

Please note: Just as when programming within a textural environment, programming standards are
of vital importance i.e. layout structure, naming conventions etc. Even though LabVIEW is a graphical
programming environment, it is still of vital importance to practice the same rigour, so, please remember
to use good naming standards and layout - you will be penalised for “spaghetti wiring that looks like
knitting!

Bad wires

From time to time you will find that you have incomplete wiring or have incorrectly wired objects together
e.g. connected two outputs together. Such wires will appear as dotted black lines instead of the usual
coloured solid lines. Whilst it is straight forward enough to use the above techniques to remove such wires,
LabVIEW includes a short cut feature that will automatically remove all bad wires - “Ctrl” + “B”, however
be careful of its use as it will remove all bad wires and not just those that you may have wished to be
removed.

Manipulating the palettes

So far you have been activating the palettes that contain either the front or block panel objects by first right
clicking on the work space etc., once the object has been selected the palette disappears. It is possible to
activate the palettes such that they remain open and always “on top”.
Select “Windows” on the main menu of the front panel and then select “Show Controls Palette”, the palette
will now remain available after each selection. The same feature exists for the block diagram (“Show
Functions Palette”), LabVIEW will only show one of these at a time dependent upon which diagram is live.
© 2006 David D. Hodgkiss & Staffordshire University 18
One of the new features that LabVIEW 7 is providing is that the initial palette of controls and / or functions
is providing a categorised view of the sub palettes, an alternative approach is to use the palette structure
from earlier versions of LabVIEW, these can be found via the “All Functions” or “All Controls” icons.

You should fully explore the palette hierarchy so that you can work in a manner that suits you.

From now on these notes will be written on the assumption that you will be working with either the “All
Functions” or “All Controls” palettes.

Boolean Operations

Diagram 22a and 22b show the front panel and block diagram of a VI that demonstrates some of the logic
functionality available within LabVIEW including

AND
OR
XOR
Compound operations (>2 inputs)

Diagram 22a : Boolean Operations Diagram 22b : Boolean Operations


front panel block diagram

All of the controls and functions used within this VI can be found within the Boolean sub palettes.

When adding the “Compound Arithmetic” function it will default with two inputs and offering the
addition function. To add extra inputs you can either right click on either of the two left hand boxes that
represent the input connections and select “Add input” (note it is possible to also remove inputs) or, using
the position / size / select tool, click on either the top or bottom edge and drag to increase or decrease the
number.

To change its function, right click on its icon and select “Change Mode” then select the desired functionality
from the subsequent menu.

© 2006 David D. Hodgkiss & Staffordshire University 19


Data types.

So far you have used just two of the many data types available within LabVIEW, Double and Boolean and
have, hopefully, seen that different wire colours have been used, Orange for Double and Green for Boolean.
Other data types are available, each using different colours for ease of identification, for example

Blue is used to indicate integers


Quad (64 bits), Long (32 bits), Word (16) and Byte (8): signed or unsigned.
Orange is used indicate floats
Extended (128), Double (64) and Single (32).
Pink is used to indicate strings
Green is used to indicate Boolean types.

Within each of the numeric data types it is possible to specify the number of bytes used to represent the
value and, therefore, its range.

Nodes

When adding controls or indicators to the front panel a corresponding wiring node is automatically placed
within the block diagram. In essence, a node can either be an input e.g. a numeric control that generates
values / data (source) or an output e.g. numeric indicator that displays or consumes values / data (sink).
LabVIEW indicates their difference by using a different border format for each. Diagram 23 shows this
difference.

Diagram 23 : Node borders


You will see that the input (generator) node has a thicker outer boarder than the output (consumer) node
and has a little arrow head on its right hand edge that points outward whilst the input node has a little arrow
head on its left hand side pointing inwards.

These arrows also give an indication of how you should aim to wire, LabVIEW generally wires from left to
right and those objects that can accept inputs and provide outputs e.g. Compound Arithmetic, will be
arranged with their input connections on the left and their output connections on their right. You are advised
to remember this and try to adhere to it whenever possible, however there will be many times when it is not
possible and you will have to be creative to prevent your wiring getting into a complete mess (knitting!).

Changing the data representation.

This can be achieved by right clicking on the node (it can also be achieved using the front panel object) and
selecting “Representation” from the generated sub menu. It is then a simple case of clicking on the desired
byte count. You should explore this feature together with two related features “Data range” and “Format
and Precision” again available via a right click.

Changing the value range.

Whilst it is possible to limit the value ranges of controls by changing the data representation it is also
possible to limit the range of values that particular front panel controls and indicators will show.

Start a new, blank VI

On the front panel place a “Knob” and a “Tank” from the Numeric sub palette. Switch to the block diagram
and wire the output of the Knob to the input of the Tank. The VI should resemble diagrams 24.a and
24.b on the following page.
© 2006 David D. Hodgkiss & Staffordshire University 20
Diagram 24.a : Knob and Tank front panel Diagram 24.a : Knob and Tank block diagram

The default values for the Knob and Tank are both 0 .. 10 even though the data representation is capable of
a much greater range. Using the text tool, click on the maximum of value of the Knob and enter a new
maximum value of 150.

Run the VI in continuous mode (click on the double arrow) and operate the knob using the cursor (it will
turn in the same way as a physical knob on a piece of equipment).

Now change the Tank’s maximum to 200 and run the VI again, note that even though the data representation
is covering a large data range the maximum and minimum values have been limited on the front panel.

Stop the VI and add a “Thermometer” from the same sub palette to the front panel. Switch to the block
diagram and add the function “Random Number (0-1)” that can be found within the Numeric sub palette, it
looks like a pair of dice.

A short aside - Context Sensitive Help.

Click on the menu item Help and select “Show Context Help”, a small floating window will appear, move
the cursor so that it is above the random number function. The contents of the new window will change and
display some information about the selected object, often a link will be provided that, when clicked, will
open the main help system and provide more detailed information.

This context sensitive help system will often provide very useful information about objects but, you should
also explore the main help system as it quite extensive and can provide some very detailed information

Back to the programming.

The context sensitive help will have indicated that the random number generator will produce values in the
range 0..1, as did its title. As the range of the Thermometer is as the default value of 0..100 and it is not
possible to directly change the functionality of random number generator, scaling functionality will have to
be added.

Add a “Multiply” function to the block diagram, positioning to the left of the Thermometer node, wire the
output of the random number generator to one of the inputs of the multiply function. Add a “Numeric
Constant” 100 (from the numeric sub palette) and wire it to the second input of the multiply function.
Change the constant’s data representation to “Double” (DBL) and edit its value so that it is 100. Finally,
Wire the output of the multiple to the thermometer node.

The VI should resemble diagrams 25.a and 25.b on the following page.

© 2006 David D. Hodgkiss & Staffordshire University 21


Diagram 25.a : Knob, Tank & Thermometer Diagram 25.a : Knob, Tank & Thermometer
front panel block diagram

Run the VI continuously and observe how the Knob and Tank run independently of the Random Number
generator and Thermometer, using the Highlight facility will aid this observation. This independence is
central to the manner in which LabVIEW operates (multithreading) and will be revisited again in later weeks.

Creating SubVIs.

A SubVI is the equivalent of a function within a text based programming language such as “C”, “C++”, VB
etc. The use of SubVIs will help simplify wiring diagrams whilst retaining their functional complexity.

As with functions, SubVIs can be used repeatedly.

Example.
Set up the Slope Calculation VI as shown in diagram 26.a and 26.b

Diagram 26.a : Slope front panel


Diagram 26.a : Slope bloack diagraml

Editing the Icon


Switch to the front panel, right click on the VI icon (top right hand corner) and select “Edit Icon”.

Use the drawing tools to draw a new, suitable icon - use of colour can be useful.

Note that three icon types are shown, the one used being dependent upon the colour depth being used by
the host computer (B&W, 16 and 256)

Click “OK” when you have created your masterpiece, a suggestion is shown in diagram 27 below.

Diagram 27 : Slope Icon


© 2006 David D. Hodgkiss & Staffordshire University 22
Adding the wiring terminals.

The wiring terminals are the equivalent of function input parameters and output values.

Right click on the newly created front panel icon and select “Show Connectors”, a pattern will appear that
corresponds to the number of inputs and outputs. Note that the four inputs are shown on the left hand side
and the single output is shown on the right hand side of the icon. This is following the standard LabVIEW
pattern as introduced earlier.

The cursor will have automatically changed to the wiring spool, this is indicating that LabVIEW is ready to
associate each of the terminals with an object on the front panel.

Click on the top left connecting connecting rectangle, it will turn black to show that the click has been
acknowledged and to confirm which connector has been chosen. Now click on the “Y1” numeric control
on the front panel, the connector will now change colour (probably to orange) to signal that the association
is recorded.

Repeat this operation with the other inputs and then connect the numeric indicator to the right hand
connector rectangle - try to be logical when associating the connections as it will help when building
more complex VIs.

If you make a mistake, it is possible to correct - you should investigate by right clicking on the icon and
the individual connections.

Finally save the VI as “Slope” - LabVIEW will automatically add the “vi” extension.

Using SubVIs.

To use a SubVI within an existing VI, use the “Select a VI” option from the functions palette, use the
browse facilities to locate the file then select and click on the “open” button (alternatively just double click
on the file).

Note that SubVIs can only be used within the block diagram and not the front panel and that it is not possible
to insert a SubVI within itself.

The SubVI’s icon will then appear on the block diagram, it can then be positioned and used as the embedded
functions.

Note how the input and output names from within the SubVI are used when wiring.

Diagrams 28.a and 28.b on the following page show SubVI reuse - note the use of decorations on the
front panel and how different types of controls and indicators from those within the SubVI have been used.

© 2006 David D. Hodgkiss & Staffordshire University 23


Diagram 28.a : Multiple Slope Diagram 28.a : Multiple Slope
front panel block diagram

Summary

This introduction to LabVIEW 8 Express has covered the following aspects

Data flow concepts within LabVIEW and, using the highlight feature, how the various functions are
activated only when all of their inputs have received data, this can be thought as “event driven
based upon data flow”.

Basic controls, indicators and and functions to demonstrate usage.

An introduction to the data types available and how they are represented within LabVIEW.

Finally, the creation of SubVIs and their usage.

This introductory chapter has been produced with a great deal of detail, future will become much
more succinct.

© 2006 David D. Hodgkiss & Staffordshire University 24


Tutorial Work - Chapter 1
The following exercises have been produced to help you familiarise yourselves with LabVIEW 7 Express,
whilst building the application VIs you should also take time to explore LabVIEW, its extensive help system
(both locally and within the National Instruments Web Site (www.ni.com).

As with any programming language, the more you practice (and “play”) the more proficient you will be-
come.

It is up to you how many of the tutorial exercises you attempt, model answers will be placed on my web site
during the following week.

1 Produce a VI that will add two word integer numbers together and give a result. Use simple digital
controls and indicators.

2 Using Slides, Knobs or Dials and either a Gauge or Meter as an output, create a simple VI to calcu-
late

(a + b) * c/d

Scale the input controls and output indicator so that all values of “a” and “b” (range 0..100) and
“c”and “d” (range 0..10) are displayed.

3 As per these notes, create a VI that will calculate a slope value given two “x” inputs and two “y” in-
puts together with an output indicator. The inputs and outputs should be using simple controls and
indicators.

4 Convert the VI created in Ex1.3 into a SubVI, create a suitable icon and document what the SubVI
does, you will need to discover what facilities LabVIEW offers for program documentation.

5 Create a new VI that two separate slopes can be calculated using the SubVI created in Ex1.4.

© 2006 David D. Hodgkiss & Staffordshire University 25

You might also like