Labview _8 _Teaching _Manual _2007

25
© 2006 David D. Hodgkiss & Staffordshire University 1 Faculty of Computing, Engineering and Technology Real Time Systems 1 CE00345-3 LabVIEW 8 TM

Transcript of Labview _8 _Teaching _Manual _2007

Page 1: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 1

Faculty of Computing,Engineering and Technology

Real Time Systems 1CE00345-3

LabVIEW8

TM

Page 2: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 2

Table of Contents

Chapter 1 - Introduction.

Introduction. 4 Tools Palette. 8 “Hello World” . 10 Editing the wiring. 19 Bad wires. 19 Manipulating the palettes. 19 Boolean operations. 20 Data types. 21 Nodes. 21 Changing the data representation. 21 Changing the value range. 21 Context sensitive help. 22 Creating SubVIs. 23 Adding the wiring terminals. 24 Using SubVIs. 24 Summary. 25 Chapter Exercises. 26

Chapter 2 - Select, Testing, Debugging and While Loops.

Select. 27 Debugging. 30 While Loops. 31 Data representation revisited. 34 Shift registers. 35 Summary. 36 Chapter Exercises. 37

Chapter 3 - For Loops, Case Structure and Sequences

For Loops. 38 Case Structure. 40 Case Example - Square Root Calculation. 40 Sequence Structures. 43 Summary. 48 Stopping the errant VI. 48 Chapter Exercises. 49 continued ........

Page 3: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 3

Chapter 4 - Formula Node, Arrays.

Formula Node 50 Arrays 52 Auto Indexing. 54 Initialising Arrays. 58 Array - Show Size. 59 Array Index. 60 Array Subset. 60 Summary. 61 Chapter Exercises. 62

Chapter 5 - String handling, File I/O & Feedback Node.

Format into String. 63 Extract from String. 66 File Input & Output. 70 Feedback Node. 72 Chapter Exercises. 74

Chapter 6 - Multithreading, Local & Global Variables and Bundles.

Multithreading. 75 Local Variables. 76 Global Variables. 78 Adding additional Global Variables. 81 Bundles. 82 Chapter Exercises. 83

Chapter 7 - Serial VIs, Properties & Designing with LabVIEW.

Serial Communications. 84 VISA Configure Serial Port. 86 Write. 86 Read. 86 Close. 86 Serial Cable Connections. 88 Object Properties. 89 Designing with LabView. 91 SubVI Terminals. 93 Testing. 93 Sequence Structures - a warning. 94 ...... And finally. 94

Appendices. Installing LabVIEW 7.1 Express. 96 Front Panel Common Controls. 101 Block Diagram Common Controls. 102

Table of Contents (continued)

Page 4: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 4

1. Introduction ___________________________________LabVIEW™ is a graphical programming environment manufactured by the National InstrumentsCorporation based in Austin, Texas, USA.

National Instruments started in much the same way as Hewlett Packard but in a garage instead of ashed. The company first announced LabVIEW in 1986 with version 1.0 for DOS being released thefollowing year. Version 2.0 for Windows™ was released in 1990 with various upgrades followingevery few years. The latest version being LabVIEW 8 that was released during October 2005.

For those of you that have had some experience using Microsoft Visual Basic™ will recognise somesimilarities between the concept of a front screen for the user controls and a “back screen” that holdsthe programmed functionality. The main difference, however, is that the programming in VB is car-ried out using a textural based procedural language. LabVIEW uses a graphical event driven languagebased upon data flow, the “code” looks like an electrical wiring diagram with the data “flowing”along the connecting wires. An application / program built within LabVIEW is referred to as a“Virtual Instrument” or “VI” the standard file extension is “.vi”

LabVIEW has, essentially, been developed to enable control of external scientific equipment such asOscilloscopes, Logic Analysers etc. You will find that a lot of the inbuilt functionality is intended pri-marily for this type of work and will not be needed for the work that we will be covering during themodule. However, you may freely include any that is relevant and pertinent, indeed you are encour-aged to explore the powers of LabVIEW beyond the features that will be covered within this manual.

For the Real Time Systems module, LabVIEW has been installed upon those computers within G1.The computers in these three laboratories have been paired using a modified RS232 connecting cableas some of the work will involve using such a link to communicate between separate applications.

To launch LabVIEW follow this path…….

Start Programs Programming Tools National Instruments LabVIEW 7.1 LabVIEW

Launching LabVIEW will initially generate a flash screen that is usually followed by the screen asshown in Diagram 1, do not worry if it doesn’t it just indicates that the launch has been set so that itdoes not present this screen.

Diagram 1 : Initial launch dialogue screen

The various links below“Resources” will open a various

documents that you may find use-ful.

To start a simple development,simply select “Blank VI”

This pane shows VIs that havebeen opened before.

Page 5: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 5

If you have not already done so, open a blank VI.

Depending upon the local configuration, you should now see four windows as shown in diagram 4, do notworry at this stage if you can only see the Front Panel and Block Diagram.

Tools Palette

Block Diagram Front PanelControls Palette(for Front Panel)

Front Panel

This is where you will place all of the control and output objects, e.g. Buttons, dials, LEDs, gauges, graphs etc. These objects are virtual implementations of the sort of objects that you would find on anydevice with which a user interacts e.g. Oscilloscope, Stereo, Mobile Phone, Power Station Control Paneletc.

Block Diagram

This is where you will place all of the objects that are used to implement the actual functionality(programming logic). As with the front panel, it will contain a virtual representation of the sort of devicesthat would be present within those example devices mentioned above.

Controls Palette

Within this palette you will find all of the objects that can be placed upon the Front Panel.

This palette will only be visible when the Front Panel is selected, Clicking on the Block Panel will bringit to the foreground, hide the Controls Palette and cause the Functions Palette to be visible.

Functions Palette(for Block Diagram)

Work Area

Diagram 4 : Work Windows

Page 6: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 6

Operate Value

Selecting this tool will allow you to change values of those objects placed upon the front panel beforethe VI is running.

Once you have started a VI you create or edit it using the Tools Palette and either the Controls Paletteor the Functions Palette.

Tools Palette

Diagram 5 shows the “Tools Palette” that contains icons representing the various manipulation objects thatyou will use when developing VIs. If this palette is not showing on the screen, select “Windows” menu fromthe menu toolbar, then select “Show Tools Palette” from the drop down menu (you may have to expand thismenu to its full size using the double chevron at the bottom of the menu).

Auto Tool Selection

Whilst the green indicator is illuminated, LabVIEW™ will attempt to automatically select the correcttool for the operation that you are attempting to implement.You should experiment with this facility to determine if it suits your way of working.

Diagram 5 : Tools Palette

Automatic Tool Selection

Set / Clear Breakpoint

Connect Wire

Operate Value

Position / Size / Select

Get Colour

Probe Data

Scroll Window

Object Shortcut MenuEdit Text

Set Colour

Page 7: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 7

Connect Wire.

This icon represents a virtual spool of connecting wire. The objects placed upon the block diagram areinterconnected using virtual wires.Within LabVIEW™ the interconnecting wires carry the data that is then processed.

Position / Size / Select

This tool is used to place objects on either the front panel or block diagram, resize object or to simplyselect them.

Edit Text

This icon represents the text-editing tool, it is used to rename objects, change range values and create or edit free text labels.

Object Shortcut Menu

Clicking on an object after selecting this tool will display a properties menu for that object. Right clickingon the object will achieve the same result when working on a PC.

Scroll Window

This tool will allow you to move the front panel or block diagram around within the desktop window.An alternative is to use the window scroll bars.

Set / Clear Break Points

This tool is used as a debugging aid and will place “stops” within the wiring of a block diagram that,when encountered by the flowing data, will temporarily halt the VI execution.

Page 8: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 8

Get Colour and Set Colour

These two tools will allow you to change the colour of both screen and object colours.You should explore the functionality of these tools your self as you develop VIs.

Don’t worry too much if some of the above is not very clear, once you start developing VIs thefunctionality of the various tools will become much clearer.

“Hello World”

As with most programming languages, it is always a good idea to start with a very simple application,LabVIEW is no different.

This first application will demonstrate the four basic mathematical rules (“+”, “-”, “x” and “¸”).

If not already open, open a new blank Virtual Instrument and ensure that the Front Panel is on top -holding focus.

Right click on the work area, the palette in diagram 6 will appear.

Diagram 6 : Controls

Page 9: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 9

Now click on the icon labeled “Numeric”, the palette in diagram 7 will appear above the “Controls” palette.

Diagram 7 : Numeric Controls

Now click on the icon labeled “Numeric Control”, initially the cursor will change to a “no entry” symbol.Now move the cursor so that it is above the Front Panel work area, the cursor will change to a small handand dotted boxes will appear underneath it. You will note that as the dotted box is moved around it will besnapping to the layout grid.

Page 10: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 10

Diagram 8 : Placing an object

Position the control towards the top left hand side of the work area and single click, the control will appearon the front panel and be given a the default name “Numeric.” You will see that the default name hasautomatically been placed into edit mode (white text on a black background), to change the name it is asimple case of typing the replacement, for this control you should rename it “First Value.”

Should focus be lost from the default name it is a simple case of selecting the text edit tool from the toolspalette and editing in the usual manner. When editing in this manner you will see a “tick” icon appear onthe left hand side of the toolbar, just under “File”, clicking on this will instruct LabVIEW to accept theamended text.

Once positioned and renamed the front panel should resemble diagram 9.

Diagram 9 : Naming and placing of first control object

Page 11: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 11

Add a second numeric control and name it “Second Value”. Position it to the left hand side of the screenbelow “First Value”, the exact position is not important at this stage.

You will have noted that the grid does help to align objects by aligning them to the grid. It is possible to modify the grid properties by following these steps.

- Using the main menu tool bar at the top of the front panel, select Tools .. Options.

- Now, using the down arrow to display the options menu, select “Alignment Grid.”

- Here you will find various options for configuring the alignment grid, you will note that it is possible to have grids on either of the two main screens.

- You should experiment with these controls as you develop the various LabVIEW applications to find which settings are most suited to you or the particular application being developed.

Now add the four output objects....Right click on the front panel work area, move the cursor to cover the “Num Inds” icon (NumericIndicators) and then select “Num Ind” from the sub palette. Position this object towards the top righthand side of the front panel work area. As before the exact position is not important at this stage, renamethe object “Add.”

Now place three more numeric indicators onto the front panel work area, positioning them under the “Add”indicator and rename them “Subtract”, “Multiply” and “Divide.”

The front panel should now resemble diagram 10.

Diagram 10 : Initial front panel

Whilst it would be quite acceptable to manually align and distribute the various objects on the front panelso that they are suitably placed, tools are available within LabVIEW that can assist this operation.

From the tools palette, make sure that the “position / size / select” tool is selected.

Drag out a rectangle on the front panel work area that includes just “First Value” and “Second Value.”

Page 12: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 12

Align Objects Distribute Objects Resize Objects Order Objects

Diagram 11 : Layout Tools

Now click on the “Align Objects” button on the tool bar (see diagram 11) and select “Left Edges” fromthe six options. The two controls will now rearrange themselves such that there left edges are aligned.

You should also explore the other layout tools as shown in diagram 11.

The “Order Objects” facility also offers a grouping function.

Do the same with the four numeric indicators so that you have a well structured front panel that resemblesdiagram 12.

Diagram 12 : A well structured front panel

Having constructed the front panel you will now use the Block Diagram screen to program the functionalitythat will make the VI operate as intended.

Switch to the Block Diagram by clicking on its window title bar, it should resemble diagram 13 onthe next page.

Page 13: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 13

Diagram 13 : Initial block diagram

You will note that there are six objects (nodes), one for each of the six objects that were placed on the frontpanel. You will also note that they are located in the same relative positions to the original placement of thefront panel objects, i.e. moving the objects around on the front panel does not move their nodes on theblock diagram, and visa versa.

As with this simple application it is appropriate to arrange the block diagram nodes in the same manner astheir front panel counterparts, you should use the layout tools as before. As VIs become more complex youfind that the front panel and block diagram node pairs will be in different relative locations and good layoutwill be essential.

You will now add the functions to make the VI operable.

Right click on the block diagram work area (not on one of the nodes), this will activate a palette named“Functions.” Now move the mouse cursor until it is above the icon “Numeric” to activate the nextpalette, “Numeric.” Now select “Add” from this palette by clicking on it.

The cursor will change to a hand with a little yellow filled triangle underneath it. This triangle is the iconthat represents the “Add” function. Position the cursor so that it is to the right of the “Add” node and single click to drop the item onto the work area. It should be noted that default setting for the alignment grid onthe block diagram is “off.”

Repeat the operation to introduce the “Subtract”, “Multiply” and “Divide” functions,positioning each to the left of the corresponding nodes.

As before the layout tools can be used to position the function icons.

Your block diagram should now resemble diagram 14.

Page 14: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 14

Diagram 14 : Block Diagram with functions added

In order to complete the programming you must now “wire” the nodes and function icons together.

On the tools palette select the connect wire tool, the cursor will change so thatit resembles a spool of wire.

Position the cursor so that it is above the “First Value” node, the node will start to flash and a connectingterminal will appear on its right hand side. Click on the node and start to move the cursor to the left towardsthe “Add” function and you will see a dotted line being drawn out of the node, this represents a connectingwire. Now if you move the cursor up or down you will see that the dotted line has a turn within it, showingthat the wires can go around corners.

It is possible to add “way points” by clicking on the block diagram work area so that wires can be routedwherever and however you like, however wires will only run horizontally or vertically.

Now, having added way points as necessary, place the cursor above the “Add” function, as with the “FirstValue,” node it will respond by flashing and offering three connection points (“x”, “y” & “x + y”), you willhave to move the cursor around over the icon in order to see all of the connection points respond. Click onthe “x” connection terminal to complete this part of the wiring. To show that a valid wiring connection hasBeen successfully completed the wire will become a solid orange wire as can be seen in diagram 15.

Diagram 15 : Detail of first wiring connection

Page 15: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 15

Now connect a wire from “Second Value” to the “y” input of the “Add” function and then a wire from the“x + y” output to the output node “Add.” Your Block Diagram should now resemble diagram 17.

Diagram 16 : Completed wiring for addition

In order to make the wiring of the remaining three functions tidier it is possible to connect new wires tothose that already exist.

Using the wiring spool, move it so that it is above an existing connecting wire, it will flash to indicate thata connection can be made. Single clicking on the wire will allow you to draw out a new wire.

In this example, single click on the vertical section of wire that connects “Second Value” to the “y” input ofthe “Add” function and draw out the wire, adding way points as necessary, and connect it to the “y” inputof the “Divide” function, ignoring “Subtract” and “Multiply” for now.

Now, using the same technique, connect a wire from the horizontal wire leading to the “y” input of the“Add” function to the “y” input of the “Divide” function. Once that is connected, connect the output of thedivide function to the “divide” output node.

If you make any mistakes during this early wiring, use the “Undo” facility that can be found within the“Edit” drop down menu. The keyboard short cut for undo is “Ctrl” + “Z”

Your Block diagram should now resemble diagram 17 on the following page.

Page 16: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 16

Diagram 17 : Adding the Divide wiring

You will note that where wire connect a small blob has been added to enhance the wiring diagram. Thisfacility is an option within LabVIEW and can be toggled via the Options facility within the Tools dropdown menu. The check box to switch the “blobbing” on or off can be found within the “Block Diagram”dialogue.

You should now complete the wiring by connecting the existing wires to the inputs of the “Subtract” and“Multiply” functions as well as connecting their outputs to the appropriate output nodes so that it resemblesDiagram 18.

That is the wiring completed, the instructions for running the application can be found on the next page.

Diagram 18 : Completed wiring

Page 17: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 17

Switch back to the front panel, at the left hand side of the tool bar you will see four icons.....

a single arrow a double arrow a (currently) greyed out red circle and an icon with two vertical bars

When pressed, the single arrow will cause the application to be run once (Run), whilst the double arrow willcause the application to be run repeatedly (Run Continuously).

Once running the red circle will cease to be greyed out and when pressed will halt execution, the icon withthe two vertical bars is the pause execution feature (similar to VCRs etc.).

Click on the double arrow icon to run the application continuously, the cursor will change to the “OperateValue” mode so that the input values (First and Second) can be modified using the little “up” and “down”arrows to the left hand side of each of the two controls. The layout grid will also disappear.

Play time!

Now switch to the Block Diagram panel, you will see that the four above icon / buttons are repeated as itis possible to run the application from the Block Diagram. You will also note that an additional button ispresent. When pressed this button will place the application into “Highlight” mode (the button is used totoggle this mode). Highlight mode is useful as it allows the user / developer to watch the data as it flowsthrough the application, it is a very useful basic debugging tool.

You should note that an application in highlight mode runs considerably slower than when in the normalrun mode.

An example of the application running in highlight mode can be seen in diagram 20 (can you spot thedeliberate programming error?)

Diagram 20 : “Hello World” running in highlight mode

Diagram 19 : Run controls

Page 18: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 18

Editing the wiring

Connecting wires can be easily edited to either move or remove them.

Before any editing can be carried out the wire(s) need to be highlighted using single, double or tripleclicking, the more clicks used corresponds to the amount of connecting wire highlighted.

Using the position / size / select tool single click on the wire between the “y” input of the “Add” functionand where the wire makes a right angle turn downwards, the result should resemble diagram 21.a.Now, using the same tool double click on the same section of wire, the results should correspond todiagram 21.b. Finally, triple click on the same section of wire to highlight it to its full extents, thisshould resemble diagram 21.c.

Diagram 21.a : Single clickwire selection

Diagram 21.c : Triple clickwire selection

Diagram 21.b : Double clickwire selection

Once selected wires can be deleted by pressing the “Delete” key or can be moved by either dragging withthe position / size / select tool or by using the cursor keys (“up”, “down”, “right” or “left”). When usingthe cursor keys alone the selected wire(s) will move by a very small amount, if the cursor keys are used inconjunction with the “Shift” key the movement will be approximately eight times as great.

Please note: Just as when programming within a textural environment, programming standards areof vital importance i.e. layout structure, naming conventions etc. Even though LabVIEW is a graphicalprogramming environment, it is still of vital importance to practice the same rigour, so, please rememberto use good naming standards and layout - you will be penalised for “spaghetti wiring that looks likeknitting!

Bad wires

From time to time you will find that you have incomplete wiring or have incorrectly wired objects togethere.g. connected two outputs together. Such wires will appear as dotted black lines instead of the usualcoloured solid lines. Whilst it is straight forward enough to use the above techniques to remove such wires,LabVIEW includes a short cut feature that will automatically remove all bad wires - “Ctrl” + “B”, howeverbe careful of its use as it will remove all bad wires and not just those that you may have wished to beremoved.

Manipulating the palettes

So far you have been activating the palettes that contain either the front or block panel objects by first rightclicking on the work space etc., once the object has been selected the palette disappears. It is possible toactivate the palettes such that they remain open and always “on top”.Select “Windows” on the main menu of the front panel and then select “Show Controls Palette”, the palettewill now remain available after each selection. The same feature exists for the block diagram (“ShowFunctions Palette”), LabVIEW will only show one of these at a time dependent upon which diagram is live.

Page 19: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 19

One of the new features that LabVIEW 7 is providing is that the initial palette of controls and / or functionsis providing a categorised view of the sub palettes, an alternative approach is to use the palette structurefrom earlier versions of LabVIEW, these can be found via the “All Functions” or “All Controls” icons.

You should fully explore the palette hierarchy so that you can work in a manner that suits you.

From now on these notes will be written on the assumption that you will be working with either the “AllFunctions” or “All Controls” palettes.

Boolean Operations

Diagram 22a and 22b show the front panel and block diagram of a VI that demonstrates some of the logicfunctionality available within LabVIEW including

AND OR XOR Compound operations (>2 inputs)

Diagram 22a : Boolean Operationsfront panel

Diagram 22b : Boolean Operationsblock diagram

All of the controls and functions used within this VI can be found within the Boolean sub palettes.

When adding the “Compound Arithmetic” function it will default with two inputs and offering theaddition function. To add extra inputs you can either right click on either of the two left hand boxes thatrepresent the input connections and select “Add input” (note it is possible to also remove inputs) or, usingthe position / size / select tool, click on either the top or bottom edge and drag to increase or decrease thenumber.

To change its function, right click on its icon and select “Change Mode” then select the desired functionalityfrom the subsequent menu.

Page 20: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 20

Data types.

So far you have used just two of the many data types available within LabVIEW, Double and Boolean andhave, hopefully, seen that different wire colours have been used, Orange for Double and Green for Boolean.Other data types are available, each using different colours for ease of identification, for example

Blue is used to indicate integers Quad (64 bits), Long (32 bits), Word (16) and Byte (8): signed or unsigned. Orange is used indicate floats Extended (128), Double (64) and Single (32). Pink is used to indicate strings Green is used to indicate Boolean types.

Within each of the numeric data types it is possible to specify the number of bytes used to represent thevalue and, therefore, its range.

Nodes

When adding controls or indicators to the front panel a corresponding wiring node is automatically placed within the block diagram. In essence, a node can either be an input e.g. a numeric control that generatesvalues / data (source) or an output e.g. numeric indicator that displays or consumes values / data (sink).LabVIEW indicates their difference by using a different border format for each. Diagram 23 shows thisdifference.

Diagram 23 : Node borders

You will see that the input (generator) node has a thicker outer boarder than the output (consumer) nodeand has a little arrow head on its right hand edge that points outward whilst the input node has a little arrowhead on its left hand side pointing inwards.

These arrows also give an indication of how you should aim to wire, LabVIEW generally wires from left toright and those objects that can accept inputs and provide outputs e.g. Compound Arithmetic, will bearranged with their input connections on the left and their output connections on their right. You are advisedto remember this and try to adhere to it whenever possible, however there will be many times when it is notpossible and you will have to be creative to prevent your wiring getting into a complete mess (knitting!).

Changing the data representation.

This can be achieved by right clicking on the node (it can also be achieved using the front panel object) andselecting “Representation” from the generated sub menu. It is then a simple case of clicking on the desiredbyte count. You should explore this feature together with two related features “Data range” and “Formatand Precision” again available via a right click.

Changing the value range.

Whilst it is possible to limit the value ranges of controls by changing the data representation it is alsopossible to limit the range of values that particular front panel controls and indicators will show.

Start a new, blank VI

On the front panel place a “Knob” and a “Tank” from the Numeric sub palette. Switch to the block diagramand wire the output of the Knob to the input of the Tank. The VI should resemble diagrams 24.a and24.b on the following page.

Page 21: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 21

Diagram 24.a : Knob and Tank front panel Diagram 24.a : Knob and Tank block diagram

The default values for the Knob and Tank are both 0 .. 10 even though the data representation is capable ofa much greater range. Using the text tool, click on the maximum of value of the Knob and enter a newmaximum value of 150.

Run the VI in continuous mode (click on the double arrow) and operate the knob using the cursor (it willturn in the same way as a physical knob on a piece of equipment).

Now change the Tank’s maximum to 200 and run the VI again, note that even though the data representationis covering a large data range the maximum and minimum values have been limited on the front panel.

Stop the VI and add a “Thermometer” from the same sub palette to the front panel. Switch to the blockdiagram and add the function “Random Number (0-1)” that can be found within the Numeric sub palette, itlooks like a pair of dice.

A short aside - Context Sensitive Help.

Click on the menu item Help and select “Show Context Help”, a small floating window will appear, movethe cursor so that it is above the random number function. The contents of the new window will change anddisplay some information about the selected object, often a link will be provided that, when clicked, willopen the main help system and provide more detailed information.

This context sensitive help system will often provide very useful information about objects but, you shouldalso explore the main help system as it quite extensive and can provide some very detailed information

Back to the programming.

The context sensitive help will have indicated that the random number generator will produce values in therange 0..1, as did its title. As the range of the Thermometer is as the default value of 0..100 and it is notpossible to directly change the functionality of random number generator, scaling functionality will have tobe added.

Add a “Multiply” function to the block diagram, positioning to the left of the Thermometer node, wire theoutput of the random number generator to one of the inputs of the multiply function. Add a “NumericConstant” (from the numeric sub palette) and wire it to the second input of the multiply function.Change the constant’s data representation to “Double” (DBL) and edit its value so that it is 100. Finally,Wire the output of the multiple to the thermometer node.

The VI should resemble diagrams 25.a and 25.b on the following page.

100

Page 22: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 22

Diagram 25.a : Knob, Tank & Thermometerfront panel

Diagram 25.a : Knob, Tank & Thermometerblock diagram

Run the VI continuously and observe how the Knob and Tank run independently of the Random Numbergenerator and Thermometer, using the Highlight facility will aid this observation. This independence iscentral to the manner in which LabVIEW operates (multithreading) and will be revisited again in later weeks.

Creating SubVIs.

A SubVI is the equivalent of a function within a text based programming language such as “C”, “C++”, VBetc. The use of SubVIs will help simplify wiring diagrams whilst retaining their functional complexity.

As with functions, SubVIs can be used repeatedly.

Example.Set up the Slope Calculation VI as shown in diagram 26.a and 26.b

Diagram 26.a : Slope front panelDiagram 26.a : Slope bloack diagraml

Editing the IconSwitch to the front panel, right click on the VI icon (top right hand corner) and select “Edit Icon”.

Use the drawing tools to draw a new, suitable icon - use of colour can be useful.

Note that three icon types are shown, the one used being dependent upon the colour depth being used bythe host computer (B&W, 16 and 256)

Click “OK” when you have created your masterpiece, a suggestion is shown in diagram 27 below.

Diagram 27 : Slope Icon

Page 23: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 23

Adding the wiring terminals.

The wiring terminals are the equivalent of function input parameters and output values.

Right click on the newly created front panel icon and select “Show Connectors”, a pattern will appear thatcorresponds to the number of inputs and outputs. Note that the four inputs are shown on the left hand sideand the single output is shown on the right hand side of the icon. This is following the standard LabVIEWpattern as introduced earlier.

The cursor will have automatically changed to the wiring spool, this is indicating that LabVIEW is ready toassociate each of the terminals with an object on the front panel.

Click on the top left connecting connecting rectangle, it will turn black to show that the click has beenacknowledged and to confirm which connector has been chosen. Now click on the “Y1” numeric controlon the front panel, the connector will now change colour (probably to orange) to signal that the associationis recorded.

Repeat this operation with the other inputs and then connect the numeric indicator to the right handconnector rectangle - try to be logical when associating the connections as it will help when buildingmore complex VIs.

If you make a mistake, it is possible to correct - you should investigate by right clicking on the icon andthe individual connections.

Finally save the VI as “Slope” - LabVIEW will automatically add the “vi” extension.

Using SubVIs.

To use a SubVI within an existing VI, use the “Select a VI” option from the functions palette, use thebrowse facilities to locate the file then select and click on the “open” button (alternatively just double clickon the file).

Note that SubVIs can only be used within the block diagram and not the front panel and that it is not possibleto insert a SubVI within itself.

The SubVI’s icon will then appear on the block diagram, it can then be positioned and used as the embeddedfunctions.

Note how the input and output names from within the SubVI are used when wiring.

Diagrams 28.a and 28.b on the following page show SubVI reuse - note the use of decorations on thefront panel and how different types of controls and indicators from those within the SubVI have been used.

Page 24: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 24

Diagram 28.a : Multiple Slopefront panel

Diagram 28.a : Multiple Slopeblock diagram

Summary

This introduction to LabVIEW 8 Express has covered the following aspects

Data flow concepts within LabVIEW and, using the highlight feature, how the various functions are activated only when all of their inputs have received data, this can be thought as “event driven based upon data flow”.

Basic controls, indicators and and functions to demonstrate usage.

An introduction to the data types available and how they are represented within LabVIEW.

Finally, the creation of SubVIs and their usage.

This introductory chapter has been produced with a great deal of detail, future will become much more succinct.

Page 25: Labview _8 _Teaching _Manual _2007

© 2006 David D. Hodgkiss & Staffordshire University 25

Tutorial Work - Chapter 1The following exercises have been produced to help you familiarise yourselves with LabVIEW 7 Express,whilst building the application VIs you should also take time to explore LabVIEW, its extensive help system(both locally and within the National Instruments Web Site (www.ni.com).

As with any programming language, the more you practice (and “play”) the more proficient you will be-come.

It is up to you how many of the tutorial exercises you attempt, model answers will be placed on my web siteduring the following week.

1 Produce a VI that will add two word integer numbers together and give a result. Use simple digitalcontrols and indicators.

2 Using Slides, Knobs or Dials and either a Gauge or Meter as an output, create a simple VI to calcu-late

(a + b) * c/d

Scale the input controls and output indicator so that all values of “a” and “b” (range 0..100) and“c”and “d” (range 0..10) are displayed.

3 As per these notes, create a VI that will calculate a slope value given two “x” inputs and two “y” in-puts together with an output indicator. The inputs and outputs should be using simple controls andindicators.

4 Convert the VI created in Ex1.3 into a SubVI, create a suitable icon and document what the SubVIdoes, you will need to discover what facilities LabVIEW offers for program documentation.

5 Create a new VI that two separate slopes can be calculated using the SubVI created in Ex1.4.