45
Elijah Kerry, Certified LabVIEW Architect (CLA) Senior Product Manager for LabVIEW, National Instruments Developing Scalable Applications with Object- Oriented Architectures

Elijah Kerry, Certified LabVIEW Architect (CLA)

Embed Size (px)

DESCRIPTION

Developing Scalable Applications with Object-Oriented Architectures. Elijah Kerry, Certified LabVIEW Architect (CLA) Senior Product Manager for LabVIEW, National Instruments. Does this sound familiar?. Adding or changing support for hardware requires significant effort and time. - PowerPoint PPT Presentation

Citation preview

Page 1: Elijah Kerry, Certified LabVIEW Architect (CLA)

Elijah Kerry, Certified LabVIEW Architect (CLA)Senior Product Manager for LabVIEW, National Instruments

Developing Scalable Applications with Object-Oriented Architectures

Page 2: Elijah Kerry, Certified LabVIEW Architect (CLA)

Does this sound familiar?

Adding or changing support for hardware requires significant effort and time.

You’re constantly copying and duplicating code to add similar, but different functionality.

Adding new functionality breaks code due to brittle design.Scalable Modular Reusable Extensible

Simple

Page 3: Elijah Kerry, Certified LabVIEW Architect (CLA)

Agenda

Multi-Process System DesignActor Framework OverviewAbstraction LayersDesigning PluginsDistributing Templates

ni.com/largeapps

Page 4: Elijah Kerry, Certified LabVIEW Architect (CLA)

User Interface Event Handler

DAQ Acquisition

DAQ

Execution: The user interface cannot respond to other input while acquiring dataDevelopment: Modifying one process requires modifying the other, introducing added riskExtensibility: How do you add a data logging process?

Why is Coupling Bad?

Page 5: Elijah Kerry, Certified LabVIEW Architect (CLA)

While Loop

Cohesion: Understanding Data Scope

Shifter defines scope of process

Processes should be very cohesive

Independent processes should be separate loops

DAQ

TDMS

User Interface

State Information

Multiple shift registers for one process indicate over-coupling

Page 6: Elijah Kerry, Certified LabVIEW Architect (CLA)

DAQ Application

Event-Driven Loop

De-Coupling Independent Processes

Best Practices

1. Identify data scope

2. Delegate actions to appropriate process

3. Do not poll or use timeouts**except for code that communicates with hardware

Considerations

4. How do you send commands?

5. How do you send data?

6. Which processes can communicate with each other?

7. How do you update the UI?

Page 7: Elijah Kerry, Certified LabVIEW Architect (CLA)

Anatomy of a Producer ProcessProcess

Stop Condition Met?

Send InformationData

Information

Action or Event

Sends message to other process, program, or target

Page 8: Elijah Kerry, Certified LabVIEW Architect (CLA)

Anatomy of a Message Producer ProcessProcess

Stop Condition Met?

Inter-Process Communicatio

nData

Command

Action or Event

Sends message to other process, program, or target

Message comprised of a command and optional data

Page 9: Elijah Kerry, Certified LabVIEW Architect (CLA)

Constructing a Message

Examples

DataVariant allows data-type to vary. Different messages may require different data

CommandEnumerated constants list all of the options

Command Data

Initialize UI Cluster containing configuration data

Populate Menu Array of strings to display in menu

Resize Display Array of integers [Width, Height]

Load Subpanel Reference of VI to Load

Insert Header String

Stop -

Page 10: Elijah Kerry, Certified LabVIEW Architect (CLA)

?

Next Steps

FIRST STATE

Case structure has a case for every command

Next steps could enqueue new action for any other loop, including this one

Data cluster for all states

After command is executed, data cluster may be updated

QueueReference

Command Execution

State Specific

Data-type Definition

Variant To Data

DequeueAction &

Data

Queued Message Handler Process

Defines the scope of operations this consumer can handle

Stop Condition Met?

Page 11: Elijah Kerry, Certified LabVIEW Architect (CLA)

New Framework for Multi-Process Systems

Makes heavy use of object-oriented programming in order to eliminate duplication of code and improve system scalability

The Actor Framework designed for large multi-process applications

Includes utility for generating messages and invoking actor methods

For more information:ni.com/

actorframework

Page 12: Elijah Kerry, Certified LabVIEW Architect (CLA)

Queue References

Scaling Multiple Consumer Systems

Scenario Two: Multiple Instances of Same Process

Traditional Solution: Dynamically load VI or duplicate code

Page 13: Elijah Kerry, Certified LabVIEW Architect (CLA)

Messages• Configure• Acquire• Measure• Close• Exit

Scaling Multiple Consumer Systems

Scenario One: Customize existing behavior

Measurement A

Messages• Configure• Acquire• Measure• Close• Exit

Measurement B

Messages• Configure• Acquire• Measure• Close• Exit

Traditional Solution: Maintain two separate copies

Page 14: Elijah Kerry, Certified LabVIEW Architect (CLA)

Messages• Configure• Acquire• Measure• Close• Exit

Scaling Multiple Consumer Systems

Scenario Two: Add Additional Capability

Measurement A

Messages• Configure• Acquire• Measure• Close• Exit

Measurement B

Traditional Solution: Maintain two separate copies

Messages• Configure• Acquire• Log• Measure• Close• Exit

Page 15: Elijah Kerry, Certified LabVIEW Architect (CLA)

Queues Exist for the Lifetime of the Creator

Everyone STOP!

When the creator of a queue leaves memory, the reference is destroyed.

Any items remaining in the buffer will not be read, including ‘Stop’

Page 16: Elijah Kerry, Certified LabVIEW Architect (CLA)

ni.com

Class: Four Door SedanExamples of Objects of this Class

Properties of these items:- Miles per gallon - Crash safety rating- Manual / Automatic- Engine size- Horse power

These items can..- Start- Drive- Change gear- Deploy airbags

Data Methods

Page 17: Elijah Kerry, Certified LabVIEW Architect (CLA)

ni.com

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 18: Elijah Kerry, Certified LabVIEW Architect (CLA)

ni.com

Anatomy of a Class

• Private data control• Accessors• Methods

• Static• Dynamic

• Access Scope• Public• Protected• Private• Community

• Class Property Menu• Define Inheritance• Define Rules• Define Iconage

Page 19: Elijah Kerry, Certified LabVIEW Architect (CLA)

ni.com

Private Data ControlThe reason some people call classes a ‘glorified cluster’

Only VIs belonging to the class can access or modify this data

Page 20: Elijah Kerry, Certified LabVIEW Architect (CLA)

ni.com

Streamlining Member VI Creation

Scripts the creation of member VIs to get and set data in the

private data control

Right-click an item in the private data control and select ‘Create Acessor’

Right click on the lvclass file in the Project and select ‘New’

Scripts the creation of member VIs with pre-populated connector panes

Page 21: Elijah Kerry, Certified LabVIEW Architect (CLA)

ni.com

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 22: Elijah Kerry, Certified LabVIEW Architect (CLA)

22

Vehicle.lvclassGet Cargo Capacity.vi

Truck.lvclassGet Cargo Capacity.vi

Car.lvclassGet Cargo Capacity.vi

Dynamic Dispatch

2610

Dynamic dispatch can be thought of as ‘polymorphism at run-time.’ The Class you pass in to the dynamic dispatch terminal determines the specific method that gets executed at run-time.

Page 23: Elijah Kerry, Certified LabVIEW Architect (CLA)

What is an Actor?

=

An actor is conceptually the same as a queued message handler (QMH) or queued state machine

(QSM).

Page 24: Elijah Kerry, Certified LabVIEW Architect (CLA)

Methods of an Actor are run when a message is received

Log Status UpdateUpdate

DataLaunch Results UIInitialize

Methods of an Actor define the messages it can consume

=

Hardware Scan

Measurement Done

Measurement ScanStart

MeasurementReceive Results Object

Page 25: Elijah Kerry, Certified LabVIEW Architect (CLA)

Messages Can Be Changed or Added by Children

Log Status UpdateUpdate

DataLaunch Results UIInitialize

=

Hardware Scan

Measurement DoneMeasurement

ScanStart MeasurementReceive Results

Object

Overridden

Receive Results ObjectReceive Request for Compatible Hardware

Types

Receive Request for Hardware Device NamesReceive Request to

Load New Measurement from

Disk

Page 26: Elijah Kerry, Certified LabVIEW Architect (CLA)

Launching Actors and Managing Queues

Actor.lvclass has two queues in the private data• Queue for sending messages to the calling actor• Queue for receiving messagesThese are stored in the actor’s private data when launched

Actors that launch another actor should store the new actor’s queue in its own private data

Page 27: Elijah Kerry, Certified LabVIEW Architect (CLA)

Understanding ‘Actor Core.vi’

This is a queued message handlerLaunching an Actor starts the ‘actor core.vi’

method.

Page 28: Elijah Kerry, Certified LabVIEW Architect (CLA)

When Do You Need to Override ‘Actor Core.vi’ ?

To maintain an additional loop within the ActorTo guarantee certain actions are performed before

any messages are handledTo create a unique user interface for a specific Actor

Page 29: Elijah Kerry, Certified LabVIEW Architect (CLA)

Actor Framework Template Demonstration

Page 30: Elijah Kerry, Certified LabVIEW Architect (CLA)

Relationship between Messages and Actors

Messages call a method of an Actor

Messages encapsulate data for that method in the private data control

Messages are therefore coupled to that Actor, but not the children of that Actor

Children may have unique messages, but they are then coupled to those messages

Items Tree

File View

Page 31: Elijah Kerry, Certified LabVIEW Architect (CLA)

When Do you Need to Override Actor Core.vi ?

Message Handler

Do.vi

Do.vi

Do.vi

Free Running Event Driven

To maintain an additional loop within the ActorTo guarantee certain actions are performed before

any messages are handledTo create a unique user interface for a specific

Actor

Page 32: Elijah Kerry, Certified LabVIEW Architect (CLA)

Actor core.vi of Operator UI.lvclassOperator User Interface Block Diagram

Page 33: Elijah Kerry, Certified LabVIEW Architect (CLA)

Measurement Abstraction Layer Application

Page 34: Elijah Kerry, Certified LabVIEW Architect (CLA)

How do we communicate between all of these different ‘things’ ?

ControllerMeasureme

ntUser

Interface

Test Step Controlle

r

Headless Controlle

rDiode I-V Strain

Resistance

Operator Admin

Actor

Class hierarchy view

Measurement System Sample Project

Page 35: Elijah Kerry, Certified LabVIEW Architect (CLA)

Test Step Task Tree

Measurement

Controller Actor

User Interface

Task Tree

Result

Page 36: Elijah Kerry, Certified LabVIEW Architect (CLA)

Test Step

Request HW Msg.lvclass

Launch UI.vi

Launch UI Msg.lvclass

Launch UI Actor

Initialize.vi

Initialize Msg.lvclass

Hardware Scan.vi

HW Scan.lvclass

User Interface

Msmt Scan.vi

Msmt Scan.lvclass

Initialize.vi

Disp Msmt.vi

Matching HW.vi

Available HW Msg.lvclass

Display Hardware.vi

Initialize Msg.lvclass Get HW Info.vi

Msmt Selected

Check Validty.vi

Validate Selection.vi

HW Selected

Page 37: Elijah Kerry, Certified LabVIEW Architect (CLA)

Test Step

Request HW Msg.lvclass

Launch UI.vi

Launch UI Msg.lvclass

Launch UI Actor

Initialize.vi

Initialize Msg.lvclass

Initialize Msg.lvclass

Hardware Scan.vi

HW Scan.lvclass

User Interface

Msmt Scan.vi

Msmt Scan.lvclass

Initialize.vi

Disp Msmt.vi

Matching HW.vi

Get HW Info.vi

Available HW Msg.lvclass

Display Hardware.vi

Check Validty.vi

Validate Selection.vi

Msmt Selected

HW Selected

Page 38: Elijah Kerry, Certified LabVIEW Architect (CLA)

Check Validty.vi

Validate Selection.vi

Launch Msmt Msg.lvclass

Start Msmt.vi

Launch MeasurementMeasuremen

t

Send Run Rqst.lvclass

Send Run Request

Run Pressed

Initialize.vi

Configure.vi

Config Msmt Msg.lvclass

Acquire.vi

Acquire Msg.lvclass

Checkout HW.vi

Send Results Msg.lvclass

Receive Results.vi

Measure.vi

Measure Msg.lvclass

Stop Msmt Msg.lvclassClose.vi

Display Results Msg.lvclass

Display Results.vi

Checkin HW.vi

Page 39: Elijah Kerry, Certified LabVIEW Architect (CLA)

Creating a New Measurement

Page 40: Elijah Kerry, Certified LabVIEW Architect (CLA)

Measurement QSM

ConfigureAcquire

MeasureClose

We are going to override Acquire and Measure

=

Page 41: Elijah Kerry, Certified LabVIEW Architect (CLA)

LabVIEW Templates and Sample Projects

• Recommended starting points for common LabVIEW applications

• Clearly indicates where to add or change functionality

• Shows best practices for code design, documentation, and organization

• Add custom templates and sample projects

Page 42: Elijah Kerry, Certified LabVIEW Architect (CLA)

Checklist for Creating a Plugin

Project Name: Advanced Sample Project SessionMeasurement: NIWeek Demo

Methods: - Acquire- Measure

Hardware- Digital Multimeter (DMM)- Power Supply (PSU)

Page 43: Elijah Kerry, Certified LabVIEW Architect (CLA)

Creating a New Template

Required1. Create the source code for template2. Create the XML document for template

Optional: Scripting on Copied Code3. Create a custom scripting method to modify

template

Optional: Custom Create Project Dialog4. Override the MetaData object (resources folder)5. Create a new ‘Spec Page’ (must have required

inputs)

Information Available Here

Page 44: Elijah Kerry, Certified LabVIEW Architect (CLA)

The Basics of an Object Factory

AB

C Generic Measurement

Location on DiskWhere Measurements are Stored

Objects Loaded Into Memory

A B C

Parent

Children

Page 45: Elijah Kerry, Certified LabVIEW Architect (CLA)

More Information on Architectures and ProcessDedicated to LabVIEW Development and Software Engineering Practices

Getting Started with the Actor Framework

ni.com/actorframework

Online Community Dedicated to Development Best Practices

ni.com/community/largeapps

Follow My Blog on Software Engineering with LabVIEW

ekerry.wordpress.com

Follow me on Twitter

elijah286