Presentation is loading. Please wait.

Presentation is loading. Please wait.

LabVIEW User Group University of Bristol

Similar presentations


Presentation on theme: "LabVIEW User Group University of Bristol"— Presentation transcript:

1 LabVIEW User Group University of Bristol
Ben Lavasani Academic 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

4 LabVIEW Design Patterns Overview

5 What Is a Design Pattern?
A template or framework for LabVIEW code Widely accepted and well-known Easily recognizable Design patterns are a hot topic amongst LabVIEW developers. There are a number of different design patterns out there, all of which have their merits and potential drawbacks. Design patterns have emerged over the years as the LabVIEW development community has sought to solve a common set of problems. They are essentially templates that make up the foundation of many large LabVIEW applications. The frameworks that are most commonly referred to as design patterns are widely accepted by the LabVIEW development community and are very likely to be recognized by anyone who has familiarized themselves with the pattern before. So why should you care about design patterns? As many of you who are here are aware, there are a number of potential benefits when using design patterns…

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 LabVIEW is often used to rapidly prototype small applications, but there is a rapidly increasing number of large applications being developed using LabVIEW. These applications often encompass large numbers of VIs being developed by groups of developers. Using a design pattern makes it easier for LabVIEW users to read and edit existing code and prevents them having to figure out how to solve classic problems for which the best possible answers already exist. Also, they’ve been put to the test. They’ve been refined and improved over the years and there are a handful of patterns that have emerged as being exceptionally useful, elegant and powerful. Because these design patterns are such a popular topic of discussion there are a number of online forums with examples, content and thoughts on various patterns (some even ship within LabVIEW)

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 When determining which design pattern to use with your application you should already have the architecture of your application in mind and a feel for the various requirements of your application. As you’ll see when we go through these design patterns, they cater to certain scenarios and they aim to solve particular problems. Many of them can address multiple issues that you need help with in your application – it’s also common to see some of the patterns we’ll look at being used in conjunction with one another. If you’re trying to re-factor an existing application to use a design pattern make sure that the investment required will yield the benefit you seek. When applications reach a point at which they’ve become unruly and difficult to edit or manage they are frequently refactored using one of the patterns we’ll look at. However, this is obviously a time-consuming activity, so make sure it’s worth your while and try to take advantage of existing code as much as possible

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! Also, after this training when you go back to your LabVIEW application to apply what you’ve learned here, don’t forget my words of caution… basic dataflow is the most basic design patterns and a lot of times it’s all you need to get the job done There’s an entire thread on the NI discussion forums called ‘please don’t do it’ that discusses the ramifications of using an overly complicated design pattern for a fairly simple task. Make sure you select the least common denominator, ie: what is the least complicated method by which you can satisfy all the goals of your application?

9 Basic Tools Loops Shift Registers Case Structures Enumerated Constants
Event Structures This slide should be extremely quick. The audience is likely already familiar with all of these items, but we want to make sure everyone has these ‘tools in their toolbelt.’ Build Loops – the two most common loops and the only ones we’ll need for this discussion are the for loop and while loop. The most significant difference is that the while loop iterates indefinitely until stopped, whereas a for loop always has a maximum number of iterations Shift registers – these are used instead of tunnels if you want to preserve data between iterations of a loop such as a for loop or while loop. On the for loop below I’ve used a set of stacked shift registers, which will remember values from previous iterations Case Structures – allow you to conditionally execute code depending upon an input, which can be a boolean, string, number, etc… if the input has infinite possibilities, you can set a default case. Enumerated constants – Allow you to enumerate integer values using words. This is commonly used to govern the case of a case structure instead of just a number. We’ll discuss these more later Event structures – are similar to case structures, but they interrupt data flow by responding to events that occur. We’ll talk more about this in a moment as well

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 All the slides for each design pattern should follow this format. We’ll make a problem statement or describe a scenario we’re trying to address. Before talking about how to implement the solution, we’ll cover any specifics to that particular pattern that you’ll need to be familiar with (code components). Then we’ll discuss implementation and I’ll step you through some demos I’ve prepared. Finally, we’ll discuss when to use each design pattern and some considerations to be aware of.

11 Design Patterns Functional Global Variable State Machine / Statecharts
Producer / Consumer We’ll start with a couple of simple design patterns and spend most of our time discussing the last two on this slide. I’ll try to go into low level detail on the last few and we’ll spend some time discussing variations of implementation and any other considerations.

12 Functional Global Variables
How do I share data across a application without using Global or Local Variables? For those of you who have taken LabVIEW training, or if you’re just familiar with good programming practices, we’re constantly advising customers to not use local or global variables. They introduce a number of inefficiencies that don’t scale well if used multiple times in a single application. However, sometimes you have to break data flow and you need to send data between independent processes, so how do you do it? Lets look at Functional Global Variables. They offer a number of advantages over local and global variables that will allow communication across your project without suffering from the same drawbacks as global and 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 Before I show you a functional global variable I want to make sure that everyone understands a few nuances of the components that are required for a Functional Global Variable. We talked about loops and shift registers earlier, but functional global variables rely upon a property of shift registers that we haven’t yet discussed: Uninitialized shift registers can be used as a memory location When you assign a value to it, it doesn’t destroy or replace that data unless it is initialized or all callers are removed from memory Demo Open the “Explain Uninitialized Shift Registers.vi’ example program and follow the instructions on the block diagram FAQ they’ve been around since LabVIEW 2.0 Also commonly called a VIG (VI Global), Uninitialized Shift Register Global (USR Global), or Action Engine

15 Demo Uninitialized Shift Registers
Before I show you a functional global variable I want to make sure that everyone understands a few nuances of the components that are required for a Functional Global Variable. We talked about loops and shift registers earlier, but functional global variables rely upon a property of shift registers that we haven’t yet discussed: Uninitialized shift registers can be used as a memory location When you assign a value to it, it doesn’t destroy or replace that data unless it is initialized or all callers are removed from memory Demo Open the “Explain Uninitialized Shift Registers.vi’ example program and follow the instructions on the block diagram FAQ they’ve been around since LabVIEW 2.0 Also commonly called a VIG (VI Global), Uninitialized Shift Register Global (USR Global), or Action Engine Demo

16 How It Works: Basic Actions
Set the value of the shift register INITIALIZE Now that you’ve demonstrated how uninitialized shift registers work, explain the basic working idea behind a fgv. This diagram shows how we can store a new value to the shift register INITIALIZE

17 How It Works: Basic Actions
Get the value currently stored in the shift register GET Similarly, we can retrieve the value stored as shown GET

18 How It Works: Action Engine
Perform an operation upon stored value and save result You can also output the new value ACTION Perhaps one of the most powerful aspects of a FGV is the ability to customize what actions are performed on the value stored in memory. The cloud in this diagram can represent any number of actions or computations that are to be performed upon any number of data-types ACTION

19 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 A functional global VI is called as a subVI from your application. The only required parameter is the action to be performed. The initialize too can be passed in or be a constant Note that it only executes once because the stop button is always set to true

20 Demo Functional Global Variables
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’ Use the example VI to demonstrate initializing, incrementing and retrieving the value of a Functional Global Variable Demo

21 Benefits: Comparison Functional Global Variables
Global and Local 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 We mentioned earlier in this presentation that FGV often make a good substit

22 Recommendations Use Cases Considerations
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 If a single parent VI that owns the functional global is stopped, then the data in the USR is destroyed, even if other parents are still active in memory. If this is a problem, consider using a queue, which is not destroyed until all references to it are stopped. If using a FGR to manage complex data, use a cluster to reduce the amount of connectors used

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

24 Background Static Sequence
Dynamic Sequence: Allows distinct states to operate in a programmatically determined sequence The diagram at the top is supposed to represent a diagram in which you always know the order of execution. The diagram below is meant to indicate that you will not know the order of execution until run-time. Each subVI has code inside of it that then determines what the next subVI will be. Allows you to execute code in an order determined at run-time

25 Soda Machine Soda costs $0.50 Initialize Wait Quarter Change Nickel
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 Each state has decision making code inside of it. For example, if you consider the Quarter state, it examines the total amount of money that has been added. If it is equal to or greater than the amount owed, it sends the application to the ‘vend’ state; otherwise, it returns to wait Walk the audience through an example of execution of this application Total > 50 Vend Total = 50 Exit Soda costs $0.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 The standard LabVIEW state machine consists of a large while loop, a shift register to remember the current state, and a case structure that holds separate code to run for each state. (If you use an enum to pass around the value for the current state, the pattern becomes much easier to read – and if you use a typedef, you only need to edit the typedef once in order to add another state to the machine) Note that each frame in the case structure must contain code for deciding what state the process should go to next. I call this the “transition” code

27 How It Works Step Execution Transition Code FIRST STATE NEXT STATE
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 The state machine pattern is one of the most widely recognized and highly useful design patterns for LabVIEW. This pattern neatly implements any algorithm explicitly described by a state diagram (flow charts work too…). More precisely, it implements any algorithm described by a “Moore machine” – that is, a state machine which performs a specific action for each state in the diagram. (Contrast this with the “Mealy machine” which performs an action for each transition…) NEXT STATE FIRST STATE

28 Transition Code Options
Step Execution Step Execution Each of these case structures shows a different standard type of “transition code” – i.e. code that chooses the next state for the state machine. The top left code clearly shows that the “Init” state has only one transition, and hence goes directly to the “Power Up” state without making any decision at all. The top right code switches between two possible transitions – the “Init” state will go to the “Shut Down” state if the “Stop” button has been pressed, otherwise it goes to the “Power Up” state. The code at the bottom left is a little more complicated, but still a common LabVIEW construct. The code for this state returns an array of boolean values, one for each transition we could take. Along with that array of boolean values is another array of enum constants specifying the new states where each possible transition could go. The index of the first “True” boolean in the array corresponds to the index of the new state in the array of enums… (Well, almost, but you can figure out the details yourself – just remember that the “Search Array” function will return –1 if the value is not found). The code at the bottom right is functionally equivalent to the code to its left. It consists of a case structure embedded in a while loop. The case structure contains one diagram for each transition arrow that leaves the current state. Each of these diagrams has two outputs – a boolean value which specifies whether or not the transition should be taken, and an enumerated constant which specifies the state to which the transition goes. By using the loop index as input to the case structure, this code effectively runs through each transition diagram one by one, until it finds a diagram with a “TRUE” boolean output, and then outputs the new state to which that transition goes. (Note that it is important to make sure the last transition always outputs a TRUE value). Though this code may appear slightly more complicated than the code to the left, it does offer the ability to add names to transitions by “casting” the output of the loop index to an enumerated type. This allows you to add “automatic documentation” to your transition code… Step Execution

29 State Machine Run the example entitled “1-Coke Machine State Machine.vi” Use highlight execution to show how it moves between states in the same manner you illustrated earlier. In order to transition to the next design pattern, demonstrate how because the program is designed to poll for user input that when it’s busy executing code, that the program can miss input (ie: rapid clicking on the dime will cause the program to piss the ‘depositing’ of several of the dimes) This implementation uses a traditional state- machine implementation. The idle case polls for events, which in this case is user input. If the user presses and de-selects an input such as a coin or button quickly enough, the state machine can potentially miss the input. In order to detect the event, the input's value must be polled before the user de-selects it. This is a processor intensive and ineffecient way to detect user input. To demonstrate this problem, rapidly click the dime and notice that it does not detect all clicks. This example demonstrates the state machine design pattern, but it illustrates one of the problems we'll address with a more sophisticated implementation later in this presentation. Demo

30 Recommendations Use Cases Considerations 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 State machines are common in applications that are basing decision making off of input from a user. Since your application can’t predict the next input from the user, a state machine can be implemented to go to certain states and thereby execute specific code based upon the input from a user while in a certain state.

31 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 I want to execute code in parallel and at asynchronous rates, but I need to communicate between them! I have two processes that need to execute at the same time, but I want them to be independent of one another, and I need to make sure one can’t slow the other down

32 Background I want to execute code in parallel and at asynchronous rates, but I need to communicate between them! I have two processes that need to execute at the same time, but I want them to be independent of one another, and I need to make sure one can’t slow the other down

33 How It Works Master Slave 1 Slave 2
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 This gives you more control on how your application is timed, and gives the user more control over your application. The standard Master/Slave design pattern approach for this application would be to put the acquisition processes into two separate loops (slave loops), both driven by a master loop that polls the user interface (UI) controls to see if the parameters have been changed. To communicate with the slave loops, the master loop writes to local variables. This will ensure that each acquisition process will not affect the other, and that any delays caused by the user interface (for example, bringing up a dialog) will not delay any iteration of the acquisition processes. Counterexample: Data-acquisition and data-logging in the same loop. It would be difficult to increase the rate of DAQ without increasing rate of data logging. If they are separate of each other then this is easier to do Slave 2

34 Breaking Down the Design Pattern
Data independent loops = Multithreading Master / slave relationship Communication and synchronization between loops The standard “design pattern” approach would be to put the acquisition processes in two separate loops, both of them driven by a master loop receives input from the UI controls. This will ensure that each acquisition process will not affect the other, and that any delays caused by the user interface (for example, bringing up a dialog), will not delay any iteration of the acquisition processes. The power of using this pattern is that it separates the data flow of your diagram into independent processes. However, in order for these to communicate, you will have to use some form of globally available, shared data. (e.g. locals, globals, occurrences, notifiers, and/or queues). This does break LabVIEW’s dataflow paradigm, leaves the door open for race conditions, and incurs a little more overhead than passing data by wire. (i.e. acquiring mutexes, etc.) The producer / consumer pattern is really just a subclass of the master / slave pattern where the main communication between the loops is via queue. Using queues rather than globals to pass data provides a buffering effect – if the data writer occasionally produces data faster than the reader can process it, data will not be lost. This can be especially useful for handling UI events that take a long time to complete (ex. Printing in response to a user)

35 Loop Communication Variables Occurrences Notifier Queues Semaphores
Rendezvous Now that we’ve discussed the concept of having multiple loops for separate processes, lets talk about how we can bridge those loops in order to communicate without creating any data-dependency. There are a number of different mechanisms we can use depending upon the communication required. For synchronization and timing an occurance or rendezous are helpful. We’re going to focus on the use of queues Notifier Operations Functions Use the Notifier Operations functions to suspend the execution of a block diagram until you receive data from another section of the block diagram or from another VI running in the same application instance. Occurrences Functions Use the Occurrences functions to control separate, synchronous activities. Queue Operations Functions Use the Queue Operations functions to create a queue for communicating data between sections of a block diagram or from another VI. Rendezvous VIs Use the Rendezvous VIs to synchronize two or more separate, parallel tasks at specific points of execution. Each task that reaches the rendezvous waits until the specified number of tasks are waiting, at which point all tasks proceed with execution. Semaphore VIs Use the Semaphore VIs to limit the number of tasks that can simultaneously operate on a shared (protected) resource. A protected resource or critical section of code might include writing to global variables or communicating with external instruments.

36 Queues Adding Elements to the Queue De-queueing Elements
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)

37 Producer / Consumer One loop produces data (via computation, DAQ, etc.) and puts the data in the queue. The other loop waits until there is data in the queue. Then it pulls the first element out of the queue and processes it.

38 Adding Your Own Design Patterns
Many developers use some form of the design patterns we’ve looked at today for application development on a regular basis. If you or your company uses a custom design pattern regularly, you can actually add it into the design patterns folder in LabVIEW for easy access by yourself and other developers 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 Teaching The NI LabVIEW Academy

42 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. Provides instructional materials

43 What Does the NI LabVIEW Academy Do?
Empowers institutions to teach LabVIEW Emphasises LabVIEW professional certification Increases the pool of qualified LabVIEW developers

44 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

45 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)

46 NI LabVIEW Academy Teaching Materials
Curriculum for both learning LabVIEW and teaching LabVIEW NI LabVIEW Academy Teaching Materials Recommended LabVIEW Textbooks

47 NI LabVIEW Academy Student Workbook

48 NI LabVIEW Academy Student Workbook

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 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

51 ni.com/academy

52

53 Tips and Tricks to Speed NI LabVIEW Development Useful Nuggets to Save You Time
Welcome to the LabVIEW Development Days 2010 presentation, Tips and Tricks to Speed LabVIEW Development. This presentation was created by Darren Nattinger, Senior Software Engineer, LabVIEW R&D and Kelly Rink, Applications Engineer, Applications Engineering Department.

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 This presentation will cover 25 “nuggets” of information designed to reduce programming effort in LabVIEW and improve development time. The tips and tricks range from simple reminders of useful LabVIEW features, to advanced functions and tools. Hopefully, everyone will come out of the presentation with some new useful tricks to apply in their everyday programming.

55 Automatically Select the Right Tool
1 / 20 Avoid manually switching among many tools Operate Value Tool Position/Size/Select Tool Auto Tool Edit Text Tool Connect Wire Tool The Auto Tool can be found on top of the Tools Palette located under View >> Tools Palette. Though most LabVIEW users are aware of this feature (it is turned on by default), many users still use the Tab key to manually switch tools. Let this slide pose a challenge: try the Auto Tool for 30 days; the vast majority of LabVIEW programmers will find that the Auto Tool greatly speeds their development after a little practice.

56 Hold down Ctrl + Space to launch Quick Drop
Quickly Drop Palette Objects 2 / 20 Hold down Ctrl + Space to launch Quick Drop 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 The Quick Drop dialogue box can be used to specify a palette object or project item by name and then place the object on the block diagram or front panel. It is launched by pressing Ctrl-Space. Quick Drop eliminates the need to navigate through the palettes to find objects. In LabVIEW 2009, three keyboard shortcuts were added to Quick Drop. You can select one or more objects on the block diagram and Press Ctrl-Space-Ctrl-D to create controls and indicators for all unwired terminals. You can use Ctrl-Space-Ctrl-R to remove one or more diagram objects and wire up pass-through terminals of matching data types. Lastly, you can use Ctrl-Space-Ctrl-T to move control and indicator terminal labels to the left and right sides of the terminals. DEMO 1 Demo

57 / Design Pattern Templates Access via File  New … Well-known designs
3 / 20 Access via File  New … Well-known designs Producer/Consumer State Machine Queued Message Handler Using design pattern templates will greatly decrease development and maintenance time of a project. Templates consist of well known designs such as Producer/Consumer, State Machine, and Queued Message Handler patterns. The templates can be accessed through the File  New… menu.

58 Switch Terminal Wires Easily
4 / 20 Hold Down Ctrl and Left-Click on Input Terminal When connecting wires to a function like subtract or divide, it can be easy to accidentally connect each wire to the wrong input. Use the “switcheroo” tool to automatically swap the wire connections; just hold down Ctrl and left click on one of the input terminals. Note: the “switcheroo” tool only works for functions with two inputs when both inputs have already been wired. In addition, this tool only works when using the Auto Tool or Wiring Tool. DEMO 2 Note: This works only for functions with two inputs when both inputs have already been wired Demo

59 Easily Scroll Through Structures
5 / 20 You can use Ctrl + Mouse Scroll to scroll through: Case Structures Event Structures Stacked Sequence Structures Diagram Disable Structures Sometimes it can be difficult or time-consuming to scroll through a multi-frame structure such as a case structure, event structure, or stacked sequence structure. By holding down the Ctrl key and scrolling the mouse wheel, you can quickly flip through frames of these structures without having to click repetitively. Ctrl + Mouse Scroll Wheel

60 Quickly Find the Right Palette
6 / 20 Right-click on a block diagram object for a palette shortcut Add Index Array To More Specific Class When performing a specific task (such as File I/O), it is common to place several objects from the same palette on the block diagram. To quickly navigate to the same palette (or a related palette) as an object that you have already placed, right click on the object and select one of the available palette shortcuts. Note: you can also place frequently used objects on the Favorites palette; simply right click on a given object in its usual palette location and select Add Item to Favorites. DEMO 3 Demo

61 Easily Navigate Arrays
7 / 20 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) Many LabVIEW users click on the array index control to (slowly) view array elements. To scroll through array elements much faster, right click on the array and choose Visible Items >> Horizontal <or Vertical> Scrollbar. In addition, you can easily view the last element of an array by selecting Advanced >> Show Last Element after right clicking on an array. There are both vertical and horizontal scrollbars, depending on how you are viewing your array. DEMO 4 Demo

62 / Selective Insert Location 8 20 Right-Click Slightly above Wire
Right-Click Slightly below Wire You can insert an object onto an existing wire by right-clicking slightly above or below the wire and selecting Insert. Position is important for this tip. If you right-click slightly above the wire, your wire will be connected to the lower terminal of the object, and if you right-click slightly below the wire, the wire will be connected to the upper terminal of the object. Wire Connected to Lower Terminal Wire Connected to Upper Terminal

63 Block Diagram Clean-Up
9 / 20 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 Note: Only available in LabVIEW 8.6 and later. LabVIEW 8.6 introduced the block diagram clean-up feature to “straighten up” your block diagram by rearranging and aligning controls and indicators, rerouting and straightening wires, etc… You can access this feature by clicking the clean-up button on the tool bar or by pressing Ctrl-U. This feature was enhanced in LabVIEW 2009 by allowing you to cleanup a selected portion of your block diagram and exclude a section of your code from any cleanup operations. You can highlight a section of your code to only clean up that section, or exclude diagram structures from clean up by right clicking them and selecting "Exclude from Diagram Cleanup“. If there is a section of code that you want to keep clean, but it doesn't have a containing structure, then you can wrap it in a single-frame Flat Sequence Structure and then choose the cleanup exclusion option on that structure. DEMO 5 Demo

64 / Quickly Wire Multiframe Structures
10 / 20 Right-click an output tunnel and select “Linked Input Tunnel » Create & Wire Unwired Cases” To automatically link tunnels, right-click an output tunnel and select Linked Input Tunnel > Create & Wire Unwired Cases. One situation where this option is especially helpful is adding a new pass-through wire to an existing case structure or event structure that has multiple frames. Another situation is adding a new frame to an existing case or event structure that already has linked tunnels. Linked tunnels are denoted by a white triangle on the edge of the input and output tunnels. DEMO 6 Note: Only available in LabVIEW 8.6 and later

65 / Easily Assess 2D Array Size Matrix Size function replaces old method
11 / 20 Matrix Size function replaces old method Assess size of 2D array regardless of data type Note: Only available in LabVIEW 2009 and later Prior to LabVIEW 2009, you needed to use the Array Size function and an Index Array function to determine the number of rows and columns in a 2D array. LabVIEW 2009 introduced the Matrix Size function, which returns the number of rows and columns of the array directly, regardless of the data type of the array.

66 / Breakpoint Manager Select View » Breakpoint Manager
12 / 20 Select View » Breakpoint Manager Right-click and select Breakpoint » Breakpoint Manager The Breakpoint Manager in LabVIEW 8.6 and later allows you to view, enable, disable, and clear any breakpoints set on VIs in memory. You can launch the Breakpoint Manager by going to View » Breakpoint Manager or by right clicking a diagram object and selecting Breakpoint » Breakpoint Manager. DEMO 7 Note: Only available in LabVIEW 8.6 and later

67 / Quickly Find VIs in the Project Window
13 / 20 Ctrl + Shift +E from an open VI with open project Pressing Ctrl-Shift-E from an open VI, while its corresponding project is open will highlight the location of the VI in its owning project. Note: Only available in LabVIEW 2009 and later

68 Easily Add Enumeration Items
14 / 20 Press Ctrl while hovering over an Enum to use the Text Tool Use Shift + Enter to repeatedly add items The most common way to add or modify items in an enumeration is to right click on the Enum and select Edit Items. A much faster way to add enumeration items is to first press Ctrl while hovering over an Enum in order to change to the Edit Text Tool, click in the enum to start editing text, then use Shift + Enter to add multiple items. This method also works for Rings. DEMO 8 Shift + Enter Demo

69 / Edit Multiple Objects Simultaneously
15 / 20 Highlight all desired front panel or block diagram objects Right-click and select “Properties” Highlighting multiple front panel or block diagram objects and navigating to their properties menu will allow you to modify all properties that overlap between the selected items. This can be a significant time saving feature, especially when working with similar front panel objects that share properties. The property list is much more limited for block diagram items. Block diagram constants are one of the few object types you can configure with the Properties dialog. DEMO 9 Demo

70 Automatically Create Control References
16 / 20 Simply drag a control into a Control Refnum Automatically creates a class-specific, type-specific reference It is easy to create a class-specific, type-specific control reference in LabVIEW without right clicking on a control reference and navigating through several menus. Simply drag a front panel control into a control Refnum to create a correspondingly typed reference; this tip can save a lot of work, especially when dealing with a class that can have more than one data type associated with it. Note: To keep the original control, use Ctrl-Drag instead

71 Drag and Drop to Save Time
17 / 20 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 Dragging and dropping items in LabVIEW is often overlooked; this tip can greatly reduce development time. For example, try dragging an image file directly into your front panel icon. This will automatically create an icon for your LabVIEW application by resizing your image. In addition, you can select any file (from your disk or desktop) and drag it directly into a path constant to automatically fill it in. Likewise, an Internet Explorer URL can be dragged into a string constant to reduce typing. One great way to improve efficiency while working with a LabVIEW project is to drag items (such as VIs and Classes) from disk or the Project Explorer window directly onto the LabVIEW block diagram.

72 Quickly Browse Properties and Methods
18 / 20 View >> Class Browser Shortcut: Ctrl + Shift + B Drag a property or method directly into your VI Instead of browsing through several property nodes in order to (hopefully) find a certain property, use the Class Browser. This can be easily accessed by pressing Ctrl + Shift + B. Inside the Class Browser, you can select an Object Library (such as VI Server, DAQmx, or VISA) and a Class (e.g. Application or DAQmx Channel) to quickly view all available properties and methods. To search for a specific property, use the search feature. You can even drag and drop a property or method onto the block diagram in order to automatically create a property node or invoke node! DEMO 10 Demo

73 Implement a For Loop Progress Bar
/ 19 20 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”) A sample VI for implementing the For Loop progress bar is located as an attachment on (http://forums.ni.com/ni/board/message?board.id=170&message.id=192115). This VI automatically opens up a progress indicator if the For Loop it is placed in takes longer than a specified amount of time to complete; this is a great way to assure users that the program did not hang! DEMO 11 Demo

74 Automatically Analyse Your VIs
20 / Tools >> VI Analyzer >> Analyze VIs Check performance, style, UI, documentation, and more Save LabVIEW VI Analyzer settings for later use The VI Analyzer is a LabVIEW toolkit that allows you to check your code’s performance, user interface (UI), documentation, and several other areas. The VI Analyzer can quickly identify programming mistakes that would have taken hours to locate manually. You can also save VI Analyzer settings for later use. DEMO 12 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


Download ppt "LabVIEW User Group University of Bristol"

Similar presentations


Ads by Google