Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Data Acquisition Using LabVIEW

You're reading from  Data Acquisition Using LabVIEW

Product type Book
Published in Dec 2016
Publisher Packt
ISBN-13 9781782172161
Pages 150 pages
Edition 1st Edition
Languages
Author (1):
Yik Yang Yik Yang
Profile icon Yik Yang

Table of Contents (18) Chapters

Data Acquisition Using LabVIEW
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
1. LabVIEW Basics 2. Most Common Communication Buses 3. Using the DAQ Assistant to Automatically Generate LabVIEW Code 4. DAQ Programming Using LabVIEW 5. Debugging Techniques 6. Real-World DAQ Programming Techniques 7. Real-Time Issues 8. DAQ at a Distance - Network and Distributed Systems 9. Alternate Software for DAQ 10. Non-National Instrument Devices DAQ 11. LabVIEW and Simple Microcontrollers

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:

You have been reading a chapter from
Data Acquisition Using LabVIEW
Published in: Dec 2016 Publisher: Packt ISBN-13: 9781782172161
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}