Labview User Group University of Bristol: Ben Lavasani Academic Field Sales Engineer Ni Uk
Labview User Group University of Bristol: Ben Lavasani Academic Field Sales Engineer Ni Uk
University of Bristol
Ben Lavasani
Academic Field Sales Engineer
NI UK
2
Agenda
• LabVIEW Design Patterns Overview
• Coffee break :)
• LabVIEW for Multi-Touch Applications - David Carberry
• LabVIEW in Teaching
• LabVIEW Tips and Tricks
3
LabVIEW Design Patterns Overview
What Is a Design Pattern?
• A template or framework for LabVIEW code
• Widely accepted and well-known
• Easily recognizable
5
Benefits of Using Design Patterns
Simplify the development process
Developers can easily understand code
Don’t have to “re-invent the wheel”
Pre-existing solutions to common problems
Reliability
Many have been used for years - they are “tried and true”
Large development community and resources online
6
Getting Started: How Do I Pick?
• Identify most important aspect of your application:
Processes that require de-coupling
Clean, easy to read code
Mission critical components
• Select a template based upon potential to improve
7
Caution
You can needlessly complicate your
life if you use an unnecessarily
complex design pattern
8
Basic Tools
• Loops
• Shift Registers
• Case Structures
• Enumerated Constants
• Event Structures
9
Today’s Discussion
• As we look at each design pattern, we’ll discuss
A problem we are trying to solve
Background
How it works
Technical implementation
Demonstration
Use cases / considerations
10
Design Patterns
• Functional Global Variable
• State Machine / Statecharts
• Producer / Consumer
11
Functional Global Variables
13
Breaking Down the Design Pattern
• While loop
• Uninitialized shift
registers have memory
• Case structure
• Enumerated control
14
Uninitialized Shift Registers
DEMO
15
How It Works: Basic Actions
• Set the value of the shift register
INITIALIZE
INITIALIZE
16
How It Works: Basic Actions
• Get the value currently stored in the shift register
GET
GET
17
How It Works: Action Engine
• Perform an operation upon stored value and
save result
• You can also output the new value
ACTION
ACTION
18
Technical Implementation
1. Functional Global Variable is a Non-Reentrant SubVI
2. Actions can be performed upon data
3. Enumerator selects action
4. Stores result in uninitialized shift register
5. Loop only executes once
19
Uninitialized shift register has memory
DEMO
20
Benefits: Comparison
Functional Global Variables Global and Local Variables
• Prevent race conditions • Can cause race conditions
• No copies of data • Create copies of data in memory
• Can behave like action engines • Cannot perform actions on data
• Can handle error wires • Cannot handle error wires
• Take time to make • Drag and drop
21
Recommendations
Use Cases
• Communicate data between code without connecting wires
• Perform custom actions upon data while in storage
Considerations
• All owning VIs must stay in memory
• Use clusters to reduce connector pane
• Using stacked shift registers will track multiple iterations
22
State Machine
Static Sequence
24
Soda Machine
Initialize No input
Wait
Nickel Deposited
Change Quarter Deposited
Requested Dime Deposited
Total < 50
Total < 50 Total < 50
Change Quarter
Nickel
Dime
Total >= 50 Total >= 50
Total >= 50
Total > 50
Vend
Total = 50
Exit
Soda costs $0.50
25
Breaking Down the Design Pattern
• Case Structure inside of a While Loop
• Each case is a state
• Current state has decision making code that
determines next state
• Use enumerators to pass value of next state to
shift registers
26
How It Works
Case structure has a case for every state Transition code determines next state
based upon results of step execution
FIRST STATE
Step Execution
Transition Code
NEXT STATE
FIRST STATE
27
Transition Code Options
Step
Execution
Step Execution
Step
Execution
28
State Machine
DEMO
29
Recommendations
Use Cases
• User interfaces
• Data determines next routine
Considerations
• Creating an effective State Machine requires the
designer to make a table of possible states.
• Use LabVIEW Statechart to abstract this process for
more sophisticated applications
30
Producer / Consumer
Slave 2
33
Breaking Down the Design Pattern
• Data independent loops = Multithreading
• Master / slave relationship
• Communication and synchronization between
loops
34
Loop Communication
• Variables
• Occurrences
• Notifier
• Queues
• Semaphores
• Rendezvous
35
Queues
Adding Elements to the Queue
De-queueing Elements
36
Producer / Consumer
37
Adding Your Own Design Patterns
38
Resources
• Example Finder
• New >> Frameworks >> Design Patterns
• ni.com/labview/power
• Expressionflow.com
39
40
LabVIEW in Teaching
The NI LabVIEW Academy
41
What Is the NI LabVIEW
Academy?
The NI LabVIEW Academy program provides classroom
curriculum, instructional materials, and hands-on exercises to
high schools, community colleges, and universities for the
specific purpose of teaching LabVIEW.
42
What Does the NI LabVIEW Academy
Do?
43
NI LabVIEW Academy Program
Requirements
Instructor Requirements
Program Requirements
• Current teaching site license
• At least one dedicated classroom (a computer lab will suffice)
• 40 hours of classroom LabVIEW specific instruction time
• One PC per student (with LabVIEW software)
• NI DAQ equipment required for lab component (2:1 student ratio)
• Submit course syllabus to NI for approval
44
NI LabVIEW Academy Instructional
Materials
Instructor Materials
Student Materials
45
NI LabVIEW Academy Teaching Materials
46
NI LabVIEW Academy CLAD Opportunity
49
The NI LabVIEW Academy Bridging the Gap
Academic Industry
“LabVIEW is getting more popular in academia “In our exhaustive search for qualified
and industry and many researchers and LabVIEW developers to fill key roles in our
companies are on the lookout for competent organization, we greatly anticipate the new pool
LabVIEW programmers. This program will of qualified candidates coming out of the
help bridge the gap between the two.” National Instruments LabVIEW Academy
– Khanjan Mehta, Professor, schools.“
Penn State University – Marvin Landrum, Section
Manager, Texas Instruments
50
ni.com/academy
51
52
Tips and Tricks to Speed NI LabVIEW Development
Useful Nuggets to Save You Time
Agenda
54
/
1
20 Automatically Select the Right Tool
Position/Size/Select Tool
Auto Tool
Edit Text Tool
55
/
2
20 Quickly Drop Palette Objects
Hold down Ctrl + Space to launch Quick Drop
Demo
56
/
3
20 Design Pattern Templates
57
/
4
20 Switch Terminal Wires Easily
Note: This works only for functions with two inputs when both
inputs have already been wired
Demo
58
/
5
20 Easily Scroll Through Structures
• You can use Ctrl + Mouse Scroll to scroll through:
Case Structures
Event Structures
Stacked Sequence Structures
Diagram Disable Structures
59
/
6
20 Quickly Find the Right Palette
• Right-click on a block diagram object for a palette shortcut
Add
Index Array
Demo
60
/
7
20 Easily Navigate Arrays
• Right-click on an array and select Visible Items >> Horizontal Scrollbar
(or Visible Items >> Vertical Scrollbar)
• To view last element, select Advanced >> Show Last Element
• Both horizontal and vertical scrollbars available (depending on array
dimensions)
Demo
61
/
8
20 Selective Insert Location
62
/
9
20 Block Diagram Clean-Up
• Click Clean Up Diagram button on toolbar or press
Ctrl + U
• Highlight a portion of the diagram for partial cleanup
• Right-click and select “Exclude from Diagram
Cleanup” option
Note: Only
available in
LabVIEW 8.6 and
later.
Demo
63
/
10
20 Quickly Wire Multiframe Structures
• Right-click an output tunnel and select “Linked Input Tunnel »
Create & Wire Unwired Cases”
64
/
11
20 Easily Assess 2D Array Size
• Matrix Size function replaces old method
• Assess size of 2D array regardless of data type
65
/
12
20 Breakpoint Manager
• Select View » Breakpoint Manager
• Right-click and select Breakpoint » Breakpoint
Manager
66
/
13
20 Quickly Find VIs in the Project Window
• Ctrl + Shift +E from an open VI with open project
67
/
14
20 Easily Add Enumeration Items
Shift + Enter
Demo
68
/
15
20 Edit Multiple Objects Simultaneously
• Highlight all desired front panel or block diagram
objects
• Right-click and select “Properties”
Demo
69
/
16
20 Automatically Create Control References
70
/
17
20 Drag and Drop to Save Time
• Drag an image into your VI icon
• Select a file and drag into a path constant
• Take a URL from Internet Explorer and drag into a string constant
• Drag items from disk or Project Explorer into a LabVIEW block diagram
71
/
18
20 Quickly Browse Properties and Methods
• View >> Class Browser
• Shortcut: Ctrl + Shift + B
• Drag a property or method directly into your
VI
Demo
72
/
19
20 Implement a For Loop Progress Bar
• Place Progress Bar VI inside a for loop
• Opens automatically after a specified amount of time
• Download sample code from ni.com/forums (search for “For Loop Progress Bar”)
Demo
73
/
20
20 Automatically Analyse Your VIs
• Tools >> VI Analyzer >> Analyze VIs
– Check performance, style, UI, documentation, and more
– Save LabVIEW VI Analyzer settings for later use
Demo
74
Other Resources
• Darren’s LabVIEW Nuggets
(decibel.ni.com/content/docs/DOC-4002)
• LabVIEW Wiki
(labviewwiki.org)
75
76