LabVIEW Design Patterns
LabVIEW Design Patterns
LabVIEW Design Patterns
Agenda
What is a design pattern (what)
Benefits of design patterns (why)
Examples of design patterns (how)
More
Onefeatures
more
feature,
.. Small
Uhh
Ilast
one
itsIbig
promise!
working
Add
Start
aHow
few
features
..think
Ithappen?
works!
no
deal
did
this
Reliability
Many have been used for years they are tried and true
Refer to large development community and resources
online
Caution
You can needlessly complicate your
life if you use an unnecessarily
complex design pattern.
Do not forget the most common design
pattern of all data flow!
Basic Tools
Loops
Shift registers
Case structures
Enumerated constants
Event structures
Todays Discussion
As we look at each design pattern, we will discuss
Design Patterns
Basic
State machine
Event-driven user interface
Producer/consumer
Advanced
Object-oriented programming
10
National Instruments
Customer Education
LabVIEW
Basics I and II
State Machine
I need to execute a sequence of events, but the
order is determined programmatically.
Flexible
Oops, I forgot to include a step to do [y]!
Easily Maintained
Thank goodness John used a state machine, we
can easily understand whats going on
12
Background
Static Sequence
Dynamic Sequence: Distinct states can operate in a
programmatically determined sequence
13
Vending Machine
Initialize
No Input
Wait
Change
Requested
Total <50
Change
Nickel Deposited
Quarter Deposited
Quarter
Dime Deposited
Total <50
Total <50
Nickel
Dime
Total 50
Total 50
Total >50
Vend
Exit
Total = 50
14
Total 50
15
Framework
Decide which state to execute
Decide which state is next
16
State Code
StateCode
Code
State
Code
State
State Code
17
Transition Logic
Figure out which state is next
18
State
State
Code
State
Code
Code
Transition
Logic
19
State
State
Code
State
Code
Code
Transition
Logic
20
State Machine
DEMO
21
Recommendations
Use Cases
Almost Always
Any program with more than a few steps
Considerations
You need to make a state diagram
LabVIEW Statechart module implements UML
statecharts
22
National Instruments
Customer Education
LabVIEW
Intermediate I
Background
Procedural-driven programming
Performs a set of instructions in sequence
Requires polling to capture events
Cannot determine order of multiple events
Event-driven programming
Determines execution at run time
Waits for events to occur without consuming CPU
Remembers order of multiple events
24
How It Works
Event structure nested within loop
Blocking function until event registered or time-out
Events that can be registered:
Notify events are only for interactions with the front
panel
Dynamic events implement programmatic registration
Filter events help you to screen events before they are
processed
25
How It Works
1.
2.
3.
4.
26
Browse controls
Browse events per control
Green arrow: notify
Red arrow: filter
27
DEMO
28
Recommendations
Use Cases
UI: Conserve CPU usage
UI: Ensure you never miss an event
Drive slave processes
Considerations
Event structures eliminate determinism
Avoid placing two event structures in one loop
Remember to read the terminal of a latched Boolean control in its
value change event case
29
National Instruments
Customer Education
LabVIEW
Intermediate I
Producer/Consumer
I have two processes that need to execute at the same time,
and I need to make sure one cannot slow the other down.
How It Works
Thread 1
Thread 2
Thread 3
31
32
Queues
Adding Elements to the Queue
Dequeueing Elements
34
Producer/Consumer
36
Producer/Consumer
DEMO
37
Recommendations
Use cases
Handling multiple processes simultaneously
Asynchronous operation of loops
Considerations
Multiple producers one consumer
One queue per consumer
If order of execution of parallel loop is critical,
use occurrences
39
National Instruments
Customer Education
LabVIEW OOP
System Design
Object-Oriented Programming
Dynamic Allocation
Inherited Functionality
Polymoprhism
41
42
Copy Machine
Inkjet Printer
43
Laser
Printer
Copy
Machine
Inkjet
Printer
44
45
DEMO
46
48
Solution: Producer/consumer
We should use the producer/consumer architecture because we
have multiple tasks that run at different speeds and cannot afford
to be slowed down. Each of the external readings will be in
separate producer loops and the data processing and logging will
be in the consumer loop.
50
DEMO
52
Resources
Example Finder
New>>Frameworks>>Design Patterns
ni.com/statechart
ni.com/labview/power
Training
LabVIEW Intermediate I and II
How to Develop
Your LabVIEW Skills
54
Experienced User
Advanced User
Courses
Begin
Here
Core Courses
LabVIEW
LabVIEW
Basics II
Basics I
Certifications
Certified LabVIEW
Associate Developer Exam
LabVIEW Advanced I
LabVIEW
Intermediate I
LabVIEW
Intermediate II
Certified LabVIEW
Architect Exam
Certified LabVIEW
Developer Exam
55
Certification
56
57
Next Steps
Visit ni.com/training
Identify your current expertise level and desired
level
Register for appropriate courses
$200 USD discount for attending LabVIEW
Developer Education Day!
58
Advanced
Intermediate
Specialty
Foundation
LabVIEW Object-Oriented
Programming System Design
LabVIEW
Real-Time
Application
Development
CompactRIO
Fundamentals
and LabVIEW
FPGA
LabVIEW
Instrument
Control
RF
Fundamentals
and RF
Application
Development
LabVIEW
Machine
Vision and
Image
Processing
LabVIEW
DAQ and
Signal
Conditioning
At Your Convenience
Self-paced course kits
On-demand training modules located in the Services Resource Center
ONE PRICE
Questions?