An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction...
Transcript of An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction...
![Page 1: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/1.jpg)
![Page 2: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/2.jpg)
An Introduction to LabVIEW
Object-Oriented Design Patterns
Jacques Cilliers
Application Engineer
![Page 3: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/3.jpg)
Agenda
Overview
Producer Consumer Queued State Machine Without
Classes
Command Pattern (Object-Oriented State Machine)
Factory Method Design Pattern (Dynamically Load
Plugins)
Sending Messages to Plugins Using User Events
Object-Oriented Hardware Abstraction Layer
ni.com/largeapps
![Page 4: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/4.jpg)
Why Should I Use One? Save time and improve the longevity and readability of your
code.
Definition: A well-established solution to a common problem.
What is a Design Pattern?
… or else…
![Page 5: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/5.jpg)
![Page 6: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/6.jpg)
Examples of Software Engineering Debt (just some of the most common LabVIEW development
mistakes)
No source code control (or Project)
Flat file hierarchy
‘Stop’ isn’t tested regularly
Wait until the ‘end’ of a project to build an application
Few specifications, documentation, or requirements
No ‘buddying’ or code reviews
Poor planning
No test plans
Poor error handling
No consistent style
Tight coupling or poor cohesion
![Page 7: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/7.jpg)
Why Use Object-Orientation in
LabVIEW?
Encapsulate and protect data
Catch errors at compile time instead of run-time
Easily extend functionality
Eliminate large data clusters
Implement established design patterns
Map real-world problems to software
![Page 8: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/8.jpg)
Understanding Object-Oriented
Programming
Class: A collection of data and the
methods that interact with that data.
Object: A specific instance of a class
![Page 9: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/9.jpg)
Examples of Classes
Class: Car Person
Data:
Make
Model
Year
Mileage
First Name
Last Name
Date of Birth
Gender
Methods: Check Brakes
Rotate Tires
Change Oil
Get Full Name
Get Age
![Page 10: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/10.jpg)
Examples of Objects
Class: Car Person
Object:
•1964 Ford Mustang
•2004 Honda Accord
•Adam Kemp
•Steven Harrison
![Page 11: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/11.jpg)
What is a LabVIEW Class?
A LabVIEW Class is…
• A glorified cluster
• A user-defined data type
• A type of Project Library
Class: A collection of data and the
methods that interact with that
data
Object: A specific instance of a
class
![Page 12: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/12.jpg)
Anatomy of a LabVIEW Class
Each LabVIEW class consists of:
A private data control (cluster)
Member VIs to access that data
Class file (.lvclass) stores class information
Private data control definition
List of member VIs
Properties of member VIs
Properties of the class itself (such as wire appearance)
![Page 13: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/13.jpg)
What is Inheritance?
Example methods:
• Initialize
• Get Cargo Capacity Vehicle Class
(Parent)
Car Class (Child)
Truck Class (Child)
A truck is a type of vehicle. A car is a type of vehicle.
![Page 14: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/14.jpg)
Inheritance Example
Vehicle Class
Car Class Truck Class
Chevy Model
2007 Model 2008 Model
Ancestors
Descendents
![Page 15: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/15.jpg)
Vehicle.lvclass
Get Cargo Capacity.vi
Truck.lvclass
Get Cargo Capacity.vi
Car.lvclass
Get Cargo Capacity.vi
Understanding Dynamic Dispatch
2 6 10
![Page 16: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/16.jpg)
State Machine versus Command Pattern These diagrams represent functionally equivalent code
![Page 17: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/17.jpg)
Dynamic Dispatching Commands
![Page 18: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/18.jpg)
Dynamic Dispatching Commands
![Page 19: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/19.jpg)
The Basics of an Object Factory
A B
C Generic Plugin
Location on Disk
Where Plugins are Stored
Objects Loaded Into Memory
A B C
Parent
Children
![Page 20: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/20.jpg)
User Interface State Machine
Event-Driven Loop
Indefinite dynamically loaded plug-ins
Self-Contained Application Framework
Plug-in State Machine
![Page 21: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/21.jpg)
User Interface State Machine
Event-Driven Loop
Indefinite dynamically loaded plug-ins
Self-Contained Application Framework
Plug-In State Machine
Plugins Need To Receive Commands
We need to be able to send
individual plugins a
command
“You’re Being Displayed”
![Page 22: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/22.jpg)
User Interface State Machine
Event-Driven Loop
Indefinite dynamically loaded plug-ins
Self Contained Application Framework
Plug-In State Machine
Plugins Need To Receive Commands
We may also want to
broadcast messages
“Everyone STOP!”
![Page 23: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/23.jpg)
The Anatomy of Dynamic Events
Dynamic Events
Terminal
Defines
Data Type
VI Gets
Run on
Event
Data Sent
Multiple Loops Can
Register for Same
Event
![Page 24: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/24.jpg)
LabVIEW API for Managing User Events
Using User Events
Register User Events With Listeners
![Page 25: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/25.jpg)
Plugin Handler Launch Plugin.lvclass –
Execute.vi
Broadcast Event Every Plug-In Object
Stores this Event
Unicast Event Unique Event for Every
Object
![Page 26: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/26.jpg)
Traditional
Benchtop
Modular PXI Simulated (software
only)
Abstract the Hardware in Software Mitigate Obsolescence With a Hardware Abstraction Layer
(HAL)
A plug-in architecture
makes it possible to
interchange hardware
without modifying code
![Page 27: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/27.jpg)
Four factory patterns are used to
load the appropriate instrument
object at run-time Dynamically dispatched at run-
time
![Page 28: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/28.jpg)
Hardware Abstraction White Paper How to Mitigate Hardware Obsolescence in Next-Generation
Test Systems
ni.com/largeapps
![Page 29: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/29.jpg)
Applying Common Object-Oriented
(OO) Design Patterns to LabVIEW Singleton Pattern - Guarantee that a given class has only a single instance in memory
Channeling Pattern - To provide a guaranteed pre-processing/post-processing around some dynamic central functionality
Factory Pattern - Provide a way to initialize the value on a parent wire with data from many different child classes based on some input value, such as a selector ring value, enum, or string input
Hierarchy Composition Pattern - To represent a single object as a tree of smaller instances of that same object type
Delegation Pattern - To have two independent classes share common functionality without putting that functionality into a common parent class
Visitor Pattern - To write a traversal algorithm of a set of data such that the traversal can be reused for many different operations
Aggregation Pattern - To treat an array of objects as a single object and define special behavior for that particular type of array
Specification Pattern - To have different functionality for a class depending upon some value of the class without updating case structures throughout your VI hierarchy when you add another value
Decorator (Wrapper) Pattern - Extend a concrete object’s responsibilities dynamically or extend the features of an existing class without refactoring tested code
Strategy (Policy) Pattern - Change the behavior of a class's method without having to edit the method's implementation
![Page 30: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/30.jpg)
Certified LabVIEW Developer
Exam
Certified LabVIEW
Architect Exam
Certified LabVIEW Associate
Developer Exam
Developer Senior Developer Software Architect
Project Manager
NI Certifications Align With Training
Managing
Software
Engineering
in LabVIEW
LabVIEW
OOP Advanced
Architecture
LabVIEW
Core 3
LabVIEW
Core 2
LabVIEW
Core 1
![Page 31: An Introduction to LabVIEW - National Instrumentssouthafrica.ni.com/sites/default/files/Introduction to Object... · An Introduction to LabVIEW Object-Oriented Design Patterns ...](https://reader035.fdocuments.us/reader035/viewer/2022082202/5a795aaf7f8b9a0b118d5eb0/html5/thumbnails/31.jpg)
Download Examples and Slides
ni.com/largeapps
Software Engineering Tools
Development Practices
LargeApp Community