LabVIEW Graphical Programming Cookbook 69 recipes to help you build, debug, and deploy modular applications using LabVIEW Yik Yang BIRMINGHAM - MUMBAI LabVIEW Graphical Programming Cookbook Copyright © 2014 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing and its dealers and distributors, will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: January 2014 Production Reference: 1160114 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78217-140-9 www.packtpub.com Cover Image by Zarko Piljak ([email protected]) Credits Author Copy Editors Yik Yang Sayanee Mukherjee Lavina Pereira Reviewers Amit Dongol Project Coordinator Chris Larson Venitha Cutinho Qizhen Ruan Proofreader Justin Smith Amy Johnson Acquisition Editor Indexer Rubal Kaur Mehreen Deshmukh Lead Technical Editors Production Coordinator Madhuja Chaudhari Conidon Miranda Mandar Ghate Cover Work Technical Editors Conidon Miranda Tanvi Bhatt Dipika Gaonkar Monica John Neha Mankare About the Author Yik Yang is a test engineer living in Chicago who has specialized in automation and data analysis. Having worked in multiple fields such as semiconductor, automotive, and power, he has experience with different types of automation and understands what are the industries' needs. He started his career after receiving his Bachelor's and Master's degrees in Electrical Engineering at Virginia Tech. In his career, he worked on automation projects that used CompactDAQ, PXI, FPGA, and so on in LabVIEW. He has also spent a lot of time with Lean Six Sigma and statistical analysis with JMP. He is a certified Professional Engineer (PE) in North Carolina and a Certified LabVIEW Developer (CLD). I would like to thank my wife Qian and my son Elijah. They have given me a tremendous amount of love and support in the process of finishing this book. Most importantly, I would like to thank God, as without him I would not be alive and capable of writing this book after my terrifying bicycle accident, when I was directly hit by a truck. About the Reviewers Amit Dongol is a Ph.D candidate (Physics). He is working on setting up a research lab with LabVIEW interface for data acquisition. Chris Larson has been using LabVIEW for nine years. Currently he is working as a researcher and developer of cloud-based functionality for LabVIEW. He is an expert at developing systems that take advantage of the connected world and Internet. Chris learned LabVIEW while working at 3M's SEMS Research and Development lab. While at 3M, he created numerous LabVIEW-based systems to develop and manufacture products for 3M's divisions including safety and security, display and graphics, and health care. His contributions include antenna designs for RFID file tracking, improved manufacturing of retro-reflective materials, improved quality control for display brightening films, and improved high-speed manufacturing of specialty medical tapes. Qizhen Ruan is a software engineer. He has over 13 years of experience in LabVIEW development. He has designed and developed many LabVIEW features. Justin Smith has a degree in Computer Science from Tennessee Technological University, and is currently a Systems and Solutions Integrator for an industrial IT firm in Nashville, Tennessee. He develops core software for interfacing with third-party hardware and software and has recently introduced this software as modules in LabVIEW. Primarily a Java developer, Justin has been using open source tools to allow the code to be run from within LabVIEW. Having grown up around computers in the '80s, Justin had always known that he wanted to pursue a career in computing. After working as an intern in college and spending over a year in Central Mexico for his company, he realized all the good that can be done by helping to improve industrial processes (safety, quality, efficiency). This made him decide that he wanted to continue working in a industrial IT and automation. He also felt that the manufacturing industry has yet to see the same technological revolutions as other business sectors through the advances of companies such as Facebook and Google. Justin has been working for Summit Management Systems, Inc of Nashville Tennessee for nearly 10 years. Celebrating its 20th anniversary in business, Summit Management Systems offers custom integration and process solutions worldwide for the industrial and manufacturing sector as well as several stand-alone software packages that aid in data acquisition from industrial devices and software for manufacturing workflow management systems. I would like to thank my father for all the opportunities that he has given me to make me who I am. From allowing me to grow up around computers to encouraging me to enter the software development field, he is the reason I was able to work on this book and review it. Thanks Dad. www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why Subscribe? f Fully searchable across every book published by Packt f Copy and paste, print and bookmark content f On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Understanding the LabVIEW Environment 5 Introduction 5 Configuring essentials 6 Configuring quick drop 9 Using debug tools 10 Creating custom probe 12 Compiling EXE 14 Debugging EXE 16 Compiling a standalone application 19 Chapter 2: Customizing the User Interface 21 Introduction 21 Customizing controls 22 Adding a menu for runtime 27 Creating a dialog 30 Sizing the dialog automatically 33 Using 2D picture control 38 Updating controls with an action engine 40 Creating a simple animation 44 Creating subpanels 45 Chapter 3: Working with Common Architectures 49 Introduction 49 Working with a case structure 50 Working with an event structure 52 Working with loops 57 Using the state machine architecture 59 Using the master slave architecture 64