Telemark University College
Department of Electrical Engineering, Information Technology and Cybernetics
Basic LabVIEW Programming
HANS-PETTER HALVORSEN, 2011.09.29
Faculty of Technology, Postboks 203, Kjlnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01
Preface
In this document you will learn basic LabVIEW programming by creating some
simple LabVIEW applications.
LabVIEW is a graphical programming language created by National Instruments
([Link]).
For more information about LabVIEW, please refer to the Tutorial
Introduction to LabVIEW: [Link] .
For a flying start, watch this video (LabVIEW Quickie!):
[Link]
3/19
Task 1: Simple Calculator
Create the following simple program that adds 2 numbers:
Simple [Link]
This simple calculator will add 2 numbers together.
Front Panel:
Add 2 Numeric
Controls and name them
Number1 and Number2
Add a Numeric Indicator
and name it Answer
Block Diagram:
Add a Add function from the Functions palette:
[Link]
4/19
Connect (wire) the different objects together like this:
Push the Run button in the Toolbar to do the calculations.
Extend your calculator (make sure to rename your file) so it can handle the 4
basic calculations (Add, Subtract, Multiply, Divide).
Front Panel:
[Link]
For selecting the different Operators (Add, Subtract, Multiply, Divide),
you should use an Enum:
[Link]
5/19
Enter Add, Subtract, Multiply, Divide inside the Enum (right-click
and select Add Item After).
Block Diagram:
The Block Diagram should look like this when you are finished:
Use the Case Structure for this.
[Link]
6/19
Wire the Enum (Operator) to the sign on the Case structure.
Push the Run button in the Toolbar to do the calculations.
[End of Task]
[Link]
7/19
Task 2: While Loop
Create the following program:
While [Link]
The program will update the date and time each second using a While loop
until you stop the program using the Stop button.
Front Panel:
Add 2 String Indicators and name them Date and Time.
Block Diagram:
The Block Diagram should look like this when you are finished:
[Link]
8/19
While Loop:
Add a While Loop to your program.
Get Date/Time String:
Use the Get Date/Time String function in order to get the current Date and
Time from the computer:
Wait (ms):
The Date and Time strings should be updated every second. You can use the
Wait (ms) for that:
[End of Task]
[Link]
9/19
Task 3: Advanced Calculator
Create the following program:
Advanced [Link]
Front Panel:
Add the User Interface objects as shown in the Figure above.
The calculations will be performed when you click the Calculate button.
Block Diagram:
You need to use the following in your program:
While Loop:
Event Structure:
Add an Event Structure inside the While Loop.
[Link]
10/19
The Block Diagram should look like this when you are finished:
[End of Task]
[Link]
11/19
Task 4: Arrays
Create the following program:
[Link]
Front Panel:
Creating an Array:
Start by dragging an empty array into your Front Panel and drag a
Numeric Control inside it:
Enter some data inside the array.
Block Diagram:
Index Array:
Next we will use the Index Array function in order to find a spesific
element in the array:
[Link]
12/19
The Block Diagram should look like this when you are finished:
Test your program by using the Run button in the Toolbar.
[End of Task]
[Link]
13/19
Task 5: SubVIs
Create a SubVI from the Calculator created in a previous task.
[Link]
Icon Editor:
This includes creating a nice icon using the Icon Editor:
Right-click in the upper right window and select Edit Icon in order to open
the Icon Editor.
[Link]
14/19
You also need to create input/output Connectors
Using and testing the SubVI:
We will now create a new program that uses the SubVI.
Block Diagram:
Create a new blank VI and open the Block Diagram.
Insert the SubVI by right-click and select Select a VI in the Functions
palette.
Right-click on the SubVI inputs and select CreateControl
[Link]
15/19
The Block Diagram should look like this when you are finished:
Front Panel:
The Front Panel could look like this:
[Link]
16/19
Test of SubVI [Link]
Test your program by using the Run button in the Toolbar.
[End of Task]
[Link]
17/19
Task 6: Plotting
Create the following program:
[Link]
Front Panel:
Use the Waveform Chart Control:
[Link]
18/19
Block Diagram:
Random Number (0-1):
Use the Random Number (0-1) function in order to create some random
data in your plot:
Waveform Chart:
Insert the Waveform Chart inside the While Loop.
Wait (ms):
Update the chart every second by using the Wait (ms):
The Block Diagram should look like this when you are finished:
[End of Task]
[Link]
Telemark University College
Faculty of Technology
Kjlnes Ring 56
N-3914 Porsgrunn, Norway
[Link]
Hans-Petter Halvorsen, [Link].
Telemark University College
Department of Electrical Engineering, Information Technology and
Cybernetics
Phone: +47 3557 5158
E-mail: [Link]@[Link]
Blog: [Link]
Room: B-237a