LabVIEW Programming Guidelines
LabVIEW Programming Guidelines
blog
LabVIEW
Programming Guidelines
Hans-Petter Halvorsen
Contents
In this tutorial I assume you are already
familiar with LabVIEW
• Blog:
https://www.halvorsen.blog/documents/pro
gramming/labview/
• LabVIEW Basics YouTube Playlist:
https://www.youtube.com/playlist?list=PLdb-
TcK6Aqj2_aDQVCQgMu9Hz77pLhVqa
Programming Guidelines
• Typically engineers often create simple
LabVIEW VIs that eventually grow out of
control, because they don't have the proper
structure and best practices.
• The solution to this problem is organizing your
code and data in a way that enables
modularity, readability, and reuse.
3
Topics – some examples
• Intuitive GUI (Front Panels)
– Add Units
– Use Controls and Indicators from the same Palette
– Resizing the Window size
– Don’t use “strong” Colors
• Structured Code (Block Diagram)
– SubVIs
– Avoid Spaghetti Code
– Resizing the Window size
– Use Labels
– Always use Project Explorer
– State Machine
What is Wrong with this GUI?
5
6
https://www.halvorsen.blog
Hans-Petter Halvorsen
8
9
10
Spaghetti Code
Since LabVIEW is a graphical programming language with lots of wires, etc., it is
extremely important to have a good and clear structure in your program!
Structure your Code
12
Alignment Tools
13
Alignment Tools
14
Alignment Tools
15
Use Comments and Labels
Use Comments and Labels
16
https://www.halvorsen.blog
Hans-Petter Halvorsen
Customizing LabVIEW IDE
18
Change Visible Palettes
19
https://www.halvorsen.blog
LabVIEW Palettes
Hans-Petter Halvorsen
LabVIEW Palettes
21
LabVIEW Palettes
• In LabVIEW we have different palettes for creating
user interface objects, like Modern, System, Silver,
Classic, etc.
• You decide which of those you want to use, but
please don’t mix controls from different palettes.
Stick to one of them.
• Personally, I think Silver has a modern and fresh
look
22
Don’t mix
Controls from
different
Palettes
23
https://www.halvorsen.blog
25
https://www.halvorsen.blog
Hans-Petter Halvorsen
Resizing the Window Size
• You don’t need to show lots of “empty” space
• Resize the window size so it fits your GUI
(Front Panel) and your code (Block Diagram)
• The Save it (Ctrl +S). It will be like this next
time you open your application!
27
28
29
https://www.halvorsen.blog
Hans-Petter Halvorsen
Colors
• Don’t use more
colors than you need
• It should look like an
ordinary Windows
Application
31
https://www.halvorsen.blog
Hans-Petter Halvorsen
Labels and Captions
• Hide Labels
• Use Captions in your GUI (Front Panel)
33
Hide Labels when not needed
34
Labels vs Captions
• Labels -> Code (Block Diagram)
• Captions -> GUI (Front Panel)
35
Labels vs Captions
Labels -> Code (Block Diagram)
Captions -> GUI (Front Panel)
36
https://www.halvorsen.blog
Project Explorer
Hans-Petter Halvorsen
Project Explorer
38
Project Explorer
39
Project Explorer
• You should always use the Project Explorer
even for simple applications
• Like the “Solutions Explorer” in Visual Studio it
Keeps all your Files for a specific project in one
place
40
https://www.halvorsen.blog
Units
Hans-Petter Halvorsen
Add Units
• A value without a Unit is useless
• Make sure to always add a Unit in Controls,
Indicators or in Plots/Charts
42
Add Units
43
Add Units in Charts (both x axis and y axis)
44
https://www.halvorsen.blog
Number of Decimals
Hans-Petter Halvorsen
Make sure to read the
Number of Decimals Datasheet and use
common sense
46
https://www.halvorsen.blog
SubVIs
Hans-Petter Halvorsen
SubVIs
• A SubVI is the same as a function or a method
used in other languages
• Hundreds or thousands of SubVIs are included
with LabVIEW
• But even better: You can create and use your
own SubVIs
Why create and use SubVIs?
• You need to use the same operation many
times in your code
• Reuse your code
• Hide complicated code
• Easier to maintain your code
• Easier to find bugs and repair them
• ...
Select Inputs and Outputs
SubVIs
Input Output
Icon that makes it easier
to understand what the
SubVI is doing
(Control) (Indicator)
Create a nice icon as well
(Icon Editor)
9
𝑇𝐹 = 𝑇𝐶 + 32
5
Use the Icon Editor in order to create
Icon Editor a descriptive icon for your SubVI.
Using SubVIs
53
https://www.halvorsen.blog
Hans-Petter Halvorsen
State Machine
55
State Machine
• Typically engineers often create simple LabVIEW VIs that
eventually grow out of control, because they don't have the
proper structure and best practices. The solution to this
problem is organizing your code and data in a way that
enables modularity, readability, and reuse. Using a state
machine approach is a good way to make it right from the
early beginning.
• The state machine is one of the fundamental architectures
LabVIEW developers frequently use to build applications.
• In LabVIEW software, you can create a basic state machine
with a While loop, a Shift Register, a Case Structure, and some
form of case selector.
56
State Machine
• I will show a State Machine that I have already
made.
• For details, see the Video “LabVIEW
Applications using State Machine”:
https://youtu.be/-b9St8wNhpQ
• Here I will through how to create and use a
State Machine in detail.
57
Hans-Petter Halvorsen
University of South-Eastern Norway
www.usn.no
E-mail: [email protected]
Web: https://www.halvorsen.blog
YouTube: https://www.youtube.com/IndustrialITandAutomation