Presentation is loading. Please wait.

Presentation is loading. Please wait.

LabVIEW Introduction Course Semester

Similar presentations


Presentation on theme: "LabVIEW Introduction Course Semester"— Presentation transcript:

1 LabVIEW Introduction Course Semester
National Instruments N. Mopac Expressway Austin, Texas (512) National Instruments Confidential

2 Graphical Programming for Test, Measurement, and Control
Rapid application development with Express VIs and easy-to-use graphical environment Interactive measurement assistants and powerful redesigned DAQ interface for connecting to all types of I/O Expanded targeting options from Real-Time to FPGA to PDA Localized in French, German, and Japanese (Korean documentation)

3 LabVIEW Awards Readers of Electronic Design name invention of LabVIEW as one of the Top 50 Milestones for the Electronics Industry LabVIEW 6.1 receives IAN Automation Excellence Award of 2002 Design News awards LabVIEW 6i Best Computer Productivity Tool of 2000 LabVIEW 6i chosen the “Best of the Best” in the software category by readers of Evaluation Engineering We’re in good company - another Top 50 Milestones for the Electronics Industry award went to the personal computer.

4 NI LabVIEW: A History of Innovation
May 2003 January 2002 August 2000 March 1998 February 1996 August 1993 September 1992 January 1990 October 1986 April 1983 • LabVIEW 7 Express VIs, I/O Assistants, FPGA/PDA targets LabVIEW 6.1 Enhanced networking capabilities, analysis LabVIEW 6i Internet-ready measurement intelligence • LabVIEW 5.0 ActiveX, Multithreading • LabVIEW 4.0 Added professional tools, improved debugging • LabVIEW 3.0 Multiplatform version of LabVIEW • LabVIEW for Windows • LabVIEW 2.0 for Macintosh • LabVIEW 1.0 for Macintosh • LabVIEW project begins LabVIEW is not a new programming language, and it was not developed overnight. It is backed by almost 20 years of continuous innovation, and our customers benefit from the expertise this experience brings. These 20 years of innovation also created a worldwide network of users who have created thousands of VIs, hundreds of user groups, and a major presence in the world of measurement and automation. LabVIEW 1.0 was first introduced for Macintosh in October Since then, we continue to combine new, innovative concepts with constant improvement. Today, LabVIEW is the industry standard for test and measurement development software. Things to consider bringing out: LabVIEW 4 introduced the “undo” feature. LabVIEW 7 can interface with .NET. If you have a personal story of filing a CAR that got fixed for a newer version of LabVIEW, talk about it here. Point out that the only way LabVIEW can get better is from comments and critiques from the users and that you can champion any requests they may have. Acquire, Analyze, and Present with NI LabVIEW 32 ni.com

5 Leveraging Commercial Technologies
Third-Party Software Wolfram Research Mathematica ® Microsoft Excel ® The MathWorks MATLAB® and Simulink® MathSoft MathCAD ® Electronic Workbench MultiSim ® Texas Instruments Code Composer Studio® Ansoft RF circuit design software Microsoft Access ® Microsoft SQL Server ® Oracle ® Communication Protocols Ethernet CAN DeviceNet USB IEEE 1394 RS-232 GPIB RS-485 NI LabVIEW takes full advantage of current and emerging commercial technologies such as operating systems, communications buses, and major technology changes such as .NET. Additionally, LabVIEW is a multiplatform programming language, which means you can take the LabVIEW source code you have written on one platform and reuse it on any of the other supported platforms. The application you develop runs without any modifications. The only exception is if your LabVIEW code contains operating system-specific calls that only execute on a given platform. © National Instruments Corporation 33 Acquire, Analyze, and Present with NI LabVIEW Seminar

6 Industrial Computer (PXI)
LabVIEW Everywhere Sensor Embedded (FPGA) Handheld Wireless Networked I/O PC Boards Industrial Computer (PXI) Tektronix Open Windows Oscilloscopes Delivers a vision for engineers to deploy LabVIEW anywhere they want. Continued innovation to enable engineers deploy LabVIEW from workstations to personal computers to distributed systems to embedded applications. Someday soon, we may even see sensors powerful enough to use house LabVIEW. Not only is LabVIEW everywhere, but it offers something for every scientist and engineer. All levels of users, ranging from experienced to non-programmers, will benefit from the interactive, configurable tools and in LabVIEW 7 Express, enabling LabVIEW to be used as a one integrated tool for measurement and automation throughout the design process. PC, Mac, Linux, Sun Workstation

7 The LabVIEW Family NI LabVIEW
Graphical Programming Software for Measurement and Automation LabVIEW Real-Time Module LabVIEW FPGA Module LabVIEW PDA Module LabVIEW Datalogging and Supervisory Control Module

8 Acquire, Analyze, and Present
Nearly all test, measurement, and control applications can be divided into 3 main components: the ability to acquire, analyze, and present data. LabVIEW is the easiest, most powerful tool for acquiring, analyzing, and presenting real-world data.

9 Acquire with LabVIEW LabVIEW can acquire data using the following devices and more: GPIB, Serial, Ethernet, VXI, PXI Instruments Data Acquisition (DAQ) PCI eXtensions for Instrumentation (PXI) Image Acquisition (IMAQ) Motion Control Real-Time (RT) PXI PLC (through OPC Server) PDA Modular Instruments LabVIEW is tightly integrated with all NI hardware, in addition to connecting to thousands of I/O devices from hundreds of different vendors.

10 Analyze with LabVIEW LabVIEW includes the following tools to help you analyze your data: More than 400 measurement analysis functions for Differential Equations, Optimization, Curve Fitting, Calculus, Linear Algebra, Statistics, etc. 12 new Express VIs specifically designed for measurement analysis, including filtering and spectral analysis Signal Processing VIs for Filtering, Windowing, Transforms, Peak Detection, Harmonic Analysis, Spectrum Analysis, etc. Powerful measurement analysis is built in to the LabVIEW development environment.

11 Present with LabVIEW LabVIEW includes the following tools to help you present your data: On your machine — Graphs, Charts, Tables, Gauges, Meters, Tanks, 3D Controls, Picture Control, 3D Graphs (Windows Only), Report Generation (Windows Only) Over the Internet — Web Publishing Tools, Datasocket (Windows Only), TCP/IP, VI Server, Remote Panels, Enterprise Connectivity Toolset — SQL Tools (Databases), Internet Tools (FTP, Telnet, HTML) Presentation with LabVIEW can be done on your PC or over a network, or you can take advantage of additional applications such as DIAdem.

12 Course Map Introduction to LabVIEW Clusters Data Acquisition
& Waveforms Modular Programming Plotting Data Instrument Control Decision Making in a VI Repetition & Loops Strings and File I/O VI Customization Arrays

13 Course Goals This course prepares you to:
Understand front panels, block diagrams, and connectors/icons Use the programming structures and data types that exist in LabVIEW Use various editing and debugging techniques Create and save your own VIs so you can use them as subVIs Display and log your data Create applications that use plug-in data acquisition (DAQ) boards Create applications that use GPIB and serial port instruments B. Course Description and Prerequisites The LabVIEW Introduction course teaches you to make optimum use of LabVIEW for developing your test and measurement applications. The course is divided into lessons, each covering a topic or a set of topics. Each lesson consists of: An introduction that describes the lesson’s purpose and what you will learn. A discussion of the topics. A summary that outlines important concepts and skills taught in the lesson. The course prerequisites include familiarity with the Windows operating system, familiarity with computer components such as the mouse, keyboard, connection ports, and plug-in slots, and experience writing algorithms in the form of flowcharts or block diagrams. C. Course Goals The course goals are listed on the slide above. Read through each goal now.

14 Course Non-Goals It is not the purpose of this course to discuss the following: Every built-in LabVIEW object, function, or library VI Analog-to-digital (A/D) theory The detailed operation of the serial port or GPIB bus How to develop an instrument driver D. Course Non-Goals The items listed above are not discussed in this course.

15 Lesson 1 Introduction to LabVIEW
TOPICS LabVIEW Environment Front Panel Block Diagram Dataflow Programming LabVIEW Help and Manuals Debugging a VI

16 Virtual Instruments (VIs)
Front Panel Controls = Inputs Indicators = Outputs Block Diagram Accompanying “program” for front panel Components wired together LabVIEW programs are called virtual instruments (VIs). Stress that controls equal inputs, indicators equal outputs. Each VI contains three main parts: Front Panel – How the user interacts with the VI. Block Diagram – The code that controls the program. Icon/Connector – Means of connecting a VI to other VIs.

17 LabVIEW Dialog Box This slide shows the startup screen for LabVIEW 7.0
The LabVIEW dialog box includes the following components: A menu bar with standard items such as File»Exit. A set of buttons for creating and opening VIs, configuring DAQ devices, and finding helpful information. Click the New button to create a new VI. Click the arrow on the New button to choose to open a blank VI or to open the New dialog box. Click the Open button to open an existing VI. Click the arrow on the Open button to open recent files. Click the Configure button to configure your DAQ devices. Click the arrow next on the Configure button to configure LabVIEW. Click the Help button to launch LabVIEW Help. Click the arrow on the Help button for other Help options, including the Example Finder.

18 Creating a new VI File»New VI to open a blank VI
File»New… to open the New dialog box and configure a VI template, global variable, control, etc… Click the New button to create a new VI. Click the arrow on the New button to choose to open a blank VI or to open the New dialog box.

19 Template Browser When you click the New button, the New dialog box appears. You also can select File»New to display this dialog box. Select a template in the Create new listbox to display the front panel in the Front Panel Preview section, to display the block diagram in the Block Diagram Preview section, and to display a description of the template in the Description section. Select a template and click the OK button to start building a VI or other LabVIEW document. Press the <Ctrl-N> keys to bypass this dialog box and create a new empty VI.

20 File Edit Operate Tools Browse Window Help
Menu File Edit Operate Tools Browse Window Help The menus at the top of a VI window contain items common to other applications, such as Open, Save, Copy, and Paste, and other items specific to LabVIEW. Some menu items also list shortcut key combinations. Some menu items are unavailable while a VI is in run mode. The File menu contains items used for basic file operations, such as opening, closing, saving, and printing files. The Edit menu contains items that allow you to search for and modify LabVIEW files and their components. The Operate menu contains items you use to control the operation of your VIs. The Tools menu contains items for configuring LabVIEW, your projects, and your VIs. The Browse menu contains items that allow you to view aspects of the current VI and its hierarchy. The Window menu contains items that allow you to configure the appearance of the current windows and palettes. You also can access the Error List window and view the contents of the clipboard. The Help menu contains items to explaining and define LabVIEW features and other components, provide full LabVIEW documentation, and access National Instruments technical support.

21 Front Panel Window Front Panel Icon Toolbar Boolean Control Graph
Legend Waveform Graph Owned Label Waveform Graph This slide represents the front panel of a typical VI. Point out the elements in the Panel window: Panel Toolbar: contains tools and command buttons used to control the VI. Discuss the controls, indicators, and labels. Plot Legend Scale Legend

22 Block Diagram Window Block Diagram Toolbar Divide Function SubVI Graph
Terminal Wire Data This slide shows the block diagram for the front panel on the last slide. Point out front panel object terminals, constants, and nodes. (Note the Wait Until Next ms Multiple function, Divide function, subVI, and wires.) Reinforce front panel object-terminal relationship. While Loop Structure Numeric Constant Timing Function Boolean Control Terminal

23 Front Panel and Block Diagram Toolbars
Run button Continuous Run button Abort button Pause/Continue button Font ring Alignment ring Distribution ring Resize ring Reorder ring Context Help Button Additional Buttons on the Block Diagram Toolbar Warning indicator Enter button Broken Run button Execution Highlighting button Step Into button Step Over button Step Out button Launch LabVIEW and discuss the buttons using the computer; never use the abort button or continuous run button when doing demonstrations. Set a good example! Tools used to create, modify, debug, and execute VIs: Panel Toolbar: Located in the Panel window. Broken Run: Click on it to find errors. Continuous Run: Use for testing sections of code. Should use a while/for loop for repeating parts of a diagram in an application. Stop: Not a clean way to terminate the program. Avoid using it. Use a switch on the panel. Diagram Toolbar: Additional tools to debug the VI. Briefly explain each button. Tell the class we will discuss them in more detail when we talk about debugging. When running a VI, the font, alignment, and distribution rings disappear because they are editing tools.

24 Tools Palette LabVIEW automatically selects the tool needed
Available on the front panel and the block diagram A tool is a special operating mode of the mouse cursor Use the tools to operate and modify front panel and block diagram objects To show the tools palette, select Window»Show Tools Palette Graphical, floating palettes. Tools can be used for editing, debugging, and operating VIs. You can hide/show palettes by enabling or disabling them via the Window menu. Shortcut key (shift-right click - Windows) Although most will use the automatic tool selection, it is important that user understand the difference between the different tools so that they know when to use it. For example, when hovering over a boolean control, you may have the labeling tool, the selection tool or the operating tool depending on where the mouse cursor is. How do you know when to click? Demonstrate! Be sure to know all the correct names for the tools in the palette and take your time familiarizing students with their names. In particular, stress the difference between the Position/Resizing Tool and the Operator as students will often have the wrong tool and if you can vocally instruct them to get the correct tool it causes much less frustration.

25 Front Panel − Controls Palette
Contains the most commonly used controls Graphical, floating palettes. You can access the Controls palette only from the Panel window. If palettes are not displayed, you can access them via the Window menu and select the Show Controls palette. OR, right click on open area of front panel or diagram window to display Controls palette. All Controls Palette Shows all controls

26 Block Diagram − Functions Palette
Contains the Express VIs (interactive VIs with configurable dialog page) and the most commonly used functions Graphical, floating palettes. You can access the Functions palette only from the Block Diagram window. If palettes are not displayed, you can access them via the Window menu and select the Show Functions palette. OR, right click on open area of front panel or diagram window to display Functions palette. All Functions Palette Shows all functions

27 Palette Tools Graphical, floating palettes
Click pushpin to tack down palette Up to Owning Palette Search Palette Options Graphical, floating palettes Subpalettes can be converted to floating palettes Use Palette Options to change palette view from Express to Advanced Graphical, floating palettes. If palettes are not displayed, you can access them via the Window menu and select the Show Functions/Controls palette. OR, right click on open area of panel or diagram window to display Controls and Functions palettes, respectively. Click on subpalettes to access functions, controls, VIs. You can tack down palettes and subpalettes using the pushpin. Tack down by clicking on the pushpin on the top left corner of the palette. Once tacked down you can set the palette options and use the find tool.

28 Searching for Controls, VIs, and Functions
Press the search button to perform text searches of the palettes Click and drag an item from the search window to the block diagram or double-click an item to open the owning palette Use the buttons on top of the palette windows to navigate, search, and edit the palettes. You can search for controls, VIs, and functions that either contain certain words or start with certain words. Double clicking a search result opens the palette that contains the search result. You also can click and drag the name of the control, VI, or function directly to the front panel or block diagram.

29 Customize Control & Function Palette
Programs» National Instruments»LabVIEW 7.0 Keep vi.lib in the LabVIEW 7.0 directory Place items in user.lib or instr.lib to have them appear in the Controls and Functions palettes For all platforms, the LabVIEW system consists of the LabVIEW application and associated files. Describe these files and directories: vi.lib, Examples, Help, user.lib, instr.lib. Windows - LabVIEW Directory (shown above) LabVIEW: Starts the LabVIEW program. MacOS - LabVIEW Folder and System Folder. LabVIEW: LabVIEW and other associated files. Sun - LabVIEW Directory Other associated files. HP-UX - Same directory structure and contents as Sun except for GPIB. There are several other supporting programs. ibconf and ibic do the same thing as on the Sun.

30 Creating a VI Front Panel
Build the front panel with controls (inputs) and indicators (outputs) Numeric Indicator Owned Labels Increment Buttons Creating the front panel (user interface): Built with controls and indicators: Controls: Supply data to the VI. Indicators: Display data generated by the VI. They can find out if it is a control or indicator by checking the right-click menu of the object and referring to the third item (Change to Indicator or Change to Control) Explain graphics on slide: Numeric controls: Point out increment buttons. Numeric indicators: No increment buttons. Boolean objects: Ask class which Boolean is a control and which is an indicator. Explain that even though an LED is an indicator in the real world, it can be changed to a control in LabVIEW. Demonstrate. Numeric Control Boolean Control Boolean Indicator

31 Shortcut Menus for Front Panel Objects
Right-click the digital display to access its shortcut menu Right-click the label to access its shortcut menu Right-click menus: Most often used LabVIEW menus. Most LabVIEW objects have these menus for modification of attributes pertaining to that object. Functions/Controls palettes are available as right-click menus.

32 Property Page Right-click a control or indicator on the front panel and select Properties from the shortcut menu to access the property dialog box for that object Explain the options available for the numeric control, as shown on the slide. Also explain that property pages will differ dependant on the object selected.

33 Creating a VI Block Diagram
Front Panel Block Diagram Control Terminals Indicator Terminals The block diagram is the “code” for the VI. Note: Wires can cross each other. You will see dots at the wire junctions, and a small gap in the wire showing that wires do not connect. If dots at wire junctions have been turned off, go to Options (Tools menu)»Block Diagram and select Show dots at wire junctions. Point out border difference and arrow direction on controls and indicator terminals. Composed of nodes, terminals, and wires: Nodes: Program execution elements (analogous to statements, functions, and subroutines). Functions: Built-in nodes for elementary functions. SubVIs: VIs you design and later call from the diagram of another VI. Structures: Control the program flow. Wires Nodes

34 Express VIs, VIs and Functions
Express VIs: interactive VIs with configurable dialog page Standard VIs: modularized VIs customized by wiring Functions: fundamental operating elements of LabVIEW; no front panel or block diagram

35 Block Diagram Nodes Function Generator VI
Icon Expandable Node Expanded Node Function Generator VI Same VI, viewed three different ways Yellow field designates a standard VI Blue field designates an Express VI Note that you can have all functions be placed as expandable nodes by enabling an option in the Tools >> Options >> New to LabVIEW 7.0 menu. You can change from an expandable function/node to an icon view, but if the option is not enabled you cannot change from the icon view to the expandable node.

36 Block Diagram Terminals
Terminals are entry and exit ports that exchange information between the panel and diagram Terminals are analogous to parameters and constants in text-based programming languages Right-click and toggle View As Icon to change the icon view

37 Wiring the Block Diagram
Scalar 1D Array 2D Array Numeric Boolean String Not a complete list of data types; just ones that are used frequently through this course. Explain that in LabVIEW, you use wires to connect multiple terminals together to pass data in a VI. The wires must be connected to inputs and outputs that are compatible with the data that is transferred with the wire, therefore understanding the different data types is key to correct wiring. Explain the difference in colors and thicknesses. Explain that arrays and strings will be covered later in the course. Also, dynamic data type does not change width based on contents. Students are often looking for a more detailed list of all the data types in LabVIEW. If they ask about that, point them to the Help >> VI, Function, & How-To Help… On the Index Tab, search for data types and double click on the keyword to get a display on all of the data types and terminal representations in LabVIEW. Dynamic

38 Wiring Techniques Automatic Wiring Use Context Help Window when wiring
Hot Spot Automatic Wiring Use Context Help Window when wiring Right-click wire and select Clean Up Wire Tip Strips Automatic wire routing Right-click terminals and select Visible Items»Terminals Demonstrate wiring by placing two controls, one indicator, and an Add function. Use the Help window (point out how terminals in the Help window flash when the tool passes over the actual function terminal). right-click on the Add function and select Show Terminals. Point out Tip Strips. If students really struggle with wiring, remember that they can enable the Terminal view and that can help. If that is still not enough, they can enable the option to have nodes placed as expandable. That won’t fix all problems, and the last option is to reduce the monitor resolution to something like 800x600. View the terminal connections to a function

39 Dataflow Programming Block diagram executes dependent on the flow of data; block diagram does NOT execute left to right Node executes when data is available to ALL input terminals Nodes supply data to all output terminals when done Most text based programs execute in an control flow model. Dataflow is the principle that governs how LabVIEW programs execute. Explain the diagram on this slide with emphasis on dataflow. The node executes when data is available at all of its input terminals. The node supplies data on output terminals when it finishes execution. Not executed left to right nor top to bottom. Test understanding by asking class what will happen first when this program runs. Then, build the above diagram on your computer and demonstrate the dataflow using execution highlighting. It is helpful to start out by asking the class what they think will happen first on this block diagram. You will get answers from Number 1-4, random number, etc., but eventually someone will say that there is no way to know. Then, show will execution highlighting.

40 Context Help To display the Context Help window, select Help»Show Context Help, press the <Ctrl-H> keys, or press the Show Context Help Window button in the toolbar Move cursor over object to display help Connections: Required – bold Recommended – normal Optional - dimmed If required is unwired, receive error when running program. If recommended is unwired, receive warning when running program. If optional is unwired, no effect when running program. Give examples! The more examples of how you have used things to solve customer problems, the more they will trust you. Something that every LabVIEW supporter uses is Context Help. Explain how we cannot all be responsible for knowing what every function or VI does and we do not expect that of them, either, but that Context Help is our encyclopedia for VIs and functions. This is also a good place to begin getting them to think about good documentation practices of their own VIs so that users of their programs can get the same help. Simple/Detailed Context Help Lock Help More Help

41 LabVIEW Help Click the More Help button in the Context Help window
Select Help»VI, Function, & How-To Help Click the sentence Click here for more help in the Context Help window. Contains detailed descriptions of most palettes, menus, tools, VIs, and functions, step-by-step instructions for using LabVIEW features, links to the LabVIEW Tutorial, PDF versions of all the LabVIEW manuals and Application Notes, and technical support resources. Use an example program to demonstrate the help tools. Suggestion: Open help and search the index using ‘menus’. You can then show the class where they can find information on the menu items discusses in the earlier slide.

42 NI Example Finder To find an example, select Help»Find Examples
Web-integrated Search by keyword, example type, hardware type, etc. Use the buttons on top of the palette windows to navigate, search, and edit the palettes. You can search for controls, VIs, and functions that either contain certain words or start with certain words. Double clicking a search result opens the palette that contains the search result. You also can click and drag the name of the control, VI, or function directly to the front panel or block diagram.

43 Debugging Techniques Finding Errors Execution Highlighting
Click on broken Run button. A window showing the error appears Execution Highlighting Click on Execution Highlighting button; data flow is animated using bubbles. Values are displayed on wires. When your VI is not executable, a broken arrow is displayed in the Run button in the palette. Execution Highlighting: Animates the diagram and traces the flow of the data, allowing you to view intermediate values. Click on the light bulb on the toolbar. Finding Errors: To list errors, click on the broken arrow. To locate the bad object, click on the error message.

44 Debugging Techniques Probe Breakpoints Conditional Probe
Right-click on wire and select probe and it shows data as it flows through the wire segment Breakpoints Right-click on wire and select Set Breakpoint; pause execution at the breakpoint. Conditional Probe Combination of a breakpoint and a probe. Right-click on wire and select custom probe. Probe: Used to view values in arrays and clusters. Click on wires with the Probe tool or right-click on the wire to set probes. Create a probe when you want to have more control over how LabVIEW probes the data that flow through a wire. When you create a new probe, the data type of the probe matches the data type of the wire you right-click. Custom probes are also available - show if time permits. Breakpoint: Set pauses at different locations on the diagram. Click on wires or objects with the Breakpoint tool to set breakpoints. Conditional probe: a probe on which conditions can be set for when to break at the probe. It is VERY easy to place additional breakpoints on a VI. Teach students that if their program is not running correctly and they think they may have a breakpoint…somewhere…that they can use the Edit >> Find, Other – Breakpoints search tool to locate all breakpoints placed on their block diagrams!

45 Debugging Techniques Step Into, Over, and Out buttons for Single Stepping Click on Step Into button to enable single stepping Once Single Stepping has begun, the button steps into nodes Click on Step Over button to enable single stepping or to step over nodes Click on Step Out button to step out of nodes Single stepping: executes the diagram node by node. You can access single stepping from the diagram toolbar by using the step functions found on the diagram toolbar. Use Step Into/Step Over to begin single stepping. Step Into: Steps into a node. If there is a subVI, it will then bring up the subVI diagram and enable single stepping through it. Step Over: Executes nodes but visually does not single step through nodes. Step Out: Steps out of nodes, if the diagram has completed execution; click on Step Out to terminate single stepping mode.

46 Summary Virtual instruments (VIs) have three main parts — the front panel, the block diagram, and the icon and connector pane The front panel is the user interface of a LabVIEW program and the block diagram is the executable code The block diagram contains the graphical source code composed of nodes, terminals, and wires Use Express VIs, standard VIs and functions on the block diagram to create your measurement code. For the most common requirements, use Express VIs with interactive configuration dialogs to define your application. Floating Palettes: Tools Palette, Controls Palette (only when Front Panel Window is active), and Functions Palette (only when Block Diagram Window is active) There are help utilities including the Context Help Window and LabVIEW Help Do not immediately display this slide. Suggested questions for class participation: What are the two main windows in the LabVIEW environment? What do the Panel and Diagram Toolbars contain? What are the differences between controls and functions? Where are each located? What are the three palettes in the LabVIEW environment? What are pop-up menus? How are they used? How do you get help? Review slide: The purpose of Lesson One was to introduce the LabVIEW environment and some simple VI concepts, LV help, and debugging techniques. When in doubt, right click!!

47 Summary Place controls (inputs) and indicators (outputs) in the front panel window Use the Operating tool to manipulate panel objects. Use the Positioning tool to select, move, and resize panel objects. Use the Wiring tool to connect diagram objects Control terminals have thicker borders than indicator terminals All front panel objects have property pages and shortcut menus Wiring is the mechanism to control dataflow and produce LabVIEW programs Broken Run arrow means a nonexecutable VI Various debugging tools and options available such as setting probes and breakpoints, execution highlighting, and single stepping See the tips and tricks and the end of the chapter to practice.

48 Tips • Common keyboard shortcuts
Access Tools Palette with <shift>-right-click Increment/Decrement faster using <shift> key Tools»Options selection — set preferences in LabVIEW VI Properties (File menu) Windows Sun Linux MacOS <Ctrl-R> <¨-R> <M-R> <z-R> Run a VI <Ctrl-F> <¨-F> <M-F> <z-F> Find object <Ctrl-H> <¨-H> <M-H> <z-H> Activate Context Help window <Ctrl-B> <¨-B> <M-B> <z-B> Remove all broken wires <Ctrl-W> <¨-W> <M-W> <z-W> Close the active window <Ctrl-E> <¨-E> <M-E> <z-E> Toggle btwn Diagram/Panel Window Demonstrate these techniques so that students can practice them throughout the course. Highlight the following tips: Hot keys (ctrl -b, ctrl-e, etc.) Accessing functions and controls palettes by right-clicking Accessing tools palette temporarily by shift - right-click (Windows) or shift - command - click (Mac) Tab to toggle through toolbars Spacebar to toggle between positioning and operating tool (panel toolbar) Spacebar to toggle between positioning and wiring tools (diagram toolbar) Wiring: spacebar to change direction Wiring: click with right mouse click to terminate wiring once started Undo and Redo in the Edit menu 1st Day Lunch

49 Lesson 2 Modular Programming
TOPICS SubVIs Icon and Connector Pane Using SubVIs Creating a SubVI from sections of a VI

50 LabVIEW Hierarchy SubVI LabVIEW is hierarchical in nature:
You can have many layers of VIs. Very modular, easy to debug and change. This is why LabVIEW is so powerful. Explain the example in the slide: Show the relationship between front panel objects and their corresponding terminals on the block diagram. Power: control for stopping the measurements. Temperature History: indicator that displays the temperatures that have been read.

51 SubVIs Function Pseudo Code SubVI Block Diagram
function average (in1, in2, out) { out = (in1 + in2)/2.0; } SubVI Block Diagram Calling Program Pseudo Code main { average (point1, point2, pointavg) } Calling VI Block Diagram A subVI is analogous to a subroutine. When creating a VI, you should: Start with the top-level VI and define input and output. Construct subVIs as necessary to implement the desired functionality in the block diagram. The modular approach makes applications easier to debug and maintain. Explain diagram. (The functionality of the subVI does not matter for this example. The important point is the passing of two numeric inputs and one numeric output.)

52 Icon/Connector An icon represents a VI in other block diagrams
terminals Icon An icon represents a VI in other block diagrams A connector passes data to and receives data from a subVI through terminals Connector Icon: Means of turning a VI into an object that can be used in other programs (compare it to a subroutine). Graphically represents the VI in the block diagram of other VIs. Connector: Terminals define where to wire inputs and outputs. Analogous to parameters of a subroutine. Terminals correspond to controls and indicators on the front panel. Hidden under the icon unless the user chooses to view it. terminals

53 SubVI Example – Calculating Slope
A VI within another VI is called a subVI To use a VI as a subVI, create an icon and a connector pane after building the front panel and block diagram Instructor: Build this example subVI slope.vi on your computer and demonstrate creating an icon/connector and calling the VI from another VI along with the next four slides.

54 Creating the Icon Icon: graphical representation of a VI
Right-click in the icon pane (Panel or Diagram) Always create a black and white icon Default Icon Create a custom icon Every VI has its icon displayed in the upper right corner of the Panel and Diagram windows. (The default is a LabVIEW icon.) Use Icon Editor to design the icon. From the Panel or Diagram window, right-click on the icon and select Edit Icon... Design separate icons for monochrome, 16-bit color, and 256-bit color modes. You must design a monochrome icon if you want the icon to display on the Functions palette. Use the Copy From command to make a copy from one color mode to another. Double-click on Select tool and press delete to clear icon Double-click on Rectangle tool to add border around icon Keep it simple, its not an art lesson Using your computer, demonstrate each tool in the Icon Editor and draw a simple icon. You can also copy and paste into the icon editor.

55 Creating the Connector
Right-click the icon (Front Panel only) The connector is a programmatic interface to a VI: Data passes from controls and to indicators via terminals on the connector. The connector is defined by assigning Front Panel objects to input and output terminals. Demonstrate the Show Connector option: A Connector Pane replaces the icon. Pattern selection is based on objects on the front panel. To select a different pattern, right-click on the connector and choose Patterns. Note the various ways to rotate and flip patterns.

56 Creating the Connector - continued
Click with wiring tool Demonstrate how you can illustrate which terminal is attached to which control/indicator. Click on a terminal or control.

57 The Connector Pane Terminal colors match the data types to which they are connected Click the terminal to see its associated front panel object Connector continued.

58 Using a VI as a SubVI All Functions » Select a VI…
<OR> Drag icon onto target diagram You can use any VI that has an icon and connector as a subVI in the block diagram of another VI. Drag the icon pane to the diagram of the target VI. Select the Select a VI... option from the Functions palette. The file dialog box is displayed. Select any VI file. Add commonly used VIs to the Functions palette by placing them in User.lib in the LabVIEW directory. SubVIs are analogous to a subroutine: A node is not a subVI itself, just a subroutine call. Identical nodes in the diagram call the same subVI. To open, double-click the left mouse button on the icon. Changes to a subVI: Saved in memory until the subVI is saved to disk. Affect all calls to it, not just the node used to open it.

59 Help and Classifying Terminals
Classify inputs and outputs: Required — Error if no connection Recommended — Warning if no connection Optional — No effect if no connection Classify controls or outputs as required, recommended, or optional to remind users to wire inputs or outputs. Classify by being in the connector pane and selecting This connector is >>. Help windows show classifications as shown above (for example, bold for a required terminal). Demonstrate using a DAQ VI Required classification - If input is not wired, VI will be broken. Will be displayed in bold text in Help Menu Recommended classification - Displayed as plain text in Help menu Optional classification - dims description or hides the description in the Simple View of the Help window.

60 Create SubVI Option Enclose area to be converted into a subVI
Select Create SubVI from the Edit Menu Can modularize VIs after the fact by using the Create SubVI option. Creates front panel, wires diagram, and creates Connector with a default icon for you. All you need to do is save once modularized. Two steps: 1. Select portion of diagram to be encompassed in subVI and 2. Select Create SubVI from the Edit menu. Some hooks to be aware - check the Users Manual

61 Summary VIs can be used as subVIs after you make the icon and connector Icon created using Icon Editor Connector defined by choosing number of terminals Load subVIs using the Select a VI option in the All Functions palette or dragging the icon onto a new diagram Online help for subVIs using the Show Context Help option Descriptions document functionality Use Create SubVI feature to easily modularize the block diagram Do not immediately display this slide. Suggested questions for class participation: A VI used as a subVI must have what two parts? How do you create an icon? How do you define a connector? How do you load a subVI into a LabVIEW diagram? How can you modularize the program in your diagram? Review the slide: The purpose of Lesson Two was to introduce the hierarchical nature of LabVIEW and the concept of subVIs. The ability to call VIs as subVIs facilitates modular block diagrams. Applications are more flexible and easier to understand, debug, and modify. Online help provides information about each node. Modularize whenever possible.

62 Lesson 3 Repetition and Loops
TOPICS While Loops For Loops Accessing Previous Loop Data

63 While Loops LabVIEW While Loop Flow Chart Pseudo Code Repeat (code);
Until Condition met; End; While Loops execute a sequence of events while a condition is True (analogous to a “Do...While” statement). While Loop functionality: A While Loop executes the code contained inside it until a Boolean False is passed to the conditional terminal. Thus, it always executes at least once. The iteration terminal contains the number of executions (zero-indexed). LabVIEW While Loop Flow Chart Pseudo Code

64 While Loops 1. Select While Loop 2. Enclose code to be repeated
3. Drop or drag additional nodes and then wire Place loops in your diagram by selecting them from the Structures palette of the Functions palette (demonstrate): When selected, the mouse cursor becomes a special pointer that you use to enclose the section of code you want to repeat. Click the mouse button to define the top-left corner, click the mouse button again at the bottom-right corner, and the While Loop boundary is created around the selected code. Drag or drop additional nodes in the While Loop if needed.

65 Select the Loop Condition
Click the Conditional Terminal with the Operating tool to define when the loop stops Default: Stop if True Iteration Terminal Conditional Terminal

66 Structure Tunnels Tunnels feed data into and out of structures.
The tunnel is a block that appears on the border; the color of the block is related to the data type wired to the tunnel. When a tunnel passes data into a loop, the loop executes only after data arrive at the tunnel. Data pass out of a loop after the loop terminates.

67 For Loops LabVIEW For Loop Flow Chart Pseudo Code N=100; i=0;
Until i=N: Repeat (code; i=i+1); End; A For Loop executes the diagram inside its border for a predetermined number of iterations (analogous to a “For...Next” statement). Explain the difference between While Loops and For Loops: While Loops run until a condition is met. For Loops run a predetermined number of times. LabVIEW For Loop Flow Chart Pseudo Code

68 For Loops In Structures subpalette of Functions palette
Enclose code to be repeated and/or resize and add nodes inside boundary Executes diagram inside of loop a predetermined number of times Count terminal (Numerical input) Enclose nodes inside the For Loop the same way as in a While Loop. N is the count terminal—It specifies how many times the loop will execute. i is the iteration terminal—It specifies the number of loops executed at any iteration. Next, we will learn more about timing functions and numeric conversion; two important issues to understand when building a looping architecture. Wait Until Next ms Multiple function

69 Wait Functions Wait Until Next ms Multiple
Functions»Time & Dialog palette Take the time to carefully explain the above slide. This chart is also printed in the book; have them follow along on page 3-10. Show how this function times on a ms Multiple; not a definite passage of time. Show how you could lose some time on the first loop due to pre-loop code.

70 Wait Functions Wait (ms) Functions»Time & Dialog palette Time Delay
Take the time to carefully explain the above slide. Show how this function counts the number of ms passing. Show how the time per loop may not be consistent since the code could take a variable amount of time. Explain that both the Time Delay Express VI and the Wait (ms) VI work the same way. Follow on page 3-11

71 Numeric Conversion Numerics default to double-precision (8 bytes) or long integer (4 bytes) LabVIEW automatically converts to different representations For Loop count terminal always converts to a long integer Gray coercion dot on terminal indicates conversion The default representation of a numeric control or indicator is a double-precision floating-point number. LabVIEW can represent a number as: Byte (8-bit) signed or unsigned integer. Word (16-bit) signed or unsigned integer. Long (32-bit) signed or unsigned integer. Single-precision (32-bit) floating-point number. Double-precision (64-bit) floating-point number. Extended-precision (96-bit*) floating-point number. * Depends upon the operating system When two terminals of different data types are wired together, LabVIEW will convert one numeric to the same representation as the other. This is signified by a gray “coercion dot.” Class participation: Ask why the while loop MUST convert an input to an integer. <hint: can you have 1.5 loops?>

72 Numeric Conversion LabVIEW chooses the representation that uses more bits. If the number of bits is the same, LabVIEW chooses unsigned over signed. To choose the representation, right-click on the terminal and select Representation. When LabVIEW converts floating-point numerics to integers, it rounds to the nearest integer. LabVIEW rounds x.5 to the nearest even integer. For example, LabVIEW rounds 2.5 to 2 and 3.5 to 4. If you wire two different numeric data types to a numeric function that expects the inputs to be the same data type, LabVIEW converts one of the terminals to the same representation as the other terminal. PREPARE for this slide. Carefully read and think through how to explain the last bullet point. A good idea is to use LabVIEW to demonstrate this point. Place a For Loop on the block diagram (note that they have not been introduced to for loops at this time, so use your best judgment about doing this first), wire a double precision numeric to the number of iterations input. Wire the index output through an increment and then out of the For loop, disabling indexing. Run the VI to show that 3.4 rounds to rounds to rounds to rounds to rounds to 4!

73 Accessing Previous Loop Data – Shift Register
• Available at left or right border of loop structures • Right-click the border and select Add Shift Register • Right terminal stores data on completion of iteration • Left terminal provides stored data at beginning of next iteration Before Loop Begins First Iteration Second Last Initial Value Value 1 Value 2 Value 3 Initial Value Shift registers transfer data from one iteration to the next: Right click on the left or right side of a For Loop or a While Loop and select Add Shift Register. The right terminal stores data at the end of an iteration. Data appears at the left terminal at the start of the next iteration. A shift register adapts to any data type wired into it. Stress why you need a shift register—to retain values from one iteration to the next. Explain the slide in detail. Go slowly and repeat yourself.

74 Additional Shift Register Elements
Right-click the left terminal to add new elements Previous values are available at the left terminals Right-click the border for a new shift register Latest value is passed to right terminal 1 loop ago 2 loops ago 3 loops ago You can configure the shift register to remember values from several previous iterations. Right click on the left terminal and choose Add Element to create additional terminals. Explain the slide: The shift register allows you to access values from the past three iterations if you have three terminals. This method is different from using separate shift registers: One shift register with added terminals is storing multiple previous values of one variable. Multiple shift registers maintain a single previous value of multiple variables. Demonstrate the difference between adding a shift register vs. adding an element to a shift register.

75 Feedback Nodes Appears automatically in a For Loop or While Loop if you wire the output of a subVI, function, or group of subVIs and functions to the input of that same VI, function, or group. Stores data when the loop completes an iteration, sends that value to the next iteration of the loop, and transfers any data type

76 Feedback Node Wire from output to input to automatically create a feedback node <OR> Place a feedback node from the Functions»Structures palette If you place the Feedback Node on the wire before you branch the wire that connects the data to the tunnel, the Feedback Node passes each value to the tunnel. If you place the Feedback Node on the wire after you branch the wire that connects data to the tunnel, the Feedback Node passes each value back to the input of the VI or function and then passes the last value to the tunnel. A good way to visualize this is to think of the execution as starting at the feedback node.

77 Initialized Shift Registers & Feedback Nodes
Output = 5 Output = 5 Run Once VI stops execution Run Again Output = 5 Output = 5

78 Uninitialized Shift Registers & Feedback Nodes
Output = 4 Output = 8 Run Once VI stops execution Run Again Output = 4 Output = 8

79 Summary Two structures to repeat execution: While Loop and For Loop
Loop timing controlled using Wait Until Next ms Multiple function, the Wait (ms) function, or the Time Delay Express VI. Coercion dots appear where LabVIEW coerces a numeric representation of one terminal to match the numeric representation of another terminal Feedback nodes and shift registers transfer data values from one iteration to the next Use shift registers only when more than one past iteration is needed Do not immediately display this slide. Suggested questions for class participation: What structure must ALWAYS run at least once? What structures are used to repeat execution of certain functions? How can you control the speed at which the loop executes? Describe the difference between the three types of charts. Why would you want to use a shift register? Why would you want to use a feedback node? How do you retain multiple values from previous iterations? Review the slide: The purpose of Lesson Four was to introduce LabVIEW structures. Structures control the flow of data in a VI.

80 Lesson 4 Arrays TOPICS Introduction to Arrays Auto Indexing Arrays
Array Functions Polymorphism

81 Arrays • Collection of data elements that are of same type
• One or more dimensions, up to 2 elements per dimension • Elements accessed by their index; first element is index 0 31 index 10-element array 1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7 2D array Arrays are lists of elements of the same data type. They are analogous to arrays in traditional languages. Arrays can have one or more dimensions. Arrays can have up to 2^31 elements per dimension. Actual array sizes that students can create is limited by memory. Elements are accessed by “index”. The index ranges from 0 to N-1 (N = number of elements in the array). Arrays are zero-indexed (first element is zero) in each dimension. A 2D array is analogous to a spreadsheet or table. Example: Temperature readings and time stamp. One column is time values, and the other column is readings. Point out element (2,3) and element (3,2) on the slide. Be careful to specify the element you really want. Example: The first element in an array is array (0), not array(1). 1 2 3 4 Five row by seven column array of 35 elements

82 Array Controls and Indicators
1. Select the Array shell from the Controls palette 2. Place data object inside shell Creating arrays in LabVIEW: Choose Array from the Array and Cluster palette You can place any data type in an array shell except an array. You cannot have an array of arrays; use a 2D array instead. Two components: index and data object. Emphasize that this is a two-step process. Students often place only empty array shells on the front panel. Remind them they must place a data type inside the array shell. Demonstrate the following on your computer: Create a numeric array. Point out index and data object components. Show how to create a 2D array. Show how to display multiple array elements. Show that index elements always reference the upper-leftmost object in the array display. Show how elements in an array are initially “grayed-out,” indicating that a portion of the array has not been defined. Add Dimension for 2D arrays

83 Creating Array Constants
1. Select Array Constant shell from the Array subpalette Creating array constants uses the same two-step process as a front panel array. Select an array constant from the Array subpalette of the Functions palette. Place a constant data type inside the empty array shell. Note again that the data types are “grayed-out” and must be manually defined if the user wants to store values in the array constant. 2. Place the data object in the array shell

84 Auto-Indexing Auto-Indexing Enabled Loops can accumulate arrays at their boundaries with auto-indexing For Loops auto-index by default While Loops output the final value by default Right-click on tunnel and enable/disable auto-indexing Wire becomes thicker 1D Array Auto-Indexing Disabled Wire remains the same size For Loops and While Loops can index and accumulate arrays at their boundaries. This is known as auto-indexing. The indexing point on the boundary is called a tunnel. The For Loop default is auto-indexing enabled. The While Loop default is auto-indexing disabled. Examples: Enable auto-indexing to collect values within the loop and build the array. All values are placed in array upon exiting loop. Disable auto-indexing if you are interested only in the final value. Only one value (last iteration) is passed out of the loop

85 Creating 2D Arrays Inner loop creates column elements
You can use two nested For Loops to create a 2D array. Auto- indexing must be enabled for both. Inner loop creates column elements. Outer loop creates row elements. Explain the different line thicknesses. Demonstrate on your computer: How to change indexing and line thickness. Enable Indexing in pop-up menu means indexing is currently disabled. The menu choice is the opposite of the current index mode. Students get confused about this feature. Inner loop creates column elements Outer loop stacks them into rows

86 Auto-Index Input An array input can be used to set the For Loop count terminal Number of elements in the array equals the count terminal input Run arrow not broken If you enable auto-indexing on an array wired to a For Loop input terminal, LabVIEW sets the count terminal to the array size so you do not need to wire the count terminal. In the following example, the For Loop executes a number of times equal to the number of elements in the array. Normally, if the count terminal of the For Loop is not wired, the run arrow is broken. However, in this case the run arrow is not broken. Auto-indexing can be used on input arrays: For calculations to be performed on each element of array, use auto-indexing. To pass the entire array into a loop, disable auto-indexing.

87 Common Array Functions
Array Size LabVIEW has many functions to manipulate arrays in the Array subpalette of the Functions palette. Array Size: The number of elements in the input array: 1D array: Output is a numeric. Multidimensional array: Array output with elements signifying size of each dimension. (Example: A 2 x 4 array will output array of two elements, with first element = 2 and second element = 4). Initialize Array: Creates an array of n dimensions containing the value tied to the element input. Initialize array can be “stretched out” to add more “dimension size” input terminals. You must have one “dimension size” input terminal for each dimension in the array. Initialize Array

88 Common Array Functions
Array Subset Returns a portion of an array starting at index and containing length elements. For example, if you use the previous array as the input, the Array Subset function returns the following array for an index of 2 and a length of 3.

89 The Build Array Function
Appending an element Concatenate Inputs Build Array: Concatenates elements together into one array or concatenates multiple arrays together into arrays of higher dimension. Build array can be “stretched-out” to add additional input terminals Input terminals are set as Array input or Element input. Popping up on the input terminals allows selection of Change to Array/Element input. To concatenate arrays or elements together into one longer array, arrays must be tied to Array input terminals and single elements must be tied to Element input terminals. To create a higher dimensional array, arrays must be tied to Element input terminals. Students often are confused by the difference. Demonstrate on your machine the difference between “Array” and “Element” input. Building a higher dimension array default

90 The Index Array Function
Extracting an Element Extracting a Row Index Array: accesses a specific element of the input array. Index Array can be “stretched-out” to add more index terminals. You must have one index terminal for each dimension in the input array. The slide example shows accessing a single element of a one-dimensional array. Index Array does not remove the element from the array. Remind students that arrays start their indices at zero. Index 2 in the example actually accesses the third element in the array. Extracting an Element of a Row

91 Polymorphism Function inputs can be of different types
All LabVIEW arithmetic functions are polymorphic Combination Result Scalar Scalar + Scalar Array + Scalar Array Array + Array Array LabVIEW arithmetic functions are polymorphic: Inputs to these functions can be of different types. The node automatically performs the appropriate function on unlike data. Greatly simplifies array arithmetic. Examples of polymorphism in slide: Scalar+Scalar: Scalar addition. Scalar+Array: The scalar is added to each element of array. Array+Array: Each element of one array is added to the corresponding element of other array. Remind students that polymorphism does not perform matrix arithmetic when inputs are 2D arrays (for example, two 2D array inputs to a multiply function does element by element multiplication, not matrix multiplication). Show an example on polymorphism if the class does not understand the concept. Array + Array Array

92 Summary Arrays group data elements of the same type. You can build arrays of numeric, Boolean, path, string, waveform, and cluster data types. The array index is zero-based, which means it is in the range 0 to n – 1, where n is the number of elements in the array. To create an array control or indicator, select an Array on the Controls»Array & Cluster palette, place it on the front panel, and drag a control or indicator into the array shell. If you wire an array to a For Loop or While Loop input tunnel, you can read and process every element in that array by enabling auto-indexing. By default, LabVIEW enables auto-indexing in For Loops and disables auto-indexing in While Loops. Polymorphism is the ability of a function to adjust to input data of different data structures. Do not immediately display this slide. Suggested questions for class participation: What is an array? Where might it be used? How would I create a 2D array of numeric controls? How can a loop create an array? Which loops can be used to do so? What does “polymorphic” mean?


Download ppt "LabVIEW Introduction Course Semester"

Similar presentations


Ads by Google