Vous êtes sur la page 1sur 6

INTRODUCTION TO LABVIEW – Part One

Exercise 1. Temperature converter


Objective. To create a simple VI to convert temperature from Celsius to Fahrenheit.

Equation to be implemented:

Fahrenheit = 1.8 Celsius + 32

 Step 1 – build the VI (front panel and block diagram)


 Step 2 – run the VI
 Step 3 – debug the VI
 Step 4 – document the VI
 Step 5 – edit the icon and connector pane
 Step 6 – use the VI as a subVI in another application

STEP 1. Build the VI

1. Launch LabVIEW.
2. Choose File > New VI. LabVIEW opens both a blank front panel and a blank block diagram.
3. Ctrl +T tiles the two windows.
4. Observe the menu bars.
5. Click Window > Show Tools Palette – explain tools
6. Click Window > Show Functions (Controls) Palette
7. Build the front panel
 Click Window > Show Controls Palette > Numeric Indicators, select a thermometer and place it on the front panel.
 Observe the block diagram.
 Note the change in the menu bar. LabVIEW allows you to type the desired label. Label your thermometer Deg C and
click on the Enter Text icon.
 Right click on the thermometer and select Visible Items > Digital Display. A digital display is added to your
thermometer.
 Right click on the thermometer and select Change to control.
 Place another thermometer and label it Deg F. Adjust the Fahrenheit scale by typing 250. Right click on the thermometer
and select Visible Items > Digital Display.
 Cosmetics (font size, rearrange and align objects).
8. Build the block diagram
 Select from Functions>Numeric a multiply block and place it close to Deg C. Note the broken arrow in the menu bar.
 Select from Functions>Numeric a numeric constant and place it close to the multiply block.
 Select from Functions>Numeric an add block and place it close to Deg F.
 Select from Functions>Numeric a numeric constant and place it close to the summing block.
 Change operating tool to wiring tool.
 Wire the Deg C terminal to one of the multiply block inputs.
 Wire the numeric constant to the other input of the multiply block.
 Wire the output of the multiply block to one of the inputs of the summing block.
 Wire the second numeric constant to the other input of the summing block.
 Note that the arrow is not broken anymore.
 Wire the output of the add block to the Deg F terminal.
 Change tool to writing tool.

1
 Type 1.8 for the constant of the multiply block and 32 for that of the summing block.
 Shortcut. Instead of placing a numeric constant from the Controls Palette and wire it to the input of a block, place the
mouse on the input of the block, right click and select Create > Constant and type the desired value for the constant.
Another way to wire objects is to place the mouse on an object and press space. The tool changes automatically to the
wiring tool. Draw the wire between objects and press space again. The wiring tool changes to operating tool.
 Cosmetics (rearrange objects).
9. Save the VI. Name it C to F.

STEP 2. Run the VI

1. Select File>Open>C to F to open the front panel of your VI. Optionally Window>Show Diagram.
2. Click on the Run button (arrow). Change the Deg C value and run again. Note the new Deg F value. The default value for Deg C
is 0. If you want to start the execution with another value, type that value and select Make Current Values Default. Save the VI
and open it again. Observe the default values.
3. Click on Run Continuously. Change the Deg C value while the VI is running and observe the changes. Stop execution.
4. Click on Highlight Execution and then on Run. The moving dots show the data flow.
5. You can run your VI step by step. Use Start Single Stepping, Step Over and Step Out buttons located on the menu bar.

STEP 3. Debug the VI

1. Open C to F.vi.
2. Remove a wire from an input of the multiply block and note that the Run arrow breaks. Click however on Run. A dialog box
appears on the screen that indicates the errors and warnings. Another solution is to click on Window > Show Error List.
3. Rewire (undo).
4. Remove a wire from the output of the add block and note that the run arrow does not break. Run the VI. Note the malfunction of
the VI despite a non broken arrow. Rewire.
5. Place a probe at the output of the multiply block and another one at the output of the summing block.
6. Run the VI step by step and observe the values indicated by the probes. Check the operations.
7. Change the value of 1.8 to 18 and run the VI again. Observe the probes. Identify and correct the error.

STEP 4. Document the VI

1. Select File>VI Properties>Documentation.


2. Type This VI converts temperature from degrees Celsius to degrees Fahrenheit. Click OK.
3. Right click Deg C on the front panel and select Description and Tip.
4. Type Provides a temperature reading in Celsius for “Deg C” Description and Celsius temperature for “Deg C” Tip.
5. Right click Deg F and select Description and Tip.
6. Type Displays the calculated temperature in Fahrenheit for “Deg F” Description and Fahrenheit temperature for “Deg F” Tip.
7. Show Context Help. Idle cursor over the thermometers and over the icon. Observe what happens.
8. Run the VI continuously. Idle cursor over the thermometers and observe what happens.

STEP 5. Edit the icon and connector pane

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. The default icon contains a number that indicates how many new VIs you have opened since
launching LabVIEW.

Complete the following steps to create or edit a VI icon.

1. Right click the icon in the upper right corner of the front panel or block diagram and select Edit Icon.
2. Click 16 or 256 colors.
3. Place a checkmark in the Show Terminals checkbox to show an outline of the connector pane on the editing area. The
connector pane is only a guide. It will not appear in your final icon.
4. Use the tools on the left side of the Icon Editor window to create the icon design in the editing area. The normal size image
of the icon appears in the appropriate box to the right of the editing area.

2
Complete the following steps to assign terminals to controls and indicators in a connector pane.

1. Right click on the icon and select Show Connector.


2. Right click on the connector and select one of the patterns.
3. Click a terminal of the connector pane. The tool automatically changes to the Wiring tool and the terminal turns black.
Although you use the Wiring tool to assign the terminals on the connector pane to front panel control and indicators, no
wires are drawn between the connector pane and these controls and indicators.
4. Click the front panel control or indicator you want to assign to the terminal. A marquee highlights the control.
5. Position the cursor in an open area of the front panel and click. The marquee disappears and the terminal changes to the
data type colour of the control to indicate that you connected the terminal. Repeat steps 3 to 5 for each terminal of the
connector pane.
6. You can specify which terminals are required, recommended and optional.
7. Save the VI.

STEP 6. Use the VI as a subVI in another application

1. Open a new VI and place 4 thermometers on the front panel (2 Celsius as controls and 2 Fahrenheit as indicators).
2. On the block diagram place two times the subVI C to F and properly wire their inputs and outputs.
3. Show Context Help. Place cursor over a subVI and observe what the Context Help window displays.
4. Run the VI.

Exercise 2. Use of sequence structures


Objective. To build a slightly modified temperature converter using sequences.

1. Open the VI created in Exercise 1.


2. Optionally, press Ctrl+T to tile the front panel and block diagram windows.
3. Open the Functions Palette, select Structure > Stacked Sequence Structure and place it on the block diagram. Resize it by
dragging one of its corners with the Size/Position Tool.
4. Right click on the sequence border and select Add Frame After. Note the label of the sequence. Add another frame. You will
have a total of 3 frames.
5. Select frame 0 and place the multiply block and the corresponding constant.
6. Right click on the sequence border and select Add Sequence Local. This adds a local variable that you can use in one ore more
subsequent frames.
7. Wire the output of the multiply block to the local variable.
8. Select frame 1 and place the add block and the corresponding constant.
9. Wire the local variable to the unwired input of the add block.
10. Select Edit > Remove Broken Wires to get rid of all unconnected wires.
11. Wire the Deg C terminal to the unwired input of the multiply block. The wire will cross the sequence border. Note that a tunnel
appears on the border.
12. Wire the output of the add block to the Deg F terminal. The wire will tunnel the sequence border.
13. Select frame 2. Frame 2 is not necessary so you will remove it. Right click on the sequence border and select Delete This
Frame.
14. Save the file under a different name.

Exercise 3. Use of case structures


Objective. To build a temperature converter for displaying the Fahrenheit temperature when the input is either a Celsius or a
Fahrenheit temperature.

1. Open the VI created in Exercise 1.


2. Optionally, press Ctrl+T to tile the front panel and block diagram windows.
3. Open the Functions Palette, select Structure > Case and place it on the block diagram. By default, it is a case with two frames
(True and False) which is enough in our case. Resize it by dragging one of its corners with the Size/Position Tool. Place it over
the calculating blocks of the VI. Note the connections to the terminals have been preserved, but they tunnel the case borders. By
default, the displayed case is True. Switch to False and draw a wire between the two tunnels.

3
4. On the front panel add above the Deg C control a Toggle Switch from Controls > Boolean. Label the two positions C and F,
respectively.
5. On the block diagram wire the Boolean terminal to the case selector.
6. Run the VI. Note the displayed Fahrenheit temperature does not correspond to the input value. On the block diagram right click
on the case border and exchange case roles by selecting Make This Case True (False).
7. Run the VI again and check it operates properly.
8. Save the VI under a different name.

Exercise 4. Use of for loops


Objective. To build a simple VI to display an array of natural numbers using a for loop.

1. Open a new VI.


2. Optionally, press Ctrl+T to tile the front panel and block diagram windows.
3. On the front panel select Controls > Numeric subpalette and place a Numeric Control and an Array from the Array &
Cluster subpalette. Place a numeric indicator inside the array. Resize the array by dragging one of its right corners so as to see
5 or 6 boxes inside it.
4. Type 5 inside the numeric control on the front panel and select Operate > Make Current Values Default.
5. On the block diagram select a For Loop from the Functions > Structures subpalette and place it between the numeric control
and the array.
6. Select a Build Array block from the Functions > Array subpalette and place it between the for loop and the array. Rearrange
block if necessary.
7. Wire the count (N) terminal of the for loop to the numeric control terminal.
8. Wire the iteration (i) terminal to the build array block. It will tunnel the for loop.
9. Wire the output of the build array block to the array. Note the wire is broken. Right click on the build array and select
Concatenate Inputs. Observe the wire is not broken anymore. Optionally, select Show Context Help, place the cursor over the
build array block and read the help.
10. Run the VI and observe the array on the front panel.
11. On the block diagram right click on the for loop tunnel and select Disable Indexing. Run the VI again and note the difference.

Exercise 5. Use of while loops


Objective. To repeat exercise 4 using a while loop.

1. Open the VI created in exercise 4.


2. On the block diagram replace the for loop with a while loop.
3. Select Edit > Remove Broken Wires.
4. From the Functions palette select Comparison > Less? and place it inside the while case.
5. Wire the iteration terminal to the x input and the numeric control at the y input of the Less? block.
6. Wire the output of the Less? block to the Loop condition terminal.
7. Right click the Loop condition terminal and select Continue if True.
8. Run the VI.

4
INTRODUCTION TO LABVIEW – Part Two

Controlling real instruments via standard interfaces with LabVIEW


A standard interface connects two or more devices in order to exchange information between them. A standard interface falls into
one of two broad categories: series or parallel.
In series interfaces information is passed from one device to another one bit at a time (in ‘series’, hence the name). Common series
interfaces are: RS 232, RS 485, I2C, CAN, USB.
In parallel interfaces information is passed from one device to another one byte at a time (eight bits at a time, on eight separate
wires), one byte after another. Common parallel interfaces are: IEEE 488, VXI, MXI.
The minimum configuration for connecting two devices through a standard interface (either series or parallel) is shown in fig. 1. Each
of the two devices must have a corresponding interfacing module (which can be an on board circuit or an add-on card). A proper
cable is also required. And, last but not least, the communication protocol (defined by the standard) must be implemented.

Device Device
#1 #2

Interface circuit Interface circuit


Interface cable

Standard interface

Fig. 1 Two devices connected through a standard interface.

The serial interface RS 232 is one of the simplest and most widespread interfaces. Its drawbacks are that it limits to two the number
of devices that can be interconnected and the transfer rate is low.
A simplified schematic of two devices connected via RS 232 is shown in fig. 2. Each device has two data lines (TxD – Transmit Data
and RxD – Receive Data) a minimum of two control lines (RTS – Request To Send and CTS – Clear To Send) and a ground line
(GND).

TxD RxD

RxD TxD

RTS CTS

CTS RTS

GND GND

Device #1 Device #2

Fig. 2. RS 232 serial interface.

The communication protocols defined by the RS 232 standard can be hardware or software.
In one of the hardware protocols the lines RTS and CTS are used. Suppose that device #1 wants to receive data from device #2. To
that purpose device #1 asserts its RTS line LOW, so the CTS input of device #2 will be LOW enabling device #2 to transmit. Device
#2 will actually transmit data only after receiving a corresponding command from device #1.
In the software protocol control lines are not used. Communication between the two devices is controlled with XON – XOFF
characters.

5
Exercise 1. Serial communication with a TDS 210 oscilloscope
Objective. To create a VI able to send commands to the oscilloscope and to get and display the received data.
The front panel of the VI should have at least:
1. one VISA resource name control
2. one string type control that will be used to send commands to the oscilloscope
3. one string type indicator that will display the “answer” of the oscilloscope.
The block diagram will contain a sequence consisting of the following frames:
1. VISA Close
2. VISA Open
3. VISA Configure Serial Port
4. VISA Write
5. VISA Read
6. VISA Close
All of the functions above can be found in the Functions palette > Instrument I/O > Serial except VISA Open which can be found
in the Functions palette > Instrument I/O > VISA > VISA Advanced.
Tips
1. Wire the Visa resource name control to the corresponding input of all VISA blocks used (in every frame!).
2. Use the following to configure the serial port: Baud rate 9600, Data bits 8, Parity 0 (None), Stop bits 10 (1,0 bits !), Flow
control 0 (None).
3. Attach at the end of the control string a LF (Line Feed) constant that can be found in the Functions palette > String. Use
Concatenate Strings that can be found in the Functions palette > String.
4. Wire the output of the Concatenate Strings block to the write buffer input of the VISA Write.
5. Wire a constant at the byte count input of the VISA Read. Set it to 400.
6. Optionally, you may add a first indicator (label it Transmitted byte count) and wire it at the return count of the VISA
Write, and a second indicator (label it Received byte count) and wire it at the return count of the VISA Read.

Type RS232? in the control string box. In the Operate submenu choose Make Current Values Default. Run the VI and observe its
front panel.
Now type RS232:BAU 4800 in the control string box and run the VI. Observe the front panel. Observe also the parameters of serial
communication on the oscilloscope. What happened? Now type RS232:BAU 2400 and run the VI. What happens? Try to explain.
Reinitialize to 9600 the baud rate of the oscilloscope. Type DAT:SOU CH1;ENC RPB;STAR 1;STOP 2500;WID 1;:CURV? in
the control string box and run the VI. Observe the front panel. Try to explain the content of the indicator string box.
Now add a Waveform Graph on the front panel of the VI. In the block diagram add a String To Byte Array function. Wire its
input at the read buffer output of the VISA Read. Wire the input of Waveform Graph to the String To Byte Array output. Type
DAT:SOU CH1;ENC RPB;STAR 1;STOP 2500;WID 1;:CURV? in the control string box and run the VI continuosly. Observe
the front panel. Optionally, you may change the colour, width, Y scale and X scale of the Waveform Graph. You may also try to
send other commands to the oscilloscope (for details see the Programmer Manual for TDS200-, TDS1000- and TDS2000-Series
Digital Oscilloscope or visit www.tektronix.com).

Vous aimerez peut-être aussi