NIWeek 2011: Beyond State Machines / Building Modular Applications in LabVIEW (JKI)

Post on 21-May-2015

4486 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Slides for presentation given by Justin Goeres at NIWeek 2011. Learn about a template for inter-process communication that’s easy enough for Intermediate developers, but powerful and flexible enough for CLAs. Nearly every significant LabVIEW-based application uses multiple loops and multiple pieces of hardware. Without a clear design pattern, coordinating all these moving pieces is a recipe for spaghetti code. In this presentation, we introduce an elegant, powerful, and easy-to-use template for inter-process communication based on the concept of “Public” and “Private” events.

Transcript

Justin GoeresSenior Engineer & Product Marketing ManagerJKI

PUSHING THE LIMITS OF LABVIEW

Beyond State Machines:Building Modular Applications in LabVIEW Using Public & Private Events

Monday, August 8, 11

1. Vote with your feet.

2. Please turn on your smartphones.

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Rules

@JustinGoeres is going Beyond State Machines at #niweek!

2

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Let’s Get This Straight

User Events are a very easy-to-use feature with a lot of cool functionality.They form the basis of JKI’s primary application frameworks & templates.If we could get a couple things fixed/added to LabVIEW, we could do even better.

3

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

A Public & Private Events Framework

4

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Agenda

What is it?

5

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Agenda

What is it?How does it work?

5

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Agenda

What is it?How does it work?What’s it good for?

5

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Agenda

What is it?How does it work?What’s it good for?What’s it bad at?

5

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Agenda

What is it?How does it work?What’s it good for?What’s it bad at?How can you use it in your projects?

5

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

What is it?

A “module” has: Statefulness / private data Asynchronous process(es) Public API Public Events

6

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Key Benefits

Module knows nothing about who’s consuming the data it producesLightweight & easy to useCompatible with by-ref and by-val architectures

7

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Client Code is Simple

Start Process & register for Public

EventsInvoke Public API

as neededExit Modulewhen done

8

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

How Does it Work?

9

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Process VI & Public Events

10

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Process VI & Public Events

Shift register for private module data(“State”)

10

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Process VI & Public Events

Shift register for private module data(“State”)

Generate a “Public Event” when “something happens”

10

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: Sending Information OUT

Process VI generates a Public Event...

11

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: Sending Information OUT

Process VI generates a Public Event...

11

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: Sending Information OUT

Process VI generates a Public Event...

11

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: Sending Information OUT

Process VI generates a Public Event...

11

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: Sending Information OUT

Process VI generates a Public Event...

11

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: Sending Information OUT

Process VI generates a Public Event...

...which is received by any other Event Structure that’s registered for

it.

11

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: One to Many

Process VI generates a Public Event...

...that can be received by any number of consumers!

12

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

The Public API

Public API VIs...

...generate Private Events...

14

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

The Public API

Public API VIs...

...generate Private Events...

...that are handled by the asynchronous Process VI

14

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

15

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

15

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

15

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

15

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

Only our Process VI can receive thisPRIVATE event

15

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

Process VI registers for“Private Events” at initialization

16

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

When the Process VI receives a Private Event, it responds

appropriately.

17

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Putting it All Together

Client code invokes Public API

Client code registers for Public

Events

19

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Putting it All Together

Start Process & register for Public

EventsInvoke Public API

as neededExit Modulewhen done

20

Monday, August 8, 11

MainApp

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Everything is a Module

AnalogInput

MotorController

LeakDetection

EKGAnalysis

21

Monday, August 8, 11

MainApp

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Everything is a Module

AnalogInput

MotorController

LeakDetection

EKGAnalysis

21

Monday, August 8, 11

MainApp

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Everything is a Module

AnalogInput

MotorController

LeakDetection

EKGAnalysis

MainApp UI

21

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Extensions & Tweaks

Use with by-value & by-ref objectsCommunity & Protected EventsDynamically unregister / reregisterSynchronous communication

22

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Things That Suck

Most annoying bug ever. Fixed in LV2011!No Event queue management or introspectionNo Notifier-like behavior (“ignore previous”)

23

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Take Home Point

User Events are a very easy-to-use feature with a lot of cool functionality.They form the basis of JKI’s primary application frameworks & templates.If we could get a couple things fixed/added to LabVIEW, we could do even better.

24

Monday, August 8, 11

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

The End!

Discussion!

25

Monday, August 8, 11

top related