73

Click here to load reader

LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

Embed Size (px)

Citation preview

Page 1: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

LabVIEW User GroupUniversity of Bristol

Ben LavasaniAcademic Field Sales Engineer

NI UK

Page 2: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

2

Page 3: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

3

Agenda

• LabVIEW Design Patterns Overview• Coffee break :)• LabVIEW for Multi-Touch Applications - David Carberry• LabVIEW in Teaching • LabVIEW Tips and Tricks

Page 4: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

LabVIEW Design Patterns Overview

Page 5: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

5

What Is a Design Pattern?

• A template or framework for LabVIEW code• Widely accepted and well-known• Easily recognizable

Page 6: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

6

Benefits of Using Design Patterns

Simplify the development process Developers can easily understand code Don’t have to “re-invent the wheel” Pre-existing solutions to common problems

Reliability Many have been used for years - they are “tried and true” Large development community and resources online

Page 7: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

7

Getting Started: How Do I Pick?

• Identify most important aspect of your application: Processes that require de-coupling Clean, easy to read code Mission critical components

• Select a template based upon potential to improve

Page 8: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

8

Caution

You can needlessly complicate your life if you use an unnecessarily complex design pattern

Don’t forget the most common design pattern of all… dataflow!

Page 9: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

9

Basic Tools• Loops• Shift Registers• Case Structures• Enumerated Constants• Event Structures

Page 10: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

10

Today’s Discussion

• As we look at each design pattern, we’ll discuss A problem we are trying to solve Background How it works Technical implementation Demonstration Use cases / considerations

Page 11: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

11

Design Patterns

• Functional Global Variable• State Machine / Statecharts• Producer / Consumer

Page 12: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

Functional Global Variables

How do I share data across a application without using Global or Local Variables?

Page 13: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

13

Background: Global and Local Variables

• Can cause race conditions• Create copies of data in memory• Cannot perform actions on data• Cannot handle error wires

Page 14: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

14

Breaking Down the Design Pattern

• While loop• Uninitialized shift

registers have memory• Case structure• Enumerated control

Page 15: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

15

DEMOUninitialized Shift Registers

Page 16: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

16

How It Works: Basic Actions

• Set the value of the shift register

INITIALIZE

INITIALIZE

Page 17: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

17

How It Works: Basic Actions

• Get the value currently stored in the shift register

GET

GET

Page 18: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

18

How It Works: Action Engine

• Perform an operation upon stored value and save result

• You can also output the new value

ACTION

ACTION

Page 19: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

19

1. Functional Global Variable is a Non-Reentrant SubVI2. Actions can be performed upon data3. Enumerator selects action4. Stores result in uninitialized shift register5. Loop only executes once

Technical Implementation

Page 20: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

20

DEMOFunctional Global Variables

Uninitialized shift register has memory

Action determines which case is executed

Only used in Initialize case

Loop only executes once

Examples of other ‘actions’

Page 21: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

21

Benefits: Comparison

Global and Local Variables• Can cause race conditions• Create copies of data in memory• Cannot perform actions on data• Cannot handle error wires• Drag and drop

Functional Global Variables• Prevent race conditions• No copies of data• Can behave like action engines• Can handle error wires• Take time to make

Page 22: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

22

Recommendations

Use Cases• Communicate data between code without connecting wires• Perform custom actions upon data while in storage

Considerations• All owning VIs must stay in memory• Use clusters to reduce connector pane• Using stacked shift registers will track multiple iterations

Page 23: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

State Machine

I need to execute a sequence of events, but the order is determined programmatically

Page 24: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

24

Background

Dynamic Sequence: Allows distinct states to operate in a programmatically determined sequence

Static Sequence

Page 25: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

25

Soda Machine

Initialize

Wait

Change QuarterDime

Nickel

Exit

Vend

Soda costs $0.50

No input

Quarter Deposited

Total < 50

Total >= 50

Change Requested Dime Deposited

Nickel Deposited

Total < 50 Total < 50

Total >= 50Total >= 50

Total > 50

Total = 50

Page 26: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

26

Breaking Down the Design Pattern

• Case Structure inside of a While Loop• Each case is a state• Current state has decision making code that

determines next state• Use enumerators to pass value of next state to

shift registers

Page 27: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

27

Transition Code

How It Works

FIRST STATE

FIRST STATE

NEXT STATE

Step Execution

Shift registers used to carry state

Case structure has a case for every state Transition code determines next state based upon results of step execution

Page 28: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

28

Transition Code Options

Step Execution

Step Execution

Step Execution

Page 29: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

29

DEMOState Machine

Page 30: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

30

Recommendations

Use Cases• User interfaces• Data determines next routine

Considerations• Creating an effective State Machine requires the

designer to make a table of possible states.• Use LabVIEW Statechart to abstract this process for

more sophisticated applications

Page 31: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

Producer / Consumer

I have two processes that need to execute at the same time, and I need to make sure one can’t slow the other down

Page 32: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

33

How It Works• One or more slave loops are told by

a master loop when they can run• Allows for a-synchronous execution

of loops• Data-independence breaks dataflow

and allows multi-threading• De-couples processes

Slave 1

Slave 2

Master

Page 33: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

34

Breaking Down the Design Pattern

• Data independent loops = Multithreading• Master / slave relationship• Communication and synchronization between

loops

Page 34: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

35

Loop Communication

• Variables• Occurrences• Notifier• Queues• Semaphores• Rendezvous

Page 35: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

36

QueuesAdding Elements to the Queue

De-queueing Elements

Reference to existing queue in memory

Select the data-type the queue will hold

Dequeue will wait for data or timeout (defaults to -1)

Page 36: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

37

Producer / Consumer

Page 37: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

38

Adding Your Own Design Patterns

C:\Program Files\National Instruments\LabVIEW 8.5\templates\Frameworks\DesignPatterns

Page 38: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

39

Resources

• Example Finder• New >> Frameworks >> Design Patterns• ni.com/labview/power• Expressionflow.com

• Visit ni.com/info and enter exhkqe

Page 39: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

40

Page 40: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

41

LabVIEW in TeachingThe NI LabVIEW Academy

Page 41: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

42

The NI LabVIEW Academy program provides classroom curriculum, instructional materials, and hands-on exercises to high schools, community colleges, and universities for the specific purpose of teaching LabVIEW.

LabVIEW Academy is for anyone seeking LabVIEW education and knowledge through an academic institution.

What Is the NI LabVIEW Academy?

Page 42: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

43

What Does the NI LabVIEW Academy Do?

Increases the pool of qualified LabVIEW developers

Emphasises LabVIEW professional certification

Empowers institutions to teach LabVIEW

Page 43: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

44

Instructor Requirements

Two instructors must be Certified LabVIEW Associate Developers (CLADs) and teach at participating organisations

NI LabVIEW Academy Program Requirements

Program Requirements• Current teaching site license• At least one dedicated classroom (a computer lab will suffice)• 40 hours of classroom LabVIEW specific instruction time• One PC per student (with LabVIEW software) • NI DAQ equipment required for lab component (2:1 student ratio)• Submit course syllabus to NI for approval

Page 44: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

45

Instructor Materials

•LabVIEW Basics I & II Instructor Manual•LabVIEW Basics I & II Lecture Slides•LabVIEW Basics I & II Exercises and Solutions•Instructor Version of Student Workbook•50 LabVIEW Exam/Homework Questions

NI LabVIEW Academy Instructional Materials

Student Materials

•LabVIEW Academy Workbook (student purchase)• 300+ questions

•Recommended LabVIEW textbook (student purchase)

Page 45: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

46

NI LabVIEW Academy Teaching Materials

Curriculum for both learning LabVIEW and teaching LabVIEW

Recommended LabVIEW Textbooks

NI LabVIEW Academy Teaching Materials

Page 46: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

49

NI LabVIEW Academy CLAD Opportunity

The NI LabVIEW Academy gives students the opportunity to take the CLAD exam as part of the program

Page 47: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

50

“LabVIEW is getting more popular in academia and industry and many researchers and companies are on the lookout for competent LabVIEW programmers. This program will help bridge the gap between the two.”

– Khanjan Mehta, Professor, Penn State University

“In our exhaustive search for qualified LabVIEW developers to fill key roles in our organization, we greatly anticipate the new pool of qualified candidates coming out of the National Instruments LabVIEW Academy schools.“

– Marvin Landrum, Section Manager, Texas Instruments

Academic Industry

The NI LabVIEW Academy Bridging the Gap

Page 48: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

51

ni.com/academy

Page 49: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

52

Page 50: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

Tips and Tricks to Speed NI LabVIEW DevelopmentUseful Nuggets to Save You Time

Page 51: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

54

Agenda

• 20 Tips and Tricks for LabVIEW Development Beginner: Simple tricks to save time Intermediate: LabVIEW tips you probably did not know about Advanced: Useful nuggets to put you ahead of the game

Page 52: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

55

Automatically Select the Right Tool

• Avoid manually switching among many tools

Operate Value Tool

Position/Size/Select Tool

Edit Text Tool

Connect Wire Tool

Auto Tool

1/ 20

Page 53: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

56

Hold down Ctrl + Space to launch Quick Drop

Quickly Drop Palette Objects2/ 20

• Ctrl + D – Create controls and indicators on selected diagram object(s)

• Ctrl + R – Remove diagram object(s) and reconnect wires

• Ctrl + T – Move control and indicator terminal labels to the left and right sides

Demo

Page 54: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

57

• Access via File New …• Well-known designs

Producer/Consumer State Machine Queued Message Handler

Design Pattern Templates3/ 20

Page 55: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

58

Switch Terminal Wires Easily

Hold Down Ctrl and Left-Click on Input Terminal

Note: This works only for functions with two inputs when bothinputs have already been wired

4/ 20

Demo

Page 56: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

59

Easily Scroll Through Structures

• You can use Ctrl + Mouse Scroll to scroll through: Case Structures Event Structures Stacked Sequence Structures Diagram Disable Structures

Ctrl + Mouse Scroll Wheel

5/ 20

Page 57: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

60

Quickly Find the Right Palette

• Right-click on a block diagram object for a palette shortcut

6/ 20

Add

To More Specific Class

Index Array

Demo

Page 58: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

61

Easily Navigate Arrays• Right-click on an array and select Visible Items >> Horizontal Scrollbar

(or Visible Items >> Vertical Scrollbar)• To view last element, select Advanced >> Show Last Element• Both horizontal and vertical scrollbars available (depending on array

dimensions)

7/ 20

Demo

Page 59: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

62

Selective Insert Location

Right-Click Slightly above Wire

Right-Click Slightly below Wire

Wire Connected to Lower Terminal

Wire Connected to Upper Terminal

8/ 20

Page 60: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

63

Block Diagram Clean-Up• Click Clean Up Diagram button on toolbar or press

Ctrl + U• Highlight a portion of the diagram for partial cleanup• Right-click and select “Exclude from Diagram

Cleanup” option

9/ 20

Note: Only available in LabVIEW 8.6 and later.

Demo

Page 61: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

64

Quickly Wire Multiframe Structures10/ 20

Note: Only available in LabVIEW 8.6 and later

• Right-click an output tunnel and select “Linked Input Tunnel » Create & Wire Unwired Cases”

Page 62: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

65

• Matrix Size function replaces old method• Assess size of 2D array regardless of data type

Easily Assess 2D Array Size11/ 20

Note: Only available in LabVIEW 2009 and later

Page 63: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

66

Breakpoint Manager

• Select View » Breakpoint Manager• Right-click and select Breakpoint » Breakpoint

Manager

12/ 20

Note: Only available in LabVIEW 8.6 and later

Page 64: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

67

• Ctrl + Shift +E from an open VI with open project

Quickly Find VIs in the Project Window13/ 20

Note: Only available in LabVIEW 2009 and later

Page 65: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

68

Easily Add Enumeration Items

• Press Ctrl while hovering over an Enum to use the Text Tool

• Use Shift + Enter to repeatedly add items

Shift + Enter

14/ 20

Demo

Page 66: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

69

• Highlight all desired front panel or block diagram objects

• Right-click and select “Properties”

Edit Multiple Objects Simultaneously15/ 20

Demo

Page 67: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

70

Automatically Create Control References

• Simply drag a control into a Control Refnum• Automatically creates a class-specific, type-specific

reference

16/ 20

Note: To keep the original control, use Ctrl-Drag instead

Page 68: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

71

Drag and Drop to Save Time• Drag an image into your VI icon• Select a file and drag into a path constant• Take a URL from Internet Explorer and drag into a string constant• Drag items from disk or Project Explorer into a LabVIEW block diagram

17/ 20

Page 69: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

72

Quickly Browse Properties and Methods• View >> Class Browser• Shortcut: Ctrl + Shift + B• Drag a property or method directly into your

VI

18/ 20

Demo

Page 70: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

73

Implement a For Loop Progress Bar

• Place Progress Bar VI inside a for loop• Opens automatically after a specified amount of time• Download sample code from ni.com/forums (search for “For Loop Progress Bar”)

19/ 20

Demo

Page 71: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

74

Automatically Analyse Your VIs

• Tools >> VI Analyzer >> Analyze VIs– Check performance, style, UI, documentation, and more– Save LabVIEW VI Analyzer settings for later use

20/ 20

Demo

Page 72: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

75

Other Resources

• Darren’s LabVIEW Nuggets (decibel.ni.com/content/docs/DOC-4002)

• LAVA: Favorite Tips and Shortcuts (forums.lavag.org)

• LabVIEW Wiki (labviewwiki.org)

Page 73: LabVIEW User Group University of Bristol Ben Lavasani Academic Field Sales Engineer NI UK

76