![Page 1: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/1.jpg)
LabVIEWProgramming Guidelines
Hans-Petter Halvorsen
https://www.halvorsen.blog
![Page 2: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/2.jpg)
ContentsIn this tutorial I assume you are alreadyfamiliar with LabVIEW• Blog:
https://www.halvorsen.blog/documents/programming/labview/
• LabVIEW Basics YouTube Playlist: https://www.youtube.com/playlist?list=PLdb-TcK6Aqj2_aDQVCQgMu9Hz77pLhVqa
![Page 3: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/3.jpg)
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
![Page 4: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/4.jpg)
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
![Page 5: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/5.jpg)
5
What is Wrong with this GUI?
![Page 6: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/6.jpg)
6
![Page 8: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/8.jpg)
8
![Page 9: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/9.jpg)
9
![Page 10: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/10.jpg)
10
![Page 11: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/11.jpg)
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!
![Page 12: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/12.jpg)
Structure your Code
12
![Page 13: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/13.jpg)
Alignment Tools
13
![Page 14: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/14.jpg)
Alignment Tools
14
![Page 15: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/15.jpg)
Alignment Tools
15
![Page 16: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/16.jpg)
Use Comments and Labels
16
Use Labels for SubVIsand built-in Functions
Use Comments and Labels
![Page 17: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/17.jpg)
Customizing LabVIEW IDE
Hans-Petter Halvorsen
https://www.halvorsen.blog
![Page 18: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/18.jpg)
Customizing LabVIEW IDE
18
![Page 19: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/19.jpg)
Change Visible Palettes
19
![Page 21: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/21.jpg)
LabVIEW Palettes
21
![Page 22: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/22.jpg)
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
![Page 23: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/23.jpg)
Don’t mix Controls from
different Palettes
23
![Page 24: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/24.jpg)
Make Current Value Default
Hans-Petter Halvorsen
https://www.halvorsen.blog
![Page 25: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/25.jpg)
Make Current Value(s) Default
25
![Page 26: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/26.jpg)
Resizing the Window Size
Hans-Petter Halvorsen
https://www.halvorsen.blog
![Page 27: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/27.jpg)
Resizing the Window Size
27
• 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!
![Page 28: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/28.jpg)
28
![Page 29: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/29.jpg)
29
![Page 30: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/30.jpg)
Don’t use “strong” Colors
Hans-Petter Halvorsen
https://www.halvorsen.blog
![Page 31: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/31.jpg)
Colors
31
• Don’t use more colors than you need
• It should look like an ordinary Windows Application
![Page 33: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/33.jpg)
Labels and Captions
• Hide Labels
• Use Captions in your GUI (Front Panel)
33
![Page 34: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/34.jpg)
Hide Labels when not needed
34
![Page 35: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/35.jpg)
Labels vs Captions
• Labels -> Code (Block Diagram)
• Captions -> GUI (Front Panel)
35
![Page 36: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/36.jpg)
Labels -> Code (Block Diagram)
Captions -> GUI (Front Panel)
36
Labels vs Captions
![Page 38: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/38.jpg)
Project Explorer
38
![Page 39: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/39.jpg)
Project Explorer
39
![Page 40: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/40.jpg)
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
![Page 42: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/42.jpg)
Add Units
• A value without a Unit is useless
• Make sure to always add a Unit in Controls,Indicators or in Plots/Charts
42
![Page 43: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/43.jpg)
Add Units
43
![Page 44: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/44.jpg)
Add Units in Charts (both x axis and y axis)
44
![Page 46: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/46.jpg)
Number of Decimals
46
Make sure to read the Datasheet and use
common sense
![Page 48: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/48.jpg)
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
![Page 49: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/49.jpg)
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
• ...
![Page 50: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/50.jpg)
SubVIsInput Output
(Control) (Indicator)
Icon that makes it easier to understand what the SubVI is doing
A SubVI is the same as a function or a method used in other languages
Select Inputs and Outputs
Create a nice icon as well(Icon Editor)
𝑇𝐹 =9
5𝑇𝐶 + 32
![Page 51: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/51.jpg)
Icon Editor Use the Icon Editor in order to create a descriptive icon for your SubVI.
![Page 52: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/52.jpg)
Using SubVIs
SubVI created in previous slide(just drag it on the Block Diagram with your mouse)
![Page 53: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/53.jpg)
LabVIEW SubVIs Video
• For details, see the Video “LabVIEW SubVIs”: https://youtu.be/zTbQxkDVSic
53
![Page 55: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/55.jpg)
State Machine
55
![Page 56: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/56.jpg)
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
![Page 57: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/57.jpg)
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
![Page 58: LabVIEW Programming Guidelines · 2020-04-14 · Programming Guidelines •Typically engineers often create simple LabVIEW VIs that eventually grow out of control, because they don't](https://reader030.vdocuments.net/reader030/viewer/2022040203/5ea5c409e785cf675d1f1c1c/html5/thumbnails/58.jpg)
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