KEMBAR78
LabVIEW Framework Design Guide | PDF | Library (Computing) | Class (Computer Programming)
0% found this document useful (0 votes)
97 views72 pages

LabVIEW Framework Design Guide

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views72 pages

LabVIEW Framework Design Guide

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

ni.

com | CUSTOMER CONFIDENTIAL 1


Designing a Framework in
LabVIEW – Borrow or Build
(Own Your Framework)
Nancy Jones, CLA
NI Field Architect – Americas Central West Region

ni.com
It’s About Saving Time

ni.com 4
“A Framework is an architecture
without the important bits.”- ShaunR on
lavag.org

ni.com
What is a Framework?

Distinguishing Features:
• Inversion of control – The overall program’s flow of control
is not dictated by the caller, but by the framework.
• Default behavior - A framework has a default behavior.
• Extensibility – A framework can be extended by selective
overriding or specialized by user code to provide specific
functionality.
• Non-modifiable framework code - The framework code, in
general, is not allowed to be modified. Users can extend the
framework, but not modify its code.

ni.com 6
The Bookends: QMH and AF

Is this where I start?

ni.com 7
Roadmap to Owning Your Framework
Learn
from
others Use
Plug-Ins Understand
Messaging Build or
borrow a
framework
Master
QMH
Explore a
Know framework
Domain & Explore
Team another
framework
Design For
Deployment

ni.com 8
Roadmap to Owning Your Framework
Learn
from
others Use
Plug-Ins Understand
Messaging Build or
borrow a
framework
Master
QMH
Explore a
Know framework
Domain & Explore
Team another
framework
Design For
Deployment

ni.com 9
Customer Needs a Sequential Test Solution

• Customer’s boss saw a cool demo that could scale and


do anything.
However…
• The framework was designed for asynchronous
processes, not sequential test applications.
• Simple test code was complicated and overly coupled to
the framework. o b l e m
th ep r
u i te d to i t 2 0 13
u l d b es L A S u mm
ti o n sho c k a t C
“Solu s R o e bu
” - C hr i a ris
a i n P
dom

ni.com 10
The Bright
Shiny Object

“Be wary of the cool


demo or the promise
that the framework
can do anything”

Gollum from Lord of The Rings

ni.com 11
Customer Hired a Consultant to Write a Basic, Three
Process Monitoring Application

• Customer received a very elegant, yet complex solution.

However…

• It was difficult for a decent CLD to understand the


solution, much less modify it.
• Therefore, the LabVIEW application was shelved.

ni.com 12
Becoming an Architect

“Software development takes


knowledge and skill. People do not
acquire this knowledge and skill
without spending years delivering
software…. With each day we get a
little more proficient in a specific
functional area” Chris Sterling -
Managing Software Debt

ni.com 13
Challenges for the Architects

Develop a modular and scalable framework such that a


development team that may have less experience can
successfully add or modify components of the framework.

Fully understand the problem domain such that


the framework, built or borrowed, fits the

X
application. Avoid shoving an application into a
framework

ni.com 14
Roadmap to Owning Your Framework
Learn
from
others Use
Plug-Ins Understand
Messaging Build or
borrow a
framework
Master
QMH
Explore a
Know framework
Domain & Explore
Team another
framework
Design For
Deployment

ni.com 15
So Now Where Do I Begin?

… perhaps we start at the end.

ni.com
Begin With the Deployed Application
How will the application be deployed? One monolithic
exe?
Main

Application - exe
UI Which components of the code
will need to scale?
Component Measure
How often will new components
Analyze be released?

How often will new, mostly


Report
similar applications be written?
Display

ni.com 17
What if only small changes will occur?
What if no component requires extensive scaling?
Continuous Measurement and Logging Sample Project
Main

UI

Measure

Analyze

Report

Display
What sample project
comes to mind?
ni.com 18
A customized Continuous Measurement
Logging application, with implementation
details removed, can be a very robust
framework and newer programmers can
immediately be successful.

ni.com
Scaling and Updating Components of an Application
However, what if most of the code remains the same, but
engineers will spend significant time modifying the analysis code
and potentially pushing out new versions of the analysis
modules.
Main
Analyze1
UI
Analyze2
Message

Measure
Call Analyze
Main remains an exe
and Analyze is deployed
Report as plug-ins that are
called by Main
Display

ni.com 20
Framework Overview
After further consideration, a high-level overview emerges...
???
Customized QMH Modular
Main.vi Analyze1

UI Analyze2

Message
???

Dynamic VIs Measure Scalable 1+N


Call Analyze XML Report

Display1
Call Report TDMS Report

Display2 Launch Displays


N

ni.com 21
Roadmap to Owning Your Framework
Learn
from
others Use
Plug-Ins Understand
Messaging Build or
borrow a
framework
Master
QMH
Explore a
Know framework
Domain & Explore
Team another
framework
Design For
Deployment

ni.com 22
Plug Ins – Where Do We Start?

What are the


characteristics
of the plug in?
How should
new modules Deployment Type
be deployed? • source, LLB, • function,
Source Vis, lvlib, lvlibp, library, process
DLL, exe
single file,
compiled?

Implementation
• static, VI Server, OO,
other

ni.com 23
Using and Deploying Modules with Packed
Project Libraries (.lvlibp)

• Develop .lvlib.
• Set access scope of subVIs as private
• Compile to PPL through build specifications
• Use the PPL from the project, just like project library

ni.com 24
Build Specifications for Application
• Main.vi is built into an exe and does not change.
• The Math.lvlibp is located in a support directory

ni.com 25
Update Without Recompiling exe
• Update the source in Math.lvlib
• Recompile the plug in to a new Math.lvlibp
• Copy compiled PPL into the support directory

ni.com 26
What are Plug-Ins?

• Plug-in architectures allow the extension of


features without changes to the main code
• New modules are detected and linked into the
application dynamically while the code is
running.
Main.vi Sine.vi

Call Wfm Triangle.vi

Square.vi

ni.com 27
Calling Plug Ins with VI Server Call by Reference

The type specifier VI refnum (strictly


typed) provides only the connector
pane information

Determine the VI to execute at run time.

ni.com 28
Plug In Libraries with OO
• Dynamically launch a series of functions
• TXT Report Library, XML Report Library, etc

Dynamic
Dispatch (or
polymorphism at
Class wire is self run time)
aware and
knows what type
of report it is.

ni.com 29
Plug In Libraries with OO
• Report Class is abstract and never instantiated
• TXT and XML Report are concrete child classes
• Easily extensible with no change to the Main.exe

Many Other
Report Types

ni.com 30
Development Process & Deployment

• Code exe and one


plug-in
• Code additional
Main.exe
child class
Report • Test child class
• Use factory to load
new child

XML Report TXT Report

How do we deploy TXT Report?


ni.com 31
Guidelines on Plug Ins

• Learn Plug Ins!


• Leverage Object Oriented Programming
• Carefully design the interface with scalability in mind
• Prototype the sub system that contains the plug in
• Evaluate pros and cons of distribution options
• Source
• Single file
• Compiled

ni.com 32
Roadmap to Owning Your Framework
Characterize Messages &
Learn Understand Messaging
from Challenges
others Use
Plug-Ins Understand
Messaging Build or
borrow a
framework
Master
QMH
Explore a
Know framework
Domain & Explore
Team another
framework
Design For
Deployment

ni.com 33
Extending the Framework – Messaging
The use case has changed, and the Measurement
component will reside in another application instance or on
another target.
Main

??? Analyze1
Measure UI

Message Analyze2

Call Analyze Report1


Display1
Call Report
Report2
Display2 Launch
Displays

ni.com 34
Data Communication: Different Categories of
Sharing Data Across Processes

• Store Data in memory during


program execution

• StreamData such as waveforms


• Send Messages from one
process to another

It is important to define the goal of the


communication method. Do I need to
send a message or store data?

ni.com 35
Specific Inter-process Communication Methods
Same target Same target, different application
Same application instance instances OR
Different targets on network

Storing - • Single-process shared • Network-published shared variables


Current variables (single-element)
Value • Local and global variables • CCC
• FGV, SEQ, DVR
• CVT
• Notifiers (Get Notifier)
Sending • Queues (N:1) • TCP, UDP
Message • User events (N:N) • Network Streams (1:1)
• Notifiers (1:N) • AMC (N:1)
• User Events • STM (1:1)
Streaming • Queues • Network Streams
• TCP

ni.com 36
Data Value Reference (DVR)
• Methodology to create a reference for any data type
• Provides a pointer to a common memory location
• Functions as global data modification and storage
When the wire This is a blocking call
forks, LabVIEW
makes a copy of
the reference,
not the data
In Place Element
Structure (IPE)

New Data Value


Reference

Both loops act on the shared memory location


ni.com 37
Create an API around the Native LabVIEW API

Encapsulate for
scalability and usability

ni.com 38
DVR - Storing Data or Sending a Message?

What does this


code look like?

Could I modify to
create a transport?
(Data item remains
in memory until
read by receiver)

ni.com 39
Demo
Messaging: Master the Native LabVIEW Data
Communication APIs

• Consider User
Events
• What happens when
you fork a Register
for Events?

• (What happens when you


obtain 2 separate queues
by name and destroy only
one?)

Take the Advanced Architectures in LabVIEWCourse on Self Paced Online Training


Learn about new User Event features in LabVIEW 2013

ni.com 40
Messaging: Design a Clean Shutdown

What happens when


the Stop button is
pressed while “process”
is executing?

The QMH template


implements a well
designed shutdown
process.

ni.com 41
Messaging: Ensure that External Messages Do Not
Interrupt Process Flow

External.vi Main.vi

External Message Main


Process Handler Process

Instead of allowing an external process to access the Main process queue


directly, consider adding code that manages the inbound messages and
determines the safe and appropriate time to enqueue the message on the
Main queue.
Don’t give your queue reference to just anyone!
ni.com 42
Do Queues Break Dataflow? No ;)

ni.com 43
Dataflow Safe

• A hand-off or transfer of data from one process to the next


• Never go back to retrieve the data!

Globals, locals, Single-


Element Queue design
patterns all let the the
originator of the hand-off
return and get the data
again.

ni.com 44
Attend the year Certified LabVIEW
Architect Summit to learn the latest
innovations in LabVIEW programming - a
free community-driven event, open to all current CLAs

ni.com
Roadmap to Owning Your Framework
Learn
from
others Use
Plug-Ins Understand
Messaging Build or
borrow a
framework
Master
QMH
Explore a
Know framework
Domain & Explore
Team another
framework
Design For
Deployment

ni.com 46
Other Frameworks (We Hope To See More Soon!)
• AF
• ALOHA We will cover a couple of frameworks that have
• Rex been presented at recent CLA Summits
• Extended Sessions Framework (Reference Designs on NI Community)
• Named Pipes (Mike Bailey, UK)
• LapDog (lavag.org)
• JAMA (lavag.org)
• Yet Another Messaging System (lavag.org)
• JKI - Beyond State Machines
• Message Pump (lavag.org)
• epimedia.com/products.php
• PTP Sequencer (NI Community)
• AQ Character Lineator (ni.com or NI Community)
• AMC (Reference Designs on NI Community)
• CVT (Reference Designs on NI Community)
• TLB/TLB’ (lavag.org)
• Featherweight
ni.com 47
Characterizing a Framework

Scope Single instance? Across instances/network?

Communication 1:1, 1:N, N:1, N:N, observer, chain of command…

OO How is it leveraged to achieve scalability?

Problem Message pipe? Process architecture? Other?

Ease of use Maintain and/or develop with framework?

ni.com 48
Actor Framework

• Ships with LabVIEW and is a supported product


• Details are covered in depth at ni.com/actorframework
and in various NIWeek presentations
• Requires careful design to fully leverage the benefits
• Ideally only one VI is not part of a class
• Every process and message is a separate class
• Development is ideally executed and maintained by very
strong LabVIEW architects
• Can inspire creative thinking about framework concepts,
even if AF is not well suited for the problem domain

ni.com 49
REx: Remote Exports – Architect Norm Kirchner

Messaging Pipeline: Send a message anywhere, local or


across the network, and receive (optional) a reply.

http://lavag.org/topic/17024-rex-remote-export-framework-and-remote-events/

ni.com 50
Demo

REx
• S - Same instance or across network
• C - Many to one messaging with a response

• OO - Allows for multiple message types

• P - Scalable messaging pipeline only. Integrates into your


architecture or framework
• E - Easy to use (Norm will maintain)

Note: Launch Listener First


ni.com 51
REx Messaging: Step 1
Remote VI sends message. It waits for the next
2 steps to execute before the message reply is received.

Like any well crafted framework, REx hides tremendous complexity. Deep
under-the-hood of the Remote Obtain, you will find VI server at work

ni.com 52
REx Messaging: Step 2
Listener receives message.

ni.com 53
REx Messaging: Step 3
Listener processes message and sends
reply.

ni.com 54
REx: Tool for Creating New Command

ni.com 55
Roadmap to Owning Your Framework
Learn
from
others Use
Plug-Ins Understand
Messaging Build or
borrow a
framework
Master
QMH
Explore a
Know framework
Domain & Explore
Team another
framework
Design For
Deployment

ni.com 56
ALOHA: Architect Craig Bedward
Goal: Develop
a framework
Agent 1 Agent 2
that defines
QMH communication
QMH
between QMHs
and facilitates
team
Broadcast Messaging development.

Agent 3 Agent 4

QMH QMH

ni.com 57
ALOHA: Each Component is a QMH

ni.com 58
Demo

SmartCom Messaging
Even directed messages are broadcast, but the recipient
knows who he is because the message is translated to
"this".

ni.com 59
ALOHA – Agent QMH Producer

ni.com 60
ALOHA - Agent QMH Consumer

ni.com 61
ALOHA Features

• All messages are broadcast


• Each Agent can chose to receive appropriate
messages.
• Common challenges are addressed
• Logging of errors to a database
• Sizing of displays for Agents Common code
• Common messages to system does not change!
• Careful ordering of shutdown

http://www.s5solutions.com
for download
ni.com 62
ALOHA – Framework Characteristics
• S - Same instance or across network
• C – Broadcast. Agents filter incoming messages.

• OO – Part of framework, invisible to developer

• P – Process architecture and message pipeline

• E - Easy to use for developer. Team lead will define


messages between modules.

Deep under-the-hood of the ALOHA SmartCom messaging system is a


named reference design.
There is an option to make communication across the network transparent.

ni.com 63
Wirebird Labs in Q4 2014

Architecture and Connectivity Outside LabVIEW!!!


ni.com 64
Actor Framework Design Quesitons
• What goes in Pre Launch Init?
• What is unique about Pre Launch Init?
• Where should references be closed?
• What is the shutdown strategy?
• Do I need the state pattern or is there simpler solution?
• What are the naming guidelines?
• How should I diagram my system?
• Do I override Actor Core?
• Do I really need a helper loop?
• How do I manage dynamic Actors

ni.com 65
Roadmap to Owning Your Framework
Learn
from
others Use
Plug-Ins Understand
Messaging Build or
borrow a
framework
Master
QMH
Explore a
Know framework
Domain & Explore
Team another
framework
Design For
Deployment

ni.com 66
Owning Your Framework – Documentation
Deliverables to Your Team

• Purpose of the framework


• Static components of the framework

• How to use the framework

• How the framework scales to various use cases

• Links to NI or the community for detailed technical


background on components of the framework.

The framework architect trains the team!

ni.com 67
Borrowed or Built - Own Your Framework

“Finally, you shouldn't be


uneasy about any parts of
the architecture. It shouldn't
contain anything just to
please the boss. It shouldn't
contain anything that's hard
for you to understand. You're
the one who'll implement it; if
it doesn't make sense to you,
how can you implement it?”
- Steve McConnell

ni.com 68
One Last Thought… Critique Your Framework

“It often brings me


down to Earth
because I realize my
own work product is
often imperfect and
penetrable.”

See the series on Humility and Better Programming at LabVIEWJournal.com

ni.com 69
New ideas pass through three periods: 1)
It can’t be done. 2) It probably can be
done, but it’s not worth doing. 3) I knew it
was a good idea all along! – Arthur C Clark

ni.com
Certification Path
SW
1 Hour 4 Hour Engineering 4 Hour
Multiple Practical in LabVIEW Practical
Choice Exam Exam

LabVIEW LabVIEW LabVIEW Advanced


Core 1 Core 2
CLAD
Core 3
CLD Architectures CLA

LabVIEW LabVIEW LabVIEW


FPGA Connectivity OOP

LabVIEW
Real Time

LabVIEW
Data Aq. &
Signal Cond.

LabVIEW
Instrument
Control

LabVIEW
Machine
Vision

LabVIEW
Modular
Instruments
ni.com 71
Missed the CLA Summit this year?
Get certified for next year!
The Certified LabVIEW Architect (CLA) Summit brings
together some of the world’s best NI LabVIEW programmers
to discuss architectures, preview new features, and network
with other CLAs and members of NI R&D.

Learn more at ni.com/cla-summit

Email certification@ni.com to register for


an exam near you.

ni.com 72
Thank You!
Nancy.Hollenback@ni.com

ni.com

You might also like