Click here to load reader
Upload
koby-wingard
View
261
Download
3
Embed Size (px)
Citation preview
LabVIEW User GroupUniversity of Bristol
Ben LavasaniAcademic Field Sales Engineer
NI UK
2
3
Agenda
• LabVIEW Design Patterns Overview• Coffee break :)• LabVIEW for Multi-Touch Applications - David Carberry• LabVIEW in Teaching • LabVIEW Tips and Tricks
LabVIEW Design Patterns Overview
5
What Is a Design Pattern?
• A template or framework for LabVIEW code• Widely accepted and well-known• Easily recognizable
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
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
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!
9
Basic Tools• Loops• Shift Registers• Case Structures• Enumerated Constants• Event Structures
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
11
Design Patterns
• Functional Global Variable• State Machine / Statecharts• Producer / Consumer
Functional Global Variables
How do I share data across a application without using Global or Local Variables?
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
14
Breaking Down the Design Pattern
• While loop• Uninitialized shift
registers have memory• Case structure• Enumerated control
15
DEMOUninitialized Shift Registers
16
How It Works: Basic Actions
• Set the value of the shift register
INITIALIZE
INITIALIZE
17
How It Works: Basic Actions
• Get the value currently stored in the shift register
GET
GET
18
How It Works: Action Engine
• Perform an operation upon stored value and save result
• You can also output the new value
ACTION
ACTION
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
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’
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
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
State Machine
I need to execute a sequence of events, but the order is determined programmatically
24
Background
Dynamic Sequence: Allows distinct states to operate in a programmatically determined sequence
Static Sequence
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
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
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
28
Transition Code Options
Step Execution
Step Execution
Step Execution
29
DEMOState Machine
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
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
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
34
Breaking Down the Design Pattern
• Data independent loops = Multithreading• Master / slave relationship• Communication and synchronization between
loops
35
Loop Communication
• Variables• Occurrences• Notifier• Queues• Semaphores• Rendezvous
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)
37
Producer / Consumer
38
Adding Your Own Design Patterns
C:\Program Files\National Instruments\LabVIEW 8.5\templates\Frameworks\DesignPatterns
39
Resources
• Example Finder• New >> Frameworks >> Design Patterns• ni.com/labview/power• Expressionflow.com
• Visit ni.com/info and enter exhkqe
40
41
LabVIEW in TeachingThe NI LabVIEW Academy
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?
43
What Does the NI LabVIEW Academy Do?
Increases the pool of qualified LabVIEW developers
Emphasises LabVIEW professional certification
Empowers institutions to teach LabVIEW
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
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)
46
NI LabVIEW Academy Teaching Materials
Curriculum for both learning LabVIEW and teaching LabVIEW
Recommended LabVIEW Textbooks
NI LabVIEW Academy Teaching Materials
49
NI LabVIEW Academy CLAD Opportunity
The NI LabVIEW Academy gives students the opportunity to take the CLAD exam as part of the program
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
51
ni.com/academy
52
Tips and Tricks to Speed NI LabVIEW DevelopmentUseful Nuggets to Save You Time
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
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
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
57
• Access via File New …• Well-known designs
Producer/Consumer State Machine Queued Message Handler
Design Pattern Templates3/ 20
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
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
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
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
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
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
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”
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
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
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
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
69
• Highlight all desired front panel or block diagram objects
• Right-click and select “Properties”
Edit Multiple Objects Simultaneously15/ 20
Demo
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
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
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
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
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
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)
76