Langkau ke kandungan utama

LabVIEW Getting Started with LabVIEW (Chapter 1)


  • Building a Virtual Instrument

In the following exercises, you will build a VI that generates a signal and displays that signal in a graph. After you complete the exercises, the front panel of the VI will look similar to the front panel in Figure 1-1.


Figure 1-1. Front Panel of the Acquiring a Signal VI


  • Launching LabVIEW
The Getting Started window, shown in Figure 1-2, appears when you launch LabVIEW. Use this window to create new VIs, select among the most recently opened LabVIEW files, find examples, and launch the LabVIEW Help. You also can access information and resources to help you learn about LabVIEW, such as specific manuals, help topics, and resources on the National Instruments 


Figure 1-2. Getting Started Window
The Getting Started window disappears when you open an existing file or create a new file. The Getting Started window reappears when you close all open front panels and block diagrams. You also can display the window from the front panel or block diagram by selecting View»Getting Started Window.



  • Opening A New VI from a Template
LabVIEW provides built-in template VIs that include the subVIs, functions, structures, and front panel objects you need to get started building common measurement applications. Complete the following steps to create a VI that generates a signal and displays it in the front panel window.

1. Launch LabVIEW.
2. In the Getting Started window,click the New or VI from Template link to display the New  dialog box.
3. From the Create New list,select VI»From Template»Tutorial (Getting Started)»Generate and Display.This template VI generates and displays a signal. 

A preview and a brief description of the template VI appear in the Description section. Figure 1-3 shows the New dialog box and the preview of the Generate and Display template VI.

4. Click the OK button to create a VI from the template. You also can double-click the name      of the template VI in the Create New list to create a VI from a template.
    LabVIEW displays two windows: the front panel window and the block diagram window.

5. Examine the front panel window.
    The user interface, or front panel, appears with a gray background and includes controls       and indicators. The title bar of the front panel indicates that this window is the front panel       for the Generate and Display VI.

Note If the front panel is not visible, you can display the front panel by selecting Window»Show Front Panel. You also can switch between the front panel window and block diagram window at any time by pressing the <Ctrl-E> keys. The <Ctrl> key in keyboard shortcuts corresponds to the (Mac OS X) <Option> or <Command> key or (Linux) <Alt> key.

6. Select Window»Show Block Diagram and examine the block diagram of the VI.
      The block diagram appears with a white background and includes VIs and structures            that control the front panel objects. The title bar of the block diagram indicates that this          window is the block diagram for the Generate and Display VI.

7. On the front panel toolbar,click the Run button, shown at left. You also can press the       <Ctrl-R> keys to run a VI.
     A sine wave appears on the graph in the front panel window.

8. Stop the VI by clicking the front panel STOP button, shown at left.


  • Adding a Control to the Front Panel
Front panel controls simulate the input mechanisms on a physical 
instrument and supply data to the block diagram of the VI. Many physical 

instruments have knobs you can turn to change an input value. 

Complete the following steps to add a knob control to the front panel.

1. If the Controls palette, shown in Figure 1-4, is not visible in the front panel window, select View»Controls Palette.
2. If you are a new LabVIEW user, the Controls palette opens with the Express palette, shown in Figure 1-4, visible by default. If you do not see the Express palette, click Express on the Controls palette to display the Express palette.


3. Move the cursor over the icons on the Express palette to locate the Numeric Controls palette.
When you move the cursor over icons on the Controls palette, the name of the subpalette, control, or indicator appears in a tip strip below the icon.
4. Click the Numeric Controls icon to display the Numeric Controls palette.
5. Click the Knob control on the Numeric Controls palette to attach the control to the cursor, and then add the knob to the front panel to the left of the waveform graph.
You will use this knob in a later exercise to control the amplitude of a
signal.
6. Select File»Save As and save the VI as Acquiring a Signal.vi in an easily accessible location.

  • Changing a Signal Type
The block diagram has a blue icon labeled Simulate Signal. This icon represents the Simulate Signal Express VI. An Express VI is a component of the block diagram that you can configure to perform common measurement tasks. The Simulate Signal Express VI simulates a sine wave by default. Complete the following steps to change this signal to a sawtooth wave.

  1. Display the block diagram by pressing the <Ctrl-E> keys or by clicking the block diagram. Locate the Simulate Signal Express VI, shown at left. The Simulate Signal Express VI simulates a signal based on the configuration that you specify.
  2. Right-click the Simulate Signal Express VI and select Properties from the shortcut menu to display the Configure Simulate Signal dialog box. (Mac OS X) Press <Command>-click to perform the same action as right-click.
  3. Select Sawtooth from the Signal type pull-down menu. The waveform on the graph in the Result Preview section changes to a sawtooth wave. The Configure Simulate Signal dialog box should appear similar to Figure 1-5.
  4. Click the OK button to save the current configuration and close the Configure Simulate Signal dialog box.
  5. Move the cursor over the down arrows at the bottom of the Simulate Signal Express VI. The down arrows indicate you can reveal hidden inputs and outputs by extending the border of the Express VI.
  6. When a double-headed arrow appears, shown at left, click and drag the border of the Express VI to add two rows. When you release the border, the Amplitude input appears.


  • Wiring Objects on the Block Diagram

To use the knob to change the amplitude of the signal, you must connect two objects on the block diagram.

Complete the following steps to wire the knob to the Amplitude input of the Simulate Signal Express VI.

  1. On the block diagram, move the cursor over the Knob terminal, shown at left.The cursor becomes an arrow, or the Positioning tool, shown at left.Use the Positioning tool to select, position, and resize objects.
  2. Use the Positioning tool to select the Knob terminal and make sure it is to the left of the Simulate Signal Express VI and inside the gray loop, shown at left. The terminals inside the loop are representations of front panel controls and indicators. Terminals are entry and exit ports that exchange information between the front panel and block diagram.
  3. Deselect the Knob terminal by clicking a blank space on the block diagram. If you want to use a different tool with an object, you must deselect the object to switch the tool. 
  4. Move the cursor over the arrow on the Knob terminal, shown at left. The cursor becomes a wire spool, or the Wiring tool, shown at left. Use the Wiring tool to wire objects together on the block diagram.
  5. When the Wiring tool appears, click the arrow on the Knob terminal and then click the arrow on the Amplitude input of the Simulate Signal Express VI, shown at left, to wire the two objects together.
  6. Select File»Save to save the VI.

  • Running a VI

  1. Display the front panel by pressing the <Ctrl-E> keys or by clicking the front panel.
  2. Click the Run button or press the <Ctrl-R> keys to run the VI.
  3. Move the cursor over the knob.The cursor becomes a hand, or the Operating tool, shown at left. Use the Operating tool to change the value of a control.
  4. Using the Operating tool, turn the knob to adjust the amplitude of the sawtooth wave. The amplitude of the sawtooth wave changes as you turn the knob. As you change the amplitude, the Operating tool displays a tip strip that indicates the numeric value of the knob. The y-axis on the graph scales automatically to account for the change in amplitude.
  5. Click the STOP button, shown at left, to stop the VI. The STOP button stops the VI after the loop completes its current iteration. The Abort Execution button, shown at left, stops the VI immediately, before the VI finishes the current iteration. Aborting a VI that uses external resources, such as external hardware, might leave the resources in an unknown state by not resetting or releasing them properly. Design the VIs you create with a stop button to avoid this problem.

  • Modifying a Signal

Complete the following steps to scale the signal by 10 and display the results in the front panel graph.

  1. In the block diagram, use the Positioning tool to click the wire that connects the Simulate Signal Express VI to the Waveform Graph terminal, shown at left.
  2. Press the <Delete> key to delete this wire.
  3. If the Functions palette, shown in Figure 1-6, is not visible, select View»Functions Palette to display it. The Functions palette opens with the Express palette visible by default. If you have selected another palette, you can return to the Express palette by clicking Express on the Functions palette.
  4. On the Arithmetic & Comparison palette, select the Formula Express VI, shown at left, and place it on the block diagram between the Simulate Signal Express VI and the Waveform Graph terminal. You can move the Waveform Graph terminal to the right to make more room between the Express VI and the terminal. The Configure Formula dialog box appears when you place the Express VI on the block diagram. When you place an Express VI on the block diagram, the configuration dialog box for that VI always appears automatically.
5. Click the Help button, shown at left, in the bottom right corner of the Configure Formula dialog box to display the LabVIEW Help topic for this Express VI. The Formula help topic describes the Express VI, the configuration dialog box options, and the inputs and outputs of the Express VI. Each
Express VI has a corresponding help topic you can access by clicking the Help button in the configuration dialog box or by right-clicking the Express VI and selecting Help from the shortcut menu. 
6. In the Formula topic, find the dialog box option whose description indicates that it enters a variable into the formula.
7. Minimize the LabVIEW Help to return to the Configure Formula dialog box.
8. Change the text in the Label column of the dialog box option you read about, shown at left, from X1 to Sawtooth to indicate the input value to the Formula Express VI. When you click in the Formula text box at the top of the Configure Formula dialog box, the text changes to match the label you entered.
9. Define the value of the scaling factor by entering *10 after Sawtooth in the Formula text box. You can use the Input buttons in the configuration dialog box or you can use the *, 1, and 0 keyboard buttons to enter the scaling factor. If you use the Input buttons in the configuration dialog box, LabVIEW places the formula input after the Sawtooth input in the Formula text box. If you use the keyboard, click in the Formula text box after Sawtooth and enter the formula you want to appear in the text box. The Configure Formula dialog box should appear similar to Figure 1-7.




10 Click the OK button to save the current configuration and close the Configure Formula dialog box.
11. Move the cursor over the arrow on the Sawtooth output of the Simulate Signal Express VI.
12. When the Wiring tool appears, click the arrow on the Sawtooth output and then click the arrow on the Sawtooth input of the Formula Express VI, shown at left, to wire the two objects together.
13. Use the Wiring tool to wire the Result output of the Formula Express VI to the Waveform Graph terminal. Examine the wires connecting the Express VIs and terminals. The arrows on the Express VIs and terminals indicate the direction that the data flows along these wires. The block diagram should appear similar to Figure 1-8. Use the block diagram figures as a reference. The arrangement of objects on your block diagram does not need to match the figure exactly.


  • Displaying Two Signals on a Graph


To compare the signal generated by the Simulate Signal Express VI and the signal modified by the Formula Express VI on the same graph, use the Merge Signals function.

Complete the following steps to display two signals on the same graph.

  1. In the block diagram, move the cursor over the arrow on the Sawtooth output of the Simulate Signal Express VI.
  2. Use the Wiring tool to wire the Sawtooth output to the Waveform Graph terminal. The Merge Signals function, shown at left, appears where the two wires connect. A function is a built-in execution element, comparable to an operator, function, or statement in a text-based programming language. The Merge Signals function takes the two separate signals and combines them so that both can display on the same graph. The block diagram should appear similar to Figure 1-9.
  3. Press the <Ctrl-S> keys or select File»Save to save the VI.
  4. Return to the front panel, run the VI, and turn the knob control. The graph plots the original sawtooth wave and the scaled sawtooth wave with 10 times the amplitude, as you specified in the Formula Express VI. The maximum value on the y-axis automatically scales as you turn the knob.
  5. Click the STOP button to stop the VI.





  • Customizing a Knob Control



The knob control changes the amplitude of the sawtooth wave, so labeling it Amplitude accurately describes the behavior of the knob.

Complete the following steps to customize the appearance of the knob.

  1.  Right-click the front panel knob and select Properties from the shortcut menu to display the Knob Properties dialog box. Click the Appearance tab to display the Appearance page.
  2.  In the Label section on the Appearance page, delete the label Knob, and enter Amplitude in the text box. The Knob Properties dialog box should appear similar to Figure 1-10.
  3. Click the Scale tab. In the Scale Style section, place a checkmark in the Show color ramp checkbox.
  4. Click the OK button to save the current configuration and close the Knob Properties dialog box.
  5. Save the VI.



  • Customizing a Waveform Graph


The waveform graph indicator displays the two signals. To indicate which plot is the scaled signal and which is the simulated signal, you can customize the plots.



Complete the following steps to customize the appearance of the waveform graph indicator.

  1. In the front panel window, move the cursor over the top of the plot legend on the waveform graph.Though the graph has two plots, the plot legend displays only one plot.
  2. When a double-headed arrow appears, shown in Figure 1-11, click and drag the border of the plot legend to add one item to the legend. When you release the mouse button, the second plot name appears.
  3. Right-click the waveform graph and select Properties from the shortcut menu to display the Graph Properties dialog box.
  4. On the Plots page, select Sawtooth from the top pull-down menu. In the Colors section, click the Line color box to display the color picker. Select a new line color.
  5. Select Sawtooth (Formula Result) from the top pull-down menu.
  6. Place a checkmark in the Do not use waveform names for plot names checkbox. This action lets you edit the labels on the graph.
  7. In the Name text box, delete the current label and change the name of this plot to Scaled Sawtooth.
  8. Click the OK button to save the current configuration and close the Graph Properties dialog box. The plot color and plot legend change.
  9. Reopen the Graph Properties dialog box and experiment with other properties of the graph. For example, on the Scales page, try disabling automatic scaling and changing the minimum and maximum value of the y-axis.
  10. Click the Cancel button to avoid applying any changes you made while experimenting. If you want to keep the changes you made, click the OK button.
  11. Save and close the VI.







Ulasan