Anda di halaman 1dari 37

Exercise 1: Create a Simple LabVIEW VI

In this exercise, you will create a simple LabVIEW VI that simulates an analog signal and plots it on a waveform graph. The VI will test the input values against a user-specified limit and light an LED if the input value exceeds that limit. Below are pictures identifying each of the palettes found in LabVIEW to assist you as you complete these exercises. For a more detailed explanation of the palette contents, as well as other facets of the LabVIEW development environment, refer to Appendix B, The LabVIEW Environment. Note: LabVIEW has a built-in Automatic Tool Selection feature that changes the behavior of the cursor depending on what type of object you are currently pointing to.

Functions Palette Controls Palette

1. If you have not already done so, click the LabVIEW icon on your quick launch toolbar.

National Instruments Corporation

LabVIEW Graphical Development Hands-On Seminar

Once you launch LabVIEW, a splash screen like the following appears.

2. Click on File and Select New... Notice the different categories on the left of the window that correspond to the types of tasks from which you can choose. Select From Template. You can also select Blank VI to start from scratch. There also are Template VIs to use as a starting point for building your application. Projects and Other Files are more advanced components and will not be described in detail. To get more information on any of the listings in the New Dialog Box, click the Help button in the lower right corner of the window.

LabVIEW Graphical Development Hands-On Seminar

ni.com

3. Select VIFrom TemplateTutorial (Getting Started) Generate and Display and click OK.

Two windows appear. The gray window is the Front Panel, and the white one is the Block Diagram. The Front Panel contains the parts of your VI used for presenting information, whereas the Block Diagram contains the code that controls the functionality of the VI. You can toggle between the two windows by selecting WindowShow Block Diagram or WindowShow Front Panel. You can also switch between the windows by pressing <Ctrl-E> on the keyboard.

National Instruments Corporation

LabVIEW Graphical Development Hands-On Seminar

4. Examine the Front Panel and Block Diagram of this template VI. The Front Panel contains a Waveform Chart and a STOP button as shown in the following figure.

The Block Diagram contains a Simulate Signal VI, which is currently configured to simulate a sine wave and plot it to the chart.

LabVIEW Graphical Development Hands-On Seminar

ni.com

5. Switch back to the Front Panel by pressing <Ctrl-E>. Since the Run button (the white arrow in the top left corner) is solid, you can run this VI as it is. Click the Run button and examine the operation of the VI. When you are finished, click the STOP button on the Front Panel to stop running the VI. Note: As you will see later in the exercise, when the Run button in the upper left corner of both the Front Panel and the Block Diagram changes from a solid white arrow, to a broken gray arrow, this new icon indicates that the VI is currently not executable. 6. Now we can add some functionality to this basic VI. We will modify the VI to flash an alarm whenever the signal value is above a certain level. Open the Controls palette (if it is not open already) by rightclicking the Front Panel window. A small pushpin icon in the upper left corner of this palette appears. Click this pushpin to force the palette to remain on your screen.

7. Click the Numeric Controls palette, and select a Vertical Pointer Slide to be placed on the Front Panel. To do this, click the Vertical Pointer Slide and drag it to the Front Panel. Click once to place it.

National Instruments Corporation

LabVIEW Graphical Development Hands-On Seminar

8. Click the Express menu item on the Controls palette to return to the Express Controls Palette. Click the LEDs subpalette, and place a Round LED on the Front Panel.

9. Right-click the Vertical Pointer Slide and select Properties. A property page will appear. Examine the different properties that you can modify. Make the following changes on the Appearance tab and click OK to apply the changes. Label: Limit Slider 1: Check Show digital display(s)

LabVIEW Graphical Development Hands-On Seminar

ni.com

10. Right-click the Round LED labeled Boolean, and select Properties. Examine the different properties that can be modified. On the Appearance tab, change the label from Boolean to Alarm. Click OK to apply your change. Move the objects on the Front Panel so it resembles the following.

11. Switch to the Block Diagram by pressing <Ctrl-E>. Double-click the Simulate Signal Express VI to bring up its properties window. Examine the different properties you can modify. Change the Amplitude of the signal to 10. Click OK to apply this change and to close the properties window.

National Instruments Corporation

LabVIEW Graphical Development Hands-On Seminar

12. Bring up the functions palette by right-clicking the Block Diagram. Select Arithmetic & ComparisonComparison and place the Comparison Express VI on the diagram.

Finding functions can be challenging in any language. The new Quick Drop feature in LabVIEW 8.6 helps you quickly find and place LabVIEW front panel and block diagram objects using predictive text. With the block diagram open, press <CTRL-Space> to open the Quick Drop dialog window. The Quick Drop window will take a moment to index the VIs installed on your machine.

Note

LabVIEW Graphical Development Hands-On Seminar

ni.com

Type comparison into the Quick Drop window. Note that the list of functions shown in the window is instantly filtered based on the text that you type. Highlight the correct function and left-click on the block diagram to place it. *With Quick Drop, you can also customize shortcuts for objects that are often used.

When you place the Comparison Express VI on the Block Diagram, a dialog box appears that lets you configure what type of comparison you will be doing. Make the following selections, then click OK to apply these changes and to close the dialog box. Compare Condition: Greater Comparison Inputs: Compare to second input

National Instruments Corporation

LabVIEW Graphical Development Hands-On Seminar

13. You can connect Controls, Functions, and Indicators on the Block Diagram by pointing to an object and clicking it when the cursor changes to a spool of wire. You can then move the cursor to the object you want to connect it to and click again. Connect the Limit control to the Alarm indicator.

Note: The Run button in the upper left corner of both the Front Panel and the Block Diagram has changed from a solid white arrow, to a broken gray arrow. This new icon indicates that the VI is currently not executable. If you click the Run button when it is solid and white, it runs the VI. Clicking it when it is broken and gray brings up a dialog box that will help you debug the VI.

14. Click the Run button now. The resulting dialog box shows that, in this case, the error results from connecting terminals of two different types. Since the Limit control is a Numeric type and the Alarm indicator is a Boolean type, we cannot wire these two terminals together. Highlight the error by clicking it, and then click Show Error. LabVIEW will highlight the location of the error.

15. Notice that the wire between Limit and Alarm is dashed and a red v is displayed on it.

To delete this broken wire, press <Ctrl-B>. This keyboard shortcut removes all broken wires from the Block Diagram.

16. Make your Block Diagram resemble the following image by completing the following steps. a. b. c. Wire the Limit control to the Operand 2 input of the Comparison function. Connect the wire between the Simulate Signals block and the Waveform Graph to the Operand 1 input of the Comparison block. Wire the Result output of the Comparison block to the Alarm indicator.

LabVIEW Graphical Development Hands-On Seminar

10

ni.com

Your Block Diagram should now resemble the following:

17. Switch to the Front Panel by pressing <Ctrl-E>. 18. Save the VI in the C:\Seminars\HandsOn\LabVIEW\CustomerWork folder by using the File menu and name it Exercise1.vi. Note: Be sure to save this VI, as you will be using it later in the seminar. 19. Run the VI. While running the VI, you can change the Limit value. Also notice that when a data point received from the Simulate Signal VI is greater than the Limit value, the Alarm indicator lights up. 20. While the VI is still running, switch to the Block Diagram by pressing <Ctrl-E>. Enable highlight execution by clicking the light bulb on the tool bar.

This will allow you to see the flow of data through your program. 21. When you are finished, stop the VI by clicking the Stop button on the Front Panel.

End of Exercise 1

National Instruments Corporation

11

LabVIEW Graphical Development Hands-On Seminar

Exercise 2: Data Acquisition in LabVIEW (Without Hardware)


In this exercise, you will learn both how to use the Simulated Device Function in the Measurement & Automation Explorer (MAX) and also the DAQ Assistant to set up a channel and configure a virtual analog measurement. To create an NI-DAQmx simulated device, NI-DAQmx 7.4 or later must be installed. 1. Open Measurement & Automation Explorer (MAX). NI-DAQmx simulated devices are created within MAX. Unless you unchecked the feature during installation, MAX was installed when NI-DAQmx was installed. If MAX is not installed, you must reinstall NI-DAQmx 7.4 or later. 2. Right-click My System>>Devices and Interfaces and select Create New... In the subsequent dialog, select NI-DAQmx Device>>NI-DAQmx Simulated Device. The Choose Device window prompts you to select a device.

Figure 1. Create an NI-DAQmx simulated device in MAX.

LabVIEW Graphical Development Hands-On Seminar

12

ni.com

3. Select the device you want to create as an NI-DAQmx simulated device. With this list, you can browse the hundreds of devices supported by NI-DAQmx. You can create an NI-DAQmx simulated device of any NI-DAQmx-supported device, with the exception of the SCXI-1600 (NI-DAQmx 7.4 and later) and B Series devices (NI-DAQmx 7.5 and later).

Figure 2. Choose from hundreds of NI-DAQmx supported devices.

4. Extend M Series DAQ and select PCI-6221 as your NI-DAQmx simulated DAQ device that you would like to created. Click OK in the Choose Device window to close the window. The NI-DAQmx simulated device appears in MAX. The icon color of the NI-DAQmx simulated devices differs from real devices. Real devices are green, and simulated devices are yellow.

National Instruments Corporation

13

LabVIEW Graphical Development Hands-On Seminar

Figure 3. Extend M Series DAQ and choosing PCI-6221 as your NI-DAQmx simulated device.

Figure 4. Real devices are green and simulated devices are yellow. An NI-DAQmx simulated device works just as a real device. You can use NI-DAQmx simulated devices to create NI-DAQmx tasks either through the DAQ Assistant or the API. Because a real device is no longer required to create an NI-DAQmx task, NI-DAQmx simulated devices allow developers to do the following:   Begin application development and logic before without hardware Develop application logic on a machine other than the target system

5. Right-click the PCI-6221 DAQ card and select Test Panels. This will bring up a window that will allow you to perform the different data acquisition tasks that are available on your board.

LabVIEW Graphical Development Hands-On Seminar

14

ni.com

National Instruments Corporation

15

LabVIEW Graphical Development Hands-On Seminar

6. Click the Analog Input tab. Under Channel Name, be sure Dev1/ai0 is selected. Under mode, select Finite. Make sure the Rate is set to 1000 Hz and Samples to Read 100. Click the Start button.

LabVIEW Graphical Development Hands-On Seminar

16

ni.com

7. You should see a sine wave. This shows the ability to use MAX as a troubleshooting and testing tool before you begin programming to ensure your hardware is set up properly. When you are finished, close the Test Panel window and Measurement & Automation Explorer and return to the LabVIEW Block Diagram.

8. Right-click the Block Diagram to bring up the functions palette. Place a While Loop on your Block Diagram by selecting ExpressExecution ControlWhile Loop.

National Instruments Corporation

17

LabVIEW Graphical Development Hands-On Seminar

9. Place a DAQ Assistant Express VI inside your While Loop. This is located in the Input subpalette of the Functions palette.

A configuration window should appear. Make the following selections. Measurement Type: Analog InputVoltage Channel: Dev1ai0 Click Finish

LabVIEW Graphical Development Hands-On Seminar

18

ni.com

National Instruments Corporation

19

LabVIEW Graphical Development Hands-On Seminar

10. Another configuration window will appear. Make the following selections and click OK. Task Timing: Acquisition Mode : Continuous

LabVIEW Graphical Development Hands-On Seminar

20

ni.com

11. Right click on the output terminal of the Add function and choose Create >> Graph Indicator. Place the Time Delay Express VI, located on the FunctionsExpressExecution Control palette, within the While Loop on the Block Diagram. In the Configure Time Delay dialog box that appears, type 0.5 and click OK to close the dialog box. This will cause the loop to execute every 500 ms. Position and wire the elements to resemble the following:

12. To perform analysis on your data, select the Statistics Express VI from the Express>>Signal Analysis subpalette of the Functions palette and place it on your Block Diagram.

National Instruments Corporation

21

LabVIEW Graphical Development Hands-On Seminar

A properties window will appear. Make the following selections and click OK. Statistical Calculations: Arithmetic Mean Extreme Values: Maximum, Minimum

13. Right-click the Arithmetic Mean output of the Statistics VI and select CreateNumeric Indicator. This will create a numeric indicator on the Front Panel that will display the Arithmetic mean. Repeat this step for both the Maximum and Minimum outputs of the Statistics VI.

LabVIEW Graphical Development Hands-On Seminar

22

ni.com

14. Switch to the Front Panel and rearrange your controls and indicators to resemble the following.

15. Save the VI in the C:\Seminars\HandsOn\LabVIEW\CustomerWork folder by using the File menu and name it Exercise2.vi. 16. Run the VI. A sine wave is read from the simulated DAQ device and this allows the developer to develop the system without hardware. Click the STOP button on the Front Panel. 17. Right-click on the block diagram and select Express Output Write to Measurement File and place it inside the while loop on the block diagram

National Instruments Corporation

23

LabVIEW Graphical Development Hands-On Seminar

A configuration window will appear. Enter the following parameters and click OK.

LabVIEW Graphical Development Hands-On Seminar

24

ni.com

Make the following connections.

LabVIEW 8.6 introduces a Block Diagram Cleanup tool to rearrange an entire block diagram in seconds with a single mouse click, without changing the functionality of your code. Though the Block Diagram Cleanup tool is not intended to perfect the layout of your block diagram, configuration options do give you the ability to specify wire spacing, block spacing, and diagram compactness at the pixel level. To access the configurable options for Block Diagram Cleanup, select Tools>>Options and choose Block Diagram: Cleanup from the category list.

Note

18. Run the VI momentarily and Stop it. Browse to the path that you have set earlier and open the file with a spreadsheet program (eg. Microsoft Excel). 19. Save your VI.

End of Exercise 2b

National Instruments Corporation

25

LabVIEW Graphical Development Hands-On Seminar

Exercise 3: Mathscript
LabVIEW MathScript adds math-oriented, textual programming to LabVIEW. At the heart of LabVIEW MathScript is a high-level text-based programming language with syntax and functionality that abstracts the complexity of tasks related to signal processing, analysis, and math. In this exercise, you will learn to utilize the hybrid approach to programming in LabVIEW. The goal of your application is to generate two test signals, add some noise to these signals, and then apply a moving-average filter to remove the noise. Using the LabVIEW front panel, you plan to test your moving-average filter using a variety of control inputs. 1. Open Starting Exercise.vi in the Exercises folder. 2. Observe the Front Panel. a. There are three inputs to our application i. Desired Length of Filter: filter length ii. flow: lowest of two frequency components for input signal iii. fhigh: highest of two frequency components for input signal b. There are four graph indicators to our application i. Low frequency component: low frequency waveform ii. High frequency component: high frequency waveform iii. Input signal: input signal to the filter (sum of two above components) iv. Output signal: output signal from the moving-average filter 3. Observe the Block Diagram

a. The three controls on our front panel are passed into the MathScript Node as inputs b. Three of the four graph indicators have been populated by outputs from the MathScript Node. c. Notice the script highlighting:

LabVIEW Graphical Development Hands-On Seminar

26

ni.com

i. LabVIEW MathScript comments are preceded by a % sign, which indicates to the compiler to ignore the text that follows on that line. Comments are turned green by default. ii. The blue color of the functions cos and ones as well as the defined constant pi.

iii. You can edit the colors used for script highlighting using Tools >> Options and choosing MathScript: Script Highlighting

4. The MathScript Node is incomplete. Enter the following code on line 10 of the Node outputsignal = filter(num,1,inputsignal)/M; This line defines our output signal by applying the moving-average filter. 5. To complete the application, the last step is to pass the newly defined variable outputsignal to the appropriate graph indicator. a. Right-click on the border of the MathScript Node below the inputsignal output, and select <Add Output> b. Type the string outputsignal into this output. The name correlates the output to the appropriate variable in the script c. Next, define the variable datatype to be passed to the LabVIEW indicator by right-clicking on the output and choosing: <Choose Data Type >> 1D-Array >> DBL 1D>

National Instruments Corporation

27

LabVIEW Graphical Development Hands-On Seminar

d. Wire the outputsignal output from the MathScript Node into the Output signal graph indicator e. The application is now complete 6. Return to the Front Panel and press the Run Arrow. Change the values of the inputs to see how they affect the output signal from the filter. 7. Return to the block diagram and use the new debugging tools to step through the application. a. Place a breakpoint on lines 7 and 10 by hovering over the gray region to the left of the line. The mouse will turn into a breakpoint indicator, as shown below. Left-click to place the breakpoints.

b. Activate the MathScript Probe to identify intermittent variable values within the Node by right-clicking on the border, and choosing Probe.

8. Run the application. The Probe will populate the values of all variables defined up until the first breakpoint: fhigh, flow, M, n, s1, and s2 a. Step over each line of the script by pressing the Step over Line of Script button on the toolbar

LabVIEW Graphical Development Hands-On Seminar

28

ni.com

b. Use the highlight execution and stepping functions to explore the remainder of the application.

END OF EXERCISE 3

National Instruments Corporation

29

LabVIEW Graphical Development Hands-On Seminar

Exercise 4: Report Generation


In this exercise, you will learn how to present your data using the Report Express VI in LabVIEW. This Express VI allows you to quickly and easily customize a report and present your data in an attractive format. 22. Click the LabVIEW icon on your desktop toolbar. If you already have a VI open, select File Close all to return to the main LabVIEW start menu. 23. Click the Blank VI to create a new VI. 24. Switch to the Block Diagram by pressing Ctrl-E. Place the Simulate Signal Express VI (Express>>Input>>Simulate Signal) on your Block Diagram and configure it as in the following image:

LabVIEW Graphical Development Hands-On Seminar

30

ni.com

25. Place the Spectral Analysis Express VI (Express>>Signal Analysis>>Spectral Measurements) on your Block Diagram and configure it as in the following image and click OK.

26. Connect the Sine with Uniform output of the Simulate Signal Express VI to the Signals input of the Spectral Measurements Express VI as shown here:

National Instruments Corporation

31

LabVIEW Graphical Development Hands-On Seminar

27. To report this data, select the Report Express VI from the Output subpalette of the Functions palette and place it on your Block Diagram.

A properties window will appear. Configure the Report VI according to the following figure and click OK.

LabVIEW Graphical Development Hands-On Seminar

32

ni.com

28. Wire the output of the DAQ Simulate Signal Express VI and the Spectral Measurement Express VI to the inputs of the Report Express VI as demonstrated here:

National Instruments Corporation

33

LabVIEW Graphical Development Hands-On Seminar

29. Switch to the Front Panel by pressing Ctrl-E. 30. Save the VI in the C:\Seminars\HandsOn\LabVIEW\CustomerWork folder by using the File menu and name it Exercise4.vi. 31. Run the VI. 32. Navigate to C:\Seminars\HandsOn\LabVIEW\CustomerWork\report.html. Open the file using Microsoft Internet Explorer. The report will have all of the data you specified in the Report VI. 33. Stop and close the VI and Web browser when you are finished.

End of Exercise 4

LabVIEW Graphical Development Hands-On Seminar

34

ni.com

Exercise 5: Remote Panels (Optional)


In this exercise, you will learn how to present your data using the Remote Panels feature in LabVIEW. This technology allows you to easily publish your VIs over the internet and allow remote users to run and control your LabVIEW application. 1. Open the VI from exercise 2a. The first thing we must do is start the LabVIEW Web Server. To do this, open the Tools menu and select Web Publishing Tool 2. Click the Start Web Server button to active the Server.

3. Next, select your VI from the VI name ring and then click Next.

National Instruments Corporation

35

LabVIEW Graphical Development Hands-On Seminar

4. The next window allows us to configure the text that is displayed on the web page. Fill in the fields as shown here and click Next.

5. LabVIEW will now generate the HTML page which displays your application over the web. In the next window, you are prompted to save this page. Click Save to Disk. LabVIEW then provides the URL for your new page. Click Connect and LabVIEW will launch your new web page.

6. To control the VI through your web browser, right-click on the Front Panel image and select Request Control of VI.

LabVIEW Graphical Development Hands-On Seminar

36

ni.com

7. Now click the Run arrow to run your VI. 8. When you are finished, close the VI and web browser.

End of Exercise 5

National Instruments Corporation

37

LabVIEW Graphical Development Hands-On Seminar

Anda mungkin juga menyukai