<p>EECE 206 Lab: LabVIEW Training Page 1 of 20 UNM The LabVIEW Programming Environment and Basic Operations Introduction In this hands-on, you will learn about the LabVIEW programming environment. You will also write a simple Virtual Instrument (VI) to incorporate basic operations in LabVIEW. Finally, you will convert your programs into subVIs. Objectives Learn the three parts of a VI. </p><p> Learn the three palettes.</p><p> Learn how data is passed in LabVIEW.</p><p> Distinguish between controls and indicators on the front pa nel and block diagram.</p><p> Create a subVI using two different methods. References Getting Started with LabVIEW. http://www.ni.com/getting-started/labview-basics/ View the 12 Units. On Youtube see: https://www.youtube.com/watch? v=ZHNlKyYzrPE&list=PLB968815D7BB78F9C View the first 10 units</p><p> LabVIEW Technical Resources: http://www.ni.com/labview/technical-resources/</p><p>Theory LabVIEW Programming Basics</p><p>Introduction</p><p>LabVIEW is a graphical programming language environment that uses icons instead of lines of text to create applications. In contrast to text-based programming languages, EECE 206 Lab: LabVIEW Training Page 2 of 20 where text instructions determine program execution, LabVIEW uses dataflow programming, where the flow of data determines the execution sequence.</p><p>In LabVIEW, you build a user interface by using a set of tools and objects. The user interface is known as the front panel. You then add code using graphical representations of functions to control the front panel objects. The block diagram contains this code. In some ways, the block diagram resembles a flowchart.</p><p>LabVIEW programs are called virtual instruments, or VIs, because initially their appearance and operation imitate physical instruments, such as oscilloscopes and multimeters. Every VI uses functions that manipulate input from the user interface or other sources and display that information or move it to other files or other computers.</p><p>A VI contains the following three components!: • Front panel—Serves as the user interface. See Figure 2. • Block diagram—Contains the graphical source code that defines the functionality of the VI. See Figure 4. • Icon and connector pane—Identifies the VI so that you can use the VI in another VI. A VI within another VI is called a subVI. A subVI corresponds to a subroutine in text- based programming languages. See Figure 3.</p><p>Front Panel</p><p>Figure 2: Blank Front Panel EECE 206 Lab: LabVIEW Training Page 3 of 20</p><p>Figure 3: Front Panel showing Drop Down Menu, Tools, & Controls Palettes</p><p>The front panel is the user interface of the VI. You build the front panel with controls and indicators, which are the interactive input and output terminals of the VI, respectively. Controls are knobs, pushbuttons, dials, and other input devices. Indicators are graphs, LEDs, and other displays. Controls simulate instrument input devices and supply data to the block diagram of the VI. Indicators simulate instrument output devices and display data the block diagram acquires or generates.</p><p>Items to Note on Front Panel In Figure 3, the Left Red Arrow shows the title of the VI. Right Red Arrow indicates the ICON and Connector Panel used when this VI is used as a SubVI.</p><p>Circle A is the drop down menu for selected the Controls and Tools Palettes Display. Also the Error List can be selected here.</p><p>Circle B is the Tools Palette used to select the function of the mouse. The four most used functions are: the controls operator, first row left; the selection control, first row middle; the text entry control, first row right; and the connection tool, second row left.</p><p>Circle C is the Controls Palette where the various controls and indicators are selected for inclusion on the Front Panel. EECE 206 Lab: LabVIEW Training Page 4 of 20 Block Diagram</p><p>Figure 4: Blank Block Diagram</p><p>Figure 5: Block Diagram with Function and Tools Palettes</p><p>After you build the front panel, you add code using graphical representations of functions to control the front panel objects. The block diagram contains this graphical source code. Front panel objects appear as terminals on the block diagram. </p><p>Additionally, the block diagram contains functions and structures from built-in LabVIEW VI libraries. Wires connect each of the nodes on the block diagram, including control and indicator terminals, functions, and structures. EECE 206 Lab: LabVIEW Training Page 5 of 20</p><p>LabVIEW Palettes</p><p>LabVIEW palettes give you the options you need to create and edit the front panel and block diagram. </p><p>The Tools palette is available on the front panel and the block diagram. A tool is a special operating mode of the mouse cursor. When you select a tool, the mouse icon changes to the selected tool icon. Use the tools to operate and modify front panel and block diagram objects.</p><p>Select Window»Show Tools Palette to display the Tools palette. You can place the Tools palette anywhere on the screen. See Figure 3.</p><p>If automatic tool selection is enabled and you move the cursor over objects on the front panel or block diagram, LabVIEW automatically selects the corresponding tool from the Tools palette.</p><p>The Controls palette is available only on the front panel. The Controls palette contains the controls and indicators you use to create the front panel. Select Window»Show Controls Palette or right-click the front panel workspace to display the Controls palette. You can place the Controls palette anywhere on the screen. See C in Figure 3. </p><p>The Functions palette is available only on the block diagram. The Functions palette contains the VIs and functions you use to build the block diagram. Select Window»Show Functions Palette or right-click the block diagram workspace to display the Functions palette. You can place the Functions palette anywhere on the screen. See Figure 5.</p><p>Dataflow Programming</p><p>LabVIEW follows a dataflow model for running VIs. A block diagram node executes when all its inputs are available. When a node completes execution, it supplies data to its output terminals and passes the output data to the next node in the dataflow path.</p><p>Creating SubVIs</p><p>Introduction</p><p>After you build a VI and create its icon and connector pane, you can use it in another VI. A VI called from the block diagram of another VI is called a subVI. A subVI corresponds to a subroutine in text-based programming languages. A subVI node corresponds to a EECE 206 Lab: LabVIEW Training Page 6 of 20 subroutine call in text-based programming languages. The node is not the subVI itself, just as a subroutine call statement in a program is not the subroutine itself.</p><p>Setting up the Connector Pane</p><p>Figure 6: Connector Pane on Front Panel</p><p>To use a VI as a subVI, you need to build/connect a connector pane. The connector pane is a set of terminals that corresponds to the controls and indicators of that VI, similar to the parameter list of a function call in text-based programming languages. The connector pane defines the inputs and outputs you can wire to the VI so you can use it as a subVI.</p><p>Define connections by assigning a front panel control or indicator to each of the connector pane terminals. In the newer versions of LabVIEW, the Connector Panel is visible in the upper right corner of the front panel window. (older version: The connector pane and the icon image toggles when one or the other is right clicked.) Each rectangle on the connector pane represents a terminal. Use the wiring tool [Figure 7] to assign inputs and outputs. The number of terminals LabVIEW displays on the connector pane depends on the number of controls and indicators on the front panel.</p><p>Figure 7: Wiring Tool in Tool Palette The connector pane has, at most, 28 terminals. If your front panel contains more than 28 controls and indicators that you want to use programmatically, group some of them into a cluster (a data type similar to an array) and assign the cluster to a terminal on the connector pane. See Figure 8. EECE 206 Lab: LabVIEW Training Page 7 of 20</p><p>Figure 8: Cluster Function for Block Diagram</p><p>To set the number of terminals needed, select a different terminal pattern for a VI by right-clicking the connector pane and selecting Patterns from the shortcut menu. See Figure 9. Select a connector pane pattern with extra terminals. You can leave the extra terminals unconnected until you need them. This flexibility enables you to make changes with minimal effect on the hierarchy of the VIs.</p><p>Figure 9: Connector Pane Terminal Patterns</p><p>If you create a group of subVIs that you use together often, give the subVIs a consistent connector pane with common inputs in the same location to help you remember where to locate each input. If you create a subVI that produces an output another subVI uses as the EECE 206 Lab: LabVIEW Training Page 8 of 20 input, align the input and output connections to simplify the wiring patterns. Place the error in clusters on the lower left corner of the connector pane and the error out clusters on the lower right corner.</p><p>Settings Required, Recommended, and Optional Inputs and Outputs</p><p>You can designate which inputs and outputs are required, recommended, and optional to prevent users from forgetting to wire subVI connections. </p><p>Right-click a terminal in the connector pane and select This Connection Is from the shortcut menu. A checkmark indicates the terminal setting. Select Required, Recommended, or Optional. See Figure 10.</p><p>Figure 10: Selecting Required, Recommended, or Optional for a terminal. For terminal inputs, required means that the block diagram on which the subVI is dropped will be broken if the required inputs are not wired. Required is not available for terminal outputs. For terminal inputs and outputs, recommended means that the block diagram on which the subVI is dropped can be run if the input is not wired but the Warnings dialog box will generate a warning that the input has not been wired. Optional means that the block diagram on which the subVI is dropped can be run and will not generate any warnings if the terminal input or output is not wired.</p><p>Inputs and outputs of VIs in vi.lib are already marked as Required, Recommended, or Optional. LabVIEW sets inputs and outputs of VIs you create to Recommended by default. Set a terminal setting to required only if the VI must have the input or output to run properly. EECE 206 Lab: LabVIEW Training Page 9 of 20 In the Context Help window, required connections are bold, recommended connections are plain text, and optional connections are dimmed if you have the Detailed view selected or do not appear if you have the Simple view selected.</p><p>Creating an Icon</p><p>Figure 11: Icon Editor Every VI displays an icon in the upper right corner of the front panel and block diagram windows. An icon is a graphical representation of a VI. It can contain text, images, or a combination of both. If you use a VI as a subVI, the icon identifies the subVI on the block diagram of the VI.</p><p>The default icon contains a number that indicates how many new VIs you have opened since launching LabVIEW. Create custom icons to replace the default icon by right- clicking the icon in the upper right corner of the front panel or block diagram and selecting Edit Icon (Figure 11) from the shortcut menu or by double-clicking the icon in the upper right corner of the front panel.</p><p> Templates—Displays icon templates you can use as a background for the icon. This page displays all .png, .bmp, and .jpg files in the LabVIEW Data\Icon Templates directory. Category—Lists categories of icon templates from which you can select. The names of the categories correspond to the names of the subfolders in the LabVIEW Data\Icon Templates directory. The All Templates category is always visible and includes all icon templates in the LabVIEW Data\Icon Templates directory. Filter templates by keyword—Specifies a keyword to use to filter the list of icon templates. The Icon Editor dialog box displays all icon templates whose name contains the keyword you specify. EECE 206 Lab: LabVIEW Training Page 10 of 20 Icon Text—Specifies the text you want to display in the icon. Line text—Specifies a line of text for the icon. Line color—Specifies the color of the corresponding line of text for the icon. Font—Specifies the font of all text you enter on the Icon Text page. Alignment—Specifies the alignment of all text you enter on the Icon Text page. Size—Specifies the font size of all text you enter on the Icon Text page. Center text vertically—Specifies whether to center the lines of text vertically within the icon. If you use an icon template with a banner and place a checkmark in this checkbox, the Icon Editor dialog box centers the icon text vertically within the body of the icon. Capitalize text—Specifies whether to capitalize all text you enter on the Icon Text page. Glyphs—Displays glyphs you can include in the icon. The Icon Editor dialog box displays all .png, .bmp, and .jpg files in the LabVIEW Data\Glyphs directory. By default, this page includes all glyphs in the Icon Library at ni.com. Select Tools»Synchronize with ni.com Icon Library to display the Synchronize with Icon Library dialog box and synchronize the LabVIEW Data\Glyphs directory with the most recent glyphs in the Icon Library. Layers—Displays all layers of the icon. Select Layers»Show Layers Page to display this page if it is not already showing. Icon Text—Displays the preview, name, opacity, and visibility of the Icon Text layer. This layer consists of all text you enter on the Icon Text page of the Icon Editor dialog box. You can change only the opacity and visibility of this layer. User Layers—Displays the preview, name, opacity, and visibility of all user layers. You can select a user layer by clicking the corresponding preview on the Layers page or by using the Move tool to select a layer in the Preview area of the Icon Editor dialog box. Add Layer—Adds a user layer. Remove Layer—Removes the layer(s) you select. Move Up—Moves the layer(s) you select up one layer level. Move Down—Moves the layer(s) you select down one layer level. Icon Template—Displays the preview, name, opacity, and visibility of the Icon Template layer. This layer consists of the icon template you select on the Templates page of the Icon Editor dialog box. You can change only the opacity and visibility of this layer. EECE 206 Lab: LabVIEW Training Page 11 of 20 Creating SubVIs from Sections of a VI</p><p>Convert a section of a VI into a subVI by using the Positioning tool to select the section of the block diagram you want to reuse and selecting Edit»Create SubVI (Figure 12). An icon for the new subVI replaces the selected section of the block diagram. LabVIEW creates controls and indicators for the new subVI and wires the subVI to the existing wires.</p><p>Creating a subVI from a selection is convenient but still requires careful planning to create a logical hierarchy of VIs. Consider which objects to include in the selection and avoid changing the functionality of the resulting VI.</p><p>Figure 12: Edit Command: Creating a SubVI EECE 206 Lab: LabVIEW Training Page 12 of 20 Equations</p><p>Converting ºC to ºF</p><p>The formula for converting degrees Celsius to degrees Fahrenheit is as follows: °F = (1.8 * °C) + 32 For example, to convert a Celsius temperature of 100 degrees into degrees Fahrenheit, first multiply the Celsius temperature reading by 1.8 to get 180. Then add 32 to 180 and get 212 degrees Fahrenheit. </p><p>Slope of a Line The formula for the slope of a line is as follows: Slope = (Y2 – Y1) / (X2 – X1) where (X1, Y1) and (X2, Y2) are points on the line. </p><p>In Class Procedure Part 1. Converting ºC to ºF </p><p>In Part 1, you will create a VI that can be used as a sub-VI in a later exercise.</p><p>1. Launch LabVIEW from Start»Programs»National Instruments LabVIEW 201x. (Where x is the year of the version being used) Click New VI to open a new front panel.</p><p>2. (Optional) Select Window»Tile Left and Right to display the front panel and block diagram side by side. See Figure 13.</p><p>Figure 13: Tile Left and Right 3. Create a numeric digital control. You will use this control to enter the value for degrees Centigrade.</p><p> a. Right click the Front Panel work area to get to the Control Palette. EECE 206 Lab: LabVIEW Training Page 13 of 20 b. Select the digital control on the Controls»Numeric palette. If the Controls palette is not visible, right-click an open area on the front panel to display it. See Figure 14.</p><p>Figure 14: Numeric Control on Controls Palette c. Move the control to the front panel and click to place the control.</p><p> d. Type deg C inside the label and click outside the label or click the Enter button on the toolbar, shown at left. If you do not type the name immediately, LabVIEW uses a default label. You can edit a label at any time by using the Labeling tool, shown at left.</p><p>4. Create a numeric digital indicator. You will use this indicator to display the value for degrees Fahrenheit.</p><p> a. Select the numeric indicator on the Controls»Numeric palette. See Figure 15. EECE 206 Lab: LabVIEW Training Page 14 of 20</p><p>Figure 15: Numeric Indicator on Controls Palette b. Move the indicator to the front panel and click to place the indicator.</p><p> c. Type deg F inside the label and click outside the label or click the Enter button. See Figure 16.</p><p>Figure 16: Front Panel User Interface for Temperature Conversion Program</p><p>LabVIEW creates corresponding control and indicator terminals on the block diagram. The terminals represent the data type of the control or indicator. For example, a DBL terminal, shown at left, represents a double-precision, floating-point numeric control or indicator.</p><p>5. Display the block diagram by clicking it or by selecting Window» Show Diagram.</p><p>6. Select the Multiply and Add functions on the Functions»Numeric palette and place them on the block diagram. If the Functions palette is not visible, right-click an open area on the block diagram to display it. See Figure 17. EECE 206 Lab: LabVIEW Training Page 15 of 20</p><p>Figure 17: Getting to Numeric Functions on the Function Palette 7. Select the numeric constant on the Functions»Numeric palette and place two of them on the block diagram. It is further down the Numeric Function Menu. When you first place the numeric constant, it is highlighted so you can type a value.</p><p>8. Type 1.8 in one constant and 32.0 in the other.</p><p>If you moved the constants before you typed a value, use the Labeling tool to enter the values.</p><p>Figure 18: C to F Program 9. Use the Wiring tool to wire the icons as shown in the block diagram in Figure 18.</p><p>• To wire from one terminal to another, use the Wiring tool to click the first terminal, move the tool to the second terminal, and click the second terminal, as shown in the following illustration. You can start wiring at either terminal.</p><p>• You can bend a wire by clicking to tack the wire down and moving the cursor in a perpendicular direction. Press the spacebar to toggle the wire direction.</p><p>• To identify terminals on the nodes, right-click the Multiply and Add functions and select Visible EECE 206 Lab: LabVIEW Training Page 16 of 20 Items»Terminals from the shortcut menu to display the connector pane. Return to the icons after wiring by right- clicking the functions and selecting Visible Items»Terminals from the shortcut menu to remove the terminals uncheck Visible.</p><p>• When you move the Wiring tool over a terminal, the terminal area blinks, indicating that clicking will connect the wire to that terminal and a tip strip appears, listing the name of the terminal.</p><p>• To cancel a wire you started, press the <Esc> key, right- click, or click the source terminal.</p><p>10. Display the front panel by clicking it or by selecting Window»Show Panel or use <cntrl E>.</p><p>11. Save the VI because you will use this VI later in the course. Select File»Save. Type ConvertCtoF.vi in the dialog box. Click the Save button.</p><p>12. Enter a number in the digital control and run the VI.</p><p> a. Use the Operating tool or the Labeling tool to double- click the digital control and type a new number.</p><p> b. Click the Run button to run the VI.</p><p>Figure 19: Run Arrow when there are no errors</p><p> c. Try several different numbers and run the VI again.</p><p>13. Double-click the icon in the upper right corner of the front panel and to activate the Icon Editor dialog box. See Figure 11. EECE 206 Lab: LabVIEW Training Page 17 of 20</p><p>14. Double-click the Select tool on the left side of the Icon Editor dialog box to select the default icon. See Figure 20.</p><p>Figure 20: Icon selection tool. 15. Press the <Delete> key to remove the default icon.</p><p>16. Select the Icon Text Tab</p><p>17. Create the following icon.</p><p> a. Use the Text tool to click the editing area.</p><p> b. Type C, several spaces and F.</p><p>18. Select the Layers Tab a. Use the Pencil tool to create the arrow pointing from C to F.</p><p> b. When the icon is complete, click the OK button to close the Icon Editor dialog box. The icon appears in the upper right corner of the front panel and block diagram.</p><p>18. Right-click the icon on the front panel and select Show Connector from the shortcut menu to define the connector pane terminal pattern. LabVIEW selects a connector pane pattern based on the number of controls and indicators on the front panel. For example, this front panel has two terminals, deg C and deg F, so LabVIEW selects a connector pane pattern with two terminals.</p><p>19. Assign the terminals to the digital control and digital indicator.</p><p> a. Select Help»Show Context Help to display the Context Help window. View each connection in the Context Help window as you make it. EECE 206 Lab: LabVIEW Training Page 18 of 20 b. Click the left terminal in the connector pane. The tool automatically changes to the Wiring tool, and the terminal turns black.</p><p> c. Click the deg C control. The left terminal turns orange, and a marquee highlights the control.</p><p> d. Click an open area of the front panel. The marquee disappears, and the terminal changes to the data type color of the control to indicate that you connected the terminal.</p><p> e. Click the right terminal in the connector pane and click the deg F indicator. The right terminal turns orange.</p><p> f. Click an open area on the front panel. Both terminals are orange.</p><p> g. Move the cursor over the connector pane. The Context Help window shows that both terminals are connected to floating-point values.</p><p>20. Select File»Save to save the VI. </p><p>21. Select File»Close to close the VI. EECE 206 Lab: LabVIEW Training Page 19 of 20 Part 2. Calculating the Slope of a Line Using the techniques you learned in Part 1, create a VI to calculate the slope of a line. Then, transform the code into a subVI using the Edit»Create SubVI method. Save the VI as Slope.vi. Save the subVI as SlopeSub.vi. The equation for slope is given in the Theory section. Open a new VI and complete the front panel and block diagram as follows:</p><p>Front Panel</p><p>Block Diagram before subVI After creating the subVI, your block diagram will resemble the one below. </p><p>Block Diagram with subVI EECE 206 Lab: LabVIEW Training Page 20 of 20 Testing the Programs Test the progarms and report the results in the report.</p><p>The test for a program should have predetermined set of test inputs and each test input should have an expected result or action. The test inputs here should test the range of the possible temperature inputs and obvious user input errors. Test inputs for the C to F converson program should include positive temperatures to positive temperatures(100 to 212), negative temperatures to positive temperatures (ie -5 deg C to ? F), and negative temperatures to negative temperatures(-40 C to ? F) , and any limits (-273.15°C or 459.67 degrees Fahrenheit). User errors would be attempting to input alpha characters into the input or enter a number below absolute zero. For the slope program test cases should product a positive slope, zero slope, negative slope, infinite slope, and no slope.</p><p>Questions 1. What is a VI? What are the three main parts of a VI? Briefly describe each.</p><p>2. What are the three palettes? Briefly describe each. </p><p>3. How is data passed in LabVIEW?</p><p>4. How can you tell the difference between controls and indicators on the front panel? On the block diagram?</p><p>5. Explain the two methods of creating a subVI. </p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages20 Page
-
File Size-