Presentation on theme: "A. Virtual Instruments (VIs)"— Presentation transcript:
1 A. Virtual Instruments (VIs) Virtual Instrument (VI) – A LabVIEW programThe appearance and operation of VIs imitate physical instruments, such as oscilloscopes and digital multimeters.
2 B. Parts of a VILabVIEW VIs contain three main components: 1. Front Panel 2. Block Diagram 3. Icon/Connector Pane
3 B. Parts of a VI – Front Panel Front Panel – User interface for the VIYou build the front panel with controls (inputs) and indicators (outputs)Just discuss how a front panel is the user interface of the VI and contains controls and indicators. A section following this slide concentrates on the front panel in more depth.
4 B. Parts of a VI – Block Diagram Block Diagram – Contains the graphical source codeFront panel objects appear as terminals on the block diagram
5 B. Parts of a VI – Icon/Connector Pane Icon: graphical representation of a VIConnector Pane: map of the inputs and outputs of a VIIcons and connector panes are necessary to use a VI as a subVIA subVI is a VI that is inside of another VISimilar to a function in a text-based programming languageIcon Connector Pane
6 E. Front Panel – Controls Palette Contains the controls and indicators you use to create the front panelAccess from the front panel by selecting View»Controls Palette
7 E. Front Panel – Controls & Indicators Knobs, push buttons, dials, and other input devicesSimulate instrument input devices and supply data to the block diagram of the VIIndicatorsGraphs, LEDs, and other displaysSimulate instrument output devices and display data the block diagram acquires or generates
8 E. Front Panel – Numeric Controls/Indicators The numeric data type can represent numbers of various types, such as integer or realNumeric ControlIncrement/Decrement ButtonsIn the next few slides, you discuss basic data types: numerics, strings and Booleans. Discuss only front panel information here, such as appearance and what type of data you put in the control/indicator.You will discuss representation, mechanical action, and string display types in the next lesson.Numeric Indicator
9 E. Front Panel – Boolean Controls/Indicators The Boolean data type represents data that only has two parts, such as True and False or On and OffUse Boolean controls and indicators to enter and display Boolean (True or False) valuesBoolean objects simulate switches, push buttons, and LEDsYou will discuss the use of Booleans later, just talk about what they are here.BooleanControlBooleanIndicator
10 E. Front Panel – StringsThe string data type is a sequence of ASCII charactersUse string controls to receive text from the user such as a password or user nameUse string indicators to display text to the userDisplay types covered later. Just cover the basic concept here.
11 E. Front Panel – Shortcut Menus All LabVIEW objects have associated shortcut menusAs you create a VI, use the shortcut menu items to change the look or behavior of front panel and block diagram objectsTo access the shortcut menu, right-click the object
12 E. Front Panel – Property Dialog Box Right-click a front panel object and select Properties to displayThe options available on the property dialog box are similar to the options available on the shortcut menu for that object
13 E. Front Panel – Configure Multiple Objects Select multiple objects to simultaneously configure shared properties
14 Configuring Your LabVIEW Environment Functions PaletteTack the Functions palette and select Customize»Change Visible Categories then click Select AllControls PaletteTack the Controls palette and select Customize»Change Visible Categories then click Select All
16 F. Block Diagram Terminals SubVIs Functions Constants Structures Wires Block diagram objects include the following:TerminalsSubVIsFunctionsConstantsStructuresWires
17 F. Block Diagram – Terminals Terminals are:Block diagram appearance of front panel objectsEntry and exit ports that exchange information between the front panel and block diagramAnalogous to parameters and constants in text-based programming languagesChange the view type of a terminal by toggling the View as Icon selection from the context menuIf you would like to, this is an excellent place to have your students change the view type of the terminal.
18 F. Block Diagram Terminals Discuss the visual difference between controls and indicators on the block diagram, and discuss the difference in operation between controls, constants and indicators. Especially that constants are only available on the block diagram.Right-click to change...
19 B. LabVIEW Data Types – Terminals Terminals visually communicate information about the data type representedShow that datatype is represented by the color, orange here, and the text on the terminal, DBL here.
20 F. Block Diagram – WiresTransfer data between block diagram objects through wiresWires are different colors, styles, and thicknesses, depending on their data typesA broken wire appears as a dashed black line with a red X in the middleDBL Numeric Integer Numeric StringScalar1D Array2D Array
21 F. Block Diagram – NodesObjects on the block diagram that have inputs and/or outputs and perform operations when a VI runsAnalogous to statements, operators, functions, and subroutines in text-based programming languagesNodes can be functions, subVIs, or structuresNodes
22 H. Selecting A ToolCreate, modify, and debug VIs using the tools provided by LabVIEWA tool is a special operating mode of the mouse cursorThe operating mode of the cursor corresponds to the icon of the tool selectedWhen using the Automatic Tool Selection, LabVIEW chooses which tool to select based on the current location of the mouse
23 PracticeLook and the block diagram of the previous practice and add the following nodes:AddMultiplyRandom numberGreater thanLess thanGet date/time in secondsThen use wires to connect all the elements of the block diagram leaving no terminal unconnected.Target:Simulate a given temperature value, add a random noise of given amplitude, then light up an alert when such a temperature is greater than setpoint and another if is less than setpoint .
25 F. Block Diagram – Function Nodes Fundamental operating elements of LabVIEWDo not have front panels or block diagrams, but do have connector panesDouble-clicking a function only selects the function – does not open it like a VIHas a pale yellow background on its icon
26 F. Block Diagram – SubVI Nodes SubVI: VIs that you build to use inside of another VIAny VI has the potential to be used as a subVIWhen you double-click a subVI on the block diagram, you can view the front panel and block diagram of the subVIThe upper right corner of the front panel and block diagram displays the icon for the current VIThis is the icon that appears when you place the VI on a block diagram as a subVIThis is where you describe what a subVI is. In lesson 7, the student will learn how to build a subVI, but should already be very familiar with what they are, and how to use them.
27 F. Block Diagram – WiresTransfer data between block diagram objects through wiresWires are different colors, styles, and thicknesses, depending on their data typesA broken wire appears as a dashed black line with a red X in the middleDBL Numeric Integer Numeric StringScalar1D Array2D Array
28 B. LabVIEW Data Types – Terminals Terminals visually communicate information about the data type representedShow that datatype is represented by the color, orange here, and the text on the terminal, DBL here.
29 B. LabVIEW Data Types – Numerics The numeric data type represents numbers of various typesTo change the representation of a numeric, right-click the control, indicator, or constant, and select Representation from the shortcut menuStudents learned about the numeric, Boolean and string datatype in Lesson 2. Now, they learn about implementing these datatypes, such as representation, Boolean action, and string display type. They will also learn a couple new datatypes: Enum and dynamic.Here, talk about the difference between integers, floating point, etc...
30 B. LabVIEW Data Types – Boolean Behavior of Boolean controls is specified by the mechanical actionIn LabVIEW, the Boolean data type is represented with the color green
31 Mechanical Action of Booleans Use the Mechanical Action of Booleans VI located in the NI Example Finder to learn about the different switch and latch actions.Have all students open this example program and experiment with it as you demonstrate.
32 B. Data Types – StringA sequence of displayable or non-displayable ASCII charactersOn the front panel, strings appear as tables, text entry boxes, and labelsChange the display type from the short-cut menu: Normal, ‘\’ Codes, Password and HexEdit and manipulate strings with the String functions on the block diagramIn LabVIEW, the string data type is represented with the color pink
33 B. Data Types – EnumAn enum represents a pair of values, a string and a numeric, where the enum can be one of a defined list of values
34 B. Data Types – Enum Enum: enumerated control, constant, or indicator Enums are useful because it is easier to manipulate numbers than strings on the block diagramPoint out that the datatype of the terminal is blue, showing that it is passing an integer
35 B. Data Types – DynamicStores the information generated or acquired by an Express VINon-Express VIs do not accept the dynamic data typeTo use a built-in VI or function to analyze or process the dynamic data type, you must convert the data typeNumeric, waveform, or Boolean data indicators or inputs automatically convert the dynamic data type when wiredIn LabVIEW, the dynamic data type is represented with the color dark blue
36 F. Block Diagram – Wiring Tips Press <Ctrl>-B to delete all broken wiresRight-click and select Clean Up Wire to reroute the wire
37 F. Block Diagram – Wiring Tips Use the Clean Up Diagram tool to reroute multiple wires and objects to improve readabilitySelect a section of your block diagramClick the Clean Up Diagram button on the block diagram toolbar
38 I. Dataflow LabVIEW follows a dataflow model for running VIs A node executes only when data are available at all of its input terminalsA node supplies data to the output terminals only when the node finishes executionNotes for instructing:LabVIEW is NOT control flow. Visual Basic, C++, JAVA, and most other text-based programming languages follow a control flow model of program execution.Sequential order of program elements determines execution order.LabVIEW follows a dataflow model for running VIs.A block diagram node executes when it receives all required inputs.When a node executes, it produces output data and passes the data to the next node in the dataflow path.The movement of data through the nodes determines the execution order of the VIs and functions on the block diagram.
39 I. Dataflow – Quiz Which node executes first? Add Subtract Random NumberDivideSineThere is no right answer to this quiz, but there are some wrong answers. This quiz is intended to encourage students to think about dataflow and its implications...
40 I. Dataflow – Quiz Answers NO CORRECT ANSWERWhich node executes first?Add – possiblySubtract – definitely notRandom Number – possiblyDivide – possiblySine – definitely not
41 Summary—Quiz Which function executes first: Add or Subtract? Add UnknownThe answer is a.
42 Summary—Quiz Answer Which function executes first: Add or Subtract? UnknownThe answer is a.
43 I. Case Structures Have two or more subdiagrams or cases Execute and displays only one case at a timeAn input value determines which subdiagram to executeSimilar to case statements or if...then...else statements in text-based programming languages
44 I. Case StructuresCase Selector Label: contains the name of the current case and decrement and increment buttons on each sideSelector Terminal: Wire an input value, or selector, to determine which case executes
45 PracticeAdd to the previous practice a button in order to update the string label ONLY if the button is pressed. Then run. Change its mechanical action and run again. Create a enum control with items “Heating”, “Cooling”, “Conditioning” and use its values to turn on label “too hot” only, label “too cold” only, or both, according to the case selected. Make the string indicator display “Hi there!” if the user inputs “Hello”, or the same input string if otherwise.
46 I. Case Structures – Default Case You can specify a default case for the Case structureIf you specified cases for 1, 2, and 3, but you get an input of 4, the Case structure executes the default caseRight-click the Case structure border to add, duplicate, remove, or rearrange cases and to select a default case
47 I. Case Structures – Input & Output Tunnels You can create multiple input and output tunnelsInputs are available to all cases if neededYou must define each output tunnel for each casePoint out difference between tunnels that have been wired for all cases, and tunnels that have not.
48 I. Case Structures – Use Default if Unwired Default values are:Avoid using the Use Default If Unwired option on Case structure tunnelsAdds a level of complexity to your codeComplicates debugging your codeData TypeDefault ValueNumericBooleanFALSEStringEmpty
49 I. Case Structures – Boolean Boolean input creates two cases: True and False
50 I. Case Structures – Integer Add a case for each integer as necessaryIntegers without a defined case use the default case
51 I. Case Structures – String Add a case for each string as necessaryStrings without a defined case use the default case
52 I. Case Structures – Enum Gives users a list of items from which to selectThe case selector displays a case for each item in the enumerated type control
53 I. Case Structures - Error Checking and Error Handling Use Case Structures inside VIs to execute the code if there is no error and skip the code if there is an error