Introduction%20to%20 labview


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Introduction%20to%20 labview

  1. 1. Virtual Instrumentation With LabVIEWLabVIEW 試用•下載試用版: 台大有購買全校版 OR Labview軟體 Labview軟體‧網路導覽與試用: 放置於 計中全校版軟體網頁 OR•購買LabVIEW學生版 請自行注意相關版權限 制及認證方式 1
  2. 2. Course Goals•Understand the components of a Virtual Instrument•Introduce LabVIEW and common LabVIEW functions• some simple VIs (applications)Build•Create a subroutine in LabVIEW•Work with Arrays, Clusters, and Structures•Learn About Printing & Documentation Features•Develop in Basic Programming Architectures Section I Introduction to the Labview Basic concepts and terms 2
  3. 3. Section I•LabVIEW terms•Components of a LabVIEW application•LabVIEW programming tools•Creating an application in LabVIEWText-based programming•Traditional computer programming involves setting down a list oftasks for the computer to execute in the given sequential order.•Each instruction is executed in the order of appearance.• may not be efficient as some instruction may not needThisprevious data.• Control flow” Figure 1. A Sequence of Instructions in “ programming. 3
  4. 4. Graphical programming • LabVIEW programming consists of drawing pictures that specify the operations and the data dependencies. • computer can execute the instructions in any order that The protects the data dependencies. • most people, pictures are much easier to understand than a For list of instructions. Figure 2. Program for Multiplying Two Numbers and Displaying the Result• LabVIEW program, called a virtual instrument (VI), is a two-window A system. The code is in one window and the user interface (inputs and outputs) appears in a separate window. The program window is the block diagram window, and the user inputs and outputs are in the front panel window. Figure 2 shows a sample program that would appear in the block diagram window. The numbers are entered into the computer and displayed in the front panel window shown in Figure 3. The two boxes on the left (labeled A and B) are controls, and the box on the right (labeled C) is the output or indicator. (The X and = are only displays showing the operation of the VI and not inputs or outputs.) The three boxes are associated with like labeled boxes in the diagram window shown in Figure 2. Figure 3. Front Panel for a Two-Number Multiplication Program 4
  5. 5. LabVIEW Programs Are Called Virtual Instruments (VIs)Front Panel (user interface, UI) •Controls = Inputs •Indicators = Outputs Click Window to exposeBlock Diagram (graphical code) •Accompanying “ program” for front panel •Components “ wired”together •Data travel on wires from controls through functions to indicators. •Blocks execute by Dataflow.VI Front PanelFront Panel IconToolbarBooleanControl Graph LegendWaveformGraphPlot ScaleLegend Legend 5
  6. 6. VI Block Diagram NodesBlockDiagramToolbar Divide FunctionSubVI Graph Terminal Wire DataWhile Loop Numeric Timing Boolean ControlStructure Constant Function TerminalVI Block Diagram wiresBlockDiagramToolbar Divide FunctionSubVI Graph Terminal Wire DataWhile Loop Numeric Timing Boolean ControlStructure Constant Function Terminal 6
  7. 7. Connection lines represent data typesData types 7
  8. 8. Terminals: links between blockVI Block Diagram diagram and the front panel Control terminals Indicator terminalsCreating a VI Terminals: links between block Front Panel Window diagram and the front panel Block Diagram Window Control Indicator terminals terminals 8
  9. 9. Controls Palette (Placethe Front Panel (right click) In items on the Front Panel Window)(Controls & Indicators) Control: Customize Numeric Palette View Indicator: Numeric Slide What Types of Controls and Indicators are Available?•Numeric Data –Number input and display –Analog Sliders, Dials, and Gauges Express Controls Palette•Boolean Data –Buttons and LEDs•Array & Matrix Data –Numeric Display –Chart –Graph –XY Graph –Intensity Graph –3D graph: point, surface, and model•Decorations –Tab Control –Arrows•Other –Strings and text boxes –Picture/Image Display –ActiveX Controls 9
  10. 10. Functions (and Structures) Palette Right click or View_Function In the block diagram (Place items on the Block Diagram Window) Structure: While LoopTools Palette View_Tool •Floating Palette •Used to operate and modify front panel and block diagram objects. Automatic Selection Tool Operating Tool Scrolling Tool pause execution Positioning/Resizing Tool Breakpoint Tool in a VI Check intermediate Labeling Tool Probe Tool values in a VI Wiring Tool Color Copy Tool Shortcut Menu Tool Coloring Tool 10
  11. 11. Status Toolbar Run Button Continuous Run Button Additional Buttons on the Block Diagram Toolbar Abort Execution Pause/Continue Button Execution Highlighting Button Text Settings Single-Stepping through a VI Align Objects Step Into Button Distribute Objects Step Over Button Reorder Step Out Button Resize front panel objectsFinding an example VI Help_Find Examples Example finder 11
  12. 12. Creating a VI Front Panel Window Block Diagram Window Control Indicator Terminals TerminalsCreating a VI –Block Diagram 12
  13. 13. Wiring Tips –Block Diagram Wiring “ Spot” Hot Click To Select WiresUse Automatic Clean Up Wiring Wire RoutingDataflow 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 13
  14. 14. Help Options Context Help •Online help •Lock help •Simple/Complex Diagram help •Ctrl + H Additional Help •Right-Click on the VI icon and choose Help •Choose “ Detailed Help.” the context help window onExercise 1 - Convert °C to °F 1 14
  15. 15. Debugging Techniques •Finding Errors Click on broken Run button Window showing error appears •Execution Highlighting Click on Execution Highlighting button; data flow is animated using bubbles. Values are displayed on wires. •Probe Right-click on wire to display probe and it shows data as it flows through wire segment You can also select Probe tool from Tools palette and click on wire Section II Sub VI 15
  16. 16. Block Diagram Nodes 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 _______________(VIs that are interactive)Section II –SubVIs•What is a subVI?•Making an icon andconnector for a subVI•Using a VI as a subVI 16
  17. 17. SubVIs• SubVI is a VI that can be used within another VIA•Similar to a subroutine•Advantages –Modular –Easier to debug –Don’t have to recreate code –Require less memoryIcon and Connector • icon represents a VI in other block An Icon diagrams Terminals • connector shows available A terminals for data transfer Connector 17
  18. 18. SubVIs Sub VIsSteps to Create a SubVI•Create the Icon•Create the Connector•Assign Terminals•Save the VI•Insert the VI into a Top Level VI 2 18
  19. 19. Create the Icon•Right-click on the icon in theblock diagram or front panelCreate the Connector Right click on the icon pane (front panel only) 19
  20. 20. Assign TerminalsSave The VI•Choose an Easy to Remember Location•Organize by Functionality –Save Similar VIs into one directory (e.g. Math Utilities)•Organize by Application –Save all VIs Used for a Specific Application into one directory or library file (e.g. Lab 1 –Frequency Response) •Library Files (.llbs) combine many VI’into a single file, ideal for s transferring entire applications across computers 20
  21. 21. Insert the SubVI into a Top Level VIAccessing user-made subVIs Functions >>All Functions >> Select a VIOr Drag icon onto target diagram 3Tips for Working in LabVIEW•Keystroke Shortcuts –<Ctrl-H> –Activate/Deactivate Context Help Window –<Ctrl-B> –Remove Broken Wires From Block Diagram –<Ctrl-E> –Toggle Between Front Panel and Block Diagram –<Ctrl-Z> –Undo (Also in Edit Menu)•Tools » Options… –Set Preferences in LabVIEW• Properties –Configure VI Appearance,VIDocumentation, etc. 21
  22. 22. Section III Loops and ChartsSection III –Loops and Charts • While Loop • Loop For • Charts • Multiplots 22
  23. 23. Loops While Loop•While Loops –i terminal counts iteration –Always runs at least once –Runs until stop condition is met For Loop• LoopsFor –i terminal counts iterations –Run according to input N of count terminalDrawing a Loop 2. Enclose code to be repeated1. Select the loop structure Drawing a Loop 3. Drop or drag additional nodes and then wire 4 23
  24. 24. 3 Types of Functions (from the Functions Palette) Express VIs, VIs and FunctionsExpress VIs: interactive VIs with configurable dialog page (blue border)3 Types of Functions (from the Functions Palette) Express VIs, VIs and FunctionsStandard VIs: consisting of a front panel and a block diagram modularized VIs customized by wiring (customizable) 24
  25. 25. 3 Types of Functions (from the Functions Palette) Express VIs, VIs and FunctionsFunctions: fundamental operating elements of LabVIEW; no front panel orblock diagram (yellow)What Types of Functions are Available?•Input and Output –Signal and Data Simulation Express Functions Palette –Acquire and Generate Real Signals with DAQ –Instrument I/O Assistant (Serial & GPIB) –ActiveX for communication with other programs•Analysis –Signal Processing –Statistics –Advanced Math and Formulas –Continuous Time Solver•Storage –File I/O 25
  26. 26. Searching for Controls, VIs, and Functions•Palettes are filled with hundreds of VIs•Press the search button to index the all VIs for text searching•Click and drag an item from the search window to the block diagram•Double-click an item to open the owning palette right click on loop borderShift Registers in Loops Add Shift registerUse shift registers with For Loops and While Loopsto transfer values from one loop iteration to thenext. Shift registers are similar to static variables intext-based programming languages. 5 26
  27. 27. Charts Waveform chart •special numeric indicator that can display a history of values •Chart updates with each individual point it receives Front Panal» Controls»Express»Graph Indicators»ChartWiring Data into Charts Single Plot Charts Multiplot Charts in functiion/Express/ functiion/Express/ Signal manipul 27
  28. 28. Exercise 3 –Using Charts 6 7 Section IV Arrays and File I/O 28
  29. 29. Section IV –Arrays & File I/O•Build arrays manually•Have LabVIEW build arrays automatically•Write to a spreadsheet file•Read from a spreadsheet fileCreating an Array (Step 1 of 2)From the Controls»Modern»Array, Matrix, andCluster subpalette, select the Array icon. Drop it on the Front Panel. 29
  30. 30. Create an Array (Step 2 of 2)1. Place an Array Shell.2. Insert datatype into the shell (e.g. Numeric Control).Creating an Array with a Loop•Loops accumulate arrays at their boundaries•Pulling a wire through a loop boundary creates an input tunnel While Loop default no autoindexing For Loop default with autoindexing 8 30
  31. 31. Creating 2D Arrays 9 9-1File I/O• I/O –Allows recording or reading data in a file.File•LabVIEW creates or uses the following file formats: –Binary: underlying file format of all other file formats –ASCII: regular text files –LVM: LabVIEW measurement data file –TDM: created for National Instruments products 31
  32. 32. High Level File I/O Functions Easy to use • High Level of abstraction • Writing to LVM file Reading from LVM fileWrite LabVIEW Measurement File•Includes the open, write, close and error handling functions•Handles formatting the string with either a tab or commadelimiter•Merge Signals function is used to combine data into thedynamic data type 10 32
  33. 33. File I/O Programming Model –Under the hood Open/ Read Close Check for Create/ and/or File ErrorsReplace File Write to FileSpreadsheet Formatting•Spreadsheet files are ASCII files with a certainformatting –Usually tabs between columns and end of line constants between rows –LabVIEW includes VIs that perform this formatting or a string can be concatenated 10-1 10- 33
  34. 34. Section V Array Functions & GraphsSection V –Array Functions & Graphs•Basic Array Functions•Use graphs•Create multiplots with graphs 34
  35. 35. Array Functions –BasicsFunctions >> All functions>> ArrayArray Functions –Build Array 35
  36. 36. Graphs•Selected from the Graph palette of Controls menuControls>>All Controls>>GraphsA Graph will display or update itsplot after receiving all data.Waveform Graph – Plot an array ofnumbers against their indicesExpress XY Graph – Plot one arrayagainst anotherDigital Waveform Graph – Plot bitsfrom binary dataGraphs Right-Click on the Graph and choose Properties to Interactively Customize 36
  37. 37. Exercise 5 –Using Waveform Graphs 11 37
  38. 38. Section VI Strings, Clusters & Error HandlingSection VI –Strings, Clusters, & Error HandlingStrings•Creating Clusters•Cluster Functions•Error I/O• 38
  39. 39. Strings• string is a sequence of displayable or nondisplayableAcharacters (ASCII)•Many uses – displaying messages, instrument control, fileI/OString control/indicator is in the Controls »Text Control or•Text IndicatorClusters•Data structure that groups data together•Data may be of different types•Analogous to struct in C•Elements must be either all controls or all indicators•Thought of as wires bundled into a cable 39
  40. 40. Creating a Cluster1. Select a Cluster shell 2. Place objects inside the shellControls >> All Controls >> Array & ClusterCluster Functions •In the Cluster subpalette of the Functions>>All functions palette •Can also be accessed by right-clicking on the cluster terminal (Terminal labels reflect data type) Bundle Bundle By Name 40
  41. 41. Cluster Functions Unbundle Unbundle By Name Unbundled cluster in the diagramError Clusters•Error cluster contains the following information: –Boolean to report whether error occurred –Integer to report a specific error code –String to give information about the error 41
  42. 42. Exercise 6 –Error Clusters & HandlingError Handling Techniques•Error information is passed from one subVI to the next• an error occurs in one subVI, all subsequent subVIs are If not executed in the usual manner•Error Clusters contain all error conditions•Automatic Error Handling error clusters 42
  43. 43. Section VII Case & Sequence Structure Formula NodesHow Do I Make Decisions in LabVIEW?1. Case Structures (/Programming/Structure) (a) (b)2. Select(/Programming/comparison) (c) 43
  44. 44. Case Structures• the Structures subpalette of Functions palette In•Enclose nodes or drag them inside the structure•Stacked like a deck of cards, only one case visibleFunctions >> Execution controlCommunicating between loops•Communicating between loops using dataflow is not possible • left loop will execute completely The before the right loop•Variables are needed when communicationwith wires does not give the desired behavior 44
  45. 45. Local Variables• Local Variables allow data to be passed between parallel loops.• single control or indicator can be read or written to from more than one Alocation in the program – Local Variables break the dataflow paradigm and should be used sparinglySequence Structures• the Execution Control subpalette of Functions palette In•Executes diagrams sequentially•Right-click to add new frame 45
  46. 46. Formula Nodes• the Structures subpalette In•Implement complicated equations•Variables created at border by “ input” “ output” add or add•every assigned variable (left of equation) must have an output terminal on the formula node.•Variable names are case sensitive•Each statement must terminate with a semicolon (;) Note semicolon Section VIII Printing & Documentation 46
  47. 47. Section VIII –Printing & Documentation• From File Menu to Printer, HTML, Rich Text FilePrint•Programmatically Print Graphs or Front Panel Images•Document VIs in VI Properties » Documentation Dialog• Comments Using Free Labels on Front Panel &AddBlock DiagramPrinting• » Print…Gives Many Printing OptionsFile –Choose to Print Icon, Front Panel, Block Diagram, VI Hierarchy, Included SubVIs, VI History• (Programmatically Prints a Front Panel)Print –Functions » All Functions » Application ControlGenerate & Print Reports (Functions » Output » Report)• 47
  48. 48. Documenting VIs• Properties » DocumentationVI –Provide a Description and Help Information for a VI• Properties » Revision HistoryVI –Track Changes Between Versions of a VI•Individual Controls » Description and Tip… –Right Click to Provide Description and Tip Strip• Labeling Tool to Document Front Panels & BlockUseDiagrams Section IX Basic Programming Architecture 48
  49. 49. Section IX –Basic Programming Architecture•Simple VI Architecture•General VI Architecture•State Machine ArchitectureSimple VI Architecture•Functional VI that produces results when run – “ or “ options No start” stop” –Suitable for lab tests, calculations•Example: Convert C to 49
  50. 50. General VI Architecture•Three Main Steps –Startup –Main Application –ShutdownState Machine Architecture•Advantages – go from any state from any other Can –Easy to modify and debug•Disadvantages – lose events if two occur at the Can same time States: 0: Startup 1: Idle 2: Event 1 3: Event 2 4: Shutdown 50
  51. 51. Exercise 7 –Simple State Machine Section X Data Acquisition 51
  52. 52. Measuring with your computer Analog and Digital 52
  53. 53. Data Acquisition DAQ Device•Data acquisition (DAQ) basics•Connecting Signals•Simple DAQ application Computer Sensors Cable Terminal BlockMultiple sensors in practical applications 53
  54. 54. Differential v.s. Referenced Single End Inputs Simultaneous sample and hold 54
  55. 55. All integrated in a multi-function DAQ deviceData Acquisition in LabVIEWTraditional NI-DAQ NI-DAQmxSpecific VIs for Next generation driver:performing: • for performing a VIs•Analog Input task•Analog Output • set of VIs for all One•Digital I/O measurement types•Counter operations 55
  56. 56. Data Acquisition TerminologyResolution - Determines How Many Different Voltage•Changes Can Be Measured –Larger Resolution  More Precise Representation of SignalRange - Minimum and Maximum Voltages• –Smaller range  More Precise Representation of SignalGain• - Amplifies or Attenuates Signal for Best Fit inRange 56
  57. 57. USB 6009 multifunctional DAQ device Analog in/out Digital in/out 57
  58. 58. Use of DAQ assistantDefining your task 58
  59. 59. Configuring your task (analog input)Appointing Channels to acquire from 59
  60. 60. Physical channels versus Global channels Configuring your analog input task Pressing OK will generate all the LabView code automatically. 60
  61. 61. USB 6009 is a low cost deviceA typical DAQ VI using traditional programming 61
  62. 62. With DAQ assistant, the whole VI can be as simple as:What Types of Instruments Can Be Controlled? • GPIB • Serial • Modular Instruments • PXI Modular Instruments • Image Acquisition • Motion Control • USB • Ethernet • Parallel Port • Voice 62
  63. 63. Section XI Remote Front PanelsSection XI –Remote Front Panels• & Control LabVIEW Front Panels from a WebViewBrowser•Requires no programming•Remote clients see “ front panel updates live”•Multiple clients can view the same panelsimultaneously• one client can control the front panel at a timeOnly 63
  64. 64. Remote Panel Web Publishing Tool•Tools » Web Publishing Tool…•Click Save to Diskand VI is embeddedinto an HTML file•After file is saved, itcan be reopened andcustomized in anyHTML editorRemote Front Panels - Resources• Developer ZoneNI( –Search for Remote Front Panel –Tutorials & Instructions Are Available for Download –Information on Incorporating Web Cameras into Remote Panel Applications 64
  65. 65. Section XII –Large Program Development and Additional TopicsA. Navigation WindowB. LabVIEW ProjectC. Shared VariableD. Additional topics – Property Nodes – Local Variables – Global Variables – DataSocket – Binary File I/OLabVIEW Navigation Window •Shows the current region of view compared to entire Front Panel or Block Diagram •Great for large programs * Organize and reduce program visual size with subVIs 65
  66. 66. LabVIEW Project•Group and organize VIs•Hardware and I/O management•Manage VIs for multiple targets• libraries and executablesBuild•Manage large LabVIEW applications•Enable version tracking and management (LabVIEW»Project»New)Shared Variables•Shared Variables are used to send data between VIs.•Variable Types: –Single Process: share the data among VIs on the local computer. –Network-published: communicate between VIs, remote computers, and hardware through the Shared Variable Engine.•Shared Variable must exist within a project library.•Shared Variable must be deployed to be available to other projects and remote computers. 66
  67. 67. Additional topics –Property Nodes –Local Variables –Global Variables –DataSocket –Binary File I/OAdditional Resources• Academic Web & Student Corner NI –•Connexions: Full LabVIEW Training Course – –Or search for “ LabVIEW basics”•LabVIEW Certification –LabVIEW Fundamentals Exam (free on –Certified LabVIEW Associate Developer Exam (industry recognized certification ) r•Get your own copy of LabVIEW Student Edition d fo da t e W 8 Up VIE – Lab By Robert H Bishop. Published by Prentice Hall. 67
  68. 68. The LabVIEW Certification ProgramArchitect•Mastery of LabVIEW Certified•Expert in large application development LabVIEW•Skilled in leading project teams ArchitectDeveloper•Advanced LabVIEW knowledge and application development Certified LabVIEW experience Developer•Project management skillsAssociate Developer•Proficiency in navigating Certified LabVIEW Associate LabVIEW environment Developer•Some applicationdevelopment experienceFundamentals Exam•Pre-Certification Skills Test Free On-Line Fundamentals Exam On-Your Next Step…Take the free LabVIEW Fundamentals Exam at Your first step to become LabVIEW Certified! 68