darwin applied to labview: the evolution of the data management

Post on 25-Jul-2016

223 Views

Category:

Documents

6 Downloads

Preview:

Click to see full reader

DESCRIPTION

The survival of the fittest applied to the LabVIEW Dataflow model... With deep humor this presentation makes the link between the evolution of the LabVIEW data and the Darwin's Theory of Evolution. PS : You can download the presentation Darwin applied to LabVIEW V2.1.pdf attachment and LabVIEW examples code. Recently, I made a new presentation (LabVIEW User group LUGE) "Darwin applied to LabVIEW: the evolution of the data management." subtitle “The survival of the fittest applied to the LabVIEW Dataflow model ”. For diner tonight: Functional Global variable (FGV, LV2), Action Engine (AE), DVR, OOP, State Machine and QMH. Speed demonstration, UI thread, memory management (buffer copies) and Race Condition with simple and downloadable examples. Auteur livre LabVIEW "Programmation et applications" édition Dunod, jusqu'au niveau pour l'examen CLD Luc Desruelle CLA : Certified LabVIEW Architect / Certifié Architecte LabVIEW

TRANSCRIPT

www.mesulog.fr

Darwin applied to LabVIEW :

The evolution of the data management

Luc DESRUELLE – Certified LabVIEW Architect

The survival of the fittest applied to the LabVIEW Dataflow model

Summary

I. MESULOG & the conference speaker

II. Overview: Dataflow model & Data communication

III. Darwin & LabVIEW

IV. Darwin & Data communication methods

V. To OOP

VI. To Framework

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 2

MESULOG

www.mesulog.fr

Activity: Test and measurement Software development

Skills: LabVIEW (Windows, RT, FPGA, PDA, DSC),

TestStand

VeriStand

Location: Grenoble (France)

National Instruments Alliance Member

LabVIEW and TestStand Certified

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 3

Luc DESRUELLE

Software Architect

NI Forums Community

CLA

The conference speaker

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 4

Community blog

• Blank diagram syndrome

• Development rules

• Animated gif to avoid code

• Transparent Windows

• LabVIEW Project

• OOP

• Modbus

• ….

Author of the LabVIEW French book « LabVIEW : programming and applications »

3rd Edition, Dunod 05/2015, Prefaced by Jeff Kodosky

book website link

Chapter 1: LabVIEW EDI and dataflow programming environment

Chapter 2: Data communication methods

Chapter 3: Advanced knowledge and skills to design, develop and deploy a

scalable, readable and maintainable application .

Chapters 4, 5 and 6: Data acquisition, analysis and report.

The conference speaker

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 5

II] Overview

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 6

LabVIEW Dataflow model

LabVIEW follows a dataflow model

Dataflow programming does not usually require variables.

For a literal implementation of this model.

Dataflow models describe nodes as:

consuming data inputs

producing data outputs.

Advanced concepts : LabVIEW contains many data communication methods.

For example, local and global variables are not inherently part of the LabVIEW

dataflow execution model.

Darwin applied to LabVIEW : The evolution of the data 7

Source: Data Communication Methods in LabVIEW

"Always" the same observation

LabVIEW Rookie mistakes:1 time OK

But Exaggeration prevents the evolution

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 8

LabVIEW

Spaghetti

The most famous LabVIEW code

Data Communication Methods

LabVIEW contains many “data communication” methods, each suited for a

certain use case.

Can by order into 3 types:

Dataflow elements, the primary methods

Variable Interfaces

Buffer Interfaces

Darwin applied to LabVIEW : The evolution of the data 9

Source: Data Communication Methods in LabVIEW

Dataflow Elements

• Wire

• Shift register

• Feedback Node

Variable Interfaces

• Local variable

• Global variable

• FGV

• AE

• DVR

• …

Buffer Interfaces

• Queue

• User events

• RT FIFO

• …

Data Communication methods

The presentation

Evolution of Data communication methods,

Dataflow element to Variable Interfaces, to Buffer Interfaces

To store a value in memory

To access the value

This presentation does answer the following questions:

why avoiding local, global, Property Node?

Which method to use? Why?

For diner tonight: local, global, FGV, AE, DVR, OOP, State Machine and QMH.

Speed demonstration, UI thread, memory management (buffer copies) and Race

Conditions with simples and downloadable examples.

Darwin applied to LabVIEW : The evolution of the data 10

III] Darwin & LabVIEW

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 11

Darwin

Charles Robert Darwin (1809 – 1882)

All species of life have descended from one common

ancestor

This branching pattern of evolution resulted from the

natural selection

The survival of the fittest

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 12

With deep humor this presentation makes the link

between

the evolution of the LabVIEW data management

and the Darwin's Theory of Evolution

the survival of the fittest

Darwin & LabVIEW

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 13

Darwin LabVIEW

One common ancestor LabVIEW Control

All species of life All data communication methods

The survival of the fittest The survival of the most scalable

II] Data communication

Once upon a time…. A very nice Data…

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 14

Dataflow elements

Data transfer

To take advantage of the dataflow

The primary data communication methods in your

application

Darwin applied to LabVIEW : The evolution of the data 15

Dataflow Elements

Dataflow Elements

•Wire = between objects

• Shift register = between loop iterations

• Feedback Node = between iterations

Variables Interfaces

Store a value in memory

Value that Readers and writers can access

Advanced concepts

Darwin applied to LabVIEW : The evolution of the data 16

Dataflow Elements

Variable Interfaces

• Local variable

•Global variable

•…

•…

Variables interfaces

others…

Quiz N°1

CLAD exam: Which of the following is the best method

to update an indicator on the front panel?

A. Use a Local variable

B. Wire directly to the indicator « Data Out »

C. Use an implicit « value » property node

D. Use an explicit « value » property node (reference)

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 17

Quiz N°1 Demo: Execution speed

Demo

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 18

For 10 000 iterations Time (ms)

Indicator 100

Local 100

Global 100

Property node (implicit) 4 000

Property node (explicit) 4 000

0

500

1000

1500

2000

2500

3000

3500

4000

4500

Indicator Local Global Property

node

(implicit)

Property

node

(explicit)

Quiz N°1: Explanation

Synchronous nodes

A few nodes are synchronous, meaning they do not multitask

with other nodes.

In a multithreaded application, they run to completion, and the

thread in which they run is monopolized by that task until the

task completes.

Property Nodes

Synchronize with the UI thread, even for the Value property

Cause the front panel of a subVI to remain in memory

Force a front-panel redraw every time you update the value

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 19

Source: Multitasking in LabVIEW

Quiz N°1 Front panel in memory

When front panel is in memory: which can cause

unnecessary memory usage -> Buffer copies

Programmation Avancée sous LabVIEW 20

Buffer copy

Operate Buffer

Transfer Buffer

Execution Buffer

Buffer copy

Quiz N°1 Explanation

Memory consideration

Local variables make copies of the data buffers

Global variables make copies of the data buffers

Have slower execution speed than using a wire

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 21

Quiz N°1 Property node VS local

Property node Buffer copies

UI Thread

Front panel redraw

Synchronous node

Front-panel in memory

Race Condition

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 22

Local variable

Buffer copies

Any Threads

Race condition

V.S.

Quiz N°1: Answer

1. Indicator

2. Local variable

3. Implicit property node

4. Explicit property node

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 23

Quiz N°2

To store the variable "Data In", what is best? Wiring

“Data In” to:

A. Local variable « Data Out »

B. Global variable « Data »

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 24

Quiz N°2 Answer

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 25

Local variable VS Global variable

The game is a draw

Overview

Avoid local variables – global variables - property nodes

Buffers Copies

Slower execution

Race Conditions

No error handler

1 time OK but Exaggeration prevents the evolution

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 26

How to avoid local variables, global variables and

property nodes

How ????

To avoid

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 27

FGV : Functional Global Variable or LV2

Provide global access to data

VI that uses uninitialized shift register (USR)

Non reentrancy is required

To store a data: Set (Writers)

To share the « global » data: Get (Readers)

FGV: Functional Global Variable

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 28

Writer Reader

Quiz N°3

Why the names :

FGV or LV2 Style Global or VIGlobals or….?

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 29

Quiz N°3 Answer : HIStory

Same as: HIStory World Tour (Michael Jackson 1997)

LabVIEW HIStory Version Tour: FGV or LV2 Style

Global or VIGlobals?

Prior to LabVIEW 2: the value of the initialized shift register

had not been defined.

LabVIEW 2: uninitialized shift register would retain its

previous value.

This technique became the methodology for storing global

data in LabVIEW.

The native global variable was not introduced until

LabVIEW 3.

FGV is a Global… VIGlobal

Source: Advanced Architectures in LabVIEW

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 30

FGV: Example

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 31

2 cases:

> Set = Store

> Get = share

Store data

Race conditions

Race conditions ?????????????

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 32

Race conditions

Race conditions: The evolution of the fittest

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 33

Race condition: a bug

Race condition or race hazard: output is dependent on

the sequence of other uncontrollable events.

The term originates with the idea of two signals racing

each other to influence the output first.

Unpredictable outcomes = A bug!!!!

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 34

Data Out = ??

X=1 or 0

Y=1 or 0(0;0) or (0;1)

or (1;0) or(1;1)

X=0 et

Y=0

Source : https://en.wikipedia.org/wiki/Race_condition

Quiz N°4

Does FGV prevents the Race Conditions?

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 35

Data Out = ??

X = ?

Y= ?

Data In

X = 0

Y= 0

Quiz N°4: Result

No (with multi-writers)

LabVIEW code demo

Download code MESULOG website >> Société >> Présentations Techniques

www.mesulog.fr/presentations_techniques

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 36

FGV: recommended Use

Only 1 writer

N Readers

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 37

To share a « global » data: only 1 writer

Race conditions & N Writers

N Writers (not only 1 writer)

How to Avoid Race conditions ?????????????

N Writers

N Readers

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 38

AE : Action Engine : FGV evolution with actions

Not only set and get methods

Actions = Encapsulate data and code = block other instance

until complete execution

Actions that modify data = critical section

Data protection: private access, data is always private

AE : Action Engine

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 39

AE : Action Engine

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 40

EncapsulationAction that modify the dataData is always private

AE: Example

Example

FGV + Actions (enum)

Reusable modules – simplified LV code – Error Handler –

more readable

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 41

LV Code that

modify the

data

ActionsStore Data

(private)

Quiz N°5

Does AE prevents Race Conditions?

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 42

Data Out = ??

X = ?

Y= ?Data In

X = 0

Y= 0

Quiz N°5: Answer

YES

Encapsulation: LV Code that modify the data, data is

always private = prevents Race Conditions

LabVIEW code demo

Download code MESULOG website >> Société >> Présentations Techniques

www.mesulog.fr/presentations_techniques

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 43

Reference

Reference

Reference

DVR: Data Value Reference

Reference is a pointer to the data

Wire is the reference, not the data

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 44

Data Copy

Data Copy

Data

Avoid Race Conditions

Quiz N°5

Which of the following statements regarding the DVR

are true:

A. Forking creates a copy of the reference, not a copy of the

data

B. Avoid data copies

C. Avoid Race conditions

D. Allow error handler

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 45

Quiz N°5: Answer

A, B, C & D are all true

LabVIEW code demo

Download code MESULOG website >> Société >> Présentations Techniques

www.mesulog.fr/presentations_techniques

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 46

Overview: variable interfaces

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 47

Variable Interfaces

1 time OK but Exaggeration prevents the evolution

The evolution of the fittest• N Writers• Reusable modules• Error Handler• Avoid data copies• Avoid Race Conditions

Overview: variable interfaces

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 48

Features - Scalable

Simplicity

to Buffer Interfaces

To avoid overwriting or losing any value

Buffer Interfaces, for example: Queue

Darwin applied to LabVIEW : The evolution of the data 49

Enqueue Element

Obtain Queue

Dequeue Element

Release Queue1 2 4

3

1 2 3 4

to go further with the… evolution

Darwin applied to LabVIEW : The evolution of the data 50

Data communication

Dataflow Elements

Wire

Shift register

Feedback Node

Variable Interfaces

Inter-Target

Local & Global

FGV -> AE

DVR

Networked Shared variable

Buffer Interfaces

Intra-TargetQueue

User events

NetworkedTCP

Network Streams

Data communication methods in LabVIEW (without RT and FPGA)

V] OOP

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 51

From variable interfaces to OOP

Variable Interfaces

OOP

OOP

A class is a collection of data (attributes) and methods that allow to

change these data

Attributes are private

Encapsulation

Inheritance

Dynamic dispatch

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 52

Class

Attributes

methodsCode

LabVIEW and OOP

OOP is a evolution from the AE (according to Darwin)

Shift Register become “attributes”

Actions become “methods”

Native LabVIEW class = by value

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 53

Action n°1

= case 1

Action n°2

= case 2

Action …

= case

1. Data = shift register

2. Actions = states

Actions = methods

1 method = 1 vi

AE = Action Engine

OOP

More advanced concepts:

Inheritance

Dispatch dynamic

Quiz N°6

Does OOP by Value prevents Race Conditions?

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 54

Data Out = ??

X = ?

Y= ?

Data In

X = 0

Y= 0

Quiz N°6: answer

OOP by Value? No

Forking creates a copy of the data

LabVIEW code demo

Download code MESULOG website >> Société >> Présentations Techniques

www.mesulog.fr/presentations_techniques

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 55

To OOP by Ref

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 56

OOP by Ref

Quizz N°7

OOP by Ref prevents the Race Conditions?

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 57

Résultat Quizz N°7

Yes

Forking creates a copy of the reference, not a copy of the data

Démonstration code LabVIEW

Code téléchargeable sur le site MESULOG >> Société >> Présentations Techniques

www.mesulog.fr/presentations_techniques

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 58

VI] Framework

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 59

Evolution to framework…

Framework

Variable Interfaces

Action Engine (AE): execute only one action then

stops

Need to add transitions to perform multiple actions

Need to describe a “Moore Machine”?

More “scalable” ?

The evolution of the Action to the state

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 60

Moore Machine or State Machine

Darwin applied to LabVIEW : The evolution of the data 61

InitCheck

statusCleanup

Measure

5000 ms

125ms

Quit buttondefault

Transitionswhich state to go to next

Moore Machine

Idle Cleanup

Quit button

« state & transition »

States = performs a specific action for each state in the

diagram

Transition = in-state calculation to determine which state to go

to next

A terminal state is the final state executed and performs

cleanup actions.

Any algorithm described by a “Moore machine”

State Machine

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 62

InitCheck

statusCleanup

Measure

5000 ms

125ms

Quit bouton

default

Source : white-paper State Machine

State Machine: grey's anatomy

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 63

Shift register to store the

value of the current state

The case structure contains one frame

for each state (Moore Machine)

Shift register to store

private data

Next state : contains state transition

information, which state to go to next

Typdef EnumFirst State Next State

State

?

Code

While Loop

State Machine: LabVIEW Example

Demo

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 64

InitCheck

statusCleanup

Measure

5000 ms

Quit bouton

default

Demo

State Machine: LabVIEW Example

Darwin applied to LabVIEW : The evolution of the data 65

One frame for each

State

Loop Timing

Shift register

State Machine: Overview

One of the fundamental LabVIEW architectures

(basic!)

Use to build applications quickly (Moore Machine)

Source CLAD exam: What is one disadvantage of

using the State Machine VI architecture?

If two state changes occur at the same time, only the first

state change will be handled and the second will be lost

Why?

Shift register is used to store the value of the next state

Shift register store only the current value

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 66

State Machine: evolution?

It is important to avoid losing any value…

No shift register

No variable interfaces

Evolution???

You must use:

Buffer interfaces

FIFO queue for example

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 67

Evolution? Queue State machine

Darwin applied to LabVIEW : The evolution of the data 68

Queue State Machine

FIFO Queue

Other? Event Structure

For handling user interactions

Dialog box for example

Waits until an event happens, then executes the appropriate

case to handle that event.

Optional Timeout (wait for an event to occur)

Darwin applied to LabVIEW : The evolution of the data 69

Event structure example

Darwin applied to LabVIEW : The evolution of the data 70

Other? Producer/Consumer

For data sharing between multiple process

Two process categories:

those that produce data,

those that consume the data produced.

Data buffering:

Data queues (Message)

Communicate data between loops

Darwin applied to LabVIEW : The evolution of the data 71

QMH

Darwin applied to LabVIEW : The evolution of the data 72

QMH: Queue Message Handler

QMH: a combination of all

QMH: Queue Message Handler

Is a combination of (evolution of!)

producer/consumer

event handler

state machine

Overview

multiple sections of code (task)

running in parallel

sending data (Message) between them (Queue)

Error handling

Project organization

Darwin applied to LabVIEW : The evolution of the data 73

= State (required)

= Data (optional)

QDMH

Grey's anatomy

1. The producer loop (EHL) contains an event structure that sends

messages to the consumer loop.

2. The consumer (MHL) receives and processes the messages in

a state machine.

3. A message can be triggered by UI events or from other states

in the state machine

Provides a powerful and efficient architecture

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 74

Source : white-paper QMH

State Machine: grey's anatomy

demo

Darwin applied to LabVIEW : The evolution of the data 75

2_Send a message

1_Obtain Queue3_ receives the

messages 5_can add a

message

4_ executes the

appropriate

case

Shift register to store

private data

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 76

The End: Exaggeration prevents the evolution

Framework

Variable interfaces

OOP

Dataflow Elements

Buffer Interfaces

Inter-Target

Inter-Target

Networked

Networked

The survival of the most scalable

More speaker Links

More technical presentationswww.mesulog.fr/presentations_techniques

National Instruments : luc desruelle's Blogue

Tutorials developpez.com : luc Desruelle

tools that wish you well (Best practices for managing large LabVIEW applications)

More French book"LabVIEW programmation et applications" 3iéme édition, Dunod

More National Instruments Francophone websitesForum francophone NI LabVIEW

Forum francophone Autres produits NI

Communauté Francophone

Luc Desruelle | LinkedIn

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 77

Where to find help?

Community is working for you

2 NI “Francophone” Forums http://forums.ni.com/t5/Discussions-au-sujet-de-NI/bd-p/4171

http://forums.ni.com/t5/Discussions-au-sujet-des-autres/bd-p/4170

1 “Francophone” community https://decibel.ni.com/content/community/regional/france/labview

Rencontre développeurs : cf LUGE

And… All websites forums et communities, for example LabVIEW Development Best Practices

Large Applications : ni.com/largeapps

LAVA

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 78

MESULOG: About us

www.mesulog.fr

Past projects

Technical Presentations

LabVIEW

TestStand

VeriStand

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 79

Past projects

Company -> Technical Presentations

MESULOG: Our customers

Our customers:

ALSTOM Grid

AREVA NP

CEA (Commissariat à l'Énergie Atomique)

CETIAT (Centre Technique des Industries Aérauliques et Thermiques)

CNES (Centre National d'Études Spatiales)

CNRS (Centre National de la Recherche Scientifique)

EDF

HONEYWELL Security

LNE (Laboratoire National d'Essais)

ONERA

PECHINEY

RADIALL

RENAULT

STMicroelectronics

THALES Alenia Space

THALES LCD...

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 80

Questions

Luc DESRUELLE - Darwin applied to LabVIEW : The evolution of the data 81

top related