View
27
Download
2
Category
Preview:
DESCRIPTION
Basics about labview programming.
Citation preview
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 1/19
Telemark University College
Department of Electrical Engineering, Information Technology and Cybernetics
Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01
Basic LabVIEW Programming
HANS-PETTER HALVORSEN, 2011.09.29
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 2/19
PrefaceIn this document you will learn basic LabVIEW programming by creating some
simple LabVIEW applications.
LabVIEW is a graphical programming language created by National Instruments
(www.ni.com).
For more information about LabVIEW, please refer to the Tutorial
“Introduction to LabVIEW”: http://home.hit.no/~hansha/?tutorial=labview .
For a flying start, watch this video (LabVIEW Quickie!):
http://home.hit.no/~finnh/videos/topics/labview/labview/labview.html
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 3/19
3/19
http://home.hit.no/~hansha
Task 1: Simple Calculator
Create the following simple program that adds 2 numbers:
Simple Calculator.vi
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:
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 4/19
4/19
http://home.hit.no/~hansha
→ 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:
Calculator.vi
For selecting the different Operators (“Add”, “Subtract”, “Multiply”, “Divide”),
you should use an “Enum”:
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 5/19
5/19
http://home.hit.no/~hansha
→ 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.
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 6/19
6/19
http://home.hit.no/~hansha
→ 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]
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 7/19
7/19
http://home.hit.no/~hansha
Task 2: While Loop
Create the following program:
While Loop.vi
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:
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 8/19
8/19
http://home.hit.no/~hansha
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]
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 9/19
9/19
http://home.hit.no/~hansha
Task 3: Advanced Calculator
Create the following program:
Advanced Calculator.vi
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.
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 10/19
10/19
http://home.hit.no/~hansha
The Block Diagram should look like this when you are finished:
[End of Task]
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 11/19
11/19
http://home.hit.no/~hansha
Task 4: Arrays
Create the following program:
Arrays.vi
Front Panel:
Creating an Array:
→ Start by dragging an empty array into your Front Panel and drag aNumeric 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:
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 12/19
12/19
http://home.hit.no/~hansha
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]
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 13/19
13/19
http://home.hit.no/~hansha
Task 5: SubVIs
Create a SubVI from the Calculator created in a previous task.
Calculator.vi
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 openthe Icon Editor.
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 14/19
14/19
http://home.hit.no/~hansha
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 “Create→Control”
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 15/19
15/19
http://home.hit.no/~hansha
The Block Diagram should look like this when you are finished:
Front Panel:
The Front Panel could look like this:
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 16/19
16/19
http://home.hit.no/~hansha
Test of SubVI Calculator.vi
→ Test your program by using the Run button in the Toolbar.
[End of Task]
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 17/19
17/19
http://home.hit.no/~hansha
Task 6: Plotting
Create the following program:
Plotting.vi
Front Panel:
Use the “Waveform Chart” Control:
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 18/19
18/19
http://home.hit.no/~hansha
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]
7/21/2019 Basic LabVIEW Programming
http://slidepdf.com/reader/full/basic-labview-programming 19/19
Telemark University College
Faculty of Technology
Kjølnes Ring 56
N-3914 Porsgrunn, Norway
www.hit.no
Hans-Petter Halvorsen, M.Sc.
Telemark University College
Department of Electrical Engineering, Information Technology and
Cybernetics
Phone: +47 3557 5158
E-mail: hans.p.halvorsen@hit.no
Blog: http://home.hit.no/~hansha/
Room: B-237a
Recommended