750 likes | 1.34k Views
LabVIEW User Group University of Bristol. Ben Lavasani Academic Field Sales Engineer NI UK. Agenda. LabVIEW Design Patterns Overview Coffee break :) LabVIEW for Multi-Touch Applications - David Carberry LabVIEW in Teaching LabVIEW Tips and Tricks.
E N D
LabVIEW User GroupUniversity of Bristol Ben Lavasani Academic Field Sales Engineer NI UK
Agenda • LabVIEW Design Patterns Overview • Coffee break :) • LabVIEW for Multi-Touch Applications - David Carberry • LabVIEW in Teaching • LabVIEW Tips and Tricks
What Is a Design Pattern? • A template or framework for LabVIEW code • Widely accepted and well-known • Easily recognizable
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
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
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!
Basic Tools • Loops • Shift Registers • Case Structures • Enumerated Constants • Event Structures
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
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?
Background: Global and Local Variables • Can cause race conditions • Create copies of data in memory • Cannot perform actions on data • Cannot handle error wires
Breaking Down the Design Pattern • While loop • Uninitialized shift registers have memory • Case structure • Enumerated control
How It Works: Basic Actions • Set the value of the shift register INITIALIZE INITIALIZE
How It Works: Basic Actions • Get the value currently stored in the shift register GET GET
How It Works: Action Engine • Perform an operation upon stored value and save result • You can also output the new value ACTION ACTION
Technical Implementation • Functional Global Variable is a Non-Reentrant SubVI • Actions can be performed upon data • Enumerator selects action • Stores result in uninitialized shift register • Loop only executes once
Uninitialized shift register has memory Loop only executes once Only used in Initialize case Functional Global Variables Action determines which case is executed Examples of other ‘actions’ Demo
Benefits: Comparison Global and Local Variables Functional Global Variables Prevent race conditions No copies of data Can behave like action engines Can handle error wires Take time to make • Can cause race conditions • Create copies of data in memory • Cannot perform actions on data • Cannot handle error wires • Drag and drop
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
Background Dynamic Sequence: Allows distinct states to operate in a programmatically determined sequence Static Sequence
Soda Machine Initialize No input Wait Nickel Deposited Change Requested Quarter Deposited Dime Deposited Total < 50 Total < 50 Total < 50 Quarter Change Nickel Dime Total >= 50 Total >= 50 Total >= 50 Total > 50 Vend Total = 50 Exit Soda costs $0.50
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
How It Works Transition code determines next state based upon results of step execution Case structure has a case for every state FIRST STATE Step Execution Shift registers used to carry state Transition Code NEXT STATE FIRST STATE
Transition Code Options Step Execution Step Execution Step Execution
State Machine Demo
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
How It Works Master • 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
Breaking Down the Design Pattern • Data independent loops = Multithreading • Master / slave relationship • Communication and synchronization between loops
Loop Communication • Variables • Occurrences • Notifier • Queues • Semaphores • Rendezvous
Queues Adding Elements to the Queue Select the data-type the queue will hold Reference to existing queue in memory De-queueing Elements Dequeue will wait for data or timeout (defaults to -1)
Adding Your Own Design Patterns C:\Program Files\National Instruments\LabVIEW 8.5\templates\Frameworks\DesignPatterns
Resources • Example Finder • New >> Frameworks >> Design Patterns • ni.com/labview/power • Expressionflow.com • Visit ni.com/info and enter exhkqe
LabVIEW in Teaching TheNI LabVIEW Academy
What Is the NI LabVIEW Academy? 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 Does the NI LabVIEW Academy Do? Empowers institutions to teach LabVIEW Emphasises LabVIEW professional certification Increases the pool of qualified LabVIEW developers
NI LabVIEW Academy Program Requirements Instructor Requirements Two instructors must be Certified LabVIEW Associate Developers (CLADs) and teach at participating organisations 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
NI LabVIEW Academy Instructional Materials • 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 Student Materials • LabVIEW Academy Workbook (student purchase) • 300+ questions • Recommended LabVIEW textbook (student purchase)
NI LabVIEW Academy Teaching Materials Curriculum for both learning LabVIEW and teaching LabVIEW NI LabVIEW Academy Teaching Materials Recommended LabVIEW Textbooks
NI LabVIEW Academy CLAD Opportunity The NI LabVIEW Academy gives students the opportunity to take the CLAD exam as part of the program
The NI LabVIEW Academy Bridging the Gap Academic Industry • “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
Tips and Tricks to Speed NI LabVIEW DevelopmentUseful Nuggets to Save You Time