Top Banner
Justin Goeres Senior Engineer & Product Marketing Manager JKI PUSHING THE LIMITS OF LABVIEW Beyond State Machines: Building Modular Applications in LabVIEW Using Public & Private Events Monday, August 8, 11
41

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

May 21, 2015

Download

Technology

JKI

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.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: NIWeek 2011: Beyond State Machines / Building Modular Applications in LabVIEW (JKI)

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

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

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

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

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

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

A Public & Private Events Framework

4

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Agenda

What is it?

5

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Agenda

What is it?How does it work?

5

Monday, August 8, 11

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

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

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

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

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

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

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

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

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

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

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

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

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

How Does it Work?

9

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Process VI & Public Events

10

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Process VI & Public Events

Shift register for private module data(“State”)

10

Monday, August 8, 11

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

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

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: Sending Information OUT

Process VI generates a Public Event...

11

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: Sending Information OUT

Process VI generates a Public Event...

11

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: Sending Information OUT

Process VI generates a Public Event...

11

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: Sending Information OUT

Process VI generates a Public Event...

11

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public Events: Sending Information OUT

Process VI generates a Public Event...

11

Monday, August 8, 11

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

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

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

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

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

The Public API

Public API VIs...

...generate Private Events...

14

Monday, August 8, 11

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

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

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

15

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

15

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

15

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

15

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

Only our Process VI can receive thisPRIVATE event

15

Monday, August 8, 11

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Public API / Private Events

Process VI registers for“Private Events” at initialization

16

Monday, August 8, 11

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

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

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

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

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

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

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

MainApp

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Everything is a Module

AnalogInput

MotorController

LeakDetection

EKGAnalysis

21

Monday, August 8, 11

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

MainApp

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Everything is a Module

AnalogInput

MotorController

LeakDetection

EKGAnalysis

21

Monday, August 8, 11

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

MainApp

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

Everything is a Module

AnalogInput

MotorController

LeakDetection

EKGAnalysis

MainApp UI

21

Monday, August 8, 11

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

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

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

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

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

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

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

PUSHING THE LIMITS OF LABVIEW | JKI CONFIDENTIAL

The End!

Discussion!

25

Monday, August 8, 11