+ All Categories
Home > Documents > Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the...

Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the...

Date post: 24-Mar-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
17
Fundamentals c01.qxd p001-017 10/18/01 11:03 AM Page 1
Transcript
Page 1: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

Fundamentals

c01.qxd p001-017 10/18/01 11:03 AM Page 1

Prentice Hall PTR
This is a sample chapter of LabVIEW for Everyone, Second Edition ISBN: 0-13-065096-X For the full text, visit http://www.phptr.com ©2002 Pearson Education. All Rights Reserved.
Page 2: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

OVERVIEW

Welcome to the world of LabVIEW! This chapter gives you a basic explanation ofLabVIEW and its capabilities and shows how it can make your life easier.

GOALSDevelop an idea of what LabVIEW really isLearn what graphical programming language and dataflow programming meanPeruse the introductory examplesGet a feel for the LabVIEW environment

KEY TERMSLabVIEW IconVirtual instrument (VI) ConnectorDataflow ToolbarGraphical language PaletteFront panel HierarchyBlock diagram

c01.qxd p001-017 10/18/01 11:03 AM Page 2

Page 3: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

1.1 What Exactly Is LabVIEW, and What Can It Do for Me?You’d probably like to know what exactly LabVIEW is before you go muchfurther. What can you do with it and what can it do for you? LabVIEW,short for Laboratory Virtual Instrument Engineering Workbench, is a program-ming environment in which you create programs with graphics; in this re-gard it differs from traditional programming languages like C, C++, or Java,in which you program with text. However, LabVIEW is much more than alanguage. It is a program development and execution system designed forpeople, such as scientists and engineers, who need to program as part oftheir jobs. LabVIEW works on PCs running Windows, MacOS, Linux, So-laris, and HP-UX.

Providing you with a very powerful graphical programming language,LabVIEW can increase your productivity by orders of magnitude. Programsthat take weeks or months to write using conventional programming lan-guages can be completed in hours using LabVIEW, because it is specificallydesigned to take measurements, analyze data, and present results to theuser. And because LabVIEW has such a versatile graphical user interfaceand is so easy to program with, it is also ideal for simulations, presentation

What in the WorldIs LabVIEW?

1

3

c01.qxd p001-017 10/18/01 11:03 AM Page 3

Page 4: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

of ideas, general programming, or even teaching basic programming concepts.

LabVIEW offers more flexibility than standard laboratory instruments be-cause it is software-based. You, not the instrument manufacturer, define in-strument functionality. Your computer, plug-in hardware, and LabVIEWcomprise a completely configurable virtual instrument to accomplish yourtasks. Using LabVIEW, you can create exactly the type of virtual instrumentyou need, when you need it, at a fraction of the cost of traditional instru-ments. When your needs change, you can modify your virtual instrument inmoments.

4 LabVIEW for Everyone

Figure 1.1The Space Industries Sheet Float Zone Furnace is used for high-temperature superconduc-tor materials processing research in a microgravity environment aboard the NASA KC-135 parabolic aircraft. LabVIEW controls the industrialized Macintosh-based system.

c01.qxd p001-017 10/31/01 2:54 PM Page 4

Page 5: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

LabVIEW tries to make your life as hassle-free as possible. It has extensivelibraries of functions and subroutines to help you with most programmingtasks, without the fuss of pointers, memory allocation, and other arcane pro-gramming problems found in conventional programming languages. Lab-VIEW also contains application-specific libraries of code for data acquisition(DAQ), General Purpose Interface Bus (GPIB), and serial instrument control,data analysis, data presentation, data storage, and communication over theInternet. The Analysis library contains a multitude of useful functions, in-cluding signal generation, signal processing, filters, windows, statistics, re-gression, linear algebra, and array arithmetic.

Because of LabVIEW’s graphical nature, it is inherently a data presenta-tion package. Output appears in any form you desire. Charts, graphs, anduser-defined graphics comprise just a fraction of available output options.This book will show you how to present data in all of these forms.

LabVIEW’s programs are portable across platforms, so you can write aprogram on a Macintosh and then load and run it on a Windows machinewithout changing a thing in most applications. You will find LabVIEW ap-plications improving operations in any number of industries, from everykind of engineering and process control to biology, farming, psychology,chemistry, physics, teaching, and many others.

1.1.1 Dataflow and the Graphical Programming Language

The LabVIEW program development environment is different from com-mercial C or Java development systems in one important respect. Whereasother programming systems use text-based languages to create lines of code,LabVIEW uses a graphical programming language to create programs in apictorial form called a block diagram, eliminating a lot of the syntactical de-tails. With this method, you can concentrate on the flow of data within yourapplication; the simpler syntax doesn’t obscure what the program is doing.Figures 1.2 and 1.3 show a simple LabVIEW user interface and the code be-hind it.

LabVIEW uses terminology, icons, and ideas familiar to scientists and en-gineers. It relies on graphical symbols rather than textual language to de-scribe programming actions. The principle of dataflow, in which functionsexecute only after receiving the necessary data, governs execution in astraightforward manner. You can learn LabVIEW even if you have little or

Chapter 1 • What in the World Is LabVIEW? 5

c01.qxd p001-017 10/18/01 11:03 AM Page 5

Page 6: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

6 LabVIEW for Everyone

no programming experience, but you will find knowledge of programmingfundamentals very helpful.

1.1.2 How Does LabVIEW Work?

LabVIEW programs are called virtual instruments (VIs) because their appear-ance and operation imitate actual instruments. However, behind the scenesthey are analogous to main programs, functions, and subroutines from pop-ular programming languages like C or Basic. Hereafter, we will refer to aLabVIEW program as a “VI” (pronounced “vee eye,” not the Roman nu-meral six as we’ve heard some people say). Also, be aware that a LabVIEWprogram is always called a VI, whether its appearance or function relates toan actual instrument or not.

A VI has three main parts:

• The front panel is the interactive user interface of a VI, so named becauseit simulates the front panel of a physical instrument. The front panelcan contain knobs, push buttons, graphs, and many other controls(which are user inputs) and indicators (which are program outputs). Auser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen.

• The block diagram is the VI’s source code, constructed in LabVIEW’sgraphical programming language, G. The block diagram is the actualexecutable program. The components of a block diagram are lower-level VIs, built-in functions, constants, and program execution control

Figure 1.3Graphical code.

Figure 1.2User interface.

c01.qxd p001-017 10/18/01 11:03 AM Page 6

Page 7: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

structures. You draw wires to connect the appropriate objects togetherto indicate the flow of data between them. Front panel objects have cor-responding terminals on the block diagram so that data can pass fromthe user to the program and back to the user.

• In order to use a VI as a subroutine in the block diagram of another VI,it must have an icon and a connector. A VI that is used within another VIis called a subVI and is analogous to a subroutine. The icon is a VI’s pic-torial representation and is used as an object in the block diagram of an-other VI. A VI’s connector is the mechanism used to wire data into theVI from other block diagrams when the VI is used as a subVI. Muchlike parameters of a subroutine, the connector defines the inputs andoutputs of the VI.

Virtual instruments are hierarchical and modular. You can use them as top-level programs or subprograms. With this architecture, LabVIEW promotesthe concept of modular programming. First, you divide an application into aseries of simple subtasks. Next, you build a VI to accomplish each subtaskand then combine those VIs on a top-level block diagram to complete thelarger task.

Chapter 1 • What in the World Is LabVIEW? 7

Figure 1.4

c01.qxd p001-017 10/18/01 11:03 AM Page 7

Page 8: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

Modular programming is a plus because you can execute each subVI byitself, which facilitates debugging. Furthermore, many low-level subVIsoften perform tasks common to several applications and can be used inde-pendently by each individual application.

Just so you can keep things straight, we’ve listed a few common LabVIEWterms with their conventional programming equivalents in Table 1.1.

1.2 Demonstration ExamplesOkay, you have enough reading for now. To get an idea of how LabVIEWworks, you can open and run a few existing LabVIEW programs.

8 LabVIEW for Everyone

Icon Connector

Figure 1.6

Figure 1.5

c01.qxd p001-017 10/18/01 11:03 AM Page 8

Page 9: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

Whether you are using the full or evaluation version of LabVIEW, justlaunch it. Make sure you can access the Everyone directory from the CD oryour hard drive, as described in the Preface; it contains the activities for thisbook. After launching LabVIEW, a dialog box will appear. To open an exam-ple, select Open VI and choose the one you want.

Throughout this book, use the left mouse button (if you have more than one) unless wespecifically tell you to use the right one. On MacOS computers, <command>-click whenright-mouse functionality is necessary. In most LabVIEW situations, the <control> key onWindows will correspond to <command> on Macs, <meta> on Suns, and <alt> onLinus and HP machines.

1.2.1 Activity 1-1: Temperature System Demo

Open and run the VI called Temperature System Demo.vi by followingthese steps:

1. Launch LabVIEW if you haven’t already. 2. Select Open from the File menu, or click the Open VI button if you

have the LabVIEW start-up dialog box.3. Next, open the Everyone directory or folder by double-clicking on it.

Then select the libary CH1.LLB (Note: A library in LabVIEW, noted

Chapter 1 • What in the World Is LabVIEW? 9

LabVIEW Conventional Language

VI program

function function or method

subVI subroutine, subprogram, object

front panel user interface

block diagram program code

“G” or LabVIEW C, C++, Java, Pascal, BASIC, etc.

Table 1.1 LabVIEW Terms and Their Conventional Equivalents.

c01.qxd p001-017 10/18/01 11:03 AM Page 9

Page 10: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

with the .llb extension, is a virtual directory of VI files. You can onlysee what’s inside a library from LabVIEW—to the operating system,it looks like a single file). Finally, open Temperature SystemDemo.vi. (If you have the full version of LabVIEW, you can also findthis example under examples/apps/tempsys.llb). After a few mo-ments, the Temperature System Demo front panel window appears,as shown in Figure 1.7. The front panel contains numeric controls,Boolean switches, slide controls, knob controls, charts, graphs, and athermometer indicator.

4. Run the VI by clicking on the Run button. The button changes ap-pearance to indicate that the VI is running. The Toolbar, which is therow of icons on the top bar of the screen, also changes, since editingfunctionality won’t be necessary while the VI is running.Notice also that the Abort button becomes active in the Toolbar. Youcan press it to abort program execution.

10 LabVIEW for Everyone

Figure 1.7Temperature System Demo test front panel window.

Run button

Run button(active)

Abort button

c01.qxd p001-017 10/18/01 11:03 AM Page 10

Page 11: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

Temperature System Demo.vi simulates a temperature monitoringapplication. The VI makes temperature measurements and displaysthem in the thermometer indicator and on the chart. Although thereadings are simulated in this example, you can easily modify theprogram to measure real values. The Update Period slide controlshow fast the VI acquires the new temperature readings. LabVIEWalso plots high and low temperature limits on the chart; you canchange these limits using the Temperature Range knobs. If the cur-rent temperature reading is out of the set range, LEDs light up nextto the thermometer.This VI continues to run until you click the Acquisition switch to off.You can also turn the data analysis on and off. The Statistics sectionshows you a running calculation of the mean and standard devia-tion, and the Histogram plots the frequency with which each tem-perature value occurs.

Tweaking Values5. Use the cursor, which takes on the personality of the Operating tool

while the VI is running, to change the values of the high and low lim-its. Highlight the old high or low value, either by clicking twice onthe value you want to change, or by clicking and dragging across thevalue with the Operating tool. Then type in the new value and clickon the enter button, located next to the run button on the Toolbar.

6. Change the Update Period slide control by placing the Operat-ing tool on the slider, and then clicking and dragging it to a newlocation.You can also operate slide controls using the Operating tool by click-ing on a point on the slide to snap the slider to that location, by click-ing on a scroll button to move the slider slowly toward the arrow, orby clicking in the slide’s digital display and entering a number.

Even though the display changes, LabVIEW does not accept the new values in digitaldisplays until you press the enter button, or click the mouse in an open area of the window.

Chapter 1 • What in the World Is LabVIEW? 11

Operating tool

Enter button

c01.qxd p001-017 10/18/01 11:03 AM Page 11

Page 12: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

7. Try adjusting the other controls in a similar manner.8. Stop the VI by clicking on the Acquisition switch.

Examine the Block DiagramThe block diagram shown in Figure 1.8 represents a complete LabVIEW ap-plication. You don’t need to understand all of these block diagram elementsright now—we’ll deal with them later. Just get a feel for the nature of a blockdiagram. If you already do understand this diagram, you’ll probably flythrough the first part of this book!

9. Open the block diagram of Temperature System Demo.vi by choos-ing Show Diagram from the Windows menu.

10. Examine the different objects in the diagram window. Don’t panic atthe detail shown here! These structures are explained step by steplater in this book.

11. Open the contextual Help window by choosing Show Context Helpfrom the Help menu. Position the cursor over different objects in theblock diagram and watch the Help window change to show descrip-tions of the objects. If the object is a function or subVI, the Help win-dow will describe the inputs and outputs as well.

12 LabVIEW for Everyone

Figure 1.8

c01.qxd p001-017 10/18/01 11:03 AM Page 12

Page 13: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

HierarchyLabVIEW’s power lies in the hierarchical nature of its VIs. After you create aVI, you can use it as a subVI in the block diagram of a higher-level VI, andyou can have as many layers of hierarchy as you need. To demonstrate thisversatile ability, look at a subVI of Temperature System Demo.vi.12. Open the Temperature Status subVI by double-clicking on its icon.

The front panel shown in Figure 1.9 springs to life.

Icon and ConnectorThe icon and connector provide the graphical representation and parameterdefinitions needed if you want to use a VI as a subroutine or function in theblock diagrams of other VIs. They reside in the upper-right corner of the VI’sfront panel window. The icon graphically represents the VI in the block dia-gram of other VIs, while the connector terminals are where you must wirethe inputs and outputs. These terminals are analogous to parameters of asubroutine or function. You need one terminal for each front panel controland indicator through which you want to pass data to the VI. The icon sitson top of the connector pattern until you choose to view the connector.

Chapter 1 • What in the World Is LabVIEW? 13

Figure 1.9

Temperature Status Icon Connector

Figure 1.10

c01.qxd p001-017 10/18/01 11:03 AM Page 13

Page 14: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

By using subVIs, you can make your block diagrams modular and moremanageable. This modularity makes VIs easy to maintain, understand, anddebug. In addition, you can often create one subVI to accomplish a functionrequired by many different VIs.

Now run the top-level VI with both its window and the Temperature Sta-tus subVI window visible. Notice how the subVI values change as the mainprogram calls it over and over.

13. Select Close from the File menu of the Temperature Status subVI.Do not save any changes.

14. Select Close from the File menu of Temperature System Demo.vi,and do not save any changes.

Selecting Close from the File menu of a VI diagram closes the block diagram windowonly. Selecting Close on a front panel window closes both the panel and the diagram.

1.2.2 Activity 1-2: Frequency Response Example

This example measures the frequency response of an unknown “black box.”A function generator supplies a sinusoidal input to the black box. (Hint: Itcontains a bandpass filter, which lets only certain signal componentsthrough it.) A digital multimeter measures the output voltage of the blackbox. Although this VI uses subVIs to simulate a function generator and adigital multimeter, real instruments could easily be hooked up to a realblack box to provide real-world data. You would then use subVIs to controldata acquisition, GPIB transfers, or serial port communication to bring in orsend out real data instead of simulating it.

You will open, run, and observe the VI in this activity.

1. Select Open from the File menu to open the VI, or click the Open VIbutton if you have the LabVIEW dialog box.

2. Select the EVERYONE directory and then CH1.LLB. Finally, double-click on Frequency Response.vi. (If you have the full version of Lab-

14 LabVIEW for Everyone

c01.qxd p001-017 10/18/01 11:03 AM Page 14

Page 15: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

VIEW, you can also find this example under examples/apps/freqresp.llb.) The front panel shown in Figure 1.11 should appear.

3. Run the VI by clicking on the Run button. You can specify the ampli-tude of the input sine wave and the number of steps the VI uses tofind the frequency response by changing the Amplitude control andthe Number of Steps control, and then run the VI again. You canalso specify the frequency sweep by inputting the upper and lowerlimits with the Low Frequency and High Frequency knobs. Playwith these controls and observe the effect they have on the output ofthe “black box.”

4. Open and examine the block diagram by choosing Show Diagramfrom the Window menu.

5. Close the VI by selecting Close from the File menu. These exercisesshould give you a basic feel for LabVIEW’s programming environ-ment. With LabVIEW, you’ll find writing powerful applications (anddebugging them) to be a snap! Read on to learn how!

Chapter 1 • What in the World Is LabVIEW? 15

Figure 1.11

Run button

c01.qxd p001-017 10/18/01 11:03 AM Page 15

Page 16: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

1.3 Wrap It Up!LabVIEW is a powerful and flexible instrumentation and analysis softwaresystem. It uses a graphical programming language, to create programscalled virtual instruments, or VIs. The user interacts with the programthrough the front panel. Each front panel has an accompanying block diagram,which is the VI’s source code. LabVIEW has many built-in functions to facili-tate the programming process; components are wired together to show theflow of data within the block diagram. Stay tuned—the next chapters willteach you how to effectively use LabVIEW’s many features.

You will find the solutions to every activity in the upcoming chapters in the EVERYONEdirectory on the CD that accompanies the book. We’ll trust you not to cheat!

1.4 Additional ActivitiesActivity 1-3: More Neat ExamplesIn this activity, you will look at some example programs that ship with Lab-VIEW.

1. From the Help menu, choose Examples.2. This will bring up the LabVIEW Help system, opened at the Exam-

ples section. Clicking on a link to a specific example will bring up thespecific VI in LabVIEW.

3. Run the example by clicking on the Run button.4. After you run an example, choose Show Diagram from the Window

menu to see what the program looks like.5. Now look through and run other VIs in the examples to try to get an

idea of the LabVIEW environment and what you can do with it. Al-though all of the examples are extremely educational, you should in-vestigate a few particularly interesting directories: Demonstrations,Measurement Examples, and I/O Interfaces. Feel free to browsethrough any VIs that strike your fancy; you can learn a lot just by

16 LabVIEW for Everyone

Run button

c01.qxd p001-017 10/18/01 11:03 AM Page 16

Page 17: Fundamentals - Pearson Educationuser will input data using a mouse and keyboard and then view the re-sults produced by the program on the screen. • The . block diagram. is the VI’s

watching how they work. Also feel free to modify and use these ex-amples for your own applications (just be sure to save them to a dif-ferent location so you don’t overwrite the built-in examples).

6. When you’re done, select Close from the File menu to close each VI.Do not save any changes you may have made.

Chapter 1 • What in the World Is LabVIEW? 17

c01.qxd p001-017 10/18/01 11:03 AM Page 17


Recommended