Book Image

Data Acquisition using LabVIEW

By : Behzad Ehsani
Book Image

Data Acquisition using LabVIEW

By: Behzad Ehsani

Overview of this book

NI LabVIEW's intuitive graphical interface eliminates the steep learning curve associated with text-based languages such as C or C++. LabVIEW is a proven and powerful integrated development environment to interact with measurement and control hardware, analyze data, publish results, and distribute systems. This hands-on tutorial guide helps you harness the power of LabVIEW for data acquisition. This book begins with a quick introduction to LabVIEW, running through the fundamentals of communication and data collection. Then get to grips with the auto-code generation feature of LabVIEW using its GUI interface. You will learn how to use NI-DAQmax Data acquisition VIs, showing how LabVIEW can be used to appropriate a true physical phenomenon (such as temperature, light, and so on) and convert it to an appropriate data type that can be manipulated and analyzed with a computer. You will also learn how to create Distribution Kit for LabVIEW, acquainting yourself with various debugging techniques offered by LabVIEW to help you in situations where bugs are not letting you run your programs as intended. By the end of the book, you will have a clear idea how to build your own data acquisition system independently and much more.
Table of Contents (18 chapters)
Data Acquisition Using LabVIEW
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
9
Alternate Software for DAQ

Example 1 - counter with a gauge


This is a fairly simple program with simple user interaction. Once the program has been launched, it uses a while loop to wait for the user input. This is a typical behavior of almost any user-friendly program. For example, if the user launches Microsoft Office, the program launches and waits for the user to pick a menu item, click on a button, or perform any other action that the program may provide. Similarly, this program starts execution but waits in a loop for the user to choose a command. In this case only a simple Start or Stop is available. If the Start button is clicked, the program uses a for loop function to simply count from 0 to 10 in intervals of 200 milliseconds. After each count is completed, the gauge on the Front Panel, the GUI part of the program, is updated to show the current count. The counter is then set to the zero location of the gauge and the program awaits subsequent user input. If the Start button is clicked again, this action is repeated, and, obviously, if the Stop button is clicked, the program exits. Although very simple, in this example, you can find many of the concepts that are often used in a much more elaborate program. Let's walk through the code and point out some of these concepts.

The following steps not only walk the reader through the example code but are also a brief tutorial on how to use LabVIEW, how to utilize each working window, and how to wire objects.

Launch LabVIEW and from the File menu, choose New VI and follow the steps:

  1. Right-click on the Block Diagram window.

  2. From Programming Functions, choose Structures and select While Loop.

  3. Click (and hold) and drag the cursor to create a (resizable) rectangle.

  4. On the bottom-left corner, right-click on the wire to the stop loop and choose Create a control. Note that a Stop button appears on both the Block Diagram and Front panel windows.

  5. Inside the while loop box, right-click on the Block Diagram window and from Programming Function, choose Structures and select Case Structures. Click and (and hold) and drag the cursor to create a (resizable) rectangle.

  6. On the Front Panel window, next to the Stop button created, right-click and from Modern Controls, choose Boolean and select an OK button. Double-click on the text label of the OK button and replace the OK button text with Start. Note that an OK button is also created on the Block Diagram window and the text label on that button also changed when you changed the text label on the Front Panel window.

  7. On the Front Panel window, drag-and-drop the newly created Start button next to the tiny green question mark on the left-hand side of the Case Structure box, outside of the case structure but inside the while loop. Wire the Start button to the Case Structure.

  8. Inside the Case Structure box, right-click on the Block Diagram window and from Programming Function, choose Structures and select For Loop. Click and (and hold) and drag the cursor to create a (resizable) rectangle.

  9. Inside the Case Structure box, right-click on N on the top-left side of the Case Structure and choose Create Constant. An integer blue box with a value of 0 will be connected to the For Loop. This is the number of irritations the for loop is going to have. Change 0 to 11.

  10. Inside the For Loop box, right click on the Block Diagram widow and from Programming Function, choose Timing and select Wait(ms).

  11. Right-click on the Wait function created in step 10 and connect a integer value of 200 similar to step 9.

  12. On the Front Panel window, right-click and from Modern functions, choose Gauge. Note that a Gauge function will appear on the Block Diagram window too. If the function is not inside the For Loop, drag and drop it inside the For Loop.

  13. Inside the For loop, on the Block Diagram widow, connect the iteration count i to the Gauge.

  14. On the Block Diagram, right-click on the Gauge, and under the Create submenu, choose Local variable.

  15. If it is not already inside the while loop, drag and drop it inside the while loop but outside of the case structure.

  16. Right-click on the local variable created in step 15 and connect a Zero to the input of the local variable.

  17. Click on the Clean Up icon on the main menu bar on the Block Diagram window and drag and move items on the Front Panel window so that both windows look similar to the following screenshots: