Home

LabVIEW™ Basics II Course Manual

image

Contents

1. LabVIEW Basics II Course Manual 2 26 ni com Lesson 2 Designing Front Panels Common Properties Visible Property EH Disabled Property There are many properties available for the various front panel objects in LabVIEW This section describes the Visible Disable Key Focus Blink Position Bounds and Value properties which are common to all front panel objects It also introduces some Property Nodes for specific kinds of controls and indicators The Visible property shown at left sets or reads the visibility of a front panel object The associated object is visible when TRUE hidden when FALSE Wiring Example Set the digital control to an invisible state A Boolean TRUE value makes the control visible as shown Block Diagram Front Panel Visible TRUE digital control Er digital control Crea MO 000 Visible FALSE digital control enr The Disabled property shown at left sets or reads the user access status Dissbled ofan object A value of 0 enables an object so that the user can operate it A value of 1 disables the object preventing operation A value of 2 disables and greys out the object Wiring Example Disable user access to the digital control The control does not change appearance when disabled digital contra CU 1 Disabled National Instruments Corporation 2 27 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Wiring Example Disable
2. LabVIEW Basics Il Course Manual Course Software Version 6 0 September 2000 Edition Part Number 320629G 01 Copyright Copyright 1993 2000 by National Instruments Corporation 11500 North Mopac Expressway Austin Texas 78759 3504 Under the copyright laws this publication may not be reproduced or transmitted in any form electronic or mechanical including photocopying recording storing in an information retrieval system or translating in whole or in part without the prior written consent of National Instruments Corporation Trademarks LabVIEW National Instruments and ni com are trademarks of National Instruments Corporation Product and company names mentioned herein are trademarks or trade names of their respective companies Worldwide Technical Support and Product Information ni com National Instruments Corporate Headquarters 11500 North Mopac Expressway Austin Texas 78759 3504 USA Tel 512 794 0100 Worldwide Offices Australia 03 9879 5166 Austria 0662 45 79 90 0 Belgium 02 757 00 20 Brazil 011 284 5011 Canada Calgary 403 274 9391 Canada Ontario 905 785 0085 Canada Qu bec 514 694 8521 China 0755 3904939 Denmark 45 76 26 00 Finland 09 725 725 11 France 01 48 14 24 24 Greece 30 1 42 96 427 Germany 089 741 31 30 Hong Kong 2645 3186 India 91805275406 Israel 03 6120092 Italy 02 413091 Japan 03 5472 2970 Korea 02 596 7456 Mexico D F 5 280 7625 Mexico Monterrey 8 357 7695 Netherla
3. Source Files Vl Settings Application Settings Installer Settings M Create installer Installation name Myapplication Installer directory CAmpapp installer OO Start menu program group Myapplication Default installation directory c Pragram Files Myapplication Installation language Engish H Media size 14MB H Estra space on first disk KE 0 Advanced Load Lave Lave As Mew Help Build Done 13 Click the Build button The files associated with the installer are then compressed into setup diskettes which are stored in the C myapp installer disks directory A Setup exe file is created as well which can be used to install the diskette images All of these files could be copied to diskettes to transfer the application to another system The LabVIEW Run Time DLL installer is included by default The executable for your application is also built and is called myApplication exe as defined on the Target tab 14 Select Done from the Build Application window to close that utility It asks you to save a script so you can build this application again Select Yes and name the script myapp b1d Now if you make changes to the original application and want to rebuild an executable and installer with the same settings you can open this script file using the Load button 15 Run myApplication exe from the C myapp directory Application Exercise should open its front panel and run automati
4. 1 is executed which does nothing Clicking the Configure button executes Case 0 which could for example call the Configure subVI Clicking the Test 1 button executes Case 1 which could call the Test 1 subVI and clicking the Test 2 button executes Case 2 The While Loop repeatedly checks the state of the Boolean cluster control until you click the Stop button The VI block diagram is as follows LabVIEW Basics II Course Manual 2 14 ni com Lesson 2 Designing Front Panels aa i Ci efault an Empty Search 10 Array returns 1 if no buttons are pressed ae Call Test 1 sub Call Test 2 sub Seach ice A E Search iDAray amp Search 1D Array 2 E returns if 4 ke returns 2 if Test 1 button is 3 E Test 2 button is pressed pressed returns if Configure button i pressed Cluster Conversion You can convert a cluster to an array if all cluster components have the same data type for example all are Boolean data types or all are numeric With this conversion you can use array functions to process components within the cluster The Cluster to Array function Functions Cluster and Functions Array palettes converts a cluster of identically typed components to a 1D array of the same data type cluster The following example shows a four component Boolean cluster converted to a four element Boolean array The index of each element in the array corresponds to the logical order of the component in the clust
5. Application SL Distribution i Custom Save Foca ts i Save for 5 0 Previous iv Template Save Options for Parallel Loops Arch vit Selected Options This option allows you to save VI architectures and other programming structures you use often for your own templates Now you will examine a couple of the template VIs National Instruments Corporation 1 21 LabVIEW Basics II Course Manual Lesson 1 Planning LabVIEW Applications Exercise 1 3 Timed While Loop with Stop VIT State Machine VIT Objective To examine two of the template Vis that ship with LabVIEW You will examine template VIs that show both the State Machine architecture and the General architecture Front Panel 1 Open the Timed While Loop with Stop vit from the LabVIEW 6 Templates directory The front panel only contains the Stop button Block Diagram 2 Open and examine the block diagram 3 You will recognize this VI as having the General VI architecture It contains a While Loop that stops when you click the button on the front panel and a wait function in the loop ensures that this loop will not use all the system resources 4 Return to the front panel and run the VI It does nothing but continues to run until you click the Stop button Stop and close this VI when you are finished Open the State Machine vit from the LabVIEW 6 Templates directory The front panel is empty LabVIEW Basics II Course Manual 1 22 ni com Les
6. Globals Outside of Loop wi La Initialize Array with Replace Element i Convert Dirs to LLB uz Initialize Array wi La Pop up 2nd Process v1 Check Filenames La Power ctl uz Process Monitor wi Ci Li Read Voltage i se Show dates slows down directory listings Ww Disable files with identical dates Sork newest to oldest Utilities to Compare VIs and Compare VI Hierarchies are also included As described earlier they are used to determine the differences between two VIs or hierarchies The LabVIEW Help and manuals for this toolkit not only provide reference material for the previous utilities but also extensive discussions on management of software projects Various development models prototyping and design techniques and project tracking methods are described in detail Documentation of VIs and tips for developing clear code are described in detail as well LabVIEW Application Builder You can use the LabVIEW Application Builder to create stand alone executable programs for users without the LabVIEW development software The executable VI or shared libraries can include a hierarchy of VIs that you have created or the VI can be configured to open and run any VI available to the user LabVIEW Basics II Course Manual 5 22 ni com Lesson 5 Developing Larger Projects in LabVIEW Required System Configuration Applications or shared libraries that you create with the Application B
7. In this exercise create this VI 1 Create a VI that sorts a 1D array This VI should also include an option to sort in ascending or descending order and pass out an error Boolean object The following example is a suggested front panel You need to create the front panel and block diagram and test the code you write Un orted Array Sorted Array sn 01 00 Min 0 00 3 00 0 00 2 00 0 00 Ao 0 00 Mi Error Ascending 9 2 Create an icon connector pane using the following configuration Unsorted Array Sorted Array Kp Note Use the same icon connector pane for the Sort 2D Array instance Otherwise the polymorphic VI produces broken wires LabVIEW Basics II Course Manual A 4 ni com 3 Appendix Save your work as Sort 1D Array vi 4 The Sort 2D Array function is already built for you However you need to complete the icon connector pane This example was downloaded from ni com support in the Example Programs Database Open this file from exercises LV Basics2 Sort 2D Array vi Create and wire the icon connector pane for the Sort 2D Array VI Even though the icon connector pane is already built you might want to modify it to help differentiate it from the Example program You do not need to wire all the controls and indicators on this front panel Recall the configuration used for the Sort 1D Array VI Unsorted Array Sorted Array 6 Save this new VI as Sort 2D Array vi Now create the polymorphic
8. LabVIEW Basics II Course Manual SG 6 Develop flowchart for Application Exervise VI Build User Interface Menu Build Acquire Data VI Build Analyze amp Present Data VI Build Disable Controls VI Build Login VI Build Save Data to File VI completes Analysis amp Present Data VI Study View Analysis File VI Assemble pieces to build Application Exercise VI and finish project ni com Student Guide F Course Conventions 5 nel bold italic monospace Platform right click The following conventions appear in this course manual The symbol leads you through nested menu items and dialog box options to a final action The sequence File Page Setup Options directs you to pull down the File menu select the Page Setup item and select Options from the last dialog box This icon denotes a note which alerts you to important information This icon indicates that an exercise requires a plug in DAQ device Bold text denotes items that you must select or click in the software such as menu items and dialog box options Bold text also denotes parameter names controls and buttons on the front panel dialog boxes sections of dialog boxes menu names and palette names Italic text denotes variables emphasis a cross reference or an introduction to akey concept This font also denotes text that is a placeholder for a word or value that you must supply Text in this font denotes text or characters that yo
9. The button should control the VI s execution that is terminate the While Loop Use a Dialog Ring to select the following options Enable and Show button Disable button Grey Out button and Hide button Use Property Nodes to implement the actions that the Dialog Ring specifies Test the different modes of operation for the button while trying to stop the VI Save the VI as Button Input vi when you are finished Open the Analyze amp Present Data VI you developed in Exercise 2 7 and modify the VI so that if the number of data points in the subset is one point or less the Log Results to File button is grayed out 2 65 LabVIEW Basics I Course Manual Lesson 2 Designing Front Panels Notes LabVIEW Basics II Course Manual 2 66 ni com Lesson 3 Data Management Techniques rer a A CE This lesson describes how you can organize the block diagrams of your VIs based upon how you transfer data from one place to another First you will be reminded of how LabVIEW runs a VI Then you will learn how to use local and global data to pass data within and between VIs and tips for using those data objects efficiently Last you will learn how to use DataSocket to pass data between VIs and computers You Will Learn About data management techniques in LabVIEW How to use Local Variables How to use Global Variables Some tips about using Locals and Globals eS SE oe How to use DataSocket National Instruments Corporation 3 1 LabVI
10. amount of information Binary files allow you to randomly access numeric data stored in the file However binary files are generally not portable to other applications Also you must carefully document the details needed to extract information stored in a binary file Creating Header Information for a Binary File When you create binary files designing an appropriate header for the file is often the single most important task You can create the header information by explicitly generating a header or by using the header input of the Write File function The following example shows how to explicitly generate a header that contains the number of rows and columns of data he file You also can generate the same file using the header input of the Write File function If you wire a Boolean value of TRUE to the header input of the Write File function it writes the same data to the file as if you had manually written a header The following example shows how to use the Write File function to create a binary file with a header header a Lise erie Simple Error Handler wi pew file National Instruments Corporation 4 5 LabVIEW Basics II Course Manual Lesson 4 Advanced File I O Techniques Using the previous block diagram example if you again wire a two dimensional array of single precision numbers with three rows and two columns the file would contain 24 bytes of data and two additional long integers four bytes each as header in
11. on disk If you know that a file stores single precision numbers which use four bytes per number you can read an arbitrary group of elements from the array as shown in the following example LabVIEW Basics II Course Manual 4 6 ni com Lesson 4 Advanced File I O Techniques SGL select mode 2 dFexisting file Index of 1st element to read pos offset 4 bytes SOL number Z gt of values to read calculate number of bytes from the beginning of the file to begin reading datal In the previous block diagram example the pos mode input of the Read File function is set to start which means that the function begins reading data at pos offset bytes from the beginning of the file The first byte in the file has an offset of zero So the location of the nt element in an array of single precision floating point numbers stored in this file is 4 x n bytes from the beginning of the file A single precision floating point constant wired to the byte stream type input tells the Read File function to read single precision floating point values from the file The values to read control connected to the count input of the Read File function tells the function how many single precision elements to read from the file Notice that when the count input is wired LabVIEW places the output data in an array because LabVIEW reads more than one value from the file The following points are important to remember about random access operations
12. the block diagram This function combines the error status Boolean and the Stop button on the front panel so that the loop stops if either of these values becomes True j Place the Simple Error Handler VI located on the Functions Time amp Dialog palette on the block diagram A dialog box in this VI appears if an error occurs and displays the error information 4 Save this VI as Generate amp Analyze Data vi into the c exercises LV Basics 2 directory 5 Observe how the subVIs you used in this block diagram use error handling Double click the Sine Waveform VI and open its block diagram Notice that the first thing it does is to check the error in cluster for previous errors If an error has occurred LabVIEW returns an empty waveform and passes out the error information If no error has occurred LabVIEW generates a sine waveform of the specified input parameters 6 Run the VI You can adjust the front panel controls to see the time and frequency waveforms change You can force an error by entering the wrong values into these controls For example a sampling frequency Fs too low or too high results in an error By turning the averaging mode on you can extract the sine wave peak from the noise regardless of their specified amplitudes Notice what affect the different averaging techniques have on the signal 7 Stop and close this VI when you are finished End of Exercise 1 1 National Instruments Corporation 1 9 LabVIEW Ba
13. 00 0 00 1 Open a new VI and build the front panel shown above The URL object is a string control To show the scale on the slide indicator right click the slide and select Scale Style Block Diagram 2 Open and build the block diagram shown above using the following components a While Loop available on the Functions Structures palette Structures the VI to continue running until you press the National Instruments Corporation 3 31 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques LabVIEW Basics II Course Manual Stop button Right click the Conditional terminal and select Stop If True b Wait Until Next ms Multiple function available on the Functions Time amp Dialog palette Causes the While Loop to execute once per second Create the constant by right clicking the input terminal and selecting Create Constant c Numeric Constant available on the Functions Numeric palette Creates the correct data type to read the value through DataSocket Make sure this constant is a DBL by right clicking it and selecting Representation Double Precision from the shortcut menu d DataSocket Read function available on the Functions Communication DataSocket palette Reads the random data value from the specified URL e Simple Error Handler VI available on the Functions Time amp Dialog palette Opens a dialog box if an error occurs and displays the error information Save thi
14. 1 0 Techniques A Working with Byte Stream Files ss 4 2 B LabVIEW Datalog Plessis Set ns Neue 4 13 Corean Data TOD koea ne li ec 4 20 Summary Tips and PACKS nn ANR Neue ES 4 21 Additional Exo OS ee a ie st 4 22 Lesson 5 Developing Larger Projects in LabVIEW A Assembling a LabVIEW Application 5 2 B LabVIEW Features for Project Development 5 13 C LabVIEW Tools for Project Mian a cement en re inerte 5 21 SUMMARY Fps AR A PCG SR A acid ia tree dede 5 35 AGNON EXCISE Soe sl liant tente 5 36 Lesson 6 Performance Issues A LabVIEW Multithreading and Multitasking Overview 6 2 Be Th Promle W widow San Ra En ane entente ii itneR 6 6 CS Pe edie UD POUR VIS de derniers conne one ae cote eco 6 12 D System M MOLVISSU S ee RE Cdi nee 6 25 Optimizing VI MEMOR USSR LS die ans 6 28 Summan Tips AR MOK S nn nana steel sl 6 46 Appendix Ar PO MOTS SNS dune den erntda ds tn are le le A 2 B Custom Graphics in Lab VIEW ns te a etes A 7 Ce The LabVIEW Web SCL Cl eue esse A 14 D Additonal Informations ESS Mat a nm dima a A 20 E ASCII Character Code Equivalents Fables aan raie A 22 LabVIEW Basics II Course Manual v ni com AS C 2 D E iy Student Guide M Thank you for purchasing the LabVIEW Basics II course kit You can begin developing an application soon after you complete the exercises in this manual This course manual and the accompanying software are used in the two day hands on LabVIEW Basics IT course You
15. A disadvantage to the State Machine VI architecture is that with the approach in the previous block diagram you can lose events If two events occur at the same time this model handles only the first one and the second one is lost This can lead to errors that are difficult to debug because they can occur only occasionally More complex versions of the State Machine VI architecture contain extra code that builds a queue of events states so that you do not miss any events National Instruments Corporation 1 15 LabVIEW Basics II Course Manual Lesson 1 Planning LabVIEW Applications More About Programming Architecture As with other programming languages many different methods and programming techniques are used when designing a VI in LabVIEW The VI architectures shown in this section are some of the common methods to give you an idea of how to approach writing a VI The VI structures will get much more complicated as applications get larger and many different hardware types user interface issues and error checking methods are combined However you will see these same basic programming architectures used Examine the larger examples and demos that ship with the LabVIEW application and write down which common VI architecture is used and why Additional resources for making LabVIEW applications are described in the LabVIEW Development Guidelines manual Next you will build a VI that uses the Simple VI architecture to verify the name an
16. Acquire Data subVI to open its front panel Select File VI Properties and select Window Appearance from the top pull down menu and click the Dialog button Click OK then save and close the Acquire Data VI 6 Remember that if one case in a Case structure passes data out of the case all other cases in the Case structure must also send out data Finish the VI so that the data pass through the other cases unchanged recall the method used in Exercise 5 1 7 Save the VI as Application Exercise 5 2 vi Run it and test it End of Exercise 5 2 LabVIEW Basics II Course Manual 5 10 ni com Lesson 5 Developing Larger Projects in LabVIEW Exercise 5 3 Application Exercise 5 3 VI Objective To finish the Application Exercise VI by adding the subVIs for the Analyze amp Present Data and View Analysis File buttons You will add the Analyze amp Present Data VI from Exercise 2 7 and the View Analysis File VI which you studied in Exercise 4 4 Block Diagram 1 Make sure that the Application Exercise 5 2 VI is open You will not modify the front panel in this exercise Open the block diagram State Machine Ho Event Login Acquire Data Eaj Analyze amp Present View File Shop Initial State 1 No Event 1 a Le ee Boa TE 4 Access Granted Es ait Until Hest ms Multiple ar National Instruments Corporation 5 11 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW 2 Delet
17. DLLs Both of these toolkits are included in the LabVIEW Professional Development System e Creating a professional stand alone application with your VIs involves four areas of understanding The architecture of your application The programming issues particular to the application The application building process The installer building process National Instruments Corporation 5 35 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW Additional Exercises 5 6 5 7 Modify Application Exercise VI so that the Configure Data Acquisition Acquire Data Analyze amp Present Data and View Analysis File buttons are disabled and grayed out if the user has not logged in with a valid user name and password Hint Use control references and the Disable Controls VI you built in Exercise 2 8 nodes to modify the buttons Save this VI as Application Exercise 5 6 vi Add one menu button to the menu cluster control in Application Exercise VI so the user can show or hide the LabVIEW Help window The text of the button should indicate what happens when the user clicks the button for example Show Help and Hide Help If you notice that the buttons and indicators on the front panel do not have descriptions in the Context Help window you need to add them in the Description and Tip shortcut dialog box for each control or indicator Make sure the VI properly tracks the state of the Context H
18. Exercise VI spends most of its time Notice how these VIs correspond with the VIs that require user interaction Waiting for user input is often the portion of execution which requires the most time In the Profile window you can capture timing statistics and information about VI memory usage To capture memory usage place a checkmark in the Profile Memory Usage checkbox E gt J F r j I l E Snapshot Save M Timing Statistics Time in milizeconds Timing Details M Profile Memory Usage Memon Usage size In kilobytes TT Sub Vis Time ee CC D Group Contig wi Hardware Config v1 Kp Note Collecting information about VI memory usage requires overhead which can create misleading timing statistics LabVIEW Basics II Course Manual 6 10 ni com Lesson 6 Performance Issues 6 Gather memory usage statistics about the CD Application Exercise VI Where is memory used and why Notice which VIs fragment memory and look to see which VIs use many blocks Why do you suppose these VIs use blocks Having fragmented memory causes VIs to execute more slowly because moving data around in memory takes overhead End of Exercise 6 1 National Instruments Corporation 6 11 LabVIEW Basics II Course Manual Lesson 6 Performance Issues C Speeding Up Your Vis LabVIEW compiles your VIs and produces code that generally executes very quickly However when working on time critical applications you need to use
19. Functions Structures palette on the block diagram This structures the VI to continue running until the user presses the Stop button Right click the Conditional terminal and select Stop If True Place the Wait Until Next ms Multiple function located on the Functions Time amp Dialog palette on the block diagram This function causes the While Loop to execute once a second Create the constant by right clicking the input terminal and selecting Create Constant Place the Random Number 0 1 function located on the Functions Numeric palette on the block diagram Creates a random number between zero and one Place the Multiply function located on the Functions Numeric palette on the block diagram Multiplies two numbers together and is used here to scale the random number to be between zero and 10 Place the Greater function located on the Functions Comparison palette on the block diagram Compares two values in this case the random value and the limit value and returns a True if the random value is greater than the limit Otherwise it returns a False Place the Select function located on the Functions Comparison palette on the block diagram You will use two of these functions This function takes a Boolean input and outputs the top value if the Boolean object is True and the bottom value if the Boolean object is False Place the Color Box Constant located on the Functions Numeric Additional Numeric Constants palette on the bl
20. LabVIEW environment to assist in project development The following section describes two of these tools that are included in the LabVIEW Professional Development System Source Code Controls Tools These tools simplify management of larger applications The first feature added with these tools is a basic source code control SCC system that is tightly integrated into the LabVIEW environment This system contains many features found in third party source code control systems such as file check in out revision tracking and support for multiple users In addition the SCC tools can support third party source code control systems such as Microsoft Visual SourceSafe As mentioned earlier in this lesson however VIs for a project must be saved as individual files instead of in LLBs because the file management features of the various operating systems do not support LabVIEW libraries The SCC tools also contain a VI Metrics tool to measure the complexity of an application similar to the widely used Source Lines of Code SLOCs metrics for textual languages With the VI Metrics tool you can view Statistics about VIs such as the number of nodes functions subVI calls structures terminals and so on of a VI and its subVIs Other statistics include the number and sizes of block diagrams number and type of user interface objects number of accesses to global and local variables and number of calls to Code Interface Nodes or shared libraries Yo
21. LabWindows CVI I ComponentWorks I TestStand J LabVIEW Add On Toolkit pack I Bridge VIEW J Lookout Additional Literature 1 NI Global Services D NATIONAL INSTRUMENTS I Analysis I HIQ 1 Measure 1 LabVIEW productivity study I DAQ I Low cost DAQ 1 Customer Education Course Schedule I Government legal 1 Research R amp D grad student I Software developer I Design I Software Showcase Windows and Macintosh CD Demos of entire software line I DAQ Designer Windows 3 5 in DAQ system integration tool _J Analytical chemistry L Education L Test and measurement GPIB GPIB chip kit HS488 Virtual instrumentation software VXI VME Luo L L L _J I use a PC regularly in my instrumentation system I I develop virtual instrumentation applications _I Production test J Systems integrator hardware _J Software consultant I Compliance testing 1 Instrupedia Windows CD includes catalogue software demos application notes and more _I Automation View newsletter I Third Party Solution CD 1 NI News e mail newsletter 1 Industrial automation L Laboratory automation PXI IMAQ Customer education C O L Computer based instruments SCXI signal conditioning L Ld LabVIEW Technical Resource Subscription Card 11500 North Mopac Expressway Austin TX 78759 3504 Tel 512 794 0100
22. Lesson 2 Designing Front Panels Exercise 2 8 Disable Controls vi and Control Refs Example vi Objective To build a VI that uses control references to access Property Nodes from a subVl You will start with the Property Node Exercise VI you built in Exercise 2 5 You will make a subVI that accesses an array of control references and assigns the Disabled property Then you will modify the Property Node Exercise VI to use the subVI rather than the original Property Nodes Kp Note You will use this VI in the project in Lesson 5 Front Panel Refnum Array Array of Control Refnume Enable Push Button 1 Open anew VI and build the front panel shown previously Block Diagram Array Disabled 2 Open and build the block diagram shown previously using the following components a Place a For Loop located on the Functions Structures palette on the block diagram The For Loop is used to auto index through the array of control refnums so that each refnum and property is handled separately Ge b Place a Property Node located on the Functions A pplication Control palette on the block diagram You will use this Property Node as a generic control type When you wire the Refnum Array to the refnum input terminal the function changes slightly as in the following example LabVIEW Basics II Course Manual 2 48 ni com Lesson 2 Designing Front Panels c Right click the Property terminal and select Properties Disab
23. Loop available on the Functions Structures palette Structures the VI to continue running until a global Boolean sends a TRUE value Right click the Conditional terminal and select Stop If True a c Wait Until Next ms Multiple function available on the zF Functions Time amp Dialog palette Ensures that data is written to the global variable every 50 ms in this exercise Create the constant by right clicking the input terminal and selecting Create Constant gt d Divide function available on the Functions Numeric palette Divides the iteration counter of the While Loop by 20 Create the constant by right clicking the bottom input terminal and selecting Create Constant e Sine function available on the Functions Numeric Trigonometric palette Accepts an input value in radians and outputs the sine of that value National Instruments Corporation 3 17 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques Stop Button D ata Value Global variable node Global variable node LabVIEW Basics II Course Manual 3 My Globals VI global variables Pass values between two concurrently running VIs in this exercise Complete the following steps to create and configure the global variables a In the block diagram select Global Variable from the Structures palette b Double click the node to bring up the global variable s front panel Create the global variable front panel as shown in
24. Loops to assemble arrays when possible rather than using While Loops or concatenating arrays with the Build Array function E For Loop VS While Loop Inplaceness When possible LabVIEW s compiler reuses a function s input buffers to store its output This buffer sharing is called inplaceness In the following example the Multiply function output uses the same buffer as the top input The array at the right is said to be inplace to array A LabVIEW Basics II Course Manual 6 30 ni com Lesson 6 Performance Issues Py YI Properties Category blemon Usage Front Panel Objects Block Diagram Objects Lode Data Total Total Size On Disk Cancel A function output reuses an input buffer 1f the output and the input have the same data type representation and in arrays strings and clusters the same structure and number of elements Functions capable of inplaceness include Trigonometric and Logarithmic functions most Numeric functions and some string and array functions such as To Upper Case and Replace Array Element A function that shifts or swaps elements of an array such as Replace Array Element can reuse buffers Some functions such as Array Subset and String Subset might not copy data but might pass pointers to the subarrays or substrings In the following illustration A B C and D identify individual buffers Build Array and Concatenate Strings are special functions They operate inplace when th
25. Variable Slower Method Faster Method Notice that you need the shift registers to pass the new value from the subVI to the next iteration of the loop Beginning LabVIEW users commonly omit these shift registers Without using a shift register the results from the subVI are never passed back to the subVI as the new input value as shown in the following block diagram In the previous block diagram the global variable is read once before the loop begins and the same value is passed to the function 10 000 times The result of the loop is the same as if you had written the code as shown in the following block diagram National Instruments Corporation 6 15 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Parallel Diagrams When several loops run in parallel on a block diagram LabVIEW changes between the loops periodically If some of these loops are less important than others you should use the Wait ms function to ensure that the less important loops use less time For example consider the following block diagram The two loops run in parallel One of the loops acquires data and must execute as frequently as possible The other loop monitors user input Currently both loops get equal time The loop monitoring the user input can execute several hundred times per second In reality this loop needs to execute only a few times per second because the user cannot make changes to the interface very quickly As
26. an installer for your application The first section of this lesson describes the architecture of your application and has you build the application in the exercises Your application is a single top level VI that runs when you launch the application and calls front panels from several subVIs when called This is the most common and easiest architecture for building a stand alone application Programming Issues You should consider several programming issues when you are building VIs that end up as built applications The first issue 1s to know what outside code is used for the application For example are you calling any system or custom DLLs or shared libraries Are you going to process command line arguments These are advanced examples that are beyond the scope of this course but you need to consider them for the application A second issue is with the path names used in the VI One example is when you use the VI Server capability to dynamically load and run VIs this is described in the LabVIEW Advanced I course Once an application is built the VIs are embedded in the executable Suppose you have a VI named test vi inside an application named test exe A Current VI s path primitive in test vi returns test exe test vi prepended with the full path of test exe Being aware of these issues will help you to build more robust applications in the future A last issue that will affect the application you have currently built is that the
27. and background Normal priority is the same as level 0 priority in previous versions of LabVIEW above normal priority is the same as level priority and so on If there are multiple VIs the VIs are placed into an execution queue VIs with higher priority except the subroutine priority still execute before lower priority VIs However VIs with a subroutine priority level behave differently than VIs with other priority levels When a VI runs at subroutine priority it runs in the thread category of its caller and no other VI can run in that thread until that VI or its subVIs complete Subroutine priority VIs can call other subroutine priority VIs only Use subroutine priority VIs only when you want to run a simple computation with no interactive elements You can skip the execution of a subroutine priority subVI when it is busy by right clicking the subVI and selecting Skip Subroutine Call if Busy Use this option when you are calling a shared subroutine from a high priority VI but you do not want to wait for the subroutine VI to become available Exercise caution when setting the priority levels for VIs Using priorities to control execution order might not produce the results you expect For example if you use the priority setting incorrectly lower priority tasks might never execute As you will see later in this lesson strategic use of Wait functions within VIs also can be a very effective way of optimizing your LabVIEW code Refer to the Lab
28. and block diagram windows 10 Run the VI You can adjust the front panel controls to see the time and frequency waveforms change Click between the Simulated and DAQ pages in the Tab Control 11 Stop and close this VI when you are finished End of Exercise 2 2 National Instruments Corporation 2 13 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels B Using Boolean Clusters as Menus You can use latched Boolean buttons in a cluster to build a menu for an application For example consider an application where an operator configures a system and runs either of two tests A possible menu VI for this application is as follows Boolean Cluster Cluster of labeled buttons mechanical action gt latch when released Cluster Order 0 Configure button 1 Test 1 button 2 Test 2 button The Cluster to Array function converts the Boolean cluster to a Boolean array with three elements That is each button in the cluster represents an element in the array The Search 1D Array function on the Functions Array palette searches the 1D array of Boolean values created by the Cluster to Array function for a value of TRUE A TRUE value for any element in the array indicates that you clicked on a button in the cluster The Search 1D Array function returns the index of the first TRUE value it finds in the array If you did not click a button Search 1D Array returns an index value of 1 If no buttons are pressed Case
29. and label it Access Granted You will write this VI so that until access is granted by the user logging in with a correct name and password the user can only use the Login and Stop buttons 4 Open the block diagram LabVIEW Basics II Course Manual 5 6 ni com Lesson 5 Developing Larger Projects in LabVIEW Block Diagram 1 Modify the following VI Only modify the While Loop and Cases 1 and 0 The Login VI is called when the user presses the Login button on the front panel Case O of the Case structure Remember to delete the One Button Dialog function that you placed in Case 0 in Exercise 2 3 State Machine N P E a as D efault EEE Login 3 Acquire Data z Analyze amp Present View File i Search 1D Ara Stop EL S Access Granted zH Check to see if a button in the cluster is pressed to determine the next state to execute ait Until Hest ms Multiple ear a Rasa Rash a Oo a iii Kp Note If you did not complete Exercise 3 1 locate Login VI in the course solutions stored on your computer National Instruments Corporation 5 7 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW 2 In addition modify the VI so that a The Operator indicator is initialized to an empty string when the VI Starts b Ifthe user has not logged in with a correct name and password only the Login and Stop menu options execute c Ifthe Login VI returns a value of FALSE f
30. and the number of averages per second The dips in performance happen when the Menu Loop executes and checks the values of the buttons on the front panel Performance increases when the Plot Loop runs Click the Show Dialog button Notice the effect on the plot speed and the Averages Sec value Recall that a loop cannot begin its next iteration until the entire block diagram inside it finishes executing In the Menu Loop the values from the buttons are read to determine which case should be executed If you click the Show Dialog button Case 0 is executed The case does not complete until you click the OK button in 6 21 LabVIEW Basics II Course Manual Lesson 6 Performance Issues LabVIEW Basics II Course Manual the dialog box Thus while the dialog box is displayed the Plot Loop does not need to share the processor with the Menu Loop Click the Pop Up VI button The Pop up 2nd Process VI opens its front panel and runs Notice the effect on the first VI s Averages Sec value As in the situation when you clicked the Show Dialog button the Menu Loop no longer executes until the Pop up 2nd Process VI ends However LabVIEW runs the second VI at the same time as the original VI The dips in performance appear when the second VI runs Therefore LabVIEW executes multiple VIs in the same way it executes parallel loops each process gets an equal time slice Click the Stop button 8 Modify the Menu Loop so it includes a Wait ms functi
31. box and give the user a choice to continue or stop the VI error code no error 0 emor source type of dialog UF msg 1 e source out error in no error Sn error out Message The General Error Handler VI also accepts the error in cluster or the error code value and a dialog box of the type specified appears when an error occurs However in addition you can set up error exception lists so that specified errors are cleared or set when they occur You also can use the General Error Handler VI to add errors to the internal error description table The error description table describes all errors for LabVIEW and its LabVIEW Basics II Course Manual 1 4 ni com Lesson 1 Planning LabVIEW Applications associated I O operations Therefore you can add your own error codes and descriptions to the error handler VIs Refer to the LabVIEW Help for information about how to modify your error handler VIs user defined descriptions user defined codes error code 0 error source code out tupe of dialog OK m g 1 p f b Source Out eror in no error sane TESS 496 exception action hone error out exception code exception source When an error occurs the Simple Error Handler and General Error Handler VIs open a dialog box that displays the information contained in the error cluster and possible reasons for that error as listed in the internal error description table Sometimes you have se
32. control you can save it for use later By default controls saved on disk has a ct 1 extension You also can place controls in the Controls palette using the same method as that you used to add subVIs to the Functions palette You also can use the Control Editor to save controls with your own default settings For example you can use the Control Editor to modify the defaults of a waveform graph save it and later recall it in other VIs National Instruments Corporation A 9 LabVIEW Basics II Course Manual Appendix Exercise A 2 Objective To use the Control Editor to modify a control 1 Open a new front panel 2 Place a Horizontal Pointer Slide located on the Controls Numeric palette on the front panel Right click the slide and select Visible Items Digital Display Modifying the Control 3 Launch the Control Editor by selecting the slide with the Positioning tool and selecting Edit Customize Control Using the Operating tool move the slide to the middle of the front panel to allow more work space 4 Right click the digital display and select Replace Numeric Meter Position the meter above the slide as shown in the following example 5 Hide the slide scale by right clicking the slide and selecting Scale Style None LabVIEW Basics II Course Manual A 10 ni com Appendix 6 Close the Control Editor by selecting Close from the File menu Save the control as Custom Slider ctl1l then click Yes to replace t
33. dialog box appears If Henu Editor File Edit Help alelet Default Preview File Edit Operate Tools Browse Window Help ltem Properties Wew ltem Type Open Application ltem Close Close All ltem Mame ltem Tag Save All APP_FILE Save with Options ME Se Page Setup Checked Print Shortcut Press key combination Print Window A On the left side of this dialog box 1s an overall organization of the menu items Menu items are classified into three types User Item Application Item or Separator A User Item can be handled programmatically in the block diagram It has a name whichis the string that appears in the actual menu and a tag which is a unique case insensitive string identifier A tag identifies a User Item in the block diagram For ease in editing when you enter the name it is copied to the tag However you can always edit the tag to make it different from the National Instruments Corporation 2 51 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels name For a menu item to be valid its tag should not be empty Invalid menu items appear as An Application Item is one that LabVIEW provides These items are part of the default LabVIEW menu To select a particular LabVIEW item click the arrow button next to the Item Name You can add individual items or entire submenus by using this process Application Items are handled implicitly by LabVIEW The
34. e When performing text and binary file I O remember that values for the pos offset terminal are measured in bytes e The count input in the Read File function controls how many bytes of information are read from the file when the byte stream type input is unwired The data read from the file is returned in a string e Ifthe byte stream type input is wired the data output of the Read File function 1s of the same data type as the byte stream type input when the count input is unwired e If the byte stream type input is wired and the count input has data connected to it then the Read File function returns an array containing count elements of the same data type as the byte stream type input e Refer to the LabVIEW Help and the LabVIEW User Manual for more information about random access operations and byte stream files National Instruments Corporation 4 7 LabVIEW Basics II Course Manual Lesson 4 Advanced File I O Techniques Exercise 4 1 Binary File Writer VI Objective To build a VI that writes data to a binary file with a simple data formatting scheme This VI saves data to a binary file using a simple formatting scheme in which the file s header is a long word integer 132 containing the number of data points in the file In the next exercise build a VI that reads the binary file Front Panel 1 Open anew VI 2 Build the following front panel When you create the menu ring recall that a shortcut for adding a new ite
35. for this VI because you will use this VI as a subVI in a later exercise To create the icon right click the icon in the top right corner of either the front panel or the block diagram and select Edit Icon from the menu Design an icon similar to the one shown here 8 Create the connector pane for this VI by right clicking the icon in the front panel and selecting Show Connector from the shortcut menu Select a pattern and connect the front panel objects to the terminals as shown in the following connector pane Hame Mame Confirmed Password Werfed 9 Save the VI under the same name 10 Stop and close this VI when you are finished End of Exercise 1 2 LabVIEW Basics II Course Manual 1 20 ni com E VI Templates Lesson 1 Planning LabVIEW Applications In the last section you learned about some of the common programming architectures for VIs So that you do not have to start building each new VI from an empty front panel and block diagram a number of templates are included with the LabVIEW package These VI templates can be found in the LabVIEW 6 Templates directory and contain the file extension vit LabVIEW provides some basic templates however not all of the VI architectures described are available as templates You can save a VI you create as a template by using the File Save with Options option as shown in the following dialog box Fe Save with Options E qn Changed Wla i Development 23 Citer i
36. from the top pull down menu A well written VI for this application should consume a total of about 25k of memory Notice how much this poorly written VI consumes 5 Modify the VI to so that this application Runs correctly for higher frequency waveforms Runs faster Uses better data structures and is easier to understand Is better documented Use the tips in this lesson information from other chapters in this course and the following tips to get started Putting High Level VIs in loops creates redundant function calls Gathering or plotting data one point at a time is less efficient than acquiring multiple points 6 42 ni com Lesson 6 Performance Issues Flat data types are more memory efficient than complex data Structures There are a variety of ways to document a VI Save the modified VI Run the VI Notice improvements in run time and memory usage Also notice the improvements in readability and simplicity of code Kp Note Make sure you save the VI before you examine its memory usage This prevents the LabVIEW Undo feature from allocating memory unnecessarily 8 When you are satisfied with the VI save it as Performance Improvements vi End of Exercise 6 6 National Instruments Corporation 6 43 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Exercise 6 7 Performance Challenge VI Maximized Performance VI Objective To improve the performance ofa VI La
37. from the top pull down menu Notice the considerable amount of memory taken by the data in this VI Modify the VI to improve the run speed and reduce the amount of memory required Use the tips in this lesson and the following guidelines to get you started e Local variables increase memory requirements and slow run speed especially when they are accessed in loops e Create arrays in an efficient manner e Minimize the amount of file I O operations performed in an application Only open and close a file when necessary e Avoid unnecessary computations and data conversions especially in loops 6 44 ni com Lesson 6 Performance Issues e Minimize and simplify front panel displays e Use simple data structures W Tip You only need to meet the requirements of the application described previously How you choose to implement this application is up to you 6 Save the modified VI 7 Run the VI noticing the speed improvements in the Profile window and the memory use improvements in VI Properties You might want to repeat steps 5 through 7 several times further optimizing the application Kp Note Make sure you save the VI before you examine its memory requirements This prevents the LabVIEW Undo feature from allocating memory unnecessarily 8 When you are satisfied with the VI save it as Maximized Performance vi End of Exercise 6 7 National Instruments Corporation 6 45 LabVIEW Basics II Course Manual Lesson 6 P
38. interface e Requires the user to log in with a correct name and password e If the user is not correctly loged in other features are disabled e Allows the user to configure the acquisition settings including sample rate number of samples or to simulate data e Acquires waveform data with the specified user configuation e As soon as the data have been acquired and any time the user selects thereafter the user can select a subset of the acquired data analyze it and save the analysis results to a file e Allows the user to load and view analysis results previously saved to disk e Stops the application with the click of a Stop button LabVIEW Basics II Course Manual 5 2 ni com Lesson 5 Developing Larger Projects in LabVIEW In Lessons 1 through 4 you concentrated on the bottom elements of the development process implementing and testing subVIs which correspond to nodes of the following project flowchart Ho Monitor User Interface Selection Made op en Logged in M selected enu Configure Dui button Acquisition Settings pressed Process Selector Load and View Analysis File Developing larger applications in LabVIEW is a different process than building the relatively straightforward mostly single task VIs we have been working with so far As you develop larger applications you will find that working in teams controlling source code and creating an intuitive hierarchy scheme for your application
39. or the Controls Array amp Cluster palette and offer a convenient way to group front panel objects together Page 1 Page 2 Page 3 Pagel Pages Page 3 String 2 Numeric Boolean VE Slide 2 Tab Control Tab Control The way you use a Tab Control is to place it on the front panel as shown previously You add tabs by right clicking an existing tab and selecting Add Page After Add Page Before or Duplicate Page from the menu You relabel the tabs with the Labeling tool and you place other front panel objects into the appropriate pages The terminals for these objects are available in the block diagram as are terminals for any other front panel object National Instruments Corporation 2 5 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels LabVIEW Basics II Course Manual ets a Page 1 Default Page 2 Page 3 The Tab Control wires directly to a Case structure as shown previously and the page name shows up as the name of the case You can then wire the data to and from the other terminals as needed Decorations One of the easiest and often overlooked methods of grouping or separating objects is to use an item from the Controls Decorations palette You can select to use various types of boxes arrows and lines from this palette as follows eH Decorations E E E a EE LU a You can find more decorations in the Controls Classic Controls palette The following palette shows the var
40. run independently from other VIs By default VIs run in the Standard execution system which runs in separate threads from the user interface The Instrument I O execution system is included to prevent VISA GPIB and Serial I O from interfering with other VIs Similarly the Data Acquisition execution system is set for the DAQ VIs While VIs that you write will run correctly if you leave them set to the Standard execution system you might want to move appropriate VIs to different execution systems For example if you are developing instrument drivers you might want to set your VIs to use the Instrument I O execution system To change the thread category in which a VI runs select Execution from the top pull down menu in the VI Properties dialog box Be VI Properties User Interface Category Esec standard instrument data acquisition _ other 1 k Priority athens PF Reentrant Execution W Auto Handling of Menus at Launch T Run hen Opened IY Allow Debugging Suspend hen Called Clear Indicators hen Called Cancel LabVIEW Basics II Course Manual 6 4 ni com Lesson 6 Performance Issues The Preferred Execution System list box lists the available categories of execution systems You also can prioritize parallel tasks in a multithreaded environment by setting the Priority of the VI Within each thread category you can specify the priority of execution normal above normal high time critical subroutine
41. s subVIs increases productivity and improves documentation and application performance Teamwork Business management experts stress the importance of teamwork in designing solutions for large complex tasks When using LabVIEW teamwork is a powerful tool for increasing your productivity in graphical programming When several people work together to develop a project in LabVIEW it is essential that all team members agree on a method of source code control and organization National Instruments Corporation 5 3 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW Source Code Control As the number of VIs used in your project grows your development team should take measures to control the source code of the project You can use the built in VI Revision History window located in Tools VI Revision History to record changes you make to VIs Then you can set up a check out system for the VIs Third party development tools that offer a check out system to protect project files typically will work with LabVIEW as long as they can manipulate binary files If you use a third party tool to manage your project s files remember that VIs and LLBs VI libraries are binary files Therefore tools that merge source files do not work correctly with LabVIEW files If you use a check out system and VIs are stored in an LLB you must check out the entire library of VIs Keep this in mind as you work on a project One V
42. shortcut menu Enter the following values f DataSocket Connection Connect To dstp localhost data Browse Connection Type Publish M Enabled Subscribe Only enabled connections publish andor Publish and Subscribe subscribe data when Vl runs Remove Cancel 11 Click the Attach button and a little gray rectangle appears to the top right side of the digital indicator This indicates that the DataSocket connection is not active 12 Run the DS Generate Data and DS Read Data VIs again The rectangle next to the Random Number indicator turns green and the value matches the values shown in the meter and the slide Kp Note If your computer is on a network with the other computers used in class you can type in URLs for other machines on the network and transfer the values between classroom computers Remember that you can use any programming language or operating system with DataSocket connections Go to the National Instruments DataSocket web page at ni com datasocket for more information National Instruments Corporation 3 33 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques 13 Stop and close both VIs and the DataSocket Server when you are finished End of Exercise 3 5 LabVIEW Basics II Course Manual 3 34 ni com Lesson 3 Data Management Techniques Summary Tips and Tricks e DataSocket is an Internet based method of transferring data that is platform independent programmi
43. should be able to use the keyboard shortcuts rather then the cursor to select the different test options 13 Close the VI End of Exercise 2 9 National Instruments Corporation 2 59 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels G Intensity Plots Intensity plots are extremely useful for displaying patterned data For example the plots work well for displaying terrain where the magnitude represents altitude Also you can demonstrate temperature patterns with intensity plots Like the waveform graph and chart the intensity chart features a scrolling display while the intensity graph features a fixed display These displays accept a block of data and map each value to an associated color with a maximum of 256 accessible colors Intensity Plot Options The displays of intensity charts and graphs use many of the same options as their waveform counterparts The following front panel shows many of the intensity graph options Intensity plots also provide options unavailable in other charts and graphs Because they display a third value color a color ramp is accessible You use these options to set and display the color mapping scheme The intensity graph also adds a third value a z value to the cursor display Intensity Graph 50 100 0 Color Ramp Y Scale S 40 Z Scale E x z g a0 50 0 iT 2 20 10 0 0 Graph Falette 0 oe eae BE Tm amp u
44. simple local variable example below The LabVIEW code appears next to the equivalent code of a sequential programming language LabVIEW Code Sequential Code X X 5 X X 2 or X X 2 X X 5 When you execute the sequential code the solution for a given value of x is clear because the statements execute from top to bottom However the LabVIEW code does not follow such a convention because LabVIEW is a dataflow language Each node executes when all of its data is available There are no data dependencies to guarantee the desired order of execution in the above block diagram In fact there are several possible solutions depending on how the VI compiles You cannot assume that the code located at the bottom of the block diagram executed after the code above it The above example illustrates what is known as a race condition The result of your program depends on the order in which its instructions execute and the code might not execute in the order you assume If you use local and global variables you might have a race condition if you notice that your code executes correctly only some times or that it executes correctly during execution highlighting but not during normal execution National Instruments Corporation 3 23 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques To avoid race conditions write to a local or global variable at a location separate from where you read from it in different locations of th
45. takes a measurement performs calculations and either displays the results or records them to disk The Simple VI architecture usually does not require a specific start or stop action from the user and can be initiated when the user clicks the run arrow In addition to being commonly used for simple applications this architecture is used for functional components within larger applications You can convert these simple VIs into subVIs that are used as building blocks for larger applications el Es gt Convert C to F_vi Diagram enfers re Convert Dix File Edit Operate Toole Browse wi File Edit Operate Tools Browse Window He 3 oLm deg L deg F 123 80 7484 LabVIEW Basics II Course Manual 1 10 ni com Lesson 1 Planning LabVIEW Applications The previous front panel and block diagram example is the Convert C to F VI built in the LabVIEW Basics I course This VI performs the single task of converting a value in degrees Celsius to degrees Fahrenheit You can use this simple VI in other applications that need this conversion function without needing to remember the equation General VI Architecture In designing an application you generally have up to three main phases Startup This section is used to initialize hardware read configuration information from files or prompt the user for data file locations Main Application This section generally consists of at least one loop that repeats until the user dec
46. that node A Control Reference is a refnum to a specific control This section shows only one way to use these versatile objects Refer to the LabVIEW manuals for more information about control references Creating Control References You create a control reference for a panel object by right clicking either on the panel object or on the terminal for that object and selecting Create Reference from the shortcut menu You then wire this Control Reference to a subVI that contains the Property Nodes However the sub VI must contain a terminal that is a Control Refnum You create the Control Refnum by selecting Controls Refnum as follows Using Control References The following subVI block diagram shows how you can use a control reference to set many of the properties for a panel object Disabled PKepFocus KepFocus Property Nodes use error clusters like many of the I O functions in LabVIEW so you can use the error handlers to keep track of the error conditions The VI that calls this subVI can use it to change the properties of any type of control The following example shows the sub VI disabling a numeric and setting a Boolean object to be the key focus LabVIEW Basics II Course Manual 2 46 ni com Lesson 2 Designing Front Panels Next you will build a subVI that changes the disabled property for an array of controls using the controls references National Instruments Corporation 2 47 LabVIEW Basics II Course Manual
47. the following figure Label the controls with the owned labels shown Notice that there is no block diagram associated with the global variable s front panel Global Variable Panel Stop Button Data Value Cc jooo c Save and close the global variable Name it My Globals vi d Return to the Data to Global block diagram e Right click the global variable node and select Visible Items Label f Using the Operating tool click the global variable node and select Stop Button You can change the variable to be readable or writable by right clicking it g Make enough copies of the My Global vi variable Use the Operating tool to select the correct item you need from the global variable Initialize the Stop Button global variable inside the Sequence structure by writing a FALSE to it The constant is wired to the loop border to force the global to initialize before the loop begins executing This prevents the While Loop from reading an uninitialized global variable or one that has an unknown value Save the VI as Data to Global vi Keep it open so you can run it in the next exercise End of Exercise 3 3 3 18 ni com Lesson 3 Data Management Techniques Exercise 3 4 Display Global Data VI Objective To build a VI that reads data from a global variable Build a VI that reads data from the global variable you created in the previous exercise and displays the data on a front panel chart Front Panel STOP Time D
48. the subVI you selected and close the hierarchy window Open the Application Exercise 5 2 VI you completed in Exercise 5 2 change to the front panel of the Application Exercise 5 3 VI and then select Tools Compare Compare VIs to display the Compare VIs dialog box E gt Compare VIs Vs to Compare Application Exercise 5 2 1 G elect Select M Vl Attributes MF Block Diagram M Front Panel M Cosmetic changes FM Position size changes FM Position size changes 10 Using the Select option make sure that the two Application Exercises 11 National Instruments Corporation are listed in the VIs to Compare box and that the Compare options are set as in the previous example Click Compare to display the Differences window and tile the two VIs Place a checkmark in the Circle Differences checkbox in the Differences window Then select a difference from the Differences listbox select a detail from the Details listbox and then click Show Detail The difference between the two VIs is highlighted Examine the various differences between the two VIs and then close the Differences window 5 19 LabVIEW Basics I Course Manual Lesson 5 Developing Larger Projects in LabVIEW 12 Close Application Exercise 5 2 vi End of Exercise 5 4 LabVIEW Basics II Course Manual 5 20 ni com Lesson 5 Developing Larger Projects in LabVIEW C LabVIEW Tools for Project Management There are several tools you can add to the
49. time for applications that use a large number of subVIs stored in LLBs is generally slower than if the subVIs are stored directly on disk using directories e VI libraries are not hierarchical You cannot create a VI library within another VI library so all VIs and subVIs are at the same level e When LLB files become large that is up to several megabytes saving edits to a VI stored in a LLB takes longer e Recall that the operating system views an LLB as a single file so when you save a VI in an LLB LabVIEW and the operating system must manipulate a very large file When working with such large files you run a higher risk of running out of memory or disk space when manipulating the file increasing the likelihood of corrupting the library and losing work e You cannot use your operating system s file searching tools to locate VIs stored in a LLB e Source code control of VIs stored in LLBs is more difficult As a rule of thumb try to limit the size of your LLB to roughly 1 MB Whether you store your VIs in an LLB or directly on disk can depend on file naming restrictions in your operating system or how you select to organize your files Refer to the LabVIEW Development Guidelines manual available at ni com for more information about designing building and testing applications in LabVIEW complete with a style guide checklists and references Creating LabVIEW Applications You are now going to create the application de
50. to help you understand how the application should operate and discuss this in detail with your customer After you design a flowchart you can develop VIs to accomplish the various steps in your flowchart It is a good idea to modularize your application into logical subtasks when possible By working with small modules you can debug an application by testing each module individually This approach also makes it much easier to modify the application in the future Error clusters are a powerful method of error handling used with nearly all of the I O VIs and functions in LabVIEW These clusters pass error information from one VI to the next An error handler at the end of the data flow can receive the error cluster and display error information in a dialog box The most common VI architectures are the Simple the General the Parallel Loops the Multiple Case Structures and the State Machine Each of these architectures has advantages and disadvantages depending upon what you want your application to do The State Machine VI architecture is very useful for user interface VIs and it generates clean simple code Several template VIs ship with the LabVIEW package so you do not need to start VI development from empty front panels and block diagrams each time Refer to the LabVIEW Development Guidelines manual for more information about designing and building VIs 1 24 ni com Lesson 1 Planning LabVIEW Applications Notes Nation
51. user access to the digital control and grey it out digital control 2 m e Disabled Key Focus Property T Blinking Property a a ea Value Property EH LabVIEW Basics II Course Manual The Key Focus property shown at left sets or reads the key focus of a front panel object When TRUE the cursor is active in the associated object On most controls you can enter values into the control by typing them with the keyboard You also can set the key focus on the front panel by pressing the lt Tab gt key while in run mode or by pressing the hot key associated with the control assigned using the Key Navigation option Wiring Example Make the digital control the key focus You can then enter a new value in the control without selecting it with the cursor digital control digital control gt I ona 7 UU The Blinking property shown at left reads or sets the blink status of an object By setting this property to TRUE an object will begin to blink You can set the blink rate and colors by selecting Tools Options and selecting Front Panel and Colors from the top pull down menu When this property is set to FALSE the object stops blinking Wiring Example Enable blinking for the digital control digital control digital control digital control T m 2 TES Blinking 000 _ 1 Block Diagram 2 Front Panel Normal 3 Front Panel Blinking The Value proper
52. you find the items quickly and strengthen the relationship between the items in the section New Vi Ctrl Hew Oper Ctrl 0 Close Cr Cloze All Mer il Ctrl M Mew Open Ctrl Save Ctrl 5 Close Ctrirw Save Ag Close All Cave Al Save Ctri S Save Ag Save All Save with Options Revert Page Setup Page Setup Print Print Print window Ctrl P Print window Ctri P Y Properties Ctrl Recently Opened Files de Y Properties Ctri Ext Ciki Save with Options Revert Recently Opened Files P Ctri Q Text is easier to read and information makes more sense when displayed in an orderly way To use this to your advantage when building front panels try grouping related controls together with white space or with lines These methods work best when they are subtle and do not distract from the information Using too many font styles can make your front panel look busy and disorganized It is better to use two or three different sizes of the same font Serifs help people to recognize whole words from a distance If you are using more than one size of a font make sure the sizes are quite different If not it will look like a mistake Similarly if you use two different fonts make sure they are distinct Operator stations can catch lots of glare or users might need to read them from a greater distance than normal computers or with a touch screen Therefore you should use larger fon
53. 00 0 10 2 0 os E i Ally Lilly 200 0 4 E il ne o o Ah i i Sampling Info Nole Amplitude 10 4 Fs 0 0 50 0mm 00 m 50 Orn 2010 ok UK f Time El i A Ez Local intranet A Pd l Done Yi Note The Animated option only works with Netscape Navigator You can only view static images using Internet Explorer 9 Return to the Web Publishing Tool window and click the Save to Disk button to save the title text and VI front panel image in an HTML document Save the document as Generate amp Analyze Data htm in the LV Basics 2 directory A warning message appears telling you where to install the file 1f you want other machines to view it 10 Click the Done button to exit the Web Publishing Tool 11 Go back to the Browser application and type the following URL into the address http 127 0 0 1 This specifies the local machine The following window appears LabVIEW Basics II Course Manual A 18 ni com Appendix E FE Rex LabVIEW Web Server Microsoft Internet Explorer File Edit Whew Favorites Tools Help CCE A a ale Back Porte Stop Refresh Home Search Favorites History Mail Pririt lAddess EJnmcvnz7001 Bl Go Links gt LabVIEW Web Server hese pages describe now you can add your LabViEV Y application to the World Vide Web using LabViEVy s integrated web server World Wide Web Overview A shart introduction to the World ide Vel LabVIEW Web Services
54. 3 VI you created in Exercise 5 3 Modify the following front panel to remove the comments Menu Cluster Operator 3 Access Granted Acquire Data Analyze amp Present Data View Data File 2 Select File VI Properties to display the VI Properties dialog box Select Window Appearance from the top pull down menu then select Top level Application Window This gives the front panel a professional appearance when it is opened as an executable 3 Save the VI as Application Exercise vi Block Diagram 4 Open the block diagram and use the following components a Place the not function located on the Functions Boolean palette on gt the block diagram This function inverts the value being sent to the While Conditional terminal When the loop ends this value is a False so a True value is actually sent through the loop boundary to the Quit LabVIEW function LabVIEW Basics II Course Manual 5 28 ni com Lesson 5 Developing Larger Projects in LabVIEW b Place the Quit LabVIEW function located on the Functions Application Control palette on the block diagram This function quits LabVIEW and quits the application after it has been built State Machine Mo Event Login Acquire Data Analyze amp Present View File ait Until Next ms Multiple Save this VI as Application Exercise vi 6 Open the front panel and run the VI When you select the Stop button the VI stops and you exit LabVIEW 7 Restart
55. 800 433 3488 Fax 512 683 9300 info ni com e ni com Product and company names mentioned herein are trademarks or trade names of their respective companies Copyright 1997 1999 National Instruments Corporation All rights reserved 340812C 01
56. And resize your window so the front panel fits inside the window as shown in the following example Channel A Channel B Position B J Timebase Chamnoil Le d Trigger POS Li Slope FE Trigger Level p Hu W Tip You need to use the Reorder button in the tool bar on the decorations to Move to Back so that the controls are visible and on top of the raised boxes 4 Select File VI Properties to display the VI Properties dialog box Select Window Size from the top pull down menu of the VI Properties dialog box In the Minimum Panel Size section click the gt gt Set to Current Window Size button to set your minimum screen size to the current size of the window Click OK to return to the front panel 5 Select the graph on the front panel then select Edit Scale Object With Panel LabVIEW resizes the graph when the entire window is resized and moves the other objects Save the VI under the same name Resize the window You notice that the graph does resize with the window and the controls maintain a proportional distance to the graph and each other but do not grow or shrink However you notice that the decorations do not resize In order to do this you must use Boolean buttons that look the same in each state and resize them programmatically This requires the use of Property Nodes and 1s covered later in this lesson 8 Close the VI when you are finished End of Exercise 2 1 National Instruments Corporatio
57. Basics II Course Manual Lesson 2 Designing Front Panels Block Diagram block menu F ait Until Nest me Multiple EN 9 Change to the block diagram of the VI and complete it as shown previously Ey MEM amp k MEM LabVIEW Basics II Course Manual 10 a Place the Current VI s Menubar function located on the Functions A pplication Control Menu palette on the block diagram This function returns the refnum for the selected VI s pull down menu so that it can be manipulated Place the Get Menu Selection function located on the Functions Application Control Menu palette on the block diagram Each time the While Loop executes the Get Menu Selection function will return the Item Tag for any user item selected in the run time menu If no user item is selected Item Tag returns an empty string This function is configured so that every time it reads the menu bar it prevents the user from making another menu selection until Enable Menu Tracking is executed Place the Enable Menu Tracking function located on the Functions Application Control Menu palette on the block diagram This function enables the pull down menu after it has been disabled by the Get Menu Selection function Save the VI and runit When the VI executes the custom run time menu appears on the front panel If you select one of the items in the Test pull down menu that item s name appears in the Item Tag indicator and a dialog box
58. Basics II Course Manual Lesson 2 Designing Front Panels Summary Tips and Tricks LabVIEW Basics II Course Manual When you are designing user interfaces keep the following things in mind the number of objects in the panel color spacing and alignment of objects and the text and fonts used LabVIEW contains the following tools to help you create user interfaces dialog controls tab controls decorations menus and automatic resizing of panel objects Latched Boolean buttons in a cluster can be used to build menus for applications You can convert a cluster containing components of the same data type to an array and then use the array functions to process the cluster components The Cluster To Array function Functions Cluster or Functions Array palette converts a cluster to a 1D array Property Nodes are powerful tools for expanding user interface capabilities You use Property Nodes to programmatically manipulate the appearance and functional characteristics of panel controls and indicators You create Property Nodes from the Create shortcut menu of a control or indicator or a terminal for a control or indicator on the block diagram You can create several Property Node terminals for a single front panel object so you can configure properties from several locations in the block diagram You can set or read properties such as user access enable disable gray out colors visibility location and blinking Prop
59. CP IP there are two parts to the name a machine name and a port number With DataSocket the resource name is in the form of a URL or uniform resource locator much like the familiar web address used by a web browser Consider how a web browser would interpret the URL ni com datasocket It tells the browser to use the TCP IP based protocol called HTTP or hyper text National Instruments Corporation 3 27 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques transfer protocol to connect to the machine named ni com and to fetch the web page named datasocket The URL is different from the names used by most I O technologies in that it not only defines what you are interested in but also indicates how to get it The how encoded in the first part of the URL 1s called the access method of protocol Web browsers typically use several access methods such as HTTP HTTPS encrypted HTTP FTP file transfer protocol and FILE for reading files on your local machine DataSocket takes the same approach for measurement data For example DataSocket can use the following URL to connect to a data item dstp mytestmachine wavel The dstp in the front tells DataSocket to open a data socket transfer protocol connection to the test machine and fetch a signal called wavel Had the URL started with file the data would have been fetched from a file instead of the DataSocket server The DataSocket Functions The DataSocket API in LabVIEW i
60. Data to Global and Display Global Data from Exercises 3 3 and 3 4 so they use a handshaking protocol to make sure that no data points are skipped or read multiple times Set up an additional Boolean in My Global vi named Handshake which will be used to indicate when VIs are ready to send or receive data In the Data to Global VI make sure to set the Handshake global Boolean to FALSE before it passes a new data point to the Data Value numeric In Display Global Data set the Handshake Boolean to TRUE before it attempts to read the numeric data In both VIs make sure to set the Handshake Boolean so the other VI knows when to access the variable Name the new global Boolean Handshake Global vi and the other two VIs Data to Handshake Global vi and Display Handshake Global vi Challenge 3 8 Open the Select and Plot Waveform VI from Exercise 3 2 Use the information at the end of Section D to rewrite this VI to no longer use the sequence structure and local variables W Tip Usea state machine architecture and pass data using shift registers or direct wire connections LabVIEW Basics II Course Manual Save the VI as Select and Plot Waveform2 vi 3 36 ni com Lesson 3 Data Management Techniques Notes National Instruments Corporation 3 37 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques Notes LabVIEW Basics II Course Manual 3 38 ni com Lesson 4 Advanced File 1 0 Techniques rer 4 A CRE Wh
61. EW Basics II Course Manual Lesson 3 Data Management Techniques A Data Management Techniques in LabVIEW The previous lesson describes how you build the user interface or front panel for a VI This lesson concentrates on block diagram issues such as passing data between nodes and controlling execution order As you already know the principle that governs how a LabVIEW program executes is called data flow The rules of data flow are e A node executes only when data is available at all its input terminals e A node supplies data to all of its output terminals when it finishes executing e The data flows through wires instantaneously Therefore a block diagram does not execute top to bottom or left to right but according to data flow rules This contrasts with the control flow method of executing a conventional program in which instructions execute in the sequence in which you write them Wires are the key to understanding how data flow works in LabVIEW When wires directly connect one node to the next the order of execution is defined If no wire connects two nodes then those nodes can run concurrently If you require those two nodes to run in order then you either use a Sequence structure or if the nodes are subVIs program data dependencies such as the error clusters to control program execution When You Cannot Use Wires Wires are the most efficient way to pass data from one node to the next when using data flow programm
62. I Acquire Waveform VI with an input specifying that you want 100 points This is faster than using the AI Sample Channel VI in a loop with a wait function to establish the timing LabVIEW Basics II Course Manual 6 12 ni com Lesson 6 Performance Issues Single Point Data Transfer Multiple Point Data Transfer Slower Method Faster Method In the previous example overhead for the AI Acquire Waveform VI is roughly the same as the overhead for a single call to the AI Sample Channel VI even though it is transferring much more data In addition the data collected by the AI Acquire Waveform VI uses hardware timers to control the sampling Calling AI Sample Channel in a loop does not provide data collected at a constant sample rate screen Display Updating controls on a front panel is another time consuming task in an application While multithreading helps to reduce the effect that display updates have on overall execution time complicated displays such as graphs and charts can adversely affect execution speed This effect can become significant on the LabVIEW platforms that do not support multithreading Although most indicators do not redraw when they receive data values that are the same as the old data graphs and charts always redraw To minimize this overhead keep front panel displays simple and try to reduce the number of front panel objects Disabling autoscaling scale markers and grids on graphs and charts improves their efficie
63. I acquires data it should turn the High Limit line red when the temperature exceeds the limit value and the Out of Range LED should blink a In the Sequence structure create a Property Node for the Temperature chart that has two terminals One terminal should be the multiplier property X Scale Offset and Multiplier Multiplier and the other terminal should be the History Data property To clear a waveform chart from the block diagram send an empty array of data to the History Data property To do this right click the property and select Create Constant Make sure that the array constant is empty b In the Case structure inside the While Loop create a Property Node for the Temperature chart that has two terminals The top terminal should be the Active Plot property and the bottom terminal should be the Plot Color property Plot Plot Color You will need these properties in both cases of the Case structure The High Limit plot is plot 1 so set the Active Plot property to one before setting the Plot Color property If the data are greater than the High Limit set the plot color to red Otherwise it should be yellow Use a Color Box constant to send the color value to this property c Right click the Out of Range indicator to create the Blink Property Node The indicator should blink when the temperature is greater than the High Limit National Instruments Corporation 2 41 LabVIEW Basics II Course Manual Lesson 2 Design
64. I management technique is to edit a copy of the VI you want to modify and lock the original VI to indicate to others that the VI should not be modified To lock a VI enable the Locked setting by selecting Security from the top pull down menu in the File VI Properties dialog box You should also indicate that you have checked out the VI by adding a comment in the VI Revision History window When you lock a VI its block diagram cannot be modified After you finish modifying the VI replace the VI stored in the LLB with the new version and unlock it so others know it is safe to check out the VI To document your VIs select Description and Tip from the top pull down menu in the File VI Properties dialog box Control descriptions also provide online help you can use in the final product Using LabVIEW Libraries LLBs You can load and save VIs to from a special file called a VI library 11b VI library files are useful for organizing VIs Some of the advantages of using LLBs are e You can use names up to 255 characters in length for your VIs e LLBs store several VIs in a compressed format which conserves disk space e You can tag VIs to be top level within a library e Porting VIs to another platform is simplified because you do not need to transfer as many files LabVIEW Basics II Course Manual 5 4 ni com Lesson 5 Developing Larger Projects in LabVIEW There are also some disadvantages when using LLBs e Loading and saving
65. Information about the builtin LabViEVY web server and how to perform basic configuration Publishing Documents Explanation on how te publish ATML and other documents using the LabVIEVY web server Publishing Vl Images acception horar ta moiblich imsasas e and aniemm satiane oF tle zz F Internet 2 12 Read the information and close the browser when you are finished 13 Turn off the Web Server by selecting Tools Options to display the Options dialog box 14 Select Web Server Configuration from the top pull down menu of the Options dialog box and remove the checkmark from the Enable Web Server checkbox 15 Click the OK button to close the Options dialog box 16 Close the Generate amp Analyze Data VI End of Exercise A 4 National Instruments Corporation A 19 LabVIEW Basics II Course Manual Appendix D Additional Information This section describes how you can receive more information regarding LabVIEW instrument drivers and other topics related to this course National Instruments Technical Support Options The best way to get technical support and other information about LabVIEW test and measurement instrumentation and other National Instruments products and services is the NI Web site at ni com The support page for the National Instruments Web site contains links to application notes the support knowledgebase hundreds of examples and troubleshooting wizards for all topics discussed in this cour
66. LabVIEW and open a new VI You will not open the Application Exercise VI because the Application Builder cannot create an executable if the VIs are loaded into memory National Instruments Corporation 5 29 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW 8 Select Tools Build Application or Shared Library DLL Build an executable from Application Exercise vi called myApplication exe and place it into the C myapp directory Modify the Target tab as shown Build Application or Shared Library DLL New script Target Source Files Vl Settings Application Settings Installer Settings Build target application EXE ll Target file name myApplication exe Destination directory CCE Support file directory 4 CAmpapp dsts 0 Build Options Single target file containing all Wla Do not compress target file faster load on slow machines Small target file with external file for subs LLE for other files 4 C Ampapp data lb Pi Load Save Save Ag Mew Help Build Done LabVIEW Basics II Course Manual 5 30 ni com Lesson 5 Developing Larger Projects in LabVIEW 9 Click the Source Files tab and select the Add Top Level VI button Add Application Exercise vi as shown Pe Build Application or Shared Library DLL New script Application Exercise v1 National Instruments Corporation 5 31 LabVIEW Basics II Course Manual L
67. Not function located on the Functions Boolean palette to invert the value going into the subVI 9 Save the VI 10 Return to the panel and run the VI Notice that when you set the Disable switch to True all the controls become grayed out as they did before 11 Close this VI when you are finished End of Exercise 2 8 LabVIEW Basics II Course Manual 2 50 ni com Lesson 2 Designing Front Panels F LabVIEW Run Time Menus Optional You can customize the menu bar for every VI you build so that you have a custom pull down menu while a VI executes There are two parts to customizing menus creating menus and handling menus You can build custom menus in two ways statically at the time of editing or dynamically at run time You can statically store a menu template in a file called the run time menu RTM file You can associate an RTM file with a VI at the time of editing When the VI runs it loads the menu from the associated RTM file You also can programmatically insert delete and modify menu items at run time from the block diagram using several LabVIEW functions In addition you can programmatically determine if an option on the menu bar is selected and programmatically handle the selection With these features you can make a custom pull down menu for your application Static Menus Static menus are stored in RTM files You can enable create or edit an RTM file for a VI by selecting Edit gt Run Time Menu The Menu Editor
68. Server is now running LabVIEW Basics II Course Manual A 16 ni com Appendix Run the VI for a few seconds and stop it Select Tools Web Publishing Tool Click the Instructions button and read how to use this tool 7 Click the continue link and configure the following window Web Publishing Tool Document Title Text that is going to be displayed This Vil was the first exercise completed in the LabVlEW Basics si are E ac course It generates noisy sine waves and calculates the frequency response Text that is going to be displayed after the image of the WI panel Now this YI is being used in the last exercise of the LabVIEW Basics Il 2 course to demonstrate the web publishing tools in Lab YTE 8 Click the Preview in Browser button to open and display the front panel in a web browser A window similar to the one shown in the next figure appears National Instruments Corporation A 17 LabVIEW Basics II Course Manual Appendix Generate amp Analyze Data Microsoft Internet Explorer File Edt Yiew Favortes Tools Help Back Bamsan Stop Refresh Home Search Favorites History Mail Print Address http customered 234 00temp00 htm r Go Links Generate amp Analyze Data This VI was the first exercise completed in the Lab VIEW Basics I course It generates noisy sine waves and calculates the trequency response Sine Frequency Sine Amplitude TME Waveform DE l 2
69. Time statistics in the table Run the Charting Benchmark Example VI The VI does nothing until you click the Run SubVIs button Run the subVIs at least three or four times Then click the Quit button to stop the Charting Benchmark Example VI After running the subVIs several times click the Snapshot button in the Profile window Locate Charting Benchmark Example VI in the Profile window and double click it to display its subVIs Notice the VI execution times for the two subVIs Recall that these are cumulative times not the amount of time needed to execute the sub VIs once Notice that updating the chart one point at a time is the slowest method and that updating the chart several points at a time is the fastest method 6 18 ni com Lesson 6 Performance Issues 8 Select the Timing Statistics option to view the average execution time for the subVIs Then select the Timing Details option and examine the Display and Draw statistics Notice that the Display statistic is largest for the Update Chart Point at a Time subVI and is very low for the Update Chart 50 Points at a Time VI Record the average execution time in the following table Refer to the LabVIEW Help or the LabVIEW User Manual for more information about these statistics 9 Click the Stop button in the Profile window to stop the profiling session Then close the Profile window 10 Close all open VIs and do not save any changes 11 If you are running LabVIEW on a multith
70. VI which is composed of the Sort 1D Array instance and the Sort 2D Array instance 7 National Instruments Corporation To combine the two instances into one polymorphic VI select File New and select Polymorphic VI If you are at the welcome screen select Polymorphic VI from the New VI pull down menu 6 Untitled 5 Polymorphic YI File Edit Tools Browse Window Help Subvls 8 m Addl Remove l Edit icon E dit Menu ltem A 5 LabVIEW Basics II Course Manual Appendix LabVIEW Basics II Course Manual 10 11 Add the Sort 1D Array and Sort 2D Array VIs using the Add VI button You might need to browse to the directories where you saved these VIs Create an icon for this new polymorphic VI by selecting the Edit Icon button Create context help for this VI by selecting Documentation from the top pull down menu in the File VI Properties dialog box Save your VI as Sort Poly Array vi 12 Use this VI as a sub VIT in another VI to test the functionality Notice the help screen Also notice what happens when you double click the polymorphic VI What happens if you select a particular context by right clicking and selecting Select Type End of Exercise A 1 A 6 ni com Appendix B Custom Graphics in LabVIEW There are several Lab VIEW features available for giving front panels a more professional custom look These features provided with the LabVIEW full and professional development
71. VIEW Help for more information about how to use Wait functions National Instruments Corporation 6 5 LabVIEW Basics II Course Manual Lesson 6 Performance Issues B The Profile Window The Profile window 1s a powerful tool for analyzing how your application uses execution time as well as memory With this information you can identify the specific VIs or parts of VIs you need to optimize For example if you notice that a particular subVI spends a great deal of time updating the display you can focus your attention on improving the display performance of that VI The Profile window displays the performance information for all VIs in memory in an interactive tabular format From the window you can choose the type of information to gather and sort the information by category You also can monitor subVI performance within different VIs To show the Profile window select Tools Advanced Profile VIs The following window appears if Profile OF x Shop Snapshot Save M Timing Statistics Time in millisecondes Land nae TORPE His Pinar Ribseeseasis LE Jarg pires 3 ne ER EI iis ue males Ne oid J Sub Vis Time Total Time Shortest Analyze and Present Data vi 12709 0 111 0 12820 0 12709 0 12709 0 onfigure Acquisition vi 10570 0 oO 10570 0 10570 0 10570 0 ogin vi 6238 0 6208 0 6208 0 cquire Data vi 1112 1018 0 1018 0 pplication Exercise 6 3 vi 30968 0 31648 680 0 680 0 ie o ave Data to Fi
72. abVIEW Clipboard you can paste it as a static picture on the front panel or you can use the Import Picture option of a shortcut menu or the Import Picture options in the Control Editor Custom Controls You can customize LabVIEW controls and indicators to change their appearance on the front panel You also can save these controls for use in other VIs Programmatically they function the same as standard LabVIEW controls National Instruments Corporation A 7 LabVIEW Basics II Course Manual Appendix Control Editor Launch the Control Editor by selecting a control on the front panel and selecting Edit Customize Control The Control Editor appears with the selected front panel object in its window The Control Editor has two modes edit mode and customize mode Edit Mode In edit mode you can right click the control and manipulate its settings as you would in the LabVIEW programming environment 13pt Application Font TE Edit Mode Type Def Align Distribute Reorder Status Objects Objects Objects Customize Mode In customize mode you can move the individual components of the control around with respect to each other For a listing of what you can manipulate in customize mode select Window Show Parts Window Control 13pt Application Font r Customize Type Def Align Distribute Reorder Mode Status Objects Objects Objects One way to customize a control is to change its type definition status You can save a cont
73. able Menu Tracking function Current VI s Menubar E menubar Returns the menubar refnum of the current VI This function must be executed before the other menu handling functions are invoked LabVIEW Basics II Course Manual 2 54 ni com Lesson 2 Designing Front Panels Get Menu Selection timed out menubar menubar out me timeout 200 tem tag block menu F 1 q S them path ermar in no error oan aor Out Returns the item tag of the last selected menu item optionally waiting for a period of time specified by timeout Item path is a string describing the position of the item in the menu hierarchy Menu selection is blocked after an item is read if block menu is set to TRUE Enable Menu Tracking menubar menubar out emor out error in no error This function enables or disables the tracking of menus Once a menu is blocked using the Get Menu Selection function Enable Menu Tracking must be executed to re enable the pull down menu National Instruments Corporation 2 55 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Exercise 2 9 Pull down Menu vi Optional Objective To build a VI using a custom run time menu LabVIEW Basics II Course Manual This VI illustrates how to edit and programmatically control a custom menu in a LabVIEW application l Open the Pull down Menu VI located in the c exercises LV Basics 2 directory The front panel and block diagram ar
74. above The URL object is a String control Block Diagram 2 Open and build the block diagram shown above using the following components a While Loop available on the Functions Structures G palette Structures the VI to continue running until you press the Stop button Right click the Conditional terminal and select Stop If True A b Wait Until Next ms Multiple function available on the Functions Time amp Dialog palette Causes the While Loop to execute once per second Create the constant by right clicking the input terminal and selecting Create Constant LabVIEW Basics II Course Manual 3 30 ni com Lesson 3 Data Management Techniques ma c Random Number 0 1 function available on the Functions Numeric palette Creates a random number between zero and one gt d Multiply function available on the Functions Numeric palette Multiplies two numbers together and is used here to scale the random number to be between zero and 10 e DataSocket Write function available on the Functions Communication DataSocket palette Writes the random data value to the specified URL f Simple Error Handler VI available on the Functions Time amp Dialog palette Opens a dialog box if an error occurs and displays the error information Save this VI as DS Generate Data vi 4 Now build the second VI to read the random value Front Panel slide UAL 10 00 dstp localhast datal 5 00 6 00 4 00 2
75. ace the Loop Control terminal outside of both loops and wire it to each conditional terminal In this case the Loop Control terminal is read only once before either While Loop begins executing Recall that this happens because LabVIEW is a dataflow language and the status of the Boolean control is a data input to both loops If a TRUE is passed into the loops the While Loops run indefinitely Turning off the switch does not stop the VI because the switch is not read during the iteration of either loop This solution does not work Method 2 Incorrect Now we move the Loop Control terminal inside Loop 1 so that it is read in each iteration of Loop 1 Although Loop 1 terminates properly there is a problem with this approach Loop 2 does not execute until it receives all its data inputs Remember that Loop 1 does not pass data out of the loop until the loop stops Thus Loop 2 must wait for the final value of the Loop LabVIEW Basics II Course Manual 3 6 ni com Lesson 3 Data Management Techniques Control available only after Loop 1 finishes Therefore the loops do not execute in parallel Also Loop 2 executes for only one iteration because its conditional terminal receives a FALSE value from the Loop Control switch in Loop 1 Method 3 Correct In this example Loop 1 is again controlled by the Loop Control switch but this time Loop 2 reads a local variable associated with the switch When you set the switch to FALSE on the fro
76. agram Extract the first column from the table Employee Into Table The name matches Indes Arra Select Hame Confirmed Auto Indesxing i r gt Enabled array Size Mame does not match 3 Open and build the previous block diagram using the following components a E LabVIEW Basics II Course Manual Place a While Loop located on the Functions Structures palette on the block diagram This structures the VI to continue checking for a match until a name match occurs or there are no more rows in the table Notice that indexing is enabled on the names array but not on the other two items entering the While Loop Enable the indexing by right clicking the tunnel and selecting Enable Indexing from the shortcut menu Place a Case structure located on the Functions Structures palette on the block diagram If the Name input matches a listing in the first column of the table the Passwords are also checked If the Name does not match the current table entry the loop continues to the next iteration To create the Boolean constant in the False case wait until the True case is completely wired Then select the False case and right click the green outlined tunnel and select Create Constant from the shortcut menu Place the Index Array function located on the Functions Array palette on the block diagram This function is used to pull the names 1 18 ni com gt Lesson 1 Planning LabVIEW A
77. agram shown in ellipses above a String Constant available on the Functions String palette Sends text values to the Current Activity front panel indicator 531 b Numeric Constant available on the Functions Numeric palette Resets the Select Waveform dialog ring to zero Stand By after the waveform is acquired c New Waveform local variable set to read local Reads the data in the New Waveform graph and passes that data to the Previous Waveform graph To create this local variable right click the New Waveform terminal and select Create Local Variable from the pop up menu Then right click the local variable and select Change To Read d Current Activity local variable set to write local Places new text into the Current Activity indicator There are several instances of this local variable in the block diagram illustrating how you can access a front panel object from several locations on the block diagram To create the local variable right click the Current Activity terminal LabVIEW Basics II Course Manual 3 12 ni com Lesson 3 Data Management Techniques and select Create Local Variable from the pop up menu Then make two more copies of this local variable e Select Waveform local variable set to write local Resets the Select Waveform control to Stand By mode To create this local variable right click the Select Waveform terminal and select Create Local Variable from the pop up menu Yi Note Make sure to correc
78. al Instruments Corporation 1 25 LabVIEW Basics II Course Manual Lesson 1 Planning LabVIEW Applications Notes LabVIEW Basics II Course Manual 1 26 ni com Lesson 2 Designing Front Panels rer 4 A CRE This lesson introduces how you can design and build the user interface to your VIs First an overview and list of things to consider while building the front panel The next few sections describe some common methods and tools for customizing panels The last few sections describe additional items and panel objects used for developing user interfaces You Will Learn About basic user interface issues How to use Boolean clusters as menus About Property Nodes About Graph and Chart Properties How to use Control References About LabVIEW Run Time Menus About Intensity Plots QHN National Instruments Corporation 2 1 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels A Basic User Interface Issues When you develop applications that other people will use you need to follow some basic rules regarding the user interface If the front panel contains too many objects or has a distracting mixture of color and text the users might not use the VI properly or not receive important information from the data This section describes some topics to consider when you are building front panels One rule to follow when building a user interface to a VI is to only show items in the front panel that the user needs t
79. alse case is empty except for passing the cluster from the left shift register to the right shift register 1 Open and examine the block diagram 2 Run the VI Click a button The corresponding digital indicator should increment each time you click a button 3 Close the VI Do not save any changes End of Exercise 2 4 National Instruments Corporation 2 23 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels C Property Nodes In some applications you might want to programmatically modify the appearance of front panel objects in response to certain inputs For example if a user enters an invalid password you might want to cause a red LED to start blinking Another example would be changing the color of a trace ona chart When data points are above a certain threshold you might want to show a red trace instead of a green one Resizing front panel objects hiding parts of the front panel and adding cursors to graphs also can be done programmatically using Property Nodes Property Nodes in LabVIEW are very powerful and have many uses This course only covers one use for Property Nodes to change the appearance and functional characteristics of front panel objects programmatically You can set properties such as display colors visibility position size blinking menu strings graph or chart scales graph cursors and many more Refer to the Help Contents and Index in LabVIEW for more information about the Property N
80. an use the LabVIEW file I O functions to work with text binary or datalog files The same basic operations of Open File Read File Write File and Close File work with all types of files Text Files Text files are files in which all data 1s stored as readable text characters Text files are useful because almost all software applications and operating systems can read them However text files can be larger than necessary and therefore slower to access It 1s also very difficult to perform random access file I O with text files You typically use text files when e Other users or applications will need access to the data file e You do not need random access reading or writing in the data file e Disk space and file I O speed are not crucial Binary Files Binary data files are files in which data is stored in binary format without any conversion to text representation Binary data files are generally smaller and thus faster to access Random access file I O presents no major difficulties However there is no industry standard format for binary files Thus you must keep precise records of the exact data types and header information used in binary files We recommend you use binary data files when e Other users or applications are unlikely to need access to your data e You need to perform random access file I O in the data file e Disk space and file I O speed are crucial Datalog Files Datalog files are a special type of binary
81. appears with the test name in it At this point if you try to select another pull down menu item you find that the menu is disabled this 1s caused by the block menu parameter of the Get Menu Selection function If you click OK on the dialog box the Item Tag indicator is cleared and the menu is re enabled by the Enable Menu Tracking function Also notice that the items from the Operate pull down menu 2 58 ni com Lesson 2 Designing Front Panels do not show up in the Item Tag string only User items are returned from the Get Menu Selection option To observe the flow of the VI you might want to turn on execution highlighting and single stepping and examine the block diagram Click Stop on the VI s front panel to halt program execution 11 Using the Menu Editor you can assign shortcut keys to User items you create Assign the keyboard shortcuts to the test options according to the following table Windows Keyboard Macintosh Keyboard Menu Item Shortcut Shortcut In addition to setting the previous shortcuts on a Windows platform you can assign an ALT keyboard shortcut to menu items This is accomplished by preceding the letter of the menu name for the shortcut with an underscore For example to assign ALI X to a menu item called Execute give the Execute option an Item Name of E xecute In this exercise assign ALI T to the Test option in the menu 12 Save the menu with the updated keyboard shortcuts and run the VI Now you
82. application repeatedly acquires data and writes it to disk you can improve the efficiency of the file I O operations if you do not open and close the file each time you access it The technique of leaving files open between the write operations is called disk streaming Disk streaming is a technique we have used in this course without describing its performance advantages Refer to Exercise 4 3 for an example of disk streaming The following examples show the advantages of using disk streaming In the first example the VI must open and close the file during each iteration of the loop The second example uses disk streaming to reduce the number of times the VI must interact with the operating system to open and close the file By opening the file once before the loop begins and closing it after the loop completes you save two file operations on each iteration of the loop Simple Error Close File Handier vi EJE LLEN E i Hii TE F Li File I O Example without Using Disk Streaming FILE En shop Disk streaming is especially important when you use the high level VIs such as Write To Spreadsheet File and Write Characters To File These VIs open write and close the file each time they run Thus if you call one of these VIs in a loop you perform unnecessary Open File and Close File operations during every iteration of the loop 4 20 ni com Lesson 4 Advanced File I O Techniques Summary Tips and Tricks You c
83. ata from the file c Place the Close File function located on the Functions File I O palette on the block diagram In this exercise this function closes the binary file after data has been read from it d Place the Simple Error Handler VI located on the Functions Time amp Dialog palette on the block diagram In the event of an error this VI displays a dialog box with information about the error and where it occurred e Place the Numeric constant located on the Functions Numeric palette on the block diagram You must create an 32 constant so the Read File function knows what data type to expect 32 is the default data type for numeric constants f Place the Numeric constant located on the Functions Numeric palette on the block diagram Create a double precision constant so the Read File function knows what data type to expect Because the default data type for numeric constants 1s 132 right click the constant and select Representation Double Precision Return to the front panel Save the VI as Binary File Reader vi Run the VI Open the data bin file created in Exercise 4 1 After the file opens the Read File function uses the byte stream type input which has a long integer four bytes wired to it to read the first four bytes from the file The function displays the number in the Number of Data Points indicator which shows how many numbers were stored in the file Recall that this header was created by the Write File fun
84. ations If you need to change this default configuration refer to the LabVIEW help The Web Server Browser Access window allows you to configure which browser addresses can view your VI front panels When a Web browser attempts to obtain a VI front panel image the Web Server compares the browser address to the entries in the Browser Access List to determine whether it should grant access If an entry in the Browser Access List matches the browser address the Web Server permits or denies access based on how you set up the entry By default all browsers have access to the LabVIEW Web Server Refer to the Context Help window for more information about the syntax used to specify browser access The WebServer Visible VIs window lets you specify which VIs are accessible to a Web browser When a Web browser attempts to obtain a VI front panel image the Web Server compares the VI name to the entries in the Visible VIs list to determine whether it should grant access If an entry in the Visible VIs list matches the VI name the Web Server permits or denies access to that VI image based on how you set up the entry By default the front panel images of all VIs are visible Refer to the Context Help window for more information about the syntax used to specify visible VIs Kp Note Use the LabVIEW Enterprise Connectivity Toolset to control VIs on the Web and to add more security features to VIs you publish on the Web Refer to the National Instruments We
85. ats in LabVIEW However datalog files like binary files do not have an industry standard format for storage Thus they are virtually impossible to read with software applications other than LabVIEW Datalog files are most useful if you intend to access the data only from LabVIEW and need to store complex data structures LabVIEW Basics II Course Manual 4 14 ni com Lesson 4 Advanced File 1 0 Techniques Exercise 4 3 Save Data to File VI Objective To finish a VI that saves data in a text binary or datalog file Kp Note Completing this VI enables the Log Results to File option in the Analyze and Present Data VI from Exercise 2 7 Recall that you will use Exercise 4 3 in the project in Lesson 5 In the application being developed you need to save a mixed data set to disk This data set contains simple numerics arrays of numerics and string data In addition this data is used only in LabVIEW Because of these requirements you will use datalog files to save the application s data subsets to disk Front Panel 1 Open the Save Data to File VI in exercises Basics2 directory The front panel is already built The two controls on the front panel are used to pass application data to this VI which functions as a subVI in the finished project The Data Cluster will contain the subset of analyzed data to save to disk and the Employee Name string will contain the Operator name to save to the file CCS 000 2 Open
86. b site for more information about this toolset LabVIEW Basics II Course Manual A 14 ni com Appendix The LabVIEW Web Publishing Tool You also can use the Tools Web Publishing Tool to create an HTML document and embed static or animated images of the front panel You also can embed images of the front panel in an existing HTML document Web Publishing Tool Document Title Sample Image not updated Generate amp Analyze Data Document Title Text 1 Text that is going to be displayed Test that is going to be displayed Before the image of the Yl Panel ee ee a Panel of FI Hame YI Hame PEEP Erb rr per rrrrridy Generate amp Analyze Data vi W Border Animated Text that is going to be displayed after the image of the WI panel Text 2 Text that is going to be displayed after the image of the VI Panel ef Save to Disk Click the Instructions button to display information about how to add a title to your HTML file and how to add text before and after your VI front panel Enter a VI name in the VI Name field or select Browse from the VI Name pull down menu and navigate to a VI Kp Note To display VI front panels on the Web the VIs must be in memory on your computer You can preview the document in your default browser by clicking the Start Web Server button and then clicking the Preview in Browser button If the Start Web Server button is dimmed the Web Server is already running When you click the Save to Di
87. bVIEW Basics II Course Manual The Performance Challenge VI performs the following tasks l Generates four runs of data Each run should consist of an array of 5 000 data points and a string containing a time stamp of when the data were taken Each element needs only digits of precision Saves all acquired data and associated time stamps to disk The file will be used only in LabVIEW applications so it does not need to be in any specific format Finds the maximum value in each run of data and plot 100 points around the maximum value to a waveform graph The final graph should contain four traces one for each run of data This VI is poorly written It runs slowly and takes more memory than necessary In this exercise optimize the VI to increase its run speed while decreasing its memory requirements l 2 Close all VIs you might have open Open the Performance Challenge VI Show the Profile window by selecting Tools Advanced Profile VIs Before running Performance Challenge select Timing Statistics and Timing Details in the Profile window so that you can gain a better understanding of the VI run time Run the VI After it finishes click the Snapshot button in the Profile window to view execution information for the VI When looking at this information notice how much time is taken updating local variables and also how many times this application calls the file I O subVIs Select File VI Properties Select Memory Usage
88. bal variable object that you want to access Global oe the node changes from the figure shown at left to display the object you have node chosen such as a numeric You might want to use this global variable in other VIs Because a global Cotai variable is a special kind of VI you can place it in other VIs using the Select node displaying a VI option in the Functions palette Then right click the node to select the ui specific object in the global variable you want to access as described above Kp Note A global variable front panel can contain references to many individual objects that are globally accessible You do not need to create a separate global variable VI for each item you need to globally access Read Globals and Write Globals Like local variables you can either read data from or write data to a global variable By default a global variable is write global when you create it You can write a new value into the global variable so a write global acts like an indicator You can change the configuration of a global variable so that it acts as a data source or a read global To do this right click the variable and select Change To Read On the block diagram a read global icon behaves like a control When this node executes on the block diagram the program reads the data in the associated front panel object To change a read global to a write global right click the variable and select Change To Write The global variable w
89. built in Exercise 2 2 Block Diagram 1 Make sure that the Application Exercise 5 1 VI is open You will not modify the front panel in this exercise Open the block diagram State Machine Ho Event Login Acquire Data 5 i i Analze amp Present 5 View File Stop EI Next State 1 No Event es Time Wavet ait Until Next ms Multic 100 Lis 2 Show Case 1 of the Case structure and delete the One Button Dialog function Add Acquire Data VI which you built in Exercise 2 2 If you did not finish that exercise use the VI from the solutions located on your computer 3 Add a shift register to the border of the While Loop Connect the Time Waveform output of the Acquire Data VI to the right side of the shift register 4 You must initialize the new shift register you created a Right click the left side of the shift register that contains the configuration cluster and select Create Control from the shortcut menu This creates an empty waveform control on the front panel b Hide this Time Waveform control by right clicking the terminal and selecting Hide Control fromt he shortcut menu This makes the waveform control invisible so it does not confuse users National Instruments Corporation 5 9 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW 5 Modify the VI Properties of the Acquire Data sub VI so that it appears like a dialog box when it is called Double click the
90. by the VI because the function creates a separate buffer to hold the converted data The coercion dot on the SGL array terminal indicates the function created a separate buffer to hold the converted data National Instruments Corporation 6 33 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Method 2 Incorrect fe VI Properties Memory Usage Method 2 is an attempt to remove the coercion dot by converting each array to SGL using the To Single Precision Float function located on the Functions Numeric Conversion palette However this method also increases the size of the data space because the function creates two new buffers C and D to hold the new SGL arrays LabVIEW Basics II Course Manual 6 34 ni com Lesson 6 Performance Issues Method 3 Correct VI Properties Memory Usage Method 3 reduces the size of the data space considerably from 24 8 KB to 12 8 KB This method converts the Random Number 0 1 function output to SGL before the array is created therefore this method creates two SGL arrays at the border of a For Loop rather than two DBL arrays National Instruments Corporation 6 35 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Simple vs Complicated Data Structures Simple Data Simple data types which include strings numbers Boolean data types clusters of numbers or Boolean data types and arrays of numbers or Boolean data types are referenced in memory O
91. cal Yarable GLOG men For example 1f the first object you create on the front panel is labeled number in the local variable icon appears as shown at left After you place the local variable on the block diagram you can select the appropriate front panel object by either clicking the variable using the Operating tool or right clicking it and selecting the front panel object from the Select Item menu 3 4 ni com Front Panel l Mumber In Switch 4 2110 00 String Iri m Read Locals and Write Locals You can either read data from or write data to a local variable After you place the local variable on the block diagram you must decide how to use it Humber Out 0 00 LED Lesson 3 Data Management Techniques Black Diagram Number Ir Change To Read Switch Help Stingin p Description and Tip Mumber OL Set Breakpoint Create Replace Open Front Panel By default a local variable assumes that it will receive data Thus this kind of local variable acts like an indicator and is a write local When you write new data into the local variable the associated front panel control or indicator updates to contain the new data You can change the configuration of a local variable so that it acts as a data source or a read local To do this right click the variable and select Change To Read On the block diagram a read local icon behaves just like a control When this node executes on the block diagram your
92. cales For each axis the VI can read or set the minimum maximum and increment values You also can use Property Nodes to programmatically read or set the plot and background colors and the X and Y grid colors You can use this capability to set plot or background colors depending on program conditions such as out of range or error values To change the size of a graph or chart use the Plot Area Size property Thus if you want to have a particular plot appear in a small window during part of your application but appear larger later you can use this property in conjunction with other properties that change the size of a VI s panel Using Property Nodes you have access to the information that cursors provide on graphs You use cursors to move a graphic selector on the plot A cursor can be locked to the plot or can float on the plotting surface Values from each cursor are returned to an optional display on the front panel Property Nodes present a means to programmatically set or read cursor position on the graph allowing user input from cursors in the VI National Instruments Corporation 2 37 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels X or Y Range Property The X or Y Range Property shown at left sets or reads the range and e increment for the graph axis The property accepts a cluster of five numeric values depending on the data type of the graph or chart X axis minimum value X axis maximum val
93. cally Operate the VI to make sure all the settings you chose are working Close the application when you are finished National Instruments Corporation 5 33 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW 16 Run the Setup exe file in the C myapp disks Myapplication directory You should be guided through a setup process the executable is created inside the C Program Files Myapplication directory and you should be able to run the application from Programs End of Exercise 5 5 LabVIEW Basics II Course Manual 5 34 ni com Lesson 5 Developing Larger Projects in LabVIEW Summary Tips and Tricks e LabVIEW has several features to assist you and your coworkers in developing your projects such as the VI Revision History window to record comments and modifications to a VI and the user login which when used with VI Revision History records who made changes to a VI You can access a VI s Revision History window at any time by selecting VI Revision History from the Tools menu e The VI Hierarchy window gives you a quick concise overview of the VIs used in your project There is also a comparison feature to identify the differences between two VIs e LabVIEW features several tools to facilitate larger project development The Source Code Control Tools contain several utilities for managing LabVIEW code and the Application Builder enables you to create stand alone executables or shared libraries
94. can apply the full purchase of this course kit towards the corresponding course registration fee if you register within 90 days of purchasing the kit Visit the Customer Education section of ni com for online course schedules syllabi training centers and class registration A About This Manual This course manual teaches you how to use LabVIEW to develop test and measurement data acquisition instrument control datalogging measurement analysis and report generation applications This course manual assumes that you are familiar with Windows Macintosh or UNIX that you have experience writing algorithms in the form of flowcharts or block diagrams and that you have taken the LabVIEW Basics I course or that you have equivalent experience The course manual is divided into lessons each covering a topic or a set of topics Each lesson consists of the following e An introduction that describes the purpose of the lesson and what you will learn e A description of the topics in the lesson e A set of exercises to reinforce those topics e A set of additional exercises to complete if time permits e A summary that outlines important concepts and skills taught in the lesson National Instruments Corporation SG 1 LabVIEW Basics II Course Manual Student Guide ip Auto Match vi File Edit Operate Tools Browse Window Help Several exercises in this manual use a plug in multifunction data acquisition DAQ device connected to a DAQ Si
95. ch 1D Array function returns a value of 1 which causes the While Loop to continuously execute state 1 Once a button is pressed however the index of the Boolean data types is used to determine the next state to execute Notice how the states of the VI correspond to the states in the table at the top of the exercise In later exercises you will substitute VIs that you create for the One Button Dialog functions to build the application 5 Click the Stop button on the VI s front panel to halt execution 6 Close the VI when you are finished End of Exercise 2 3 National Instruments Corporation 2 21 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Exercise 2 4 Cluster Conversion Example VI Optional Objective To examine a VI that uses clusters to process data You will examine a VI that uses clusters to process data The VI features a cluster containing four labeled buttons The VI keeps track of the number of times you click each button Front Panel 1 Open the Cluster Conversion Example VI in the c exercises LV Basics 2 directory LabVIEW Basics II Course Manual 2 22 ni com Lesson 2 Designing Front Panels Block Diagram Cluster constant Display Cluster F Cluster to Arra Jepe Be P Use the indes of the button to extract at i the corresponding element from the numeric cluster add 1 and replace a the element in the array Check if user clicks on button o 100 F
96. ction in the Binary File Writer VI in Exercise 4 1 The second Read File function reads the array of data points from the file using the byte stream type input which has a double precision floating point value wired to it The count input specifies how many values should be read from the file 6 Close the VI End of Exercise 4 2 LabVIEW Basics II Course Manual 4 12 ni com Lesson 4 Advanced File I O Techniques B LabVIEW Datalog Files If your data has a mixture of data types formatting it into text or binary strings for storage can be tedious or inefficient LabVIEW datalog files use a data storage format for saving records of data of an arbitrary data type For example you might want to save records of data that contain several hundred data points including a date and time stamp for each set A datalog file stores information as a series of records of any data type Although all of the records in a file must be of the same type those records can be arbitrarily complex Each record is written to the file as a cluster containing the data to be stored In the following example each record consists of a cluster containing the name of the test operator information about the test a time stamp and an array of numeric values for the actual test data Data Record Uperatar E Test Hame SE o Time Test Data Use the same file I O functions to work with datalog files that you use for byte stream files How
97. d password of a user LabVIEW Basics II Course Manual 1 16 ni com Lesson 1 Planning LabVIEW Applications Exercise 1 2 Verify Information VI Objective To build a VI that demonstrates the simple VI architecture You will build a VI that accepts a name and password and checks for a match in a table of employee information If the name and password match the confirmed name and a verification Boolean object are returned Kp Note You will use this VI in Lesson 3 Front Panel Hame Name Confirmed oe Joe String control E String indicator Limit to single line enabled Password verified O String control Round LED Password Display enabled Limit to single line enabled Employee Info Table Employee Name O Joe dog Table Fou Headers Visible Column Headers Visible Current Values Made Default 1 Open anew VI and build the previous front panel Modify the string controls as described in the labels by right clicking the control The Table control located on the Controls List amp Table palette is a two dimensional array of strings where the first cell 1s at element 0 0 2 Enter the information shown in the previous front panel in the Table and save those values as default by right clicking the Table and selecting Data Operations Make Current Value Default from the shortcut menu National Instruments Corporation 1 17 LabVIEW Basics II Course Manual Lesson 1 Planning LabVIEW Applications Block Di
98. dvantage of this VI architecture 1s that you can use wires to pass data This helps improve readability This also reduces the need for using global data and consequently makes it less likely that you will encounter race conditions You can use shift registers on the loop border to remember values from one iteration to the next to pass data as well Several disadvantages exist to the multiple case structure VI architecture First you can end up with block diagrams that are very large and consequently are hard to read edit and debug In addition because all event handlers are in the same loop each one is handled serially Consequently if an event takes a long time your loop cannot handle other events A related problem is that events are handled at the same rate because no event can repeat until all objects in the While Loop complete In some applications you might want to set the priority of user interface events to be fairly low compared to I O events National Instruments Corporation 1 19 LabVIEW Basics II Course Manual Lesson 1 Planning LabVIEW Applications State Machine VI Architecture LabVIEW Basics II Course Manual You can make the block diagrams more compact by using a single case structure to handle all of your events The State Machine VI architecture is a method for controlling the execution of VIs in a nonlinear fashion This programming technique is very useful in VIs that are easily split into several simpler tasks s
99. e STOP button to the Stop Button global variable object That value is then read in Data to Global 3 21 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques and passed to the conditional terminal to control its loop as well When you press the STOP button a TRUE passes through the global variable to Data to Global where that TRUE value is read to stop that VI as well 8 Close both VIs End of Exercise 3 4 LabVIEW Basics II Course Manual 3 22 ni com Lesson 3 Data Management Techniques D Important Advice about Local and Global Variables Initialize Local and Global Variables Verify that your local and global variables contain known data values before your program begins Otherwise the variables may contain data that causes the program to behave incorrectly If you do not initialize a local variable before reading data from it it will contain the current value of the control The first time your program reads a global variable it contains the default value of the object it reads unless you have previously initialized the global variable Race Conditions Local and global variables in LabVIEW do not behave like local and global variables in text based programming languages Recall that LabVIEW is a dataflow language not a sequential programming language Overusing local and global variables can lead to unexpected behavior in your program because functions might not execute in the order you expect Consider the
100. e block diagram or structure or in different structures or VIs When using global variables in VIs that execute in parallel you might want to use an additional Boolean global variable that indicates when a global variable s data has changed Other VIs can monitor this Boolean to see if the data has changed and read the new value Use Local and Global Variables Only When Necessary Local and global variables are powerful tools that you can use to accomplish useful goals For example you can create parallel loops on a single block diagram that are controlled with one front panel object or you can send data between separately running VIs However local and global variables are inherently not part of the LabVIEW dataflow programming concept Block diagrams can become more difficult to read when using local and global variables Race conditions can cause unpredictable behavior Accessing data stored in a local or global variable is slower than using dataflow and less memory efficient Therefore use local and global variables sparingly and only when necessary For example do not use locals and globals to avoid long wires across the block diagram or to access values in each frame of a sequence structure Consider the following block diagram LabVIEW Basics II Course Manual 3 24 ni com Lesson 3 Data Management Techniques This three frame sequence structure performs the usual tasks for all VIs Frame 0 reads the controls on the panel for c
101. e partially complete You will build a custom run time menu for this VI using the Menu Editor and complete the block diagram so that you can access this menu Select Edit Run Time Menu to display the Menu Editor dialog box If Henu Editor File Edit Help ltem Properties Wew ltem Type Open Application Item Close Close All ltem Mame File ltem Tag APP_FILE FF Enabled Page Setup Checked Print Print Window Shortcut Press key combination The current run time menu for the application is the LabVIEW default menu In the next several steps you will replace that menu with a custom list of selections Change the top ring control in the Menu Editor from Default to Custom The menu listed on the left portion of the dialog box should be replaced with a representing a single unnamed item In the Item Type ring control select Application Item Operate Entire Menu The LabVIEW Operate menu should be added to the custom menu Default LabVIEW options as well as selections you create can be added to a custom menu Take a moment to navigate the Operate menu in the editor Notice that you can select various items and collapse submenus using the triangle icons As you select individual items in the menu their Item Name and Item Tag appear in the Item Properties box of the editor When finished collapse the Operate menu by clicking the triangle next to the Operate option You should now see onl
102. e terminal on the block diagram and you might need to update or read a front panel object from several locations on the block diagram Using local variables you can access front panel objects in several places and pass data between structures that cannot be connected by a wire Creating Local Variables Local variable node number in Local variable icon with number in selected LabVIEW Basics II Course Manual There are two ways to create local variables on the block diagram If you have already created a front panel object you can create a local variable by right clicking the object or its terminal and selecting Create Local Variable from the pop up menu You can use this method on the front panel or the block diagram A local variable icon for the front panel object appears next to the terminal on the block diagram When you right click a terminal to create a local variable the local variable refers to the object you right clicked to create the icon You also can select Local Variable from the Structures palette A local variable node shown at left appears on the block diagram You can select the front panel object you want to access by right clicking the variable node and selecting an object from the Select Item menu This menu lists the owned labels for the front panel controls and indicators Thus always label your front panel controls and indicators with descriptive names using owned labels al ke Structures Lo
103. e the One Button Dialog function in Case 2 of the Case structure Add the Analyze amp Present Data VI to this case You completed this VI in Exercise 2 7 a Connect the string containing the operator name to the Operator input b Connect the waveform containing the collected data to the Data input 3 Show Case 3 of the Case structure and delete the One Button Dialog function Add the View Analysis File VI You do not need to make any connections to it 4 Save the VI as Application Exercise 5 3 viandrunit You should now be able to perform all of the options available in the menu after you log in with a valid name and password Kp Note You must select a subset of the acquired data when you select Analyze amp Present Data After you select the data subset click the Analyze button and then select the button to save the data to file Otherwise the file does not contain any waveform data End of Exercise 5 3 LabVIEW Basics II Course Manual 5 12 ni com Lesson 5 Developing Larger Projects in LabVIEW B LabVIEW Features for Project Development VI History One of the most useful LabVIEW tools for team oriented development is the VI Revision History window Every VI has a History window that displays the comments recorded by those who worked on the VI You can use the VI Revision History window to track changes and revisions to VIs and applications You can configure LabVIEW with several different VI Revision History options w
104. e this VI in Lesson 5 Front Panel LabVIEW Basics II Course Manual l Open the View Analysis File VI in exercises Basics2 directory This VI has already been built Data Collected by Data Cluster Data from File Data ES No of Points i 1 0 0 8 DC Value 0 6 fo oo a RMS Value 2o foon 3 02 Frequency Fo 0 6 Amplitude DE fo oo LE l Phase deg Return 2 Open the block diagram 4 18 ni com Lesson 4 Advanced File I O Techniques Block Diagram a False ER cc Select a data file E 5 d LE LE Data Collected by 3 Data Cluster Initial Cluster gj True case is empty 3 Examine the behavior of the VI If the user cancels the file dialog box nothing happens Notice that the datalog type input of the File Dialog function is wired to a dummy cluster of the same data type to be read This connection causes the LabVIEW file dialog to display only directories and files of the appropriate data type Once the file is selected the file 1s opened as a datalog file and a single data record 1s read Finally notice the use of error checking in this application 4 After you run the VI and test it close it Do not save any changes End of Exercise 4 4 National Instruments Corporation 4 19 LabVIEW Basics II Course Manual Lesson 4 Advanced File I O Techniques C Streaming Data to Disk LabVIEW Basics II Course Manual When your
105. ected Number of packets As shown above the DataSocket Server keeps track of the number of clients connected to it as well as how many packets of data have been exchanged You can select to have the DataSocket Server run hidden by selecting Hide DataSocket Server from the Server menu Broadcasting data with the DataSocket Server requires three actors a publisher the DataSocket Server and a subscriber A publishing application uses the DataSocket API to write data to the server A subscribing application uses the DataSocket API to read data from the server Both the publishing and the subscribing applications are clients of the DataSocket Server The three actors can reside on the same machine but more often the three actors run on different machines The ability to run the DataSocket Server on another machine improves performance and provides security by isolating network connections from your measurement application The DataSocket Server restricts access to data by administering security and permissions With DataSocket you can share confidential measurement data over the Internet while preventing access by unauthorized viewers A URL to Any Data Source Before you can start using the DataSocket functions in LabVIEW you need to understand how DataSocket connects to different I O technologies and how you name the device or resource you are transferring data to or from For example in file I O the resource name 1s a file path For T
106. ecting the Timing Details option The subcategories are Diagram Display Draw Tracking and Locals Refer to the LabVIEW Help or the LabVIEW User Manual for more information about these statistics The SubVIs statistic column shows the total execution time for all the subVIs called by the main VI In addition timing information can be displayed in seconds milliseconds or microseconds The Total Time statistic column shows the sum of the VI and subVIs values which represents the total execution time for the main VI If you select the Timing Statistics option four new categories of information appear Runs displays how many times each VI has been executed The Average value represents the VI time value divided by the Runs or the average amount of time the VI takes to run Shortest and Longest show the least and greatest amount of time required for a run of the VI Memory Statistics To collect memory statistics with the Profile window select the Profile Memory Usage option before starting the profiling session You also can select the Profile Memory Usage option after starting the Profiler to collect additional memory information The Profile window displays two sets of memory use data One set of data shows the number of bytes of memory used and the other shows the blocks of memory LabVIEW stores data such as arrays strings and paths in contiguous blocks of memory If a VI uses a large number of blocks of memory the memory can
107. elay ms 200 1501 100 50 E vertical pointer slide waveform chart 1 Open a new VI and build the front panel shown previously Block Diagram Mu Globals v1 Dats Value read global ait Until Next ms Multiple My Globals vi ime Delay ms amp Stop Button write global 2 Build the block diagram shown previously a While Loop available on the Functions Structures i palette Structures the VI to continue running until you press the Stop button Right click the Conditional terminal and select Stop If True a b Wait Until Next ms Multiple function available on the Functions Time amp Dialog palette Sets the loop rate Make sure the default is 20 iterations per second or 50 msec National Instruments Corporation 3 19 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques 3 My Globals VI global variables Pass values between two concurrently running VIs in this exercise These global variables were not created from a global variable node on this block diagram so the steps for creating and configuring them on this block diagram are as follows a Select Functions Select a VI and select My Globals vi from c exercises Basics 2 directory where you saved the global Global variable variable you created in Exercise 3 3 The global variable object node displayed in the node is either Stop Button or Data Value depending on the order in wh
108. elopment National Instruments Corporation 1 3 LabVIEW Basics II Course Manual Lesson 1 Planning LabVIEW Applications C Error Handling Techniques In the LabVIEW Basics I course you used the error in and error out clusters to pass error information between functions and subVIs These error clusters contain three pieces of information a status Boolean indicating a True value for an error a numeric that indicates the error number and the source string that displays which function or subVI generated the error You can use either the Unbundle or the Unbundle By Name function located on the Functions Cluster palette to extract this information as shown in the following block diagram Close File Simple Error Handler wi Unbundle By Name po Error clusters m The previous example illustrates a typical usage of the error in error out approach That is the File I O VIs and functions use error clusters to pass information from one operation to the next You can then use the error handling VIs from the bottom row of the Time amp Dialog palette to notify the user of any error conditions that occur The Error Handler VIs The Simple Error Handler takes the error in cluster or the error code value and if an error occurs opens a dialog box that describes the error and possible reasons for it You also can change the type of dialog box it opens from displaying an OK button to not display a dialog box at all or to display a dialog
109. elp window For example if the user clicks the Show Help button to show the Context Help window but closes the Context Help window from the Help Show Context Help menu your VI incorrectly assumes that the Context Help window is showing Save this VI as Application Exercise 5 7 vi Kp Note Use a Property Node to set the button text The mechanical action of the button should be Latch When Released Use a shift register to retain the status of the Context Help window s visibility and use the Control Help Window function to show and hide the Context Help window LabVIEW Basics II Course Manual 5 36 ni com Lesson 5 Developing Larger Projects in LabVIEW Notes National Instruments Corporation 5 37 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW Notes LabVIEW Basics II Course Manual 5 38 ni com Lesson 6 Performance Issues rer 4 A CRE This lesson describes how to maximize the performance of your VIs including how to improve run time speed and memory use You Will Learn About LabVIEW multithreading and multitasking How to use the Profile window About methods for speeding up your VIs How system memory issues affect LabVIEW performance ZOO Dw gt How to optimize memory use and related performance for individual VIs National Instruments Corporation 6 1 LabVIEW Basics II Course Manual Lesson 6 Performance Issues A LabVIEW Multithreading and Multitasking Ove
110. en implementing sub VISs for file I O you might need to account for different file formats For example if a third party application needs to read data acquired by LabVIEW you should save that data in text format because most applications have support for text files On the other hand if only LabVIEW will access the data and file size is critical binary files are a better choice Advanced File I O techniques and the built in file I O functions allow this flexibility You Will Learn How to work with byte stream files How to create and work with datalog files About streaming data to disk J OW gt About the advantages and disadvantages of text binary and datalog files Application SubVis You Will Build A Save Data to File VI B View Analysis File VI National Instruments Corporation 4 1 LabVIEW Basics II Course Manual Lesson 4 Advanced File I O Techniques A Working with Byte Stream Files LabVIEW s file I O functions make working with byte stream files or text and binary files quite simple You use the same functions to manipulate these files However when working with binary files the data 1s generally not in a readable form Also because you cannot rely on special characters such as the lt Tab gt and lt Return gt keys you must know the structure of the data stored in the file before reading it Without this knowledge you cannot successfully interpret the data stored in the binary file Fre
111. ensity Graph Example vi Objective To use an intensity graph You will use a VI that displays a wave interference pattern on an intensity graph You will also use the VI to plot a 2D array of data on the graph 1 Open and run the Intensity Graph Example VI in the c exercises LV Basics 2 directory By default the VI plots an interference waveform A Property Node on the block diagram defines the color range used in the intensity graph You can change the color range by opening the block diagram and modifying the Color Array constant User Data Intensity Graph gt y 3 00 gro 14 00 2110 00 11 00 2 5 00 2010 00 foo oo o o e 80 00 000 foo AC O0 oo 28000 280 00 AC O0 1 Ci t f Ti apnd mm mm Frequency Flot Uzer Data prae alu Interference Pattern Frequency me w rr Lau Amplitude IPH EE 2 Change the Plot switch on the front panel to User Data and enter values between 0 0 and 10 0 in the User Data array control Run the VI Notice how the magnitude of each element is mapped to the intensity graph User Data Intensity Graph 2 p 4 10 0 rl A J 2 ire m 0 0 0 Plat User Data l joins alu Interference Pattern Frequency a Lau Amplitude afu LabVIEW Basics II Course Manual 2 62 ni com Lesson 2 Designing Front Panels 3 Close the VI Do not save changes End of Exercise 2 10 National Instruments Corporation 2 63 LabVIEW
112. er For example Button 1 component 0 corresponds to the first element index 0 in the array Button 2 component 1 to the second element index 1 and so on National Instruments Corporation 219 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels boolean cluster boolean array J boolean cluster ati To ra boolean ara 1 Front Panel 2 Cluster Panel 3 Block Diagram The Array to Cluster function Functions Cluster and Functions Array palettes converts a 1D array to a cluster in which each component in the cluster is the same type as the array element Kp Note You must right click the function icon to set the number of components in the cluster The default number of components in the output cluster 1s nine You can combine the concept of a state machine with a Boolean menu cluster to provide a powerful system for menus For example perhaps you need to provide the following application which can be divided into a series of states potas Nae Value pete nae Name aS State 21 Default Keven Event Monitor Eee ado on the menu to determine Boolean button the next state pressed If no button is pressed next state is No Event l Configure Configure Acquire 2 acquisition LabVIEW Basics II Course Manual 2 16 ni com Lesson 2 Designing Front Panels The following is an example of a state machine for this application Menu Cluster Search 10 Arra ntil N ait U ext me Mu
113. erformance Issues Summary Tips and Tricks LabVIEW Basics II Course Manual Depending on the operating system LabVIEW uses either multithreading or co operative multitasking to perform tasks simultaneously With multithreading different tasks can use different execution threads whereas in a co operative multitasking system different tasks use the same execution thread Use the Profile window to gauge VI performance and to help you locate the tasks that require most of your VI s run time and memory use You can then concentrate on improving those troublesome areas to enhance the overall performance of your VI Use the following tips to speed up your VIs e Reduce the number of I O calls you make by reducing the amount of data you acquire or by acquiring more data in fewer calls e Reduce the number of controls and indicators you have on the front panel e Avoid using autoscaling on graphs and charts e Update graphs and charts with several points at a time not one point at a time e Force less important parallel tasks to wait using the Wait ms function so more crucial ones have more processor time e Avoid unnecessary computation in looping structures Although LabVIEW removes much of the difficulty in managing computer memory you also have less control over that process Remember you can monitor your computer s memory by accessing the Memory Usage page in the File VI Properties dialog box and in the Tools Ad
114. erties select the All Elements option from the property s shortcut menu For example you can access all the elements in the Position property by selecting Position All Elements or you can access a single element from that bundle Property Node Execution Order Property Node terminals execute from the top down For example in the waveform graph Property Node as follows the graph is first made visible Then Plot 0 is set as the active plot its color set to red and the name of the plot in the legend is updated Finally Plot 1 is set as the active plot its color set to green and the name of the plot in the legend is changed oF Execution Order Using the Context Help Window Use the LabVIEW Context Help window and the Help Contents and Index to find descriptions data types and acceptable values for Property Nodes With the Context Help window active pass the cursor over terminals in the Property Node to display information The following example shows help for both a single property and a cluster of several properties Property Disabled Disabled unsigned byte Can control be operated Ce O Enabled 1 Disabled Disabled Disabled amp Graved Out Test Selection Property Selection Text Selection cluster of 2 elements Ca Selection Start unsigned long Ca Selection End unsigned long Text selection specihed in terme of character positions for the beginning and end of selection both inclusive
115. erty Nodes greatly expand graph and chart functionality by changing plot size adjusting the scale values and operating or reading Cursors Use the Context Help window to learn more about individual properties You can use Control References and refnums to access Property Nodes inside subVIs To create your own run time menus select Edit Run Time Menu to display the Menu Editor dialog box You can programmatically create and read run time menus with the functions in the Functions A pplication Control Menu palette You can use intensity charts and graphs to plot three dimensional data The third dimension is represented by different colors corresponding to a color mapping that you define Intensity charts and graphs are commonly used in conjunction with spectrum analysis temperature display and image processing 2 64 ni com Lesson 2 Designing Front Panels Additional Exercises 2 11 2 12 2 13 National Instruments Corporation Modify Exercise 2 4 by adding a cluster of four labeled buttons Each time you click a button in the new cluster decrement the display by one Use the front panel as follows to get started Save the Vilas Cluster Example 2 vi Add 1 Subtract 1 Display Cluster 1 L e o digital indicator cluster Representation gt 32 labeled button cluster Mech Acton Latch when released in a 7 Build a VI that manipulates a button control on the front panel
116. esson 5 Developing Larger Projects in LabVIEW 10 Click the VI Settings tab Leave these settings at their default values the top level VI runs when opened and the block diagrams and front panels are only saved if they are necessary Examine these settings they should resemble the following examples Build Application or Shared Library DLL New script Target Source Files YI Settings Application Settings Installer Settings Use this page to specify changes to make to Vie as part of the build process IF you are dynamically loading the panel of a Vl be sure to set the Remove Panel setting for the Vl to no Remove Panel Show Panel Run when Opened Al Waveform Scan wi Analyze amp Present Data wi Application Exercise wi Averaged OC AMS vi Basic Averaged DL AMS v1 Blackman window i Blackman H arris Window wi B AFF i ades wi 4 Selected file 11 Click the Application Settings tab This is where you would enable ActiveX settings or give your application a custom icon Leave the icon as the default LabVIEW icon Do not change any of these settings LabVIEW Basics II Course Manual 5 32 ni com Lesson 5 Developing Larger Projects in LabVIEW 12 Click the Installer Settings tab Build a distribution kit for your application that installs into the C Program Files Myapplication directory Configure the Installer tab as shown gt Build Application or Shared Library DLL New script Target
117. ever you use the data type input differently for datalog files To create a new datalog file wire a cluster matching the data record cluster to the datalog type terminal of the New File function This cluster specifies how the data is written to the file Then wire the actual data record to the data terminal of the Write File function The datalog type cluster wired to New File need not be an actual data record you need it only to establish the type of data that you can store in the file The following example shows how to create a new datalog file data record National Instruments Corporation 4 13 LabVIEW Basics II Course Manual Lesson 4 Advanced File I O Techniques To read the record of information from the datalog file you must wire an input to the datalog type of the Open File function that exactly matches the data type of the records stored in the file The following example shows how to open and read an existing datalog file Kp Note The cluster wired to the datalog type input of the Open File function must be identical to the cluster used to create the file and write data to it including numeric data types and cluster order When the count input of the Read File function remains unwired the function reads a single record from the datalog file If you wire an input to the count terminal Read File returns an array of records When to Use Datalog Files You can use datalog files to store and retrieve complex data form
118. ey can but sometimes they must allocate new buffers National Instruments Corporation 6 31 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Replace Aray Subset P Build Array Sting Subset To Double Precision Float l a Multiply Spreadsheet String To Array Concatenate Strings ET hcrement ae i gt 5 Match Pattern dre Array Subset abe oo oo Functions that Reuse Butters Functions that May Allocate New Buffers Functions that Allocate New Buffers Coercion and Consistent Data Types Consider the Random Number 0 1 function commonly used in the examples shown in this course This function produces double precision floating point DBL data Therefore DBL arrays are created at the border of For Loops To save memory you might consider using single precision floating point SGL arrays instead of DBL arrays Of the following three methods to create these SGL arrays one is correct and two are incorrect Recall that each DBL value requires 8 bytes of memory while each SGL value requires 4 bytes of memory LabVIEW Basics II Course Manual 6 32 ni com Lesson 6 Performance Issues Method 1 Incorrect FF copy of A Pe YI Properties Memory Usage Method 1 might be your first attempt to save data space memory You might think changing the representation of the array on the front panel FP to SGL can save space memory However this method does not affect the amount of memory needed
119. f which all subsequent allocations are performed When you load a VI its components are loaded into this block of memory Likewise when you run a VI all the memory that it manipulates is allocated from this block On the Macintosh you configure the amount of memory that LabVIEW allocates at launch time by selecting the Get Info option from the File menu in the Finder Note that if LabVIEW runs out of memory it cannot increase the size of this memory pool Therefore you should set this parameter as large as possible Make sure to leave enough memory for any other applications that you want to run at the same time as LabVIEW National Instruments Corporation 6 25 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Virtual Memory VI Components LabVIEW Basics II Course Manual When using Windows or Macintosh you can use virtual memory to increase the amount of memory available for your applications Virtual memory uses available disk space for RAM storage If you allocate a large amount of virtual memory applications perceive this as memory that is available for storage On the Macintosh you allocate virtual memory using the Memory device in the Control Panel folder Windows Sun and HP UX automatically manage virtual memory allocation LabVIEW does not differentiate between RAM and virtual memory The operating system hides the fact that the memory is virtual However accessing data stored in virtual memory is much s
120. file for saving and retrieving complex data structures in LabVIEW Like binary files they have no industry standard format We recommend using datalog files when e Your data is made up of mixed or complicated data types e Other users or applications are unlikely to need access to your data e Users who write VIs to access the data know the datalog structure Disk streaming is a technique of writing data to a file multiple times without closing the file after each write operation Recall that the high level file VIs open and close files each time they run incurring unnecessary overhead in each iteration of the loop National Instruments Corporation 4 21 LabVIEW Basics II Course Manual Lesson 4 Advanced File I O Techniques Additional Exercises 4 5 Write a VI that uses the Advanced file I O functions to create a new file Then write to that file a single string composed of a string input by the user concatenated with a number converted to a text string using the Format Into String function Name the VI File Writer vl 4 6 Write a VI that uses the Advanced File I O functions to read the file created in Exercise 4 5 Name the VI File Reader vi W Tip Use the EOF function located on the File I O Advanced File Functions palette to obtain the length of the written file LabVIEW Basics II Course Manual 4 22 ni com Lesson 4 Advanced File I O Techniques Notes National Instruments Corporation 4 23 LabVIEW Basics II Course Man
121. file window Close the VI and do not save changes End of Exercise 6 5 National Instruments Corporation 6 41 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Exercise 6 6 Performance Enhancements VI Objective To improve the performance ofa VI LabVIEW Basics II Course Manual The Performance Enhancements VI was created to perform the following tasks 1 Acquire 1000 points of a waveform from a channel 2 Save this data to disk 3 Display the power spectrum of the acquired waveform The VI is poorly written The VI consumes a lot of memory runs slowly and is poorly documented In addition the VI does not give the desired results for waveforms above 60 Hertz This project requires you to utilize information from the previous chapter as well as draw upon other information in the course 1 Close all VIs you might have open 2 Open the Performance Enhancements VI in the Exercises LV Basics2 directory Show the Profile window by selecting Tools Advanced Profile VIs Select Timing Statistics in the Profile window 3 Run the VI After it finishes click the Snapshot button in the Profile window to view execution information about the VI Notice how many times VIs are called and which VIs being called multiple times are likely to be slow Notice which VIs were run many times and observe which VIs you guess are likely to take longer execution times 4 Select File VI Properties and select Memory Usage
122. formation The first four bytes contains the number of rows in the array the second four bytes contains the number of columns As shown in the following example you can read the binary file from the previous examples by using the Read File function Notice that the byte stream type input of the Read File function has a two dimensional array of single precision numbers wired to it The Read File function uses only the data type of this input to read the data in the file assuming that it has the correct header information for that data type Random Access in Byte Stream Files If you store arrays of numeric data in a file you might find it necessary to access data at random locations in the file You cannot randomly access data stored in text files when the data contains negative signs varying number of digits in individual data points and other factors For example if you have an array of 100 numbers ranging in value from 0 to 1 000 you cannot predict where a given element in the array is located within the text file The problem is that in text the number 345 requires three bytes of storage while the number 2 requires only one byte Therefore you cannot predict the location of an arbitrary array element in the file Such obstacles do not occur in binary files In a binary file the flattened format of a number in LabVIEW is a binary image of the number itself Therefore each number in the array uses a fixed number of bytes of storage
123. fragment which degrades LabVIEW performance in general not VI execution The Average Bytes statistic column shows the average number of bytes of memory used by a VI s data space during its execution Min Bytes and Max Bytes represent the least and greatest amount of memory used by a VI during an individual run Average Blocks indicates how many blocks of memory a VI needs on average while the Min Blocks and Max Blocks show the fewest and greatest number of blocks of memory used by a VI during an individual run National Instruments Corporation 6 7 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Exercise 6 1 The Profile Window Objective To use the Profile window to get information about how your application VI runs The Profile window is a powerful tool for analyzing how your application uses execution time as well as memory With this information you can identify the areas of your VI that you need to optimize In this exercise examine the project just completed using the Profile window 1 Open your final project called CD Application Exercise VI If you did not complete this final project you can open the solution 2 Before running your final project select Tools Advanced Profile VIs to display the Profile window The Profile window is not yet capturing data LabVIEW Basics II Course Manual 6 8 ni com Lesson 6 Performance Issues IB Profile Start Snapshot D Timing Statistics Time in milizeco
124. global variable node Place controls and indicators on the front panel in the same way you place them on a standard VI s front panel Kp Note You must label each control or indicator with an owned label because a global variable refers to an item by its name The following example shows a global variable front panel with three objects a numeric a string and a cluster containing a digital and a Boolean control Notice that the toolbar in the window does not show the Same items as a normal front panel gt Global 2 File Edit Operate Tools Browse Window Help Tapt Application Fort wi Cluster Numeric goo Item 1 200 00 er ltem 2 String After you finish placing objects on the global variable s front panel save the global variable and return to the block diagram of the original VI Select the specific object in the global variable VI that you want to access To select a specific object right click the global variable node and select the object from the Select Item menu This menu lists the owned labels for all the objects on the panel Notice that you also can open the front panel containing the objects in the global variable from this pop up menu National Instruments Corporation 3 15 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques You also can click the node with the Operating tool and select the global variable you want to access CH c After you select the specific glo
125. gnal Accessory containing a temperature sensor function generator and LEDs If you do not have this hardware you still can complete most of the exercises Be sure to use the demo versions of the VIs when you are working through exercises Exercises that explicitly require hardware are indicated with an icon shown at left You also can substitute other hardware for those previously mentioned For example you can use another National Instruments DAQ device connected to a signal source such as a function generator Each exercise shows a picture of a finished front panel and block diagram after you run the VI as shown in the following illustration After each block diagram picture is a description of each object in the block diagram File Edit Operate Tools Browse Window Help Number to Match 950 digital control Data Range in 0 Max 10000 Inc 1 Default 50 Out of Range gt Coerce Precision 0 1 Front Panel LabVIEW Basics II Course Manual F3 LeemOies ses sell olx N A Current Number 50 digital indicator Precision 0 of iterations 4725 digital indicator Precision 0 Number to Match of iterations gt DBL i starts at 0 so increment by 1 2 Block Diagram 3 Comments do not enter these SG 2 ni com Student Guide B What You Need to Get Started Before you use this course manual make sure you have all of the following items Q Wind
126. h e Plan for future modifications and additions LabVIEW Basics II Course Manual 1 2 ni com Lesson Planning LabVIEW Applications B The Implementation Process After completing the planning process implement your application by developing subVIs that correspond to flowchart nodes Although you cannot always use this approach it helps to modularize your application By clearly defining a hierarchy of your application s requirements you create a blueprint for the organization of the VIs you develop In addition modularization makes it much easier for you to test small portions of an application and later combine them If you build an entire application on one block diagram without subVIs you might not be able to start testing until you have developed the majority of the application At that point it is very cumbersome to debug problems that might arise Further by testing smaller more specific VIs you can determine initial design flaws and correct them before investing hours of implementation time By planning modular hierarchical development it is easier to maintain control of the source code for your project and keep abreast of the project s status Another advantage of using subVIs is that future modifications and improvements to the application will be much easier to implement After you build and test the necessary subVIs you will use them to complete your LabVIEW application This is the bottom up portion of the dev
127. he existing one The modified slider is shown on the front panel Kp Note You can save controls that you create like you save VIs You can load saved controls using Select a Control from the Controls palette Controls have a ct1 extension 7 Manipulate the slider and watch the meter track its data value 8 Close the VI Do not save changes End of Exercise A 2 National Instruments Corporation A 11 LabVIEW Basics II Course Manual Appendix Exercise A 3 Custom Picture Exercise VI Objective To create a custom Boolean indicator Build a VI that uses custom Boolean indicators to show the state of a Bunsen burner and flask being heated The pictures representing the on and off states of the Bunsen burner and the flask are already drawn for you Front Panel Burner Switch 1 Open the Custom Picture Exercise VI in exercises Basics2 directory The VI contains a vertical rocker switch to turn the Bunsen burner on and off and a button to quit the application It also contains two graphics representing the on and off states of the Bunsen burner and two graphics representing the boiling and non boiling states of the flask 2 To create the custom flask Boolean object complete the following steps a Right click an open area on the front panel and select Square LED from the Controls Classic Controls Boolean palette Label the LED Flask b Using the Positioning tool select the graphic that shows the contents of the fla
128. he first page of the Tab Control LabVIEW Basics II Course Manual 2 10 ni com Lesson 2 Designing Front Panels 3 Name the two pages of the tab control Simulate and DAQ respectively National Instruments Corporation Click the DAQ page and add the objects as follows le em EE EARN 1 0 rails ii i i Je E il ll H of Paints Be al vi 200 D5 Sampling Rate 4 D es a a0 5 0m 15 0m 200m Fou ime ra 6 17 5k Power Spectrum ha d 0 5 5 k 20 0k 0 4 TS averaging parameters averaging mode SNo averaging weighting mode O 1 E sponential number of averages I I I l i l 00 10000 2000 0 3000 0 4000 0 5000 0 6000 0 STOF iia Frequency Amplitude La Le 0 0 Save this VI as Acquire Data vi Right click the DAQ Channel Name control and make sure the Allow Undefined Names option is selected To change the scale on the knob to read 20 0k instead of 20 000 right click the knob and select Format amp Precision Select Engineering Notation and the k is added to represent one thousand 2 11 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Block Diagram Time Waveform Po oise Amplitude A averaging 4 parameters p Uniform White Noise Waveform wi A AL rn Peo Po Pe Poe eo Pee Pe ee Pee PoP Po Unbundle By Mame ait Until Nest me Multiple LD status 7 Open and mod
129. he hierarchies of all top level VIs in memory You can use the options available in the toolbar at the top of the Hierarchy window to show or hide various categories of objects used in the hierarchy such as global variables or VIs shipped with LabVIEW as well as whether the hierarchy expands horizontally or vertically Clicking the small arrow appearing next to a VI expands or collapses the view of that VI s hierarchy Thus you can expand different branches of the overall hierarchy 5 14 ni com Lesson 5 Developing Larger Projects in LabVIEW The following Hierarchy window contains the hierarchy of the application you completed in the previous exercise The VIs from the LabVIEW vi lib directory are not shown The entire hierarchy is shown by right clicking a blank area of the window and choosing Show All VIs Redo Layout Horizontal Layout Include Globals Vertical Layout Include VI Library Include Type Def it Hierarchy Window HONG Ven Took dyse Yindow He Ajs Ier Top Level APE Y Apolication Exerciee 5 3 v1 As you move the cursor over the icons shown in the Hierarchy window the name of the VI follows the VI You can double click an icon to open the VI You can also locate a VI in the hierarchy by typing in the name of a VI while in the Hierarchy window As you type the name the Hierarchy window scrolls to the appropriate VI You can also use the Find feature to search the Hierarchy window for a VI The Hierarchy wi
130. he reported memory requirements of a VI Saving the VI purges the copies generated by Undo resulting in accurate reports of memory information LabVIEW Basics II Course Manual 6 28 ni com Lesson 6 Performance Issues General Rules for Better Memory Use Use the following rules to create VIs that use memory efficiently Breaking a VI into subVIs usually improves memory use because LabVIEW can reclaim subVI data memory when the subVI is not executing Do not overuse global and local variables to store arrays or strings reading a global or local variable generates a copy of the data stored in the variable On open front panels display large arrays and strings only when necessary Indicators on open front panels retain a copy of the data that they display If the front panel of a subVI will not be displayed do not leave unused Property Nodes on the subVI Property Nodes cause the front panel of a subVI to remain in memory which increases memory use Do not use the Suspend Data Range option on time or memory critical VIs The front panel for the subVI needs to be loaded for range checking and extra copies of data are made for the subVI controls and indicators When designing block diagrams watch for places where the size of an input is different from the size of an output For example if you frequently increase the size of an array or string using the Build Array or Concatenate Strings function you generate copies of data increa
131. hich apply on a global or per VI basis using the LabVIEW preferences in Tools Options or File VI Properties To open the Revision History window for a VI select Tools VI Revision History fe Maximized Performance vi History User crystald Nest Revizion 14 Comment Updated diagram for L 6 0 performance issues Ww History Reset Add UE rev 19 Tue Jul 25 2000 10 13 05 4M crystal Updated panel to LY 6 0 objects rev 11 Thu Dec 18 1997 11 37 29 AM Ron Grasse Revised exercise for multithreaded Labview and faster computers rev Z Mon Feb 14 1996 3 06 03 PM stevena Y was converted from Lab lE version 4 06175 to Lab version 4 0 _ After typing your comments into the Comment area of the Revision History window click Add to add them to the VI s history The VI Revision History window also keeps track of revision numbers Each time you save the VI the revision number for the VI increments by one In addition to the revision number and the date and time at which a comment is added to a VPs history the current user s name appears in the User field You can configure the LabVIEW preferences to prompt for a user name at launch time by selecting Revision History from the top pull down menu in the Tools Options dialog box or you can change the user name by selecting Tools User Name National Instruments Corporation 5 13 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Pro
132. ich they were placed on the global variable s front panel b Copy the global variable so that you have two instances one Stop Button global and one Data Value global To access a different global variable object click the node with the Operating tool and select the object you want c Change the Data Value global to a read global by right clicking the node and selecting Change To Read from the pop up menu The VI reads a value from the Data Value and passes the value to the waveform chart It also writes the current value of the STOP button to the Stop Button global variable object each time through the loop Using a global variable the Boolean value is read in the Data to Global VI to control its While Loop Save the VI as Display Global Data vi Switch to the Data to Global VI front panel and position the two front panels so both are visible 6 Run Data to Global Switch back to the Display Global Data VI and run it The waveform chart on the Display Global Data VI front panel displays the data Data to Global continually writes the value it calculates to the Data Value global variable object The following example shows the Display Global Data reading the global variable object and updating the chart LabVIEW Basics II Course Manual 3 20 ni com Lesson 3 Data Management Techniques Ha D LES RS File Edit Operate Toole Browse Window Help Value aM This is the data written 1 OU to the global variable digital indica
133. ics Click the Start button in the Profile window to begin a profiling session Do not gather any memory statistics 4 Run the Assembling Arrays VI To test the different array building methods click the Test button The Method indicator shows which method is being tested The VI tests six different methods 5 After running the test several times click the Snapshot button in the Profile window We will now describe the six different array building techniques and why the performance of these VIs differs Using the Profile window place a checkmark in the Timing Statistics checkbox and notice the average execution times shown National Instruments Corporation 6 39 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Number of Array Elements The Initialize Array function is slightly faster than an Auto Indexing For Loop In both instances the array size is known and LabVIEW can allocate the correct amount of memory only once Recall that resizing requires more execution time Therefore the Initialize Array function or an Auto Indexing For Loop are the best ways to create arrays Element Initialize Array Number of Array Elements Array Data A For Loop executes a predetermined number of times A While Loop does not so LabVIEW cannot predetermine how much memory to allocate if an array is built inside a While Loop When the array is built in a While Loop it is resized as needed Each resizing requires the operat
134. ides to exit the program or the program terminates for other reasons such as I O completion Shutdown This section usually takes care of closing files writing configuration information to disk or resetting I O to its default state The following block diagram shows this general architecture For simple applications the main application loop can be fairly straightforward When you have complicated user interfaces or multiple events such as user action I O triggers and so on this section can get more complicated The next few illustrations show design strategies you can use to design larger applications Enter your code here Stop lf True Li S Notice in the previous block diagram that the error cluster wires control the execution order of the three sections The While Loop cannot begin running until the Startup VI is finished running and returns the error cluster Consequently the Shutdown VI cannot run until the main program in the While Loop is finished and the error cluster is passed out of the loop Another thing to notice in the previous block diagram is the wait function A wait function is required in most loops especially 1f that loop is National Instruments Corporation 1 11 LabVIEW Basics II Course Manual Lesson 1 Planning LabVIEW Applications monitoring user input on the front panel Without the wait function the loop might run continuously so that it uses all of the computer s system resources The wait func
135. ify the block diagram as shown previously using the following components p a Place a Case structure located on the Functions Structures palette A on the block diagram When used with the tab control one case handles the Simulate page and the other case is for the DAQ page al b Place the AI Acquire Waveform VI located on the Functions Data Pti Acquisition Analog Input palette on the block diagram This VI acquires data from an analog input channel on the DAQ device Kp Note If you do not have a DAQ device or a DAQ Signal Accessory use the Demo Acquire Waveform VI located on the Functions User Libraries Basics 2 Course palette on the block diagram in place of the AI Acquire Waveform VI The Demo Acquire Waveform VI simulates acquiring data from an analog input channel at a specified sampling rate and returning the specified number of samples LabVIEW Basics II Course Manual 2 12 ni com Lesson 2 Designing Front Panels c Create a Cluster constant by right clicking the Case structure tunnel and selecting Create Constant from the shortcut menu This constant passes the default values for the error cluster out of the DAQ case Save the VI 9 Observe how you have added quite a bit of new functionality to this VI without adding a lot of extra code Using the Tab Control is a very efficient way to add new front panel objects to the user interface and also add block diagram functionality without having to enlarge the front panel
136. ilder includes functionality for creating installers in Windows Common tools for creating installers on a Macintosh are DragInstall and Vise On UNIX systems you can create a shell script to install your application The installers you create with the LabVIEW Application Builder install all files that are part of the source files list You must add all files that you want to install to this list By specifying custom destinations for source files you can create arbitrarily complex directory structures within the installation directory 5 26 ni com Lesson 5 Developing Larger Projects in LabVIEW You will learn about each of the steps and options of the Application Builder when you build an application in the next exercise After defining your build specifications using the LabVIEW Application Builder you will save those settings to disk in the form of a build script b1d file National Instruments Corporation 5 27 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW Exercise 5 5 My Application executable Objective To create a stand alone application with the Application Builder Kp Note You must have the Application Builder properly installed to run this example To determine whether it is installed select the Tools menu If the option Build Application or Shared Library DLL appears in the Tools menu then the Application Builder is properly installed Front Panel 1 Open the Application Exercise 5
137. ill change its data direction so that it receives data instead of providing data When this node executes on the block diagram the program sends new data into the global variable On the block diagram you can visually distinguish read globals from write globals just as you distinguish controls from indicators A read global has a thick border emphasizing that it is a data source A write global has a thin border because it acts as a data sink In the figure below both global variables refer to the same item on the global variable s front panel Read Global Write Global LabVIEW Basics II Course Manual 3 16 ni com Lesson 3 Data Management Techniques Exercise 3 3 Data to Global VI Objective To build a VI that writes data into a global variable Create a global variable and use it to send data to the VI in the next exercise Value ne j This is the data written joon to the global variable digital indicator 1 Open a new VI and build the front panel as shown previously Block Diagram DONC My Glabals v1 Stop Button write global ait Until Nest ms Multiple pau Globals vi Ley read global E 2 Build the block diagram as shown previously on a Sequence Structure available on the Functions Structures palette Initializes a global variable using artificial data dependency with the Boolean Constant available on the Functions Boolean palette and the While Loop OO O b While
138. ime 1 0 O0 4100 20 0 200 400 s500 Time National Instruments Corporation 2 39 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Exercise 2 6 Temperature Limit vi Objective To create a VI that uses Property Nodes to clear a waveform chart and notify the user if the data exceed a limit Front Panel LabVIEW Basics II Course Manual You will finish building a VI that uses Property Nodes to perform the following tasks l Set the delta X value of the chart to the sample rate in seconds Clear the waveform chart so it initially contains no data Change the color of a plot if the data exceed a certain value Make an alarm indicator blink if the data exceed a certain value Temperature 65 0 04 0 83 0 82 0 1 0 20 0 ue ro CS 76 0 75 0 US eV 24 0 30 0 40 0 a Data High Limit Date and Time Cut of Range e Open the Temperature Limit VI in the c exercises LV Basics 2 directory The front panel and a portion of the block diagram are already built for you 2 40 ni com Lesson 2 Designing Front Panels Block Diagram Sample Rate ms ait Until Next ms Multiple Temperature CE _ re cale Multiplier t Into Stri Points 4cquired Paints to 4cquire Abort ormat Into String Te ELEH Plot Color 1 Modify the VI so that it sets the delta X value to the sample rate and clears the Temperature chart before starting While the V
139. ing On the block diagram data is transferred from one function or VI to another by connecting them with a wire The data then flows from the producer to the consumer as shown below LabVIEW Basics II Course Manual 3 2 ni com Lesson 3 Data Management Techniques This approach does not work 1f you need to exchange data between block diagrams that run in parallel Parallel block diagrams can be in two parallel loops on the same block diagram or in two VIs that are called without any data flow dependency Consider the following block diagram This block diagram does not run the two loops in parallel because of the wire passing between the two subVIs The wire creates a data dependency where the second loop does not start until the first loop is finished and passes the data through its tunnel The only way to make the two loops run concurrently is to remove the wire connection However then the subVIs cannot pass data between each other unless you use another technique of data management This lesson describes local variables global variables and DataSocket as methods to pass data between parts of the same block diagram and between different block diagrams National Instruments Corporation 3 3 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques B Local Variables Up until now you have read data from or updated a front panel object using its terminal on the block diagram However a front panel object has only on
140. ing Front Panels 2 Save the VI under the same name 3 Run the VI to confirm that it behaves correctly Save and close the VI End of Exercise 2 6 LabVIEW Basics II Course Manual 2 42 ni com Exercise 2 7 Objective Lesson 2 Designing Front Panels Analyze amp Present Data vi To use Property Nodes with graph cursors You will create a VI in which you use graph cursors to select a subset of data for analysis In a later exercise you will build a subVI that saves the results to disk You will also use the Value property to initialize an indicator We Front Panel Er Ea National Instruments Corporation Note You will use this VI in the project in Lesson 5 Data Analysis Results Waveform Subset Amplitude 4 Mo of Points in Subset fon DEM melir RAMS Value 17 Frequency 45065 D Amplitude 2 57 Cursor o oo o7 Haa Phase aeie ro Analyze Selected Subset Log Results to File Peum Open the Analyze amp Present Data VI in the c exercises Lv Basics 2 directory The front panel for this VI is already built You will complete the block diagram 10 0m Time You will use the two cursors shown to select a subset of data to analyze A cursor can move freely or be locked to the plot You control this action using the Lock Control button at the far right side of the cursor display Movement locked to the plot points Movement unrestricted in the plot window In this e
141. ing data is costly both in terms of memory and performance The solution is to make the data structures as flat as possible In this case you could store the data in two arrays as shown in the following block diagram The first array is an array of strings The second array is a 2D array where each row is a given test s results In the following example the front panel contains new controls to store the data and the block diagram performs the same change to the test data as shown in the previous block diagram National Instruments Corporation 6 37 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Test Data A0 fu Li o be LabVIEW Basics II Course Manual 6 38 ni com Lesson 6 Performance Issues Exercise 6 5 Assembling Arrays VI Objective To observe the speed of building arrays using several different methods Load and run a VI that creates an array of numbers using several methods Using the Profile window compare the performance of VIs using For Loops While Loops Auto Indexing and the Build Array function to create arrays Also compare these methods with a technique that uses the Replace Array Element function on an existing array Front Panel Method Idle Number of Array Elements zj E onang 1 Close all other VIs that you might have open 2 Open the Assembling Arrays VI 3 To display the Profile window select Tools Advanced Profile VIs Select the option to display timing statist
142. ing if the operating system supports it If you want to verify that multithreading is enabled select Performance and Disk from the top pull down menu in the Tools Options dialog box You can check or uncheck the box labeled Run with multiple threads 6 2 ni com Lesson 6 Performance Issues ee Options Performance and Disk MF Deallocate memory as soon as possible Use default timer MF Check available disk space during launch Abort if less than KBytes 500 M Use default ardtess than KBytes 2000 I Use default i Run with multiple threads Cancel Changes to this option will take effect when you relaunch This option is available only on operating systems that support multithreading If you remove the checkmark from this checkbox the execution system behaves as though you have only a single thread Single thread execution removes some overhead from the execution system However you do not benefit from the advantages of multithreading such as multiple processor support and the ability for a higher priority operation to interrupt a long operation such as a screen redraw to get better responsiveness from the application Remove the checkmark from this checkbox for VIs that are not compatible with a multithreaded execution system Benefits One important benefit of multithreaded LabVIEW is the separation of the user interface from block diagram execution Any activities conducted in the user interface
143. ing system to allocate a new buffer and then copy the contents of the old buffer into the new larger buffer The more resizing that occurs the more time execution takes A For Loop requires less resizing so it executes faster than a While Loop Notice this difference when comparing the Average execution time for the For Loop using the Auto Indexing VI and While Loop using the Auto Indexing VI While Loop For Loop i or Loop Auto Indesing Auto Indexing Number of Array Elements If you can predetermine the maximum size of the array to be built then you can initialize this array and pass it into the While Loop Once inside the While Loop each element can be updated or replaced as needed This is somewhat efficient because the array does not need to be reallocated once it is passed into the While Loop This is still not as efficient as the For Loop or Initialize Array function LabVIEW Basics II Course Manual 6 40 ni com Lesson 6 Performance Issues Initialize Aray While Loop to Replace Elements Initialize Array Array Data Number of Array Elements Avoid using the Build Array function inside a loop Every time a new value is appended to the array LabVIEW must reallocate the buffer and copy the entire array to the new location Thus execution times for the Build Array function are the slowest Number of while Loop Number of For Loop Array Elements Build Array Array Elements Build Array 6 Close the Pro
144. ining the number of values written to the file The second instance writes the array of data to the file c Place the Close File function located on the Functions File I O palette on the block diagram In this exercise this function closes the binary file after data has been written to it d Place the Simple Error Handler VI located on the Functions Time amp Dialog palette on the block diagram In the event of an error this VI displays a dialog box with information about the error and where it occurred e To create this constant right click the pos mode input of the Write File function and select Create Constant Set the position mode to start to ensure that new data are written relative to the beginning of the file f To create this constant right click the function input of the Open Create Replace File VI and select Create Constant By selecting create or replace you allow the user to create a new file or overwrite an existing file 4cq g Place the Acquire Signal VI located on the Functions User Ae Libraries Basics II Course palette on the block diagram In this exercise this VI generates the waveform selected by the Select Waveform control National Instruments Corporation 4 9 LabVIEW Basics II Course Manual Lesson 4 Advanced File I O Techniques h Place the Array Size function located on the Functions gt Array palette on the block diagram In this exercise this function returns the number of element
145. ious boxes borders lines arrows circles and triangles HDecorations E E E Ou O ro 04 VA 2 6 ni com Lesson 2 Designing Front Panels Menus Menus are a good way to present most of a front panel s functionality in an orderly way and in a relatively small space This leaves room on the front panel for actions that are needed in an emergency items for beginners items needed for productivity and items that do not fit well into menus Also be sure to add menu shortcut keys for the frequently accessed items Later in this lesson you will learn how to create your own menus in a VI Automatic Resizing of Front Panel Objects As mentioned previously you can use the VI Properties Window Appearance options to modify the appearance of the front panel when a VI is running With the VI Properties Window Size options you can set the minimum size of a window keep the window proportion with screen changes and set front panel objects to resize in two different modes Most professional applications do not enlarge each and every control when the window changes size but pick a table graph or list to enlarge with the window leaving other objects near the window s edge To resize one front panel object with the front panel select that object and select Edit Scale Object With Panel The following exercise uses some of the techniques described to create a VI with a user interfaces that is easy to use National Instr
146. issions file path group deny mode 2 error in 2 overnite F naiss i New File The Write File function on the Functions File I O palette writes data to an open file The behavior of this function varies slightly depending on whether you are writing data to a byte stream file or to a LabVIEW datalog file coner egl F nn anse header F ee E refnum ILEJE pos mode 0 21 pos offset 0 error in data Write File The Read File function on the Functions File I O palette reads data from an open file When reading byte stream files you can use the byte stream type input to indicate how LabVIEW should interpret data in the file We will describe this concept later in this lesson convert ggl F se line mode F ee 7 refnum ILE ES dup refnum pos mode 0 21 TR a data pos offset 0 FR offset eon In Ha Bor out count byte stream type Read File The Close File function on the Functions File I O palette closes the file associated with refnum refnum error I Close File National Instruments Corporation 4 3 LabVIEW Basics II Course Manual Lesson 4 Advanced File I O Techniques Byte Stream Files You can use the Write File function to create both types of byte stream files text and binary Creating a text file is as simple as sending a string containing characters to the Write File function 4 he file t When to Use Text Files Text files are useful and common for man
147. istinguish a text string from a binary string when writing the data to the file it places the data in the file The data terminal of the Write File function is polymorphic which means that it adapts to any kind of data you wire into it Thus you can create a binary file by wiring binary data to the Write File function in the previous example However you will find that header information is vital for interpreting the binary file For example if you wire a two dimensional array of numbers into the data terminal the Write File function places a byte for byte copy of the input data into the file It does not convert the numbers to text nor does it place LabVIEW Basics II Course Manual 4 4 ni com Lesson 4 Advanced File I O Techniques any information about the number of rows or columns in the array into the file Even if you know that the data were originally single precision floating point numbers you cannot successfully reconstruct the two dimensional array If the file contains 24 bytes of data and knowing that single precision floating point numbers use four bytes of memory each you can figure out that the array contained six values 24 4 6 However the original data might have been stored in a one dimensional array of six elements a two dimensional array with one row and six columns or a table with three columns and two rows When to Use Binary Files Compared to text files binary files require less disk space to store the same
148. jects in LabVIEW VI Hierarchy LabVIEW Basics II Course Manual One of the most important advantages of breaking your main application into subVIs is that you save memory In addition the responsiveness of the LabVIEW editor improves because smaller VIs are easier to handle Hierarchical applications are easier to develop read document and modify Therefore as a general rule it is recommended that you keep the block diagram for your top level VI under 500 KB in size In general your subVIs should be significantly smaller To check the size of a block diagram select Memory Usage from the top pull down menu in the File VI Properties dialog box Typically you should consider breaking a VI into several subVIs if the block diagram for your VI is too large to fit entirely on the screen i gt I Properties Category Menor Usage Front Panel Objects Block Diagram Objects Lode Data Total Total 1 Size On Disk Cancel If you find that the block diagram for a VI is getting too large you can convert part of it into a subVI by using Edit Create Sub VI This capability gives you a fast and easy method to create your application s VI hierarchy as you develop the source code The VI Hierarchy window is also a valuable tool for locating subVIs and viewing the overall layout of the project as your application grows To view the Hierarchy window select Browse Show VI Hierarchy A new window appears showing t
149. k diagram Save the VI under the same name Return to the front panel and run the VI Turn the Burner Switch on and off and notice the custom Boolean change Stop the VI by clicking the Quit button If you click the Quit button while the burner is on a dialog box notifies you that the burner must be off before you can shut down the system 10 Close the VI when you are finished End of Exercise A 3 A 13 LabVIEW Basics II Course Manual Appendix C The LabVIEW Web Server The Web is one of the most popular ways to share information and it is a good way to share your measurement and automation data LabVIEW contains several methods to help you publish your data to the web and create HTML documents Lesson 3 describes DataSocket and how it uses the URL method to describe and access LabVIEW data Another method is to use the LabVIEW Web Server to publish images of your VI front panels on the Web By default after you enable the Web Server all VIs are visible to all Web browsers However you can control browser access to the published front panels and configure which VIs are visible on the Web To display VI front panels on the Web the VIs must be in memory on your computer To configure the Web Server select Tools Options and select Web Server Configuration from the top pull down menu The Web Server Configuration window is where you enable the Web Server The default Web Server configuration is suitable for most applic
150. largest label first e Set the mechanical action to Latch When Released e Use Copy and Paste to create the other buttons e Use Align and Distribute to arrange the buttons National Instruments Corporation 2 19 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Block Diagram State Machine Mo Event 5 Login Check to see if a button in the Acquire Data cluster is pressed to determine Analyze amp Present 5 the next state to execute View File a Stop Initial State 1 Mo Event Next State 1 No Event Stop the Yl Hest State 1 Mo Event 1 Build the block diagram as shown previously a Place a While Loop located on the Functions Structures palette on the block diagram This structures the VI to continue to generate and analyze data until the user presses the Stop button Create the shift register by right clicking the left or right side border of the loop and selecting Add Shift Register from the shortcut menu LabVIEW Basics II Course Manual 2 20 ni com Lesson 2 Designing Front Panels b Place a Case structure located on the Functions Structures palette on the block diagram This structure makes the states for the state machine Add cases by right clicking the border of the Case structure Be sure to define the 1 case as being the default c Place the Wait Until Next ms Multiple function located on the Functions Time amp Dialog palette on the block diagram This f
151. le wi DD coess Verification vi 2 oof 300 300 aoo ep vi o 5 rocess Monitor wi DD ir O 0 0 0 w Analysis File wi 0 o 17 5 4 30 o o y a f 00 ea a a Notice that you must select the Profile Memory Usage option before starting a profiling session Collecting information about VI memory use adds a significant amount of overhead to VI execution which affects the accuracy of any timing statistics you gather during the profiling session Therefore you should perform memory profiling separate from time profiling Many of the options in the Profile window are available only after you begin a profiling session During a profiling session you can grab a snapshot of the available data and save the data to an ASCII spreadsheet file The timing measurements accumulate each time you run a VI Kp Note All statistics measured in a profiling session are collected for a complete run of a VI not a partial run of a VI LabVIEW Basics II Course Manual 6 6 ni com Lesson 6 Performance Issues Execution Time Statistics To collect execution time statistics with the Profile window click the Start button The previous example shows the Profile window after a time profiling session The VI Time statistic column shows the amount of time spent executing the VI and displaying its data as well as the time spent by the user interacting with the front panel This time consists of five subcategories which you can show by sel
152. lecting it from the Properties menu Right click this node and select Change To Write from the menu l Create the Limit Property Node on the block diagram To create this node right click the Limit terminal and select Create Property Node from the shortcut menu Select the Disabled property shown by right clicking the terminal and selecting it from the Properties menu Right click this node and select Change To Write from the menu Tank Vertical Position M Create the Tank Vertical Position Property Node on the block Disabled diagram To create this node right click the Tank Vertical Position terminal and select Create Property Node from the shortcut menu Select the Disabled property shown by right clicking the terminal and selecting it from the Properties menu Right click this node and select Change To Write from the menu n Create the Tank Horizontal Position Property Node on the block diagram To create this node right click the Tank Horizontal Position terminal and select Create Property Node from the shortcut menu Select the Disabled property shown by right clicking the terminal and selecting it from the Properties menu Right click this node and select Change To Write from the menu OU Save this VI as Property Node Exercise vi 4 Return to the front panel and run the VI Several things should be happening 5 First as new random numbers are generated and written to the tank the fill color is red if the rand
153. led Right click the terminal again and select Change To Write d Place the Select function located on the Functions Comparison palette on the block diagram This function takes a Boolean input and outputs the top value of 0 enabled if the Boolean is True and the bottom value of 2 disabled and grayed out if the Boolean is False a e Place a Numeric constant located on the Functions Numeric palette on the block diagram You will need two of these with a value of O and 2 for the Select function 3 Save this VI as Disable Controls vi Return to the front panel You will now build an icon and connector pane as follows for the VI Refnum Array Enable 6 Open the Property Node Exercise VI you built in Exercise 2 5 You will not modify the panel 7 Select File Save As and rename this VI Control Refs Exercise vi National Instruments Corporation 2 49 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Tank Horizontal Position Disable Tank Yertical Position 8 Open the block diagram and modify it as shown previously a Create Control References for the six controls by right clicking their terminals and selecting Create Reference from the shortcut menu b You use the Build Array function located on the Functions Array palette to combine all the control references into an array to pass it to the Disable Controls subVI located on the Functions Select A VI palette c You also need the
154. lish this Global variables are similar to local variables but instead of being limited to use in a single VI global variables can pass values between several VIs Consider the following example Suppose you have two VIs running simultaneously Each VI writes a data point to a waveform chart The first VI also contains a Boolean to terminate both VIs Remember that when both loops were on a single block diagram you needed to use a local variable to terminate the loops Now that each loop is in a separate VI you must use a global variable to terminate the loops Sine Wave H 1 0 Creating Global Variables Global variables are built in LabVIEW objects They appear as special VIs in the computer s memory A global variable has a front panel where you can place controls and indicators of any type However a global variable has no block diagram The front panel is simply a container from which you access data from other VIs LabVIEW Basics II Course Manual 3 14 ni com Lesson 3 Data Management Techniques ke Structures Global Variable Fecal re To create a global variable select Global Variable from the Structures palette A global variable node appears on the block diagram The icon for Se lable a global variable on the block diagram is similar to a local variable icon except that a small picture of a globe appears to the left of the global variable name Open the panel of a global variable by double clicking the
155. lower than accessing data stored in physical RAM With virtual memory you might occasionally notice more sluggish performance because data are swapped to and from the hard disk by the operating system Virtual memory can help run larger applications but it is probably not appropriate for applications that have critical time constraints VIs have the following major components e Front Panel e Block Diagram e Code block diagram compiled to machine code e Data control and indicator values default data block diagram constant data and so on When you load a VI LabVIEW loads the front panel the code if it matches the platform and the data for the VI into memory If the VI needs to be recompiled because of a change in platform or in the interface to a subVI LabVIEW also loads the block diagram into memory LabVIEW also loads the code and data space of subVIs into memory Under certain circumstances LabVIEW also loads the front panel of some subVIs into memory For example if the subVI uses Property Nodes LabVIEW must load the front panel because Property Nodes manipulate the characteristics of front panel controls As shown in the following example you can save memory by converting some of your VI components into subVIs If you create a single large VI with no subVIs the front panel code and data for that top level VI end up in memory If the VI is broken into subVIs the code for the top level VI is smaller and only the c
156. ltiple z CEE REEE EEE EEE PRIE yay ae En eget ghe gage Tey eg eye ae a a T e oT or T e oT or T 5 The front panel consists of a Boolean button cluster with each button triggering a state in the state machine In state 1 the No Event state the Boolean button cluster is checked to see if a button has been pressed The Search 1D Array function returns the index of the button pressed or 1 if no button is pressed to determine the next state to execute That state value is loaded into the shift register so that on the next iteration of the while loop the selected state will execute In each of the other states the shift register is loaded with the next state to execute using a numeric constant Normally this is state 1 so that the Boolean menu will be checked again but in state 1 Configure the subsequent state is state 2 Acquire National Instruments Corporation 2 17 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Exercise 2 3 Menu vi Objective To build the menu system for the sample application A set of dependencies exist between the different operations of the application to be built in this course Under most circumstances after performing a certain action the application should return to a No Event state in which the application should monitor a menu to see which button should be pressed The dependencies of the application can be described as a simple state machine
157. m a front panel object Right click any front panel object and select Data Operations DataSocket Connection to display the DataSocket Connection dialog box In the Connect To field enter a URL and select whether you want to publish subscribe or both Then check the Enabled box When you click the Attach button the front panel object is now available at the specified URL in the DataSocket Server A small rectangle in the top right of the control or indicator appears indicating the status of the DataSocket connection If the rectangle is green as shown below the connection is good Murneric 4 25 00 If the rectangle is gray there is no connection to the server at that time If the rectangle is red the connection has an error Now build two VIs that transfer data using DataSocket National Instruments Corporation 3 29 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques Exercise 3 5 DS Generate Data VI and DS Read Data VI Objective To build two Vis that use DataSocket to transfer data Build a VI that generates a random number and displays this value in a meter and sends the data to a DataSocket URL Then build a second VI that reads the DataSocket URL and displays the value in a slide Last use the automatic publish and subscribe features to send the data through a DataSocket connection Front Panel Meter UR L dstp localhost datal STOP 1 Open anew VI and build the front panel shown
158. m to the list of options 1s to press lt Shift Enter gt after entering the text for an item in the list Enter Zero for item 0 1in the list Sine for item one and so on To view the numeric value of the menu ring right click the control and select Visible Items Digital Display Macintosh lt Shift Return gt Sun lt Shift Return gt HP UX lt Shift Enter gt and Linux lt Shift Enter gt Kp Note The appearance of the menu ring control varies from one platform to the next Select Waveform Waveform Graph Sine Er l Menu Ring Elements ZETO Sne Square 5awtooth Representation U16 Amplitude Humber of Data Points 100 Digittal Indicator Representation gt laz 3 Open the block diagram LabVIEW Basics II Course Manual 4 8 ni com Lesson 4 Advanced File I O Techniques Block Diagram 4 Build the following block diagram Open Create Replace File v1 Write File Close File Simple Error Handler vi FILE create or replace eit Select Waveform Number of Data Points Wayvetorm Graph a Place the Open Create Replace File VI located on the Functions File I O palette on the block diagram This VI creates or replaces a file b Place the Write File function located on the Functions File I O palette on the block diagram This function appears twice in this exercise The first function writes the binary file s header information which is a four byte integer conta
159. main advantage of the Parallel Loops VI architecture is its ability to handle simultaneous multiple independent processes The main disadvantages of the parallel loop VI architecture lie in coordinating and communicating between different loops The Stop button LabVIEW Basics II Course Manual 1 12 ni com Lesson 1 Planning LabVIEW Applications for the second loop in the previous block diagram is a local variable You cannot use wires to pass data between loops because that would prevent the loops from running in parallel Instead you have to use some global technique for passing information between processes This can lead to race conditions where multiple tasks attempt to read and modify the same data simultaneously resulting in inconsistent results and are difficult to debug Kp Note Refer to Lesson 3 Data Management Techniques of this course for more information about global variables local variables and race conditions Multiple Case Structure VI Architecture The following block diagram shows how to design a VI that can handle multiple events that can pass data back and forth Instead of using multiple loops you can use a single loop that contains separate case structures for each event handler This VI architecture would also be used in the situation where you have several buttons on the front panel that each initiate different events The following FALSE cases are empty poo al z i Action Fax E code here An a
160. n in the plot where the cursor resides The Active Cursor property accepts an integer corresponding to the desired cursor when there is more than one cursor on the graph LabVIEW Basics II Course Manual 2 38 ni com Lesson 2 Designing Front Panels Cursor Position consists of a cluster of two floating point numbers representing the X and Y positions on the plot To create the Cursor Position property select Cursor Cursor Position AIl Elements Cursor Index accepts an integer corresponding to an element in the array plot To access the Cursor Index property select Cursor Cursor Index Wiring Example Place a cursor at position 55 5 34 8 When selecting the cursor the Active Cursor terminal must precede the Cursor Position terminal Because the node executes from top to bottom you can set another cursor s location by adding another set of Active Cursor and Cursor Position properties to this node Active Cursor aveform Graph 7 Plot Area Size Property To read or change the size of a graph or chart send new Width and Height values to the Plot Area Size property The Width and Height are in units of screen pixels Wiring Example Resize a graph to increase its width and height by 25 percent EL CO es 1 Plot4reaSize Before Execution After Execution Waveform Graph Waveform Graph 1 0 1 0 0 5 0 0 f 0 5 Do TX J5 Amplitude La gS I l I I I 00 100 20 0 300 40 0 50 0 T
161. n 2 9 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Exercise 2 2 Acquire Data vi Objective To modify a VI to use the Tab Control along with proper user interface design techniques You will modify the Generate amp Analyze VI so that it uses the tab control One page of the tab will be for the generation of data as before and a second page will be for acquiring the data from a DAQ device Kp Note You will use this VI in the project in Lesson 5 Front Panel i s Time Wawel Plot 0 See DAC d a 8 0 Sine Frequency Sine Amplitude IE 500 0 in 400 0 g w 5 20 Ml i 300 0 B HK pp L i 200 0 4 T iL La if Ge 100 0 2 a ne 0 i Sampling Info Noise Amplitude oo 50 0mm 100 0m 1500m 200 0m 10 Time Fs dl 0k Hs 2200 00 E j averaging parameters averaging mode No averaging weighting mode JE sponential D nam p j xl ily Y F i th w tt yy ri number of averages l l l I l 100 0 200 0 300 0 400 0 500 0 STOP _ sn Frequency 1 Open the Generate amp Analyze VI you built in Exercise 1 1 Resize the front panel to make room on the left of the other front panel objects as you will be adding the tab control 2 Place a Tab Control located on the Controls Array amp Cluster palette on the front panel as shown previously Select the Sine Frequency Sine Amplitude Sampling Info and Noise Amplitude controls and place them into t
162. n output To understand this concept we will look at an example that shows another use of local variables Below is a single string indicator Suppose you want to update that indicator to display the loop that is currently executing Without a local variable there is no way to accomplish this task You can place the indicator terminal in only one loop However using a local variable you can access the same front panel indicator from more than one location on the block diagram so that a single indicator displays the loop that is executing The Which Loop indicator is placed in Loop 1 and a local variable instance of that indicator is placed in Loop 2 Although this example is simple it shows how an indicator can be updated from two separate locations on the block diagram which Loop Aun Which Loop Loop Aba which Loop be LabVIEW Basics II Course Manual 3 8 ni com Lesson 3 Data Management Techniques Exercise 3 1 Login VI Objective To use local variables to initialize controls on the front panel Ky Note Use this VI in the project in Lesson 5 Front Panel Login Name Operator Name Access Granted Password Ss 1 Open the Login VI in the c exercises LV Basics 2 directory The front panel of the VI is already created Finish building the block diagram Block Diagram ccess Granted s 1 Complete the block diagram Notice that the local variables are enclosed in a single frame Sequence st
163. nch LabVIEW a palette called Basics 2 Course will be in the User Libraries palette of the Functions palette Optional Double click LVB2So1 exe to install the solutions to all exercises in the c solutions LV Basics 2 directory As shown in steps 1 and 2 of the Windows installation use a Windows based PC to extract the files and transfer them to your Macintosh If you do not have access to a PC contact National Instruments for uncompressed files Copy the files to your hard disk using the directory structure described in the Windows section As shown in steps 1 and 2 of the Windows installation use a Windows based PC to extract the files and transfer them to your workstation If you do not have access to a PC contact National Instruments for uncompressed files Mount the PC disk you are using to transfer the files The course assumes the directory structure described in the Windows section Copy all files to the appropriate location SG 4 ni com Student Guide D Course Goals and Non Goals This course prepares you to do the following e Understand the VI development process e Understand some common VI programming architectures e Design effective user interfaces front panels e Use data management techniques in VIs e Use advanced file I O techniques e Use LabVIEW to create your applications e Improve memory usage and performance of your VIs You will apply these concepts in Lesson 5 Developing La
164. ncy The design of subVIs also can reduce display overhead If subVIs have front panels that remain closed during execution none of the controls on the front panel can affect the overall VI execution speed As shown in the following block diagram you can reduce display overhead by minimizing the number of times your VI updates the display Drawing data on the screen is an I O operation similar to accessing a file or GPIB instrument For example you can update a waveform chart one point at a time or several points at a time You get much higher data display rates if you collect your chart data into arrays so that you can display several points at a time This way you reduce the amount of I O overhead required to update the indicator National Instruments Corporation 6 13 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Single Update Charting Multiple Update Charting Slower Method Faster Method Other Issues SubVI Overhead Each call to a sub VI involves a certain amount of overhead This overhead is fairly small on the order of tens of microseconds especially in comparison to I O overhead and display overhead which can range from milliseconds to tens of milliseconds However if you make 10 000 calls to a subVI in a loop the overhead could significantly affect your execution speed In this case you might consider embedding the loop in the subVI Another way to minimize subVI overhead is to turn your subVIs i
165. nd the precision to 4 Numeric D 31416E 0 aA LabVIEW Basics II Course Manual 2 30 ni com Lesson 2 Designing Front Panels Boolean Property Strings 4 o E ey Stringelt The Strings 4 property shown at left sets or reads the labels on a Boolean control The input is an array of four strings that correspond to the False True True Tracking and False Tracking states True and False On and Off states of the Boolean object True and False Tracking Temporary transition levels between the Boolean states True Tracking is the transition state when the Boolean object is changed from True to False The tracking applies only to Boolean objects with Switch When Released and Latch When Released mechanical actions These mechanical actions have a transitional state until you release the mouse The text strings True Tracking and False Tracking are displayed during the transitional state Wiring Example Set the display strings for the Switch control to the string choices Stop Run Stop and Run False state True state Boolean Boolean Un m STOP Run True tracking False tracking Boolean Boolean String Property Display Style C_i DizpStyle The Display Style property shown at left sets or reads the display for a string control or indicator An unsigned long integer determines the display mode 0 Normal Display 1 V Codes Display 2 Password Display 3 Hex Display National In
166. ndow can also be used a development tool when planning or implementing your project For example after developing a flowchart of the VIs required for an application you can create from the bottom of the hierarchy up each of these VIs so that they have all necessary inputs and outputs on their front panel and the subVIs they call on their block diagrams This will build the basic application hierarchy which will now appear in the Hierarchy window You can then begin to develop each subVI National Instruments Corporation 5 15 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW perhaps color coding their icons which will also be colored in the Hierarchy window to reflect their status For example white icons could represent untouched VIs red icons could represent subVIs in development and blue icons could represent completed VIs While this is only one example of using the Hierarchy window as a development tool it demonstrates the usefulness of this window for organizing a project Using Online Help in Your LabVIEW Applications As you put the finishing touches on your application you might want to provide online help to the user LabVIEW offers several mechanisms for doing this By using the Description and Tip option available on every front panel control and indicator you create not only well documented VIs but also VIs that have extensive online help available to the user If you select Help Show Co
167. nds PF Timing Details Profile Memory Usage M Memon Usage size in kilobytes Sub Vis Time TotalTime 3 To collect timing information about your final project place a checkmark in the Timing Statistics checkbox and click the Start button Snapshot Save M Timing Statistics Time in milizeconds Timing Details Profile Memory Usage Memon Usage size in kilobytes i Sub Vis Time You are now capturing timing information about the VIs in memory National Instruments Corporation 6 9 LabVIEW Basics II Course Manual Lesson 6 Performance Issues 4 Run the CD Application Exercise VI and go through the steps as 1f you were a typical user At any time you can return to the Profile window and take a snapshot of timing Taking a snapshot does not effect the final timing statistics 5 When you finish using your project return to the Profile window and click the Snapshot button again You can sort any column of data by clicking the column heading You also can select whether the timing Statistics are displayed in seconds milliseconds or microseconds By double clicking VIs listed in the Profile window you can view the Statistics of the VI that compose it This allows you to drill down to the subVIs to see where time is being spent You can display the front panel of the individual VIs by right clicking the VI listed in the Profile window Sort the Total Time column and look at where the CD Application
168. nds 0348 433466 New Zealand 09 914 0488 Norway 32 27 73 00 Poland 0 22 528 94 06 Portugal 351 1 726 9011 Singapore 2265886 Spain 91 640 0085 Sweden 08 587 895 00 Switzerland 056 200 51 51 Taiwan 02 2528 7227 United Kingdom 01635 523545 Contents Student Guide TOO gt Lesson 1 Planning LabVIEW Applications The Planning and Design Process The Implementation Process Error Handling Techniques LabVIEW Programming Architectures VI Templates ummary Tips and Tricks MOO W gt YN Lesson 2 Designing Front Panels A Basic User Interface Issues B Using Boolean Clusters as Menus C Property Nodes Common Properties D Graph and Chart Properties E Control References F LabVIEW Run Time Menus Optional G Intensity Plots Summary Tips and Tricks Additional Exercises National Instruments Corporation About This Manual What You Need to Get Started Installing the Course Software Course Goals and Non Goals Course Map Course Conventions iji LabVIEW Basics II Course Manual Contents Lesson 3 Data Management Techniques A Data Management Techniques in LabVIEW 3 2 Be Local WV arable RS RS tnt E een 3 4 Cs Gopal V AIA ICS RSR RE a Late ratio an doi tite 3 14 D Important Advice about Local and Global Variables cc ceeeeeseeeeeeeeeeees 3 23 D AS OCR Se de ee re 3 26 Summan PIDS Ad Tricks oreen araa a ER 3 35 ACCUTUONAlEX ICISES nement nine 3 36 Lesson 4 Advanced File
169. ng language independent and protocol independent DataSocket uses URLs to specify the specific data connection e DataSocket consists of two parts the DataSocket API and the DataSocket Server e The DataSocket API for LabVIEW consists of the Functions Communication DataSocket palette The two main functions are DataSocket Write and DataSocket Read e You can have any control or indicator publish and or subscribe data through the DataSocket Server by right clicking that front panel object and using the Data Operations DataSocket Connection window e You can use global and local variables to access a given set of values throughout your LabVIEW application These variables pass information between places in your application that cannot be connected by a wire e Local variables access front panel objects of the VI in which you placed the local variable e When you write to a local variable you update its corresponding front panel control or indicator e When you read from a local variable you read the current value of its corresponding front panel control or indicator e Global variables are built in LabVIEW objects that pass data between VIs They have front panels in which they store their data e Always write a value to a global variable before reading from it so that it has a known initial value when you access it e Write to local and global variables at locations separate from where you read them to avoid race condition
170. nstant located on the Functions String palette on the block diagram You will use two of these functions one in the True case and one in the False case If the names match but not the passwords or if neither match then an empty string 1s returned in the Name Confirmed indicator Place the Select function located on the Functions Comparison palette on the block diagram This function is used along with the password matching If the password matches the current name is sent to the Name Confirmed indicator otherwise the Empty String 1s sent Save this VI as Verify Information vi Go to the front panel and make sure you have some names the names do not have to be the same ones used in the course manual and passwords in the table control If you have not already done so right click the table and select Data Operations Make Current Values Default so that the names and passwords are permanently stored in the table National Instruments Corporation 1 19 LabVIEW Basics I Course Manual Lesson 1 Planning LabVIEW Applications 6 Enter values into the Name and Password controls and run the VI If the Name and Password match one of the rows in the table the name is returned in the Name Confirmed indicator and the Verified LED is lit Otherwise an empty string 1s returned and the Verified LED 1s off Be sure to try various combinations of names and passwords to make sure that this VI shows the correct behavior 7 Create an icon
171. nt panel the switch terminal in Loop 1 writes a FALSE value to the conditional terminal in Loop 1 Loop 2 reads the Loop Control local variable and writes a FALSE to Loop 2 s conditional terminal Thus the While Loops run in parallel and terminate simultaneously when the single front panel switch is turned off y Cac h Les Read This simple example demonstrates the need for local variables As previously shown using the local variable gives access to a single front panel object from several locations on the block diagram Local variables are also necessary when you cannot accomplish your goal using wires to carry the data Thus far you have learned that you can read input data from controls and send results to an indicator But for example what if you want to determine which parameters were used to run a VI previously and you want to place those values in controls for the users to modify How can you write those values into a control National Instruments Corporation 3 7 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques You cannot do this with standard controls and indicators Using local variables you can overcome this limitation You can update a control from the block diagram Also you can have any number of local variable references for a given front panel control with some in write mode and others in read mode With a local variable reference you can access a front panel object as both an input and a
172. ntext Help the Context Help window appears As you move the cursor over an object the Context Help window updates to show its description You can programmatically show or hide the Context Help window with the Get Help Window Status and Control Help Window functions which you find in the Functions Application Control Help palette Use this function to determine if the Context Help window is visible and the location of the upper left corner of the window Get Help Window Status With this function you can control whether the Context Help window is visible and where it will appear when shown Control Help Window You can also use the Control Online Help function to access the LabVIEW Help or custom help files that you compile using third party tools The type of online reference development tools you can use to develop this type of help file depend on the platform on which your application will run e Windows Microsoft Help hlp files e Macintosh QuickView e Sun HP UX HyperHelp LabVIEW Basics II Course Manual 5 16 ni com Lesson 5 Developing Larger Projects in LabVIEW With this function you manipulate an online help file You can list the contents of the help file jump to keywords in the file or close the online help file Operation ami String to search for HE Error Output Path to the help file Error Input Control Online Help Providing online help and reference materials for your application makes it ea
173. nto subroutines by selecting Execution from the top pull down menu in the File VI Properties dialog box However there are some trade offs Subroutines cannot display front panel data call timing or dialog box functions or multitask with other VIs Subroutines are generally most appropriate for VIs that do not require user interaction and are short frequently executed tasks Unnecessary Computation in Loops Avoid placing calculations in loops if the calculation produces the same value for every iteration Instead move the calculation out of the loop and pass the result into the loop For example consider the following two block diagrams The result of the division is the same every time through the loop SO you can increase performance by moving the division out of the loop Unnecessary Computation in Loop Only Necessary Computation in Loop Slower Method Faster Method LabVIEW Basics II Course Manual 6 14 ni com Lesson 6 Performance Issues Also avoid accessing local and global variables unnecessarily in loops For example the following first block diagram wastes time by reading from the global variable and writing to the global variable during each iteration of the loop If you know that the global variable is not read from or written to by another block diagram during the loop consider using shift registers to store the data as shown in the second block diagram Frequent Access to Global Variable Minimize Access to Global
174. o see at that time The example following shows a subVI that prompts the user for a login name It has error clusters because it is a subVI but the user does not need to see those items or the path name of the file gt Get Operator Name vi File Edit Operate Tools Browse Window Help Sfm 13pt Application Font This is the Pre UUT Loop step Please enter the operator s name here Operator Name Joe Smith Test report file path 4 error In no error error out status code status code The next example shows the same subVT after the front panel has been resized and the menu bar scrollbars and toolbar have been removed with the VI Properties Window Appearance Dialog option LabVIEW Basics II Course Manual 2 2 ni com Lesson 2 Designing Front Panels Fu 7 e Get Operator Hame vi This is the Pre UUT Loop step Please enter the operator s name here Operator Name Joe Smith Using Color Proper use of color can improve the appearance and functionality of your front panel Using too many colors however can result in color clashes that cause the front panels to look too busy and distracting Here are some color matching tips e Start with a gray scheme select one or two shades of gray and highlight colors that have good contrast with the background e Add highlight colors sparingly on plots abort buttons and perhaps the slider thumbs for important settings Small objects need brighter colors and mo
175. o vanish from the front panel when the LabVIEW Basics II Course Manual 2 24 ni com Lesson 2 Designing Front Panels Property Node receives the data Wiring a TRUE causes the control to reappear Wisible You can read the current state of a property by right clicking the Property Node terminal and selecting Change To Read When the Property Node is called it will output a Boolean TRUE if the control is visible or a Boolean FALSE if it is invisible From the terminal on the Property Node you can select properties by clicking the node with the Operating tool shown at left and selecting the Bo desired property from the shortcut menu ool You can read or set more than one property with the same node by enlarging 3 the Property Node Using the Positioning tool shown at left click the lower Positioning corner of the Property Node and drag the corner down to enlarge the node aa As you enlarge the node you add more terminals You can then associate each Property Node terminal with a property from its shortcut menu T r P a Some properties are clusters These clusters contain several properties that you can unbundle using the Unbundle function located on the Functions Cluster palette Writing to these properties requires the Bundle function as follows iting Bundled Properties National Instruments Corporation 2 25 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels To access bundled prop
176. ocate it when you are finished You also must be particularly careful not to accidentally write past the end of the memory you have allocated Failure to allocate memory or to allocate enough memory is one of the biggest mistakes that programmers make in text based programming languages LabVIEW s dataflow programming removes much of the difficulty of managing memory In LabVIEW you do not allocate variables nor assign values to and read values from them Instead you create a block diagram with graphical connections representing the transition of data Functions that generate data allocate storage for those data When data are no longer needed LabVIEW deallocates the associated memory When you add new information to an array or a string LabVIEW allocates the necessary memory This automatic memory handling is one of the chief benefits of LabVIEW However because it is automatic you have less control over it You should understand how LabVIEW allocates and deallocates memory so you can design applications with smaller memory requirements Also an understanding of how to minimize memory use can help you increase VI execution speed because memory allocation and copying data can take a considerable amount of time LabVIEW Memory Windows Sun and HP UX LabVIEW allocates memory dynamically taking as much as needed This process is transparent to the user Macintosh LabVIEW allocates a single block of memory at launch time out o
177. ock diagram This constant is used to color the panel objects through their Property Node You will need two of these constants Use the operating tool to select the color and make one red and the other blue Create the Tank Property Node on the block diagram To create this node right click the Tank terminal and select Create Property Node from the shortcut menu Resize this node by dragging the corner with the positioning tool to show three terminals Select the properties shown by right clicking each terminal and selecting the item from the Properties menu Right click this node and select Change All To Write from the menu Place the Bundle function located on the Functions Cluster palette on the block diagram This function clusters together the left and top positions into the Position property for the tank 2 34 ni com Lesson 2 Designing Front Panels j Create the Boolean Property Node on the block diagram To create this node right click the Boolean terminal and select Create Property Node from the shortcut menu Select the Disabled property shown by right clicking the terminal and selecting it from the Properties menu Right click this node and select Change To Write from the shortcut menu k Create the String Property Node on the block diagram To create this node right click the String terminal and select Create Property Node from the shortcut menu Select the Disabled property shown by right clicking the terminal and se
178. ode Creating Property Nodes You create Property Nodes by selecting the Create Property Node option from the shortcut menu of a front panel object or from its terminal on the block diagram Selecting Create Property Node creates a new node on the block diagram near the terminal for the object If the object has an owned label the Property Node has the same label You can change the label after creating the node You can create any number of Property Nodes for a front panel object Because there are many different properties for front panel objects we will cover only some of the common properties Select Help Contents amp Index to find information about a particular property Using Property Nodes When you create a Property Node it initially has one terminal representing a property you can modify for the corresponding front panel object Using this terminal on the Property Node you can either set write the property or read the current state of that property For example if you create a Property Node for a digital control it appears on the block diagram with the Visible property showing in its terminal A small arrow appears on the right side of that terminal indicating that you can read a value from the Visible property for the digital control You can change it to a write property by right clicking the node and selecting Change To Write from the shortcut menu Wiring a Boolean FALSE to that terminal will cause the digital control t
179. ode and data of the subVIs is in memory In some cases you might actually see lower run time memory use 6 26 ni com Lesson 6 Performance Issues block block block diagram iront panel diagram DELLE diagram Top Level VI always resident resident when necessary National Instruments Corporation 6 27 LabVIEW Basics II Course Manual Lesson 6 Performance Issues E Optimizing VI Memory Use This section describes specific issues about using VI memory more efficiently We will discuss how to monitor and improve your memory use and suggest ways to efficiently assemble and process arrays and data Structures How to Monitor Memory Use As shown in the following example select Memory Usage from the top pull down menu in the File VI Properties dialog box to get a breakdown of the memory usage for a specific VI The left column summarizes disk use and the right column summarizes how much RAM 1s used for the various components of the VI Notice that the information does not include memory use of subVIs i YI Properties Category Memon Usage Front Panel Objects Block Diagram Objects Code Data Total Total Yl Size On Disk Cancel You also can use the Profile window to monitor the memory used by all VIs in memory Kp Note When monitoring VI memory use be sure to save the VI before examining its memory requirements The LabVIEW Undo feature makes temporary copies of objects and data which can increase t
180. ollowing four subVIs Run the subVIs at least three or four times H loop iterations loop iterations H loop iterations gt Ress i DEL National Instruments Corporation 6 23 LabVIEW Basics II Course Manual Lesson 6 Performance Issues LabVIEW Basics II Course Manual 5 After running the subVIs several times stop the VI and click the Snapshot button in the Profile window Locate the Computation and Global Benchmark VI in the Profile window and double click it to display its subVIs if they are not already displayed Notice the amount of time spent in each subVI Specifically compare the amount of time spent executing Update Globals Inside Loop VI versus Globals Outside of Loop VI and the time spent executing Unnecessary Loop Computations VI versus Unnecessary Computations Removed VI Is this the behavior you expected How would you apply what you have learned in this exercise to your programming Click the Stop button in the Profile window to stop the profiling session Then close the Profile window 7 Close the VI Do not save any changes End of Exercise 6 4 6 24 ni com Lesson 6 Performance Issues D System Memory Issues LabVIEW transparently handles many of the details that you normally deal with in text based programming languages One of the main challenges of programming with a text based language is memory use In a text based programming language you must allocate memory before you use it and deall
181. om value is greater than the Limit value and the color is blue if the random value is less than the Limit 6 The two sliders change the position of the tank on the panel Move these values and see how the tank moves National Instruments Corporation 2 35 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels 7 The Disable switch controls whether you can change the values Flip the Disable switch to True and all the panel objects except the Disable switch and the Stop button are grayed out and you cannot change their values 8 Stop and close this VI when you are finished End of Exercise 2 5 LabVIEW Basics II Course Manual 2 36 ni com Lesson 2 Designing Front Panels D Graph and Chart Properties Property Nodes greatly enhance the programmatic flexibility of graphs and charts You can control most graph and chart features with Property Nodes Some of these properties are plot color X and Y scale information visibility of the legends and palette size of the plotting area and cursors Waveform Graph 1 0 Flot Legend 0 5 D o0 E I 0 5 Graph Falette a ba I I I I I I I I I I 0 0 1 00 Orn 300 Orn ROO Om 00 m 900 Om 1 0 Time re oa QI mme tt all pt nt iaiaeiaeiaa 2 ahh ririrbchoe z RERS i Cursor Legend Scale Legend You have many scale options for graphs and charts With Property Nodes you can set or read scale information for the X and Y s
182. omer Education Fax to Customer Education National Instruments Corporation National Instruments Corporation 11500 North Mopac Expressway 512 683 6837 Austin Texas 78759 3504 Course Evaluation Course Location Instructor Date Student Information optional Name Company Phone Instructor Please evaluate the instructor by checking the appropriate circle Unsatisfactory Poor Satisfactory Good Excellent Instructor s ability to communicate course concepts O O O O O Instructor s knowledge of the subject matter O O O O O Instructor s presentation skills O O O O O Instructor s sensitivity to class needs O O O O O Instructor s preparation for the class O O O O O Course Training facility quality O O O O O Training equipment quality O O O O O Was the hardware set up correctly O Yes O No The course length was O Too long O Justright O Too short The detail of topics covered in the course was O Too much O Justright O Not enough The course material was clear and easy to follow O Yes O No O Sometimes Did the course cover material as advertised O Yes O No I had the skills or knowledge I needed to attend this course O Yes O No Ifno howcould you have been better prepared for the course What were the strong points of the course What topics would you add to the course What part s of the course need to be condensed or removed What needs to be added to the course to make it better Are there others at your company who ha
183. on Wire a 10 constant value of 300 to the input of the function Notice how the speed of the Plot Loop changes Close the VI and do not save any changes If you are running LabVIEW on a multithreaded operating system place a checkmark in the Run with Multiple Threads checkbox on the Execution page in the File VI Properties dialog box Exit and restart LabVIEW Repeat steps 2 through 9 and notice how multithreading affects the execution speed of the Dialog amp SubVI Demo VI If you want to magnify the results of this exercise move windows with your cursor while the Dialog amp SubVI Demo VI runs This increases the processor workload creating more drastic results End of Exercise 6 3 6 22 ni com Lesson 6 Performance Issues Exercise 6 4 Computation amp Global Benchmark VI Objective To observe the effects of unnecessary computation and global variable activity on VI execution speed Use the Profile window to compare the performance of VIs that perform the same tasks using different programming techniques Front Panel Status Fe H loop iterations 75000 Run Sub y s 1 Close all other VIs you might have open 2 Open the Computation amp Global Benchmark VI The VI is already built for you 3 Select Tools Advanced Profile VIs Click the Start button in the Profile window Do not gather any memory statistics 4 Run the Computation amp Global Benchmark VI Click the Run SubVIs button to run the f
184. on is to break the application into an executable file and one Vi library In this packaging the application Builder embeds all top level and dynamic VIs in the resulting executable file and all subVIs of these VIs are placed in a single VI library While this package involves two files the file that the end user launches can be quite small Depending upon the nature of your application it can require the presence of non VI files to function correctly Files commonly needed include a preferences in1 file for the application the LabVIEW serpdrv file and any help files that your VIs call The LabVIEW serpdrv file Windows and UNIX is required for any application that uses serial port I O Note that run time menu files and shared library files called using the Call Library Node are not support files The Application Builder includes run time menu files in the main files for the application It automatically stores any shared libraries needed in the support file directory for the application External subroutines for CINs are also stored in the main files for the application Kp Note Refer to the LabVIEW Help in Help Contents and Index for more detailed descriptions of how to use the Application Builder and make a preferences file for your application LabVIEW Basics II Course Manual Building the Installer The last phase in creating a professional stand alone application with your VIs is to create an installer The LabVIEW application Bu
185. onfiguring the test system Frame 1 uses the local variables for the controls to acquire data and Frame 2 uses the locals to write the data to file Although there 1s nothing inherently wrong with using the sequence structure and the local variables in this way it is not the most efficient method of using dataflow programming When you look at one of the frames it is not obvious where the values for the locals are coming from and where they were last updated Dou sequence local sequence local The block diagram shown above eliminates the use of local variables by putting the original control terminals outside the sequence structure so that each frame of the sequence now has access to the values The data are passed between frames of the sequence through a sequence local umber of Readings The block diagram shown above removes the sequence structure and uses dataflow to define how the program works The error clusters define the execution order of the subVIs and also maintain the error conditions which are checked at the end with the error handler VI This is the most efficient way to build a program and manage data in LabVIEW Not only is the block diagram smaller and easier to read but passing data through wires 1s the most efficient method for memory use National Instruments Corporation 3 25 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques E DataSocket So far in this lesson you learned three main thing
186. ontext help for the polymorphic VI by selecting Documentation from the top pull down menu in the File VI Properties dialog box Yi Note Context help for the polymorphic VI is not associated with context help for the VIs that compose the polymorphic VI Therefore you must create new context help by using the Documentation page in the File VI Properties dialog box A polymorphic VI is a collection of subVIs with the same connector pane patterns Each subVI is an instance of the polymorphic VI When data are wired to a polymorphic subVI LabVIEW automatically chooses which instance to use based on the types of data wired to the inputs of the polymorphic subVI If the instance 1s not available a broken wire appears You can override LabVIEW s automatic selection by right clicking the polymorphic subVI and selecting a specific instance VI from the Select Type pull right menu National Instruments Corporation A 3 LabVIEW Basics II Course Manual Appendix Exercise A 1 Sort Poly Array Objective To create a polymorphic VI and use it as a subVI Using polymorphic VIs allows you to present a much simpler interface to the users of your VIs Consider the case of a polymorphic VI that can sort either 1D or 2D arrays Two individual VIs can do this function Sort 10 Array Sort 2D Array vi i i 7 Instead of having one VI for sorting 1D arrays and another sub VI for sorting 2D arrays one VI called Sort Array handles both types of inputs
187. or the access granted output the Operator indicator should show an empty string Yi Note The VI needs the Operator and Access Granted information in subsequent loop iterations Therefore this VI uses two more shift registers to store the data You will need to make sure that the other cases in the Case structure pass the data through correctly straight through the cases By using the shift registers notice that only Case 0 in which the Login VI runs can change the Operator and Access Granted values The loop verifies that the value stored in the Boolean shift register which is the Access Granted status is TRUE or if the user pressed the Login button component 0 in the menu cluster or Stop button component 4 to determine which case to execute If all of these conditions are FALSE then Case 1 executes 3 Run the VI and test it to make sure it behaves properly Use the LabVIEW debugging tools execution highlighting single stepping probes and breakpoints to determine the dataflow of the VI 4 Save the VI as Application Exercise 5 1 vi Do not close the VI End of Exercise 5 1 LabVIEW Basics II Course Manual 5 8 ni com Lesson 5 Developing Larger Projects in LabVIEW Exercise 5 2 Application Exercise 5 2 VI Objective To add the Acquire Data VI to the application started in Exercise 5 1 In the previous exercise you began building the Application Exercise VI Now you will add the Acquire Data VI which you
188. oving debugging code block diagrams and unnecessary front panels If you open a front panel dynamically using the VI Server you must specify that the front panel is needed using the VI Settings tab From the Application Settings tab you can customize the features in your application You can choose to specify the memory size for the Macintosh or customize icons and ActiveX server features on Windows From the Installer Settings tab Windows only you create an installer The installer is written to the directory that contains your application When you develop an executable VI with LabVIEW on Windows and ship it to another computer you must also include the LabVIEW Run Time DLL The computer on which the VI runs must install this DLL using the LabVIEW Run Time DLL Installer before the VI runs If you distribute a VI using Build Application the Run Time DLL is installed automatically Note After the Run Time DLL is properly installed on a machine it can run any executable VI developed in LabVIEW You need to include only the Run Time DLL with the first VI sent to each computer Creating LabVIEW Applications LabVIEW Basics II Course Manual To create a professional stand alone application with VIs you must understand four areas The architecture of your application Programming issues particular to the application 5 24 ni com Lesson 5 Developing Larger Projects in LabVIEW e How to build your application e How to build
189. ows Windows 95 or later installed on your computer Macintosh Power Macintosh running MacOS 7 6 1 or later UNIX Sun workstation running Solaris 2 5 or later and X Windows system software an HP 9000 workstation model 700 series running HP UX 10 20 or later or a PC running Linux kernel 2 0 x or later for the Intel x86 architecture Q Windows Multifunction DAQ device configured as device using Measurement amp Automation Explorer Macintosh Multifunction DAQ device in Slot 1 Q DAQ Signal Accessory wires and cable Q LabVIEW Professional Development System 6 0 or later Q Optional A word processing application such as Windows Notepad WordPad Macintosh TeachText UNIX Text Editor vi or vuepad Q LabVIEW Basics IT course disk containing the following files LVB2SW exe Self extracting archive containing VIs used in the course LVB2Sol exe Self extracting archive containing completed course exercises Text file describing how to install the course software National Instruments Corporation SG 3 LabVIEW Basics II Course Manual Student Guide C Installing the Course Software Windows Macintosh UNIX LabVIEW Basics II Course Manual Complete the following steps to install the LabVIEW Basics IT course software Run the program called LVB2SW exe The course files will be extracted to the c exercises LV Basics 2 directory Basics2 11b will be installed in the LabVIEW user 1ib directory When you lau
190. parate lines of operations that run in parallel in LabVIEW and each operation maintains their own error clusters You can use the Merge Errors VI to combine several error clusters into one error In no error error In 2 no error error In 2 no error The Merge Errors VI looks at the incoming error clusters or the array of error clusters and outputs the first error found If no errors occur LabVIEW returns the first warning message error code 1s a positive value Otherwise LabVIEW returns a no error condition National Instruments Corporation 1 5 LabVIEW Basics II Course Manual Lesson 1 Planning LabVIEW Applications Incorporating Error Handling into Your VIs You should build error handling into your own VIs in addition to using the error clusters for built in VIs and functions For example when you are building a subVI to use in a larger project you might not want that subVI to run if an error occurred previously You can wire the error cluster to a Case structure to get Error and No Error cases as shown in the following example Place code here to execute when no prior errors have occured As shown in the previous example you place the code you wish to run in the No Error case and then define the error out value for that case depending upon what is occurring in that case In the next exercise you will build a VI that generates data analyzes those data and presents the data to the front panel while using e
191. pplications array out of the table When you wire the table to the array input of this function two indices rows and columns appear Right click the bottom index columns and select Create Constant from the shortcut menu You will use two of these functions so make a copy of the Index Array function and place it into the True Case Place the Array Size function located on the Functions Array palette on the block diagram This function returns the size of the names array Place the Decrement function located on the Functions Numeric palette on the block diagram This function decreases the number of names in the array by one so that it can control the While Loop which starts indexing at 0 Place the Equal function located on the Functions Comparison palette on the block diagram You will use two of these functions to check if the Name input matches a table entry and if the Password also matches the table entry Place the Less Than function located on the Functions Comparison palette on the block diagram This function controls the While Loop conditional The loop continues to run while the current iteration number is less than the number of rows in the table Place the Not Or function located on the Functions Boolean palette on the block diagram This function also controls the conditional of the While Loop so that the loop continues until a match is found or there are no more rows in the table Place the Empty String co
192. program reads the data in the associated front panel control or indicator To change a read local to a write local right click the variable and select Change To Write The local variable will change its data direction so that it receives data instead of providing data On the block diagram you can visually distinguish read locals from write locals just as you distinguish controls from indicators A read local has a thick border emphasizing that it is a data source similar to a control A write local has a thin border because it acts like a data sink similar to an indicator In the following figure both local variables refer to the same item on the front panel Read Local number in Write Local number in National Instruments Corporation 3 5 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques Local Variable Example As an example of when you might need a local variable consider how you would use a single front panel switch to control two parallel While Loops Parallel While Loops are not connected by a wire and they execute simultaneously First we will study two unsuccessful methods using one terminal for the switch on the block diagram Methods 1 and 2 Then we will show how a local variable accomplishes the task Method 3 The front panel of this example VI appears below Loop Control Chart 1 Chart 2 S 1 1 0 0 5 0 0 Method 1 Incorrect As a first attempt we pl
193. programming techniques to obtain the best possible execution speed Consider the following three areas when speeding up your VIs e Input Output files instrument control data acquisition and networking e Screen display efficient controls and displays e Memory management efficient use of arrays strings and data Structures Other factors such as execution overhead and subVI call overhead usually have minimal effects on execution speed Input Output Input Output I O calls generally take much more time than a computational operation For example a simple serial port read operation can have an associated overhead of several milliseconds This overhead is present not only in LabVIEW but also in other applications The reason for this overhead is that an I O call involves transferring information through several layers of an operating system The best method of reducing this I O overhead is to minimize the number of I O calls you make in your application Structure your application so that you transfer larger amounts of data with each call instead of making several I O calls that transfer a small amount of data For example consider creating a data acquisition DAQ application that acquires 100 points of data For faster execution use a multi point data transfer function such as the AI Acquire Waveform VI instead of using a single point data transfer function such as the AI Sample Channel VI To acquire 100 points use the A
194. quently Used File 1 0 Functions Before describing byte stream files in detail we will first briefly review the basic LabVIEW file I O functions These functions are located on the Functions File I O and Functions File I O Advanced File Functions palettes Kp Note Refer to the Help Contents and Index for more information about these functions The File Dialog function on the File I O Advanced File Functions palette displays a file dialog box for file selection You can select new or existing files or directories from this dialog box We will describe the use of the datalog type input later in this lesson path select mode 2 eater default name hee cancelled paktter datalog type File Dialog The Open File function on the File I O Advanced File Functions palette opens an existing file You must wire a valid path to the file path input This function is not capable of creating or replacing files It opens only existing files The datalog type input is used only when opening LabVIEW datalog files datalog type file path open mode deny mode 2 error if Open File LabVIEW Basics II Course Manual 4 2 ni com Lesson 4 Advanced File I O Techniques The New File function on the Functions File I O Advanced File Functions palette creates a new file for reading or writing You must wire a path to the file path input Use the datalog type input only when creating new LabVIEW datalog files datalog type perm
195. re contrast than larger objects e Use spacing and alignment to group objects instead of matching colors e Good places to learn about color are stand alone instrument panels maps magazines and nature Also keep in mind that approximately twenty percent of engineers are color blind to some degree They rely on contrast more than color when differentiating items Spacing and Alignment White space and alignment are probably the most important techniques for grouping and separation The more items that your eye can find on a line the more cohesive and clean the organization seems When items are on a line the eye follows the line from left to right or top to bottom This is related to the script direction Although some cultures might see items right to left almost all follow top to bottom Centered items are better than random but much less orderly than either left or right A band of white space acts as a very strong means of alignment Centered items typically have ragged edges and the order is not as easily noticed Menus are left justified and related shortcuts right justified as shown in the bottom left example of the LabVIEW File menu It is more difficult to locate National Instruments Corporation 2 3 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Text and Fonts items in the center justified menu as shown in the bottom right example Notice how the simple dividing lines between menu sections help
196. reading operating system place a checkmark in the Run with multiple threads checkbox on the Execution page in the File VI Properties dialog box and restart LabVIEW Repeat steps 3 through 10 noting in the table how much faster the VIs execute when the display is running under its own execution subsystem Table 6 1 Record of Execution Times Average Execution Time Multithreading Off Multithreading On Percent Faster Charting Benchmark Example VI Update Chart 1 Point at a Time VI Update Chart 50 Points ata Time VI End of Exercise 6 2 National Instruments Corporation 6 19 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Exercise 6 3 Dialog amp SubVI Demo VI Objective To observe how dataflow structure can affect execution speed Load and run a VI that plots a waveform pattern Notice how the dataflow affects the execution of the VI Front Panel 1 If you are running LabVIEW on an operating system that supports multithreading Windows Solaris2 or Concurrent PowerMAX complete steps a though c If you are on a system that does not support multithreading skip to step 2 a Configure LabVIEW so that it does not use multithreading when it runs VIs Select Tools Options to display the Options dialog box b From the top pull down menu of the Options dialog box select Performance and Disk In the Performance and Disk section remove the checkmark from the Run with multiple threads checkbo
197. rformance and Disk In the Performance and Disk section remove the checkmark from the Run with multiple threads checkbox Click OK c Exit and restart LabVIEW so that the updated preferences take effect Lab VIEW is now configured to run VIs under a single thread using co operative multitasking National Instruments Corporation 6 17 LabVIEW Basics II Course Manual Lesson 6 Performance Issues 2 Close all other VIs you might have open 3 Open the Charting Benchmark Example VI The VI is already built for you When you open it two other VIs also open The Charting Benchmark Example VI generates an array of 1 000 random numbers When you click the Run SubVIs button two subVIs are executed The Update Chart 1 Point at a Time subVI updates a chart 1 000 times The second subVI Update Chart 50 Points at a Time updates a chart 20 times displaying 50 points each time Select Tools Advanced Profile VIs Stop Snapshot Timing Statistics Time in milliseconds F Timing Details M Profile Memory Usage Memory Usage size in kilobytes Sub Vis Time Total Time J A Update Chart 60 Points at a Tine vi Update Chart 1 Point at a Time vi harting Benchmark Example vi LabVIEW Basics II Course Manual E E EE ne eS EE eS EE eS EE SE Move the window so that it does not overlap any of the VI front panels Click the Start button in the Profile window You see the VI Time SubVIs Time and Total
198. rger Projects in LabVIEW In Lesson 5 you will build a project that uses VIs you create in Lessons 1 2 3 and 4 While these VIs individually illustrate specific concepts and features in LabVIEW they constitute part of a larger project you will finish in Lesson 5 The project you will build must meet the following criteria e Provides a menu like user interface e Requires the user to log in with a correct name and password e Ifthe user is not correctly logged in other features are disabled e Acquires data with the specified user configuration e The user can analyze a subset of data and save the results to a file e The user can load and view analysis results previously saved to disk The following course map contains notes about the parts of the project you will develop in various sections of the course Exercises within the lessons also remind you when you are working on a VI used in a later exercise This course does not describe any of the following e LabVIEW programming methods covered in the LabVIEW Basics I course e Programming theory e Every built in VI function or object e Developing a complete application for any student in the class National Instruments Corporation SG 5 LabVIEW Basics II Course Manual Student Guide E Course Map Planning LabVIEW Applications Designing Front Panels Data Management Techniques Advanced File I O Techniques Creating Larger Projects Performance Issues
199. ring the string constant to a local variable right click the local and select Change to Write Local 2 Save the VI under the same name Return to the front panel and run the VI Notice that the Login Name and Password controls reset to empty strings when you start the VI 4 Nowresize the front panel to show only the necessary objects as shown Login Name Password 2 5 Save and close the VI End of Exercise 3 1 LabVIEW Basics II Course Manual 3 10 ni com Lesson 3 Data Management Techniques Exercise 3 2 Select and Plot Waveform VI Optional Objective To use local variables to modify both indicators and controls on the front panel Front Panel New Waveform Select Waveform stand By gt dialog ring Curent Activity Idle string indicator Previous Waveform ES stop button O 0 1 Open the Select and Plot Waveform VI in the c exercises Basics 2 directory The front panel is already built Finish the block diagram 2 Open and examine the block diagram National Instruments Corporation 3 11 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques Block Diagram Select Waveform A pen UU Ltt UL 1 0 2 gt a 2 0 2 be string constant write local variable sting constant write local varat 1 Generating New Waveformpe Current Activity Acquire Signal wi 1 Complete the portions of the block di
200. rol as a control a type definition or a strict type definition depending on the selection showing in the Type Def Status ring The control option is the same as a control you would select from the Controls palette You can modify it in any way you need to and each copy you make and change retains its individual properties A Type Definition control is a master copy of a custom control All copies of this kind of custom control must be of the same data type For example if you create a Type Definition custom control having a numeric representation of Long you cannot make a copy of it and change its representation to Unsigned Long Use a Type Definition when you want to place a control of the same data type in many places If you change the data type of the Type Definition in the Control Editor the data type updates automatically in all VIs using the custom control However you can still individually customize the appearance of each copy of a Type Definition control LabVIEW Basics II Course Manual A 8 ni com Appendix A Strict Type Definition control must be identical in all facets everywhere you use it In addition to data type its size color and appearance must also be the same Use a Strict Type Definition when you want to have completely identical objects in many places and to modify all of them automatically You can still have unique labels for each instance of a Strict Type Definition saving Controls After creating a custom
201. rors VI located on the Functions Time amp Dialog palette on the block diagram This VI combines the error clusters coming from the Sine and Noise VIs into a single error cluster e Place the Add Waveforms VI located on the Functions Waveform Waveform Operations palette on the block diagram This function adds the two waveforms to obtain a noisy sinewave TA f Place the FFT Power Spectrum VI located on the Functions Analyze Waveform Measurements palette on the block diagram This VI calculates the frequency response of the time waveform input and averages the data according to the specified averaging parameters To create the averaging parameters cluster control F iF T LabVIEW Basics II Course Manual 1 8 ni com Lesson 1 Planning LabVIEW Applications right click that input terminal and select Create Control from the shortcut menu A g Place the Wait Until Next ms Multiple function located on the Functions Time amp Dialog palette on the block diagram This function causes the While Loop to execute every half second To create the constant right click the input terminal and select Create Constant from the shortcut menu En h Place the Unbundle By Name function located on the Functions Cluster palette on the block diagram This function extracts the status Boolean from the error cluster in order to stop the loop if an error Occurs Ww 1 Place the Or function located on the Functions Boolean palette on
202. rporation 2 53 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Set Menu Item Info item tag menubar AU menubar out tem name enabled t pmt eror In no eror F checked Si 7 short cut Sets properties of the menu item specified through item tag Item properties include item name enabled checked and shortcut Unwired properties remain unchanged Get Menu Shortcut Info menubar menubar out short cut 7 item tag ermar in no error tem path emor out Returns the menu item that is accessible through a given shortcut Menu Selection Handling Menu Selection functions handle your menu selections The menus might have been built statically in VI Properties or dynamically during run time To set up the block diagram to handle menu selections acquire control over the menu selection process with the Get Menu Selection function While the VI controls the menu selection it waits for a selected menu item using the same function Get Menu Selection All the LabVIEW menu items are implicitly handled by LabVIEW only the user menu selections are obtained through Get Menu Selection Once you select an item you cannot select another item until the Get Menu Selection function reads the first item Under such conditions Get Menu Selection is invoked under block menu mode wherein menu tracking 1s blocked out after a selection is read The menu is enabled after you process the selection using the En
203. rror clusters appropriately LabVIEW Basics II Course Manual 1 6 ni com Exercise 1 1 Objective Lesson 1 Planning LabVIEW Applications Generate amp Analyze Data VI To build a VI that generates analyzes and displays data while using error handling techniques You will build a VI that generates a noisy sine waveform computes the frequency response of those data and plots the time and frequency waveforms in waveform graphs You will use the error clusters and the error handling VIs to properly monitor error conditions 3 Front Panel l Sine Frequency Sine Amplitude 500 0 10 400 0 8 300 0 b 200 0 i 100 0 a 0 le Sampling Info Noite Amplitude Fs lt 1 00k J E Hs 2 200 00 k g averaging parameters averaging mode RMS averaging La Le weighting mode E ponential number of averages i E x E El Open a new VI Note You will use this VI in the appendix Time Waveform Armplitude 0 2 ana af i Plot 0 ii ir yi 6 0 6 0 4 0 20 0 0 l l l 100 0m 150 0m 200 Orn Time l 0 0 500m 0 3 i HH LA Hit ar Win 1 A A ii i sa H ya l l l l 200 0 300 0 4000 S000 Frequency l 100 0 2 Add the three Vertical Pointer Slides located on the Controls Numeric National Instruments Corporation 1 7 palette the Stop button located on the Controls Boolean palette and the t
204. ructure and that the empty string constant is wired to the border of the While Loop This setup ensures that both local variables are updated before the While Loop starts a Login Name local variable set to write local Resets the login name to an empty string To create this local variable right click the Login Name terminal and select Create Local Variable from the pop up menu Password local variable set to write local Resets the password string to an empty string To create this local variable right click the Password terminal and select Create Local Variable from the pop up menu Password National Instruments Corporation 3 9 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques c Empty String constant available on the Functions String palette Passes string values to the Login Name and Password local variables Login M d Login Name Property Node To create this node right click the Login Name terminal and select Create Property Node Change the property to key focus and wire a TRUE Boolean constant to it ie e Place the Verify Information VI on the block diagram To select this VI select Functions Select a VI navigate to c exercises LV Basics 2 double click the Verify Information VI which you built in Exercise 1 2 and place the VI on the block diagram This VI uses the name and password and checks for a match in a table of employee information Kp Note If you have trouble wi
205. rview LabVIEW Basics II Course Manual In LabVIEW 4 and earlier versions you could run several VIs simultaneously and the VIs still responded to user input from the cursor or keyboard To accomplish this the execution system used cooperative multitasking each different activity processed one at a time and in turn Cooperative multitasking works well but processor time is not evenly distributed to each activity Executing a long computational routine or displaying a large amount of data on a graph can use a disproportionate amount of the processor s time The activities take turns with the processor and a lengthy activity is not divided into smaller shorter ones With this architecture multiple tasks executed under a single thread or process in the system Versions of LabVIEW after 5 0 support multithreading With multithreading different portions of an application can run under different threads or processes in a computer system This architecture allows the Operating system to preempt a thread of execution to give processor time to another thread So CPU time is more evenly shared among the threads To take advantage of multithreading use LabVIEW 5 0 or later on an operating system that supports multithreading such as Windows Solaris 2 or Concurrent PowerMAX On operating systems that do not support multithreading LabVIEW continues to operate with cooperative multitasking By default LabVIEW takes advantage of multithread
206. s e The most efficient way to manage data in the block diagram is through a direct wire connection e Local variables can be used to access front panel objects in multiple places in the block diagram e Global variables can be used to pass data between separate VIs without using a wire There are many other ways to manage data in LabVIEW This lesson covers one other method DataSocket DataSocket is an Internet programming technology based on TCP IP that simplifies data exchange between computers and applications With DataSocket you can efficiently pass data over the Internet and respond to multiple users without the complexity of low level TCP programming Therefore you can use DataSocket to pass live data not only between VIs running on the same machine but also between VIs running on separate computers that are connected through a network You also can use DataSocket to communicate between LabVIEW and any other programming language that contains support for TCP IP such as Excel Visual Basic C and so on How Does DataSocket Work DataSocket consists of two components the DataSocket API and the DataSocket Server The DataSocket API presents a single user interface for communicating with multiple data types from multiple programming languages The DataSocket Server simplifies Internet communication by managing TCP IP programming for you DataSocket API DataSocket is a single unified end user API based on URLs for connec
207. s e Use local and global variables only when necessary Overuse can cause slower execution and inefficient memory usage in your application e Local and global variables do not use dataflow so if you use them too frequently they can make your block diagrams difficult for others to understand Use locals and globals wisely National Instruments Corporation 3 35 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques Additional Exercises 3 6 3 7 Open the In Range VI Examine the block diagram This simple VI generates five random numbers and turns on an LED if the last number generated is between 0 1 and 0 9 Run the VI several times until the LED turns on Notice that if the LED turns on during one run of the VI it remains on during the second run until the For Loop completes and the last number is passed to the In Range function available on the Functions Comparison palette Modify the VI using a local variable so that the LED is turned off when the VI starts execution Save your VI after you have finished As mentioned earlier the transfer of data through a global variable is not a synchronized process If you try to read data from a global variable too quickly or slowly you may read copies of the same value or skip data points entirely This was shown in Exercise 3 4 where you could adjust the time delay between reads of the Data Value global faster or slower than the data was actually available Modify
208. s Ht 0 00 0 00 0 00 HT amp Frequency el ooo foo foo eh Amplitude fi 2 223 Cursor Legend scale Legend To change the color associated with a specific intensity value right click the marker appearing next to the color ramp and select Marker Color from the menu The color palette appears from which you select a color to associate with that particular numeric value To add more values to the color ramp right click it and select Add Marker You can drag the tick mark that appears to the appropriate location on the color ramp or select the text next to the tick mark with the Labeling tool and type in the location of the marker After you have placed the marker at the appropriate location on the ramp right click it and select Marker Color LabVIEW Basics II Course Manual 2 60 ni com Lesson 2 Designing Front Panels Intensity Plot Data Types The intensity chart and intensity graph accept a 2D array of numbers The location of each element in the array its row and column indices maps it to the X and Y value on the chart or graph The magnitude of each array element maps to a corresponding color The example following shows a 4 x 3 array plotted on an intensity graph Notice how the Intensity Graph transposes the array elements a Wasco Pao Tao ap fo so fo aeo 200 00 eo oo oo National Instruments Corporation 2 61 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Exercise 2 10 Int
209. s VI as DS Read Data vi Position the front panels of the DS Generate Data and DS Read Data VIs so that you can see both front panels Start the DataSocket Server by going to the Start menu and selecting Programs National Instruments DataSocket DataSocket Server The DataSocket Server window similar to the one below appears Le DataSocket Server Me x Server Help Statistics for Custed98 flagstatf npg pchannel co Processes connected Number of packets Return to the two VI front panels and make sure that the URLs have been entered the same for both VIs e dstp tThe DataSocket transfer protocol e localhost The current computer you are using e datal tThe name given to the random number you will be sending Run the DS Generate Data and the DS Read Data VIs The DataSocket Server window shows one process connected and the Number of packets value increments each second as the meter and slide show the same random numbers 3 32 ni com Lesson 3 Data Management Techniques 8 Stop both VIs when you are finished Now modify the VIs to use the automatic publish and subscribe capabilities of front panel objects Front Panel Slide URL 10 00 dstp localhost datal 8 00 6 00 Random Number no 0 00 2 00 0 00 STOF 9 Place a digital indicator on the front panel of the DS Read Data VI as shown above 10 Right click the new digital indicator and select Data Operations DataSocket Connection from the
210. s a palette of functions and VIs located in the Functions Communication DataSocket palette DataSocket communication is simple You can do all the basic operations with the following functions and VIs duplicate URL error out The DataSocket Write function writes the data input to the specified URL The data can be in any format or LabVIEW data type The error in and error out clusters maintain the error conditions UAL DE duplicate UAL tupe Wariant za data me timeout 10000 F jr imed out efor in Sass error out wait for updated value T The DataSocket Read function reads the data type specified by type from the specified URL The ms timeout value has a default of 10 seconds and you can specify a different timeout value The timed out Boolean indicates a TRUE if this function timed out The error in and error out clusters maintain the error conditions LabVIEW Basics II Course Manual 3 28 ni com Lesson 3 Data Management Techniques Options 0 StartURL empty Title Select URL Error in no error Filter empty The DataSocket Select URL VI is only used when you do not know the URL for an object and you want to search for a data source or target from a dialog box Direct DataSocket Connection to Any Panel Object You do not need to use the DataSocket Write and DataSocket Read functions to publish and subscribe data using the DataSocket Server You can establish a DataSocket connection fro
211. s in the 1D array of data to be written to the file 5 Save the Vlas Binary File Writer vi Run it saving data to the file on disk named data bin End of Exercise 4 1 LabVIEW Basics II Course Manual 4 10 ni com Lesson 4 Advanced File I O Techniques Exercise 4 2 Binary File Reader VI Objective To build a VI that reads the binary file created in the last exercise Front Panel 1 Open anew VI and build the following front panel waveform Graph Flot 0 LA 10 0 aaile a Number of Data Points T F 2 p0 o Digital Indicator Representation 34 5 0 10 0 T Ime 2 Open the block diagram Block Diagram 3 Build the following block diagram Number of Data Points Open Create Replace Filavi Read File Close File Simple Error Handler wi E Wavetorm Graph byte stream type DBL 10 00 a Place the Open Create Replace File VI located on the o Functions File I O palette on the block diagram This VI opens a N file b Place the Read File function located on the Functions File I O palette on the block diagram This function appears twice in this exercise The first function reads the binary file s header information which is a four byte integer containing the number of National Instruments Corporation 4 11 LabVIEW Basics II Course Manual Lesson 4 Advanced File I O Techniques elements in the array stored in the file The second instance reads the array of d
212. scribed on the previous few pages The first step in creating a professional stand alone application with VIs is to understand the architecture of your application You are going to use the State Machine VI Architecture described in Lesson 1 for this application This application contains a single top level VI that calls all other VIs as subVIs In the next four exercises you will build the Application Exercise VI Each exercise adds a state or two to the application This method is used so you can incrementally test the application as it is being built National Instruments Corporation 5 5 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW Exercise 5 1 Application Exercise 5 1 VI Objective To use the Login VI created in Exercise 3 1 to provide password security to an application You will begin creating an application that uses several of the VIs you wrote earlier in the course The first stage of this development is to add a user login procedure to the Menu VI created in Exercise 2 3 Front Panel 1 Open the Menu VI in the exercises Basics2 directory You created this VI in Exercise 2 3 Ky Note If you did not complete Exercise 2 3 locate Menu VI in the course solutions stored on your computer 2 Add a String indicator located on the Controls String amp Path palette on the front panel Label it Operator 3 Add a Square LED located on the Controls Boolean palette on the front panel
213. se and more Another excellent place to obtain support while developing various applications with National Instruments products is the NI Developer Zone at ni com zone The NI Developer Zone also includes direct links to the instrument driver network and to Alliance Program member Web pages The Alliance Program The National Instruments Alliance Program joins system integrators consultants and hardware vendors to provide comprehensive service and expertise to customers The program ensures qualified specialized assistance for application and system development Information about and links to many of the Alliance Program members are available from the National Instruments Web site User Support Newsgroups The National Instruments User Support Newsgroups are a collection of Usenet newsgroups covering National Instruments products as well as general fields of science and engineering You can read search and post to the newsgroups to share solutions and find additional support from other users You can access the User Support Newsgroups from the National Instruments support Web page Other National Instruments Training Courses National Instruments offers several training courses for LabVIEW users The courses are listed in the National Instruments catalog and online at ni com custed These courses will continue the training you received here and expand it to other areas You can purchase just the course materials or sign up for an instruc
214. se item tags do not appear in block diagrams You cannot alter the name tag or other properties of an Application Item LabVIEW reserves tags starting with APP_ for Application Items A Separator inserts a separation line in the menu You cannot set any of the properties for a Separator item The Menu Editor ensures that the tag is unique to a given menu hierarchy by appending numbers when necessary A User Item can be enabled disabled or checked unchecked by setting the respective properties You can set a shortcut accelerator for a User Item by selecting an appropriate key combination The Menu Editor allows you to insert delete or reorder menu items in the menu hierarchy Clicking the button adds a new menu item You also can change the type of a menu item by selecting from the Item Type ring In addition you can reorder the menu items and create submenus using the arrow buttons Finally clicking the Delete Item button deletes the selected menu item The Preview portion of the Menu Editor provides an up to date view of the run time menu On the Menu Editor pull down menu the Open New Save and Save As buttons allow you to load and save RTM files Once you close the Menu Editor you will have the option of updating the VIs run time menu with the menu you edited Dynamic Menus While a VI executes you can change items in the VI menu bar by using the menu management functions described in the following sections All of these func
215. shown in the following block diagram you can call the Wait ms function in the user interface loop to give significantly more execution time to the other loop Search 10 ra LabVIEW Basics II Course Manual 6 16 ni com Lesson 6 Performance Issues Exercise 6 2 Charting Benchmark Example VI Objective To observe the relative speeds of single point and multiple point charting using the Profile window and the effects of multithreading on systems that support this feature When you open the Charting Benchmark Example VI two other subVI front panels also open These two subVIs plot the same data under different conditions Front Panels Charting Benchmark Example vi File Edit Operate Tools Browse Window Help Selo This Vl sends the same data to two subila Each displays the data using a different technique Use the Profile Window to measure the display performance of each subi Run Sub vl s gt Update Chart 1 Point at a Time_vi Waveform Chart Ml Np vy i i ih ih I l n i 1 If you are running LabVIEW on an operating system that supports multithreading Windows Solaris2 or Concurrent PowerMAX complete steps a through c If you are on a system that does not support multithreading skip to step 2 a Configure LabVIEW so that it does not use multithreading when it runs VIs Select Tools Options to display the Options dialog box b From the top pull down menu of the Options dialog box select Pe
216. sics II Course Manual Lesson 1 Planning LabVIEW Applications D LabVIEW Programming Architectures You can develop better programs in LabVIEW and in other programming languages if you follow consistent programming techniques and architectures Structured programs are easier to maintain and understand Now that you have created several VIs in LabVIEW through either the LabVIEW Basics I course or from similar programming experience this concept of structured programming is described in more detail One of the best ways to create a program architecture that is easy to understand is to follow modular programming techniques and make subVIs for reusable or similarly grouped operations For example refer to the VI you built in Exercise 1 1 The subVIs you used make the VI very easy to follow and understand while each piece can be reused in other VIs Combined with documentation on the block diagram and in the File VI Properties Documentation option a modular VI is easy to understand and modify in the future You can structure VIs differently depending on what functionality you want them to have This section describes some of the common types of VI architectures along with their advantages disadvantages simple general parallel loops multiple cases and state machines Simple VI Architecture When doing calculations or making quick lab measurements you do not need a complicated architecture Your program might consist of a single VI that
217. sier to use and gives it a more polished professional look VI Comparison The LabVIEW Professional Development System includes a utility to determine the differences between two VIs loaded into the memory From the LabVIEW pull down menu select Tools Compare Compare VIs to display the Compare VIs dialog box E gt Compare VIs Vs to Compare Application Exercise 5 2 1 Select Select M 1 Attributes MF Block Diagram M Front Panel M Cosmetic changes M Position size changes FM Position size changes From this dialog box you can select the VIs you want to compare as well as the characteristics of the VIs to check When you compare the VIs both VIs will be displayed along with a Differences window that lists all differences between the two VIs In this window you can select various differences and details to view which can be circled for clarity National Instruments Corporation 5 17 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW Exercise 5 4 Objective To examine some of the built in LabVIEW features for handling applications In this exercise you will explore some of the features built into LabVIEW for handling applications 1 Open the Application Exercise 5 3 VI you created in the previous exercise Close any other VIs loaded into memory 2 Select Tools VI Revision History The history window for the VI should appear 3 Click Reset in the Revision History windo
218. signing Front Panels Bounds Property Es The Bounds property shown at left reads the boundary of an object on the front panel in units of pixels The value includes the control and all of its parts including the label legend scale and so on This property consists of Height a Cluster of two unsigned long integers The first item in the cluster Width is the width of object in pixels and the second item in the cluster Height is the height of the object in pixels This 1s a read only property It does not resize a control or indicator on the front panel Some objects have other properties for resizing such as the Plot Area Size property for graphs and charts Wiring Example Determine the bounds of the digital control digital control gt ee Numeric Property Format and Precision The Format and Precision property shown at left sets or reads the format type of notation and precision number of digits displayed after the fs decimal point of numeric front panel objects The input is a cluster of two unsigned byte integers The first element sets the format and the second sets the precision The Format property can be one of the following integer values 0 Decimal Notation 1 Scientific Notation 2 Engineering Notation 3 Binary Notation 4 Octal Notation 5 Hexadecimal Notation 6 Relative Time Notation Wiring Example Set the format of the digital control to scientific notation a
219. sing the number of memory allocations LabVIEW must perform These operations can fragment memory Use consistent data types for arrays and watch for coercion dots when passing data to subVIs and functions When LabVIEW changes data types the output is a new buffer Do not use complicated hierarchical data types for example arrays of clusters containing large arrays or strings or clusters containing large arrays or strings The Simple vs Complicated Data Structures section later in this lesson contains more information about designing efficient data types Assembling and Processing Arrays When designing the block diagram there are several steps you can take to make your VI use memory more efficiently For example you can assemble and process arrays in ways that minimize the amount of memory access required LabVIEW stores arrays of numeric elements in contiguous blocks of memory If you use For Loops to assemble these arrays LabVIEW can determine the amount of memory needed and allocate the necessary space prior to the first iteration However if you use While Loops LabVIEW National Instruments Corporation 6 29 LabVIEW Basics I Course Manual Lesson 6 Performance Issues cannot predetermine the space requirements you will need LabVIEW might need to relocate the entire buffer as the array grows in size perhaps several times The time needed for relocation increases with the size of the array Therefore you should use For
220. sk boiling and select Edit Cut Click the Flask LED indicator and select Edit Customize Control The Control Editor now appears with the Flask LED displayed Right click the LED and select Import Picture True This custom picture now represents the TRUE state Kp Note The default state of the LED is FALSE If you do not see the picture the LED is probably in the FALSE state LabVIEW Basics II Course Manual A 12 ni com Block Diagram National Instruments Corporation Appendix c Change to the front panel by clicking it Using the Positioning tool select the graphic of the flask that shows the contents of the flask not boiling and select Edit Cut Change to the Control Editor window by clicking it d Right click the boiling flask and select Import Picture False This custom picture now represents the FALSE state e Select Apply Changes from the File menu and close the Control Editor Do not save the custom control Right click an open area and select Square LED from the Controls Classic Controls Boolean shortcut menu Label the LED Flame Using the previous steps make the LED look like a Bunsen burner The TRUE state should show the burner on the FALSE state should show the burner off Hide the labels of both Boolean indicators by right clicking them and selecting Visible Items Label Select both Boolean indicators and align them on horizontal centers using the Align Objects tool Complete the following bloc
221. sk button the title text and VI front panel image are saved in an HTML document If you want to view the document from a remote computer save the HTML document in the Web Server root directory usually labview www The Document URL dialog box appears with the URL for your HTML document National Instruments Corporation A 15 LabVIEW Basics II Course Manual Appendix Exercise A 4 Generate amp Analyze Data Objective To use the LabVIEW Web Server tools to display a front panel in a web browser Front Panel Open the VI you built in Exercise 1 1 the Generate amp Analyze Data VI and save its front panel into an HTML document Sin Frequency Sine Amplitude 500 0 10 400 0 8 300 0 6 200 0 4 100 0 oas 0 0 0 Sampling Info Noise Amplitude 10 Hs 21 200 00 averaging parameters averaging mode No averaging weighting mode E sponential number of averages amo Time Waveform Amplitude ol un NY il i Hl i 50 Or i 200 Om 00 1000 2000 2000 4000 5000 SPAR 1 Open the Generate amp Analyze Data VI from the exercises LV Basics2 directory 2 Enable and configure the Web Server by selecting Tools Options 3 Select Web Server Configuration from the pull down menu at the top of the Options dialog box and place a checkmark in the Enable Web Server checkbox 4 Click the OK button to close the Options dialog box The LabVIEW Web
222. son 1 Planning LabVIEW Applications Block Diagram 7 Open and examine the block diagram 8 This State Machine VI architecture is implemented in a slightly different manner as the one previously described This VI uses a string constant to contain the states for the Case structure whereas the previous VI showed an enumerated type similar to a ring control to control the states Because the Case structure accepts both numeric and string data it does not matter how you specify the different states The key to the State Machine architecture is that you have a While Loop with a Case structure inside where each case 1s a different state of the overall application The next state is determined while the VI is running based upon what happens in the current state 9 Close this VI when you are finished End of Exercise 1 3 National Instruments Corporation 1 23 LabVIEW Basics II Course Manual Lesson 1 Planning LabVIEW Applications Summary Tips and Tricks LabVIEW Basics II Course Manual In most cases a top down approach is used to plan the overall strategy for a project Development and implementation of an application usually occurs from the bottom up When designing a LabVIEW application it is important to determine the end user s expectation exactly what the application must accomplish and what future modification might be necessary before you invest a great deal of time developing subVIs You should design a flowchart
223. strative messages to the info labview list maintainer at info labview REQUEST pica army mil Post a message to subscribers at info labview pica army mil You might also want to search the ftp archives at ftp ftp pica army mil pub labview The archives contain a large set of donated VIs for doing a wide variety of tasks National Instruments Corporation A 21 LabVIEW Basics II Course Manual Appendix E ASCII Character Code Equivalents Table The following table contains the hexadecimal octal and decimal code equivalents for ASCII character codes LabVIEW Basics II Course Manual A 22 ni com Appendix National Instruments Corporation A 23 LabVIEW Basics II Course Manual Appendix Le oe iin ase me T ocet it asen mu 1 M6 1 ci LabVIEW Basics II Course Manual A 24 ni com Documentation Comment Form National Instruments encourages you to comment on the documentation supplied with our products This information helps us provide quality products to meet your needs Title LabVIEW Basics II Course Manual Edition Date September 2000 Part Number 320629G 01 Please comment on the completeness clarity and organization of the manual If you find errors in the manual please record the page numbers and describe the errors Date manual was purchased month year Thank you for your help Name Title Company Address E mail Address Phone ___ 77777 Fax _ Mail to Cust
224. struments Corporation 2 31 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Wiring Example Show the text in the string control in the three other modes vY Codes Display String The squick brown shox eu Us e gt mpesovervetheslazysadag Password Display Dispotyle D Mc String CEE EEE EE UE EEE EEE EEE SEE EE EEE Hex Display 5468 6520 7175 6963 6620 6272 BFF BE20 666F 7820 pary BA75 GD70 7220 6F76 6672 A4 RARR ANA 7A 7AA LabVIEW Basics II Course Manual 2 32 ni com Lesson 2 Designing Front Panels Exercise 2 5 Property Node Exercise vi Objective To build a VI that uses Property Nodes to manipulate common characteristics of panel objects You will build a VI that programmatically changes the position disabled and color properties of front panel objects Front Panel 1 Open a new VI and build the front panel shown previously Block Diagram FillColor Position Tank Horizontal Position Disabled k Boolean Tank Vertical Position H zE H Tank Vertical Position Disabled Fr E Tank Horizontal Position re es Disabled Gr i pal Disabled Limit Disabled National Instruments Corporation 2 33 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels LabVIEW Basics II Course Manual Open and build the block diagram shown previously using the following components a Place the While Loop located on the
225. such as drawing on the front panel responding to mouse clicks and so on operate in their own thread This prevents the user interface from robbing the block diagram code of execution time So displaying a lot of information about a graph does not prevent the block diagram code from executing Likewise executing a long computational routine does not prevent the user interface from responding to mouse clicks or keyboard strikes Computers with multiple processors benefit even more from multithreading On a single processor system the operating system preempts the threads and distributes time to each thread on the processor On a multiprocessor computer threads can run on the multiple processors simultaneously so more than one activity can occur at the same time National Instruments Corporation 6 3 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Using Multithreading When an existing LabVIEW application runs it takes advantage of the multithreaded system automatically without any modification to the application However when working with multiple VIs there are different classifications of threads called execution systems available to organize your application There are six execution systems available to run VIs e User Interface e Standard Instrument I O e Data Acquisition e Other e Other 2 The purpose of having a few different execution systems is to provide some rough partitions for VIs that need to
226. system provide custom graphics and animation features to the user interface Decorations One of the most straightforward methods to enhance a user interface is to apply the LabVIEW Decorations to a front panel as you did in Lesson 2 Designing Front Panels Through careful use of the decorations you can increase the readability of the front panels Importing Graphics You can import graphics from other VIs for use as background pictures items in ring controls or parts of other controls However before you can use a picture in LabVIEW you need to load it into the LabVIEW Clipboard There are one or two ways to do this depending on your platform e Windows lIf you can copy an image directly from a paint program to the Windows Clipboard and then change to LabVIEW LabVIEW automatically imports the picture to the LabVIEW Clipboard You also can use the Import Picture from File option from the LabVIEW Edit menu to import a graphics file into the LabVIEW Clipboard LabVIEW recognizes graphics files in the following formats CLP EMF GIF PCX BMP TARGA TIFF LZW WFM and WPG e Macintosh If you copy from a paint program to the Clipboard and then change to LabVIEW LabVIEW automatically imports the picture to the LabVIEW Clipboard e UNIX You can use the Import Picture from File option from the UNIX Edit menu to import a picture of type X Window Dump X WD which you can create using the xwd command After a picture is on the L
227. t I HiQ I ComponentWorks J VirtualBench 1 Measure Tell Us About Your Applications Number and type AC DC thermocouple and so on of signals My systems are developed by J In house staff System description 4 DAQ 3 SCXITM 3 GPIB 3 VXI 1 Mac OS 1 Concurrent PowerMax _J Macintosh DAQ SCXI GPIB I System s integrator LULL VXI 1 Fieldbus J IMAQ Vision I Serial E Motion control I HP UX _I DEC Fieldbus IMAQ Vision Serial CL O L Motion control _J consultant Which statements best describe your role in the purchase of instrumentation or data acquisition products I I set company standards I I influence product purchases _J I evaluate and recommend software Which statement best describes your function in the company check only one _J Education 1 Manufacturing automation 1 Reseller sales I Service repair Please Check Below for Free Product Information Software Tools Catalogues and Newsletters I Academic Catalogue Industry specific Literature I Aerospace 1 Telecommunications 1 Automotive _J Calibration J Engineering management I Purchasing contracts I Student co op I Measurement and Automation Catalogue 1 VXI Product Solutions Guide 1 Instrumentation Newsletter LJ Semiconductor LJ Vibration acoustics I Physiology Product Literature check up to three I
228. th a top down approach That is you first define the general characteristics and specifications of the project After you define the requirements of the application with input from your customer you begin developing the subVIs you will eventually assemble to form the completed project This stage represents the bottom up development period Customer feedback helps you determine new features and improvements for the next version of the product bringing you back to the project design phase The following chart illustrates this project development process Process Define Project Customer Feedback Test amp Release Final Product Design Integrate SubVIs Flowchart into Project Implement Nodes as VIs Test SubVls Bottom Up LabVIEW Project Development Process Designing a flow diagram can help you visualize how your application should operate and set up the overall hierarchy of your project Because LabVIEW is a data flow programming language and its block diagrams are similar to typical flowcharts it is important to carefully plan this chart You can directly implement many nodes of the flowchart as LabVIEW subVIs By carefully planning the flowchart before implementing your LabVIEW application you can save development time later Also keep in mind the following development guidelines e Accurately define the system requirements e Clearly determine the end user s expectations e Document what the application must accomplis
229. the block diagram National Instruments Corporation 4 15 LabVIEW Basics II Course Manual Lesson 4 Advanced File I O Techniques Block Diagram 3 Complete the Case structures for the following block diagram The cases that are not shown are already built prompt pew file data file LabVIEW Basics II Course Manual m Simple Error Hew File Write File Close File Handler wi Delete the Boolean constant labeled Delete Me Place the File Dialog function located on the Functions File I O Advanced File Functions palette on the block diagram This function prompts for the name of the new file Connect the output of the exists and cancelled terminals to the inputs of the OR function Wire the exists value to the Case structure as shown in the previous block diagram To create this constant right click the select mode input of the File Dialog function and select Create Constant With the Operating tool set this constant to the value new file To create this constant right click the prompt input of the File Dialog function and select Create Constant This string displays a prompt message in the file dialog box The outside Case structure writes the data to a LabVIEW datalog file Notice that bundling the Employee Name and Data Cluster together provides the data type for the datalog file Place the New File function located on the Functions File I O Advanced File Functions palette on the block diagram This f
230. ther data referred to as nested or complicated data is more difficult to reference Examples of nested data include arrays of strings clusters containing arrays of clusters and arrays of clusters containing arrays Complicated Data For the best performance avoid creating complicated data structures Performance can suffer because it is difficult to access and manipulate the interior elements without generating copies of data Therefore keep your data structures as flat as possible Flat data structures can generally be manipulated easily and efficiently Consider an application in which you want to record the results of several tests In the results you want a string describing the test and an array of test results One data type that you might use to store this information is an array of clusters containing a description string and an array of test data as shown in the following front panel LabVIEW Basics II Course Manual 6 36 ni com Lesson 6 Performance Issues Test Data E Heos Me Now consider what you need to do to change an element in the Test Data array First you must index an element of the overall Tests array For that element which is a cluster you must unbundle the elements to get to the array You then replace an element of the array and store the resulting array in the cluster Finally you store the resulting cluster in the original array An example of this is shown in the following illustration Copy
231. ting to measurement and automation data located anywhere be it on a local computer or on the Internet It is a protocol independent language independent and OS independent API designed to simplify binary data publishing The DataSocket API is implemented so you can use it in any programming environment and on any operating system The DataSocket API automatically converts your measurement data into a stream of bytes that is sent across the network The subscribing DataSocket application automatically converts the stream of bytes back into its original form This automatic conversion eliminates network complexity which accounts for a substantial amount of code that you must write when using TCP IP libraries LabVIEW Basics II Course Manual 3 26 ni com Lesson 3 Data Management Techniques DataSocket Server The DataSocket Server is a lightweight stand alone component with which programs using the DataSocket API can broadcast live measurement data at high rates across the Internet to several remote clients concurrently The DataSocket Server simplifies network TCP programming by automatically managing connections to clients Access the DataSocket Server by selecting Start Programs National Instruments DataSocket DataSocket Server When you select the DataSocket Server it opens the following window and begins running Le DataSocket Server le x Server Help Statistics for Custed98 flagstatf npg ispchannel co Processes conn
232. tion forces the loop to run asynchronously even if the wait period is specified as zero milliseconds If the operations inside the main loop react to user inputs then the wait period can be increased to a level acceptable for reaction times A wait of 100 200 ms is usually good as most users will not detect that amount of delay between pushing a button on the front panel and the subsequent event executing Parallel Loop VI Architecture Some applications require the program to respond to and run several events concurrently One way of designing the main section of this application is to assign a different loop to each event For example you might have a different loop for each action button on the front panel and for every other kind of event such as a menu selection I O trigger and so on The following block diagram shows this Parallel Loop VI architecture Enter your code here for the first process Enter your code here for the second process Stop lf True E G This structure is straightforward and appropriate for some simple menu type VIs where a user is expected to select from one of several buttons that lead to different actions This VI architecture also has an advantage over other techniques in that taking care of one event does not prevent you from responding to additional events For example 1f a user selects a button that causes a dialog box to appear parallel loops can continue to respond to I O events Therefore the
233. tions are located under Functions A pplication Control Menu All of these functions operate on a refnum for the menu retrieved using the Current VI s Menu function LabVIEW Basics II Course Manual 2 52 ni com Lesson 2 Designing Front Panels Insert Menu Items menu tag menubar menubar out item names item tags out _ ther tags fF error out error In no error after item Inserts a menu item or an array of menu items identified by item names or item tags into a menu menu bar or submenu The position of the item is specified either through the after item parameter or through a combination of the menu tag and after item pair Delete Menu Items menubar menubar out menu tag FA terns pl Emor out error in ho error Deletes a menu item or an array of menu items identified by items from a menu identified by menu tag from the menu bar if menu tag is not specified Items can be a tag array of tags position number or an array of position numbers Get Menu Item Info tem tag 7 submenu tagg menubar menubar out paa tem name ermar In no error enabled b rror Out SPA PE re checked short cut Returns properties of the menu item specified through item tag or the menubar if the item tag is unspecified Item properties include item name enabled checked and shortcut If the item has a submenu attached its item tags are returned in submenu tags National Instruments Co
234. tly set each local variable as a read local or a write local To change a write local to a read local right click the icon and select Change to Read Local from the pop up menu To change a read local to a write local right click the icon and select Change To Write f Wait ms function available on the Functions Time amp Dialog i palette Generates a delay so you can observe the front panel activities ag g Acquire Signal VI available on the User Libraries Basics 2 Signal Course palette Generates the data for the waveform specified by the Select Waveform control 2 Save the VI under the same name Return to the front panel and run the VI Notice that the VI updates the string indicator and stores the old waveform in the Previous Waveform graph Also observe that after the new waveform is acquired and sent to the screen the Select Waveform control is reset to Stand By zero 4 Close the VI when you are finished End of Exercise 3 2 National Instruments Corporation 3 13 LabVIEW Basics II Course Manual Lesson 3 Data Management Techniques C Global Variables Recall that you can use local variables to access front panel objects at various locations in the block diagram Those local variables are accessible only in that single VI Suppose that you need to pass data between several VIs that run concurrently or whose subVI icons cannot be connected by wires in the block diagram You can use a global variable to accomp
235. top level VI does not quit LabVIEW or close the VIs front panel when it is finished executing To completely quit and close the top level VI you must call the Quit LabVIEW function located on the Functions A pplication Control palette on the block diagram of the top level VI quit T Quit Lab IEW Building the Application As described earlier in this section you use the Application Builder in LabVIEW to make either an executable or a shared library DLL for your application This course describes how to build an executable and the LabVIEW Advanced I course describes how to build and use a shared library DLL National Instruments Corporation 5 25 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW The LabVIEW Application Builder can package your application in one of two forms as a single executable or as a single executable and one VI library Depending upon how you want your application to appear to the end user as well as how complex the installation process can be you might prefer one format to the other The default packaging for applications is a single executable file All VIs that are part of the application are embedded in the executable file These include top level VIs dynamic VIs and all their subVIs While this packaging 1s simple because it results in a single file these files can become quite large depending on the number of VIs in your application The second packaging opti
236. tor 6 Display Global Data vi STOF Time Delay ms 200 1502 100 50 a vertical pointer slide wavetorm chart The Time Delay control determines how often the global variable is read Notice how the Time Delay affects the values plotted on the waveform chart If you set the Time Delay to 0 the same Data Value value is read from the global variable several times appearing to decrease the frequency of the sine wave generated in Data to Global If you set the Time Delay to a value greater than 50 ms Display Global Data may never read some values generated in Data to Global and the frequency of the sine wave appears to increase If you set the Time Delay to 50 ms the same rate used in the While Loop in Data to Global Display Global Data reads and displays each point of the Data Value global only once Yi Note When using globals if you are not careful you may read values more than once or you may not read them at all If you must process every single update take special care to ensure that a new value is not written to a global variable until the previous one has been read and that after a global has been read it is not read again until another value has been written to the global T National Instruments Corporation Press the STOP button on the Display Global Data front panel to stop the VI Notice that both Display Global Data and Data to Global stop The VI continually writes the value of th
237. tor led hands on course by contacting National Instruments LabVIEW Basics II Course Manual A 20 ni com Appendix LabVIEW Publications LabVIEW Technical Resource LTR Newsletter Subscribe to LabVIEW Technical Resource to discover power tips and techniques for developing LabVIEW applications This quarterly publication offers detailed technical information for novice users as well as advanced users In addition every issue contains a disk of LabVIEW VIs and utilities that implement methods covered in that issue To order LabVIEW Technical Resource call LTR publishing at 214 706 0587 or visit ltrpub com LabVIEW Books Many books have been written about LabVIEW programming and applications The National Instruments Web site contains a list of all the LabVIEW books and links to places to purchase these books Publisher information is also included so you can directly contact the publisher for more information on the contents and ordering information for LabVIEW and related computer based measurement and automation books The Info labview Listserve Info labview is an e mail group of users from around the world who discuss Lab VIEW issues The people on this list can answer questions about building LabVIEW systems for particular applications where to get instrument drivers or help with a device and problems that appear Send subscription messages to the info labview list processor at listmanager pica army mil Send other admini
238. ts and more contrast User Interface Tips and Tools It is not necessary or wise to spend time making every front panel look polished concentrate on the ones that users see the most Some of the built in Lab VIEW tools for making user friendly front panels include dialog controls tab controls decorations menus and automatic resizing of front panel objects LabVIEW Basics II Course Manual 2 4 ni com Lesson 2 Designing Front Panels Dialog Controls A common user interface technique is to have dialog boxes appear at appropriate times to interact with the user You can make a VI behave like a dialog box by checking that option in the File VI Properties Window Appearance dialog box The Controls Dialog Controls palette contains the same kinds of objects available in system dialog boxes You should use these dialog controls to build system like dialogs Dialog controls change appearance according to the operating system and Window Appearance settings and they typically ignore all color clicks except transparent If you are integrating a graph or non dialog controls into the front panel try to make them match by hiding some borders or selecting colors similar to the system Tab Controls Physical instruments usually have good user interfaces Borrow heavily from them but move to smaller or more efficient controls such as rings or tab controls where this makes sense Tab Controls are found in the Controls Dialog Controls palette
239. ty shown at left reads or sets the current value of an object When you set the Value property to write it writes the wired value to object whether it is a control or indicator When you set the Value property to read it reads the current value in either a control or indicator The example 2 28 ni com Lesson 2 Designing Front Panels following shows a value of pi written to a numeric control and the value inside one string being written to another string Numeric EL ri i gt pju String Out a Labview Property Nodes Position Property ess The Position property shown at left sets or reads the position of an object s upper left corner on the front panel The position is determined in units of pixels relative to the upper left corner of the front panel This property consists of a cluster of two unsigned long integers The first item in the cluster Left is the location of the left edge of the control relative to the left edge of the front panel and the second item in the cluster Top is the location of the top edge of the control relative to the top edge of the front panel Wiring Example Make the digital control change its location on the front panel File Edit Operate Tools Browse Wi S 13pt Application Mumeric 00 00 File Edit Operate Tools Browse Wi Olm 13pt Application Numeric 0 00 National Instruments Corporation 2 29 LabVIEW Basics II Course Manual Lesson 2 De
240. u access the followin VI Metircs window from the Tools Advanced menu 5 Bes YI Metrics Yi Show statistics for M Diagram User interface M Globals locals M CINs shared lib calls T Sub l interface Select a 1 Application Exercise 6 31 Hofuservils Hof vilib Yla 83 Save FE Done I Exclude wilib files from statistics H of nodes structures diagrams mas diag depth diag width ps total 16 15 Application Exercise 6 31 35 2 Lagin wi 15 Acquire Data vi 26 Analyze amp Present Data af Wiew Analysis File vi 18 Yerty Information wi 21 Save Data to File v1 15 National Instruments Corporation 5 21 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW A VI Library Manager tool is also included in this toolkit This utility enables you to copy rename and delete VIs whether they are located in LLBs or not The VI Library Manager can also convert existing LLBs into files in a subdirectory to make implementation of SCC tools easier Be VI Library Manager Basics lib Labview 6 La Demo Acquire Waveform wi on uz Demo Al Sample Channel wi Rename La Demo Read Voltage wi i La Demo Thermometer wi fur 20 Wave Generator wi Delete uz Acquire Signal vi J instr lib La For Loop using Auto Indes New D LabVIEW exe La For Loop using Build Array vi D LabVle WwW int O global gbl Convert LLBs to Dirs uz
241. u should enter from the keyboard sections of code programming examples and syntax examples This font is also used for the proper names of disk drives paths directories programs subprograms subroutines device names functions operations variables filenames and extensions and code excerpts Text in this font denotes a specific platform and indicates that the text following it applies only to that platform Macintosh Press lt Command gt click to perform the same action as a right click National Instruments Corporation SG 7 LabVIEW Basics II Course Manual Planning LabVIEW Applications VAY Lesson 1 A Ces l This lesson describes some of the issues involved when developing LabVIEW applications including the design process the organization of sub VI components and the process of combining those components to create a complete application This lesson also describes common LabVIEW programming architectures along with some tools to help you build VIs You Will Learn Planning and design tips for developing a LabVIEW application How to convert your design outline into actual LabVIEW subVIs Error handling techniques Common LabVIEW programming architectures About VI templates ee ee National Instruments Corporation 1 1 LabVIEW Basics II Course Manual Lesson 1 Planning LabVIEW Applications A The Planning and Design Process To design large LabVIEW projects you will find that you usually begin wi
242. ual Lesson 4 Advanced File I O Techniques Notes LabVIEW Basics II Course Manual 4 24 ni com Developing Larger Projects in LabVIEW VAY Lesson 5 coy A This lesson describes some of the issues involved when building larger LabVIEW projects including the design process the organization of sub VI components and the process of combining those components to create a complete application You Will Learn A How to assemble your LabVIEW application from developed subVIs B The LabVIEW features for managing project development C About LabVIEW tools for project management National Instruments Corporation 5 1 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW A Assembling a LabVIEW Application Lesson of this course described a general approach to developing LabVIEW applications This approach involved a top down design of an application followed by a bottom up implementation of the project as a series of subVIs Following is a review of this development cycle Process Define Project Customer Feedback Test amp Release Final Product Design Integrate SubVIs Flowchart into Project Implement Nodes as VIs Test SubVIs Top Down Bottom Up LabVIEW Project Development Process In this lesson you will put the VIs built in previous lessons into a large application You will develop a generic data acquisition VI that meets the following criteria e Provides a menu like user
243. ubVls LabVIEW built in functions can handle different types of data for the same terminal a capability called polymorphism An example of polymorphism is the Add function Scalar Cluster 4 Resulting Array It is also possible to create your own polymorphic VIs which can handle more than one type of data for the same terminal These polymorphic VIs can then be used as polymorphic subVIs Using polymorphic VIs allows you to present a much simpler interface to the users of your VIs Consider the case of a polymorphic VI that can sort either 1D or 2D arrays Instead of having one VI for sorting 1D arrays and another subVI for sorting 2D arrays one VI called Sort Array handles both types of inputs Unsorted Array Sorted Array Sort Poly Array vi Complete the following steps to create your own polymorphic VI 1 Create a set of VIs having the same connector pane pattern one for different sets of data types 2 Create a polymorphic VI by selecting File New and selecting Polymorphic VI in the New dialog box The Polymorphic VI builder dialog box appears LabVIEW Basics II Course Manual A 2 ni com Appendix Untitled 1 Polymorphic VI File Edit Tools Browse Window Help m Add Yl Remove l Edit icon Edit Menu ltem 3 Add each of the set of VIs to the polymorphic VI using the Add VI button 4 You can create an icon for the polymorphic VI using the Edit Icon button You also can create c
244. uch as VIs that act as a user interface You create a state machine in LabVIEW with a While Loop a Case structure and a shift register Each state of the state machine 1s a case in the Case structure You place VIs and other code that the state should execute within the appropriate case A shift register stores the state to be executed upon the next iteration of the loop The block diagram of a state machine appears in the following figure ce a Action 1 code here 1 14 ni com Lesson 1 Planning LabVIEW Applications rar ma EE Action 2 code here In this architecture you design the list of possible events or states and then map that to each case For the VI in the previous block diagram the possible States are startup idle event 1 event 2 and shutdown These states above are stored in an enumerated constant Each state has its own case where you place the appropriate nodes While a case is running the next state is determined based on the current outcome The next state to run is stored in the shift register If an error occurs an any of the states the shutdown case is called The advantage of the State Machine VI architecture is that the block diagram can become much smaller making it easier to read and debug One drawback of the Sequence structure is that it cannot skip or break out of a frame The State Machine architecture solves that problem because each case determines what the next state will be as it runs
245. ue major and minor increments between the X axis markers and the start value of the scale To create this property select X Scale Range All Elements from the property list If there is not enough space to display all the increment values you have specified LabVIEW will select an alternate increment value Wiring Example Set the X axis range to 0 to 50 with major axis increments of 10 minor increments of 1 and a start value of zero Waveform Graph 1 0 E 50 00 Scale Range Increment 10 00 1 00 tart Z mn l 1 00 0 00 Amplitude 2 o T 100 200 200 400 500 Time Active Plot and Plot Color Properties Es The properties shown at left set or read the active plot the trace for which subsequent trace specific properties are set or read and the plot color for the active plot Active Plot is an integer corresponding to the desired plot and Plot Color is an integer representing a color The Plot Color property is accessed by selecting Plot Plot Color from the property list Wiring Example Set the color of the active plot using a Color Box Constant set to Red in this example When selecting the active plot the Active Plot terminal must precede appear previous the Plot Color terminal Plot Color Active Cursor Cursor Position and Cursor Index Properties ESS The properties shown at left set or read the active cursor the position of that cursor on the graph and the index X axis positio
246. uilder will generally have the same system requirements as the LabVIEW development system Memory requirements will vary depending on the size of the application created Turning Your Application into a Stand Alone Executable Before LabVIEW 5 1 the process for building an application was to save your VIs to a library build an application using the Build Application dialog box and then create an installer using the Create Distribution Kit dialog box In LabVIEW 5 1 you can use the Build Application dialog box to do all of these operations When you select Tools Build Application or Shared Library DLL a tabbed dialog box appears By making settings in the various tabbed pages on the dialog box you can define the application you want to build You can save a script and use it later to rebuild the application The Build Application Shared Library dialog box contains the following tabbed pages Target Source Files VI Settings Application Settings and Installer settings as shown in the following example Build Application or Shared Library DLL New script Target Source Files Vl Settings Application Settings Installer Settings Build target Application EXE L T arget file name Application exe Destination directory h CAWINDOWS TEMPSapp 000 Support file directory r CAWINDOWS TEMPSapphdata 00000 Build Options i Single target file containing all V s F Do not compress target file nae faster load on slo
247. uments Corporation 2 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels Exercise 2 1 Scope Panel vi Objective To logically arrange and separate front panel objects to make the user interface of a VI easier to read and use You will resize reorganize and rearrange the objects on the front panel to make the user interface easier to use You will also setup the graph to resize along with the front panel Front Panel Trigger Level Yolts Div A 2 i Trigger ras slope NEG Yolts Div B Timebase DU ON Channel A Channel Position B Trigger oN r Fr s3 Channel Position A 3 Z 2 9 1 Open the Scope Panel VI from the c exercises LV basics 2 directory The front panel is shown previously 2 Move the controls around as to logically group the controls that share similarities not all can relate to a group For example the Channel A ON OFF button Channel A Position knob and Channel A Volts Div knob all operate on channel A and it makes sense to have them close to one another Two other example groups would be the three Channel B controls and the three trigger controls W Tip Remember to use the Align Objects and Distribute Objects features in the tool bar 3 After making groups out of the controls use the Raised Box decoration on the Controls Decorations palette to make visible separations LabVIEW Basics II Course Manual 2 8 ni com Lesson 2 Designing Front Panels between the groups
248. unction causes the While Loop to execute ten times a second Create the constant by right clicking the input terminal and selecting Create Constant d Place the Cluster To Array function located on the Functions Cluster or Functions Array palette on the block diagram In this exercise this function converts the cluster of Boolean buttons into an array of Boolean data types The Boolean object at cluster order 0 becomes the Boolean element at array index 0 cluster order 1 becomes array index 1 and so on gem e Place the Search 1D Array function located on the e Functions Array palette on the block diagram In this exercise this function searches the Boolean array that Cluster to Array returns for a TRUE value A TRUE value for any element indicates that you clicked on the corresponding button The function returns a value of 1 if you did not click a button f Place the One Button Dialog function located on the Functions Time amp Dialog palette on the block diagram You will use four of these functions to indicate which state has been selected and loaded into the shift register 2 Save the VI as Menu vi Run the VI When you click the Login Acquire Data Analyze amp Present Data or Data File View buttons a dialog box appears to indicate that you are in the associated state 4 Using the Single Step and Execution Highlighting features observe how the VI executes Notice that until you click a button the Sear
249. unction creates the new file Notice that the datalog type input to this function must receive an input Place the Write File function located on the Functions File I O palette on the block diagram This function writes a record to a datalog file Place the Close File function located on the Functions File I O palette on the block diagram In this exercise this function closes the file after the data is written to it 4 16 ni com Lesson 4 Advanced File I O Techniques h Place the Simple Error Handler VI located on the Functions Time amp Dialog palette on the block diagram In the event of an error this VI displays a dialog box with information about the error and where it occurred 4 After you finish the VI save and close it 5 Open Analyze and Present Data vi which you completed in Exercise 3 3 This VI calls Save Data to File VI When you run this VI and click the Log Results to File button a dialog box in the Save Data to File VI appears so you can name the data file to save Once you select the filename LabVIEW saves the data set as a datalog file End of Exercise 4 3 National Instruments Corporation 4 17 LabVIEW Basics II Course Manual Lesson 4 Advanced File I O Techniques Exercise 4 4 View Analysis File VI Objective To study a VI that reads data files created by the Save Data to File VI from Exercise 4 3 This VI reads and displays the data stored by the Save Data to File VI Yi Note You will us
250. vanced Profile VIs window Virtual memory has advantages and disadvantages It can significantly increase the amount of RAM available for LabVIEW and your VIs However because that RAM 1s located on the hard drive performance suffers when it 1s accessed Breaking large top level VIs into several smaller sub VIs reduces the amount of memory consumed in your application and can improve performance Use the following tips to improve the overall performance of your VIs e Avoid overusing local and global variables e Avoid displaying and manipulating large arrays and strings e Use functions that reuse data buffers 6 46 ni com National Instruments Corporation Lesson 6 Performance Issues Use consistent data types In other words avoid coercion dots Use simple data structures that are as flat as possible When generating arrays inside loops whose representation must be changed change the representation inside the loop not after 6 47 LabVIEW Basics II Course Manual Lesson 6 Performance Issues Notes LabVIEW Basics II Course Manual 6 48 ni com Appendix ka CLS SE This appendix contains the following sections of useful information for LabVIEW users A B Custom Graphics in LabVIEW C The LabVIEW Web Server D E ASCII Character Code Equivalents Table National Instruments Corporation Polymorphic subVIs Additional Information A 1 LabVIEW Basics II Course Manual Appendix A Polymorphic S
251. ve training needs Please list Do you have other training needs that we could assist you with How did you hear about this course O National Instruments web site O National Instruments Sales Representative O Mailing O Co worker O Other Customer Education Student Profile Name Company Mailing Address City Telephone E Mail Date State Province Industry and Application Information Which industry does your company primarily serve check only one _J Automotive I Computer I Consumer products 1 Electronics J Graphics I Industrial systems factory floor integrator I Medical 1 Military space J Paper pulp I Petrochemical plastics Title Mail Stop Country Fax Event Location _J Pharmaceutical I Aero avionics I Semiconductor 1 ATE automated test I Other Zip I Test measurement and instrumentation d Telecommunications I University education If you are currently a customer of National Instruments please check the products you use 1 LabVIEW 1 LabWindows CVI I BridgeVIEW 1 Lookout I HiQ I ComponentWorks J VirtualBench 1 Measure Please check the operating system s you use _J Windows NT _I Windows 95 LJ Windows 3 1 _J Sun Please check the bus architecture s you use PC XT AT I PCMCIA I PCI LI VME What other products are of interest to you 1 LabVIEW I LabWindows CVI I Bridge VIEW I Lookou
252. w machines 7 Small target file with external file for subla LLE tor other files 4 ILW4INDOMWSSTEMP appdata lib National Instruments Corporation 5 23 LabVIEW Basics II Course Manual Lesson 5 Developing Larger Projects in LabVIEW We From the Target tab you can specify 1f you want to create a stand alone executable or a shared library the name of your application and the directory in which to create it Optionally you can choose to write sub VIS to an external file if you want to keep the main application small From the Source Files tab you can define the VIs that make up your application When you click Add Top Level VI you add the main VI s for your application You need to select only the top level VI and LabVIEW automatically includes all subVIs and related files such as menu files or DLLs If your VI dynamically calls any subVIs using the VI Server LabVIEW cannot detect them automatically so you must add them by clicking the Add Dynamic VI button If you want to include any data files with your application click the Add Support File button and the data files automatically copy over to your application directory From the VI Settings tab specify modifications to make to your VIs as part of the build You can choose to disable certain VI Properties These settings only apply to the build process and do not affect your original source VIs LabVIEW automatically creates your application as small as possible by rem
253. w to clear the current history Click Yes to confirm the deletion of the history and resetting of the revision number 4 In the Comment box of the History window type in Initial Application Created and then click the Add button Your comment should appear in the Revision History listing along with a date and time stamp Close the Revision History window 5 Select Browse Show VI Hierarchy The application s hierarchy appears A Hierarchy window AHALTZE FRESEHT LabVIEW Basics II Course Manual 5 18 ni com Lesson 5 Developing Larger Projects in LabVIEW Experiment with expanding and collapsing the hierarchy Notice that as you click the small black and red arrows in the hierarchy they expand or collapse branches of the hierarchy You might see some icons with a red arrow by them indicating that they call one or more subVIs In addition you might also see icons with a blue arrow next to them which occurs when a subVI is called from multiple places in an application but not all calls are currently indicated in the hierarchy Examine the operation of the buttons in the hierarchy toolbar Notice how you can arrange the hierarchy using the Layout buttons or by dragging the icons or include various application components using the Include buttons Use Redo Layout to redraw the window layout to minimize line crossing and maximize symmetry Double click any subVI icon in the hierarchy to display the appropriate subVI Close
254. where each numeric state leads to another subsequent state The following table summarizes this series of dependencies pate yale Value ate ane Name ae State RESTE evens Event Monitor Mo one on the menu to determine Boolean button the next state pressed If no button is pressed next state is No Event ee a m Analyze data Event possibly save to file View View saved data No Event files Stop VI No Event Event In this exercise you will build the state machine to be used in this application and observe its operation Kp Note You will use this VI in Lesson 5 LabVIEW Basics II Course Manual 2 18 ni com Lesson 2 Designing Front Panels Front Panel menH cluster Configure Data Acquisition Acquire Data Analyze amp Present Data View Analysis File cluster Autosizing selected Labelled Square Buttons Mechanical Action Latch When Released Rectangular Stop Button 1 Open anew VI 2 Build the front panel according to the previous example Each button in the cluster will trigger an appropriate state when it is pressed When building the front panel make sure that the Login button is at cluster order 0 Acquire Data is cluster order 1 Analyze amp Present Data is cluster order 2 View Analysis File is cluster order 3 and Stop is cluster order 4 The cluster order of the menu cluster will determine the numeric state which will be executed Hints e Create the button with the
255. wo Waveform Graphs located on the Controls Graph palette to the front panel as shown in the previous front panel Label them appropriately You will create the two clusters Sampling Info and averaging parameters from the block diagram LabVIEW Basics II Course Manual Lesson 1 Planning LabVIEW Applications Block Diagram Ine Freguernc Sine Waveform wi Decne averaging narameters p Uniform White Noise Waveform v1 Unbundle By Name ait Until Hest me Multiple cmp status E A Ta 3 Open and build the block diagram using the following components a Place a While Loop located on the Functions Structures palette on the block diagram This structures the VI to continue to generate and analyze data until the user clicks the Stop button Right click the Conditional terminal and select Stop If True b Place the Sine Waveform VI located on the Functions Analyze Waveform Generation palette on the block diagram This VI generates a sine waveform with the specified frequency amplitude and sampling information To create the sampling info cluster control right click that input terminal and select Create Control from the shortcut menu c Place the Uniform White Noise Waveform VI located on the Functions Analyze Waveform Generation palette on the block diagram This VI generates a waveform of uniform white noise specified by the amplitude and sampling information a d Place the Merge Er
256. x Click OK c Exit and restart LabVIEW so that the updated preferences take effect LabVIEW is now configured to run VIs under a single thread using co operative multitasking 2 Open the Dialog amp SubVI Demo VI The VI is already built for you The front panel contains a strip chart and several option buttons This chart shows two pieces of data the running average of a simulated temperature and a red plot showing how quickly these averages are calculated Averages Sec a 20000 84 24 Chart Temp Avg 200 0 175 0 150 0 125 0 100 0 5 0 50 0 25 0 LL a 1679 1700 1720 1740 1760 Show Dialog 4 Pop Up vl LabVIEW Basics II Course Manual 6 20 ni com National Instruments Corporation Lesson 6 Performance Issues Plot Loop Gi Menu Loop One Button E Pop up 2nd Frocess wi Dialog Ce ce E Sub l Set Up Options Show wher called Close aftenwards Open the block diagram and examine it Two While Loops run in parallel One loop handles data collection and analysis while the other handles the user interface Run the VI Notice the plot speed and the averages second being calculated Notice that the Averages Sec value is periodic and dips very low The block diagram contains two While Loops running in parallel The Plot Loop top is the one generating the temperature average
257. xercise use cursors that are locked to the plot Use Property Nodes to initially set the cursor indices to the beginning and end of the array of data when the VI starts When the user clicks the Analyze Selected Subset button read the location of each cursor and use this information to find the DC RMS frequency amplitude and phase values of the subset of data LabVIEW Basics I Course Manual Lesson 2 Designing Front Panels Block Diagram ao00000000000000000 Ca jf IR OCOUOUOCOOOUOCOOUUE CO D Locked to plot Cursor Locked Cursor Locked T iti Analvsis Results Initial Cluster EH 1 Complete the block diagram shown previously To create the Property Nodes right click the Data and Analysis Results terminals and select Create Property Node from the shortcut menu Use the Positioning tool to resize the Property Node so it has enough terminals You can then select the property by right clicking the newly created node and selecting the property from the Properties menu The Cursor Index property is found in Cursor Cursor Index Place the Array Subset function located on the Functions Array a7 palette on the block diagram In this exercise this function extracts the set of data points to analyze g Place the Max amp Min function located on the Functions Comparison FL palette on the block diagram In this exercise this function determines the first and last index for finding the subset of data to analy
258. y reasons Almost every operating system and a majority of software applications can read and write files in text format Historically most instrument control applications such as GPIB and serial use text strings to send control statements Because of the universality of the text format there are several situations where text files are preferable for data storage For example text files are preferable when you plan to read or manipulate the data with other software applications such as spreadsheet or word processing applications Text files also have some significant disadvantages It 1s difficult to randomly access numeric data in text files Although each character in a string takes up exactly one byte of space the space required to express a number as text typically is not fixed To find the ninth number in a text file LabVIEW must first read and convert the preceding eight numbers You might lose precision if you store numeric data in text files Computers store numeric data as binary data and typically you write numeric data to a text file in decimal notation A loss of precision might occur when you read the data from the text file Loss of precision is not an issue with binary files As shown in the previous block diagram the Write File function skips over any header information that LabVIEW uses to store the string in memory and writes the contents of the string data control to the file In fact the Write File function does not d
259. y the Operate item in the menu list 2 56 ni com Lesson 2 Designing Front Panels 5 Click the button in the Menu Editor toolbar A new unnamed item 277 appears in the menu list With this item highlighted enter Test into the Item Name property This menu item now has an item name and tag of Test 6 Click the button again to add another entry under the Test item Click the right arrow button on the toolbar and this unnamed option becomes a subitem under the Test menu Type in the Item Name Test 1 for this new item 7 Add two more subitems under the Test submenu called Test 2 and Test 3 The Menu Editor dialog box should now resemble the following If Menu Editor Untitled rtm File Edit Help Preview Operate Test Operate ltem Properties Test ltem Type Test 1 User ltem Test 2 ltem Name Test 3 ltem Tag Test 3 M Enabled T Checked Shortcut Press key combination RE In the Preview area of the Menu Editor you can see how the custom menu will behave during run time 8 Select File Save from the Menu Editor dialog box Save the run time menu as Menu Exercise rtminthec exercises LV Basics 2 directory Then close the Menu Editor dialog box When LabVIEW asks if you want to change the run time menu to Menu Exercise rtm select Yes You have configured a custom pull down menu which will be invoked while the VI executes National Instruments Corporation 2 57 LabVIEW
260. ze LabVIEW Basics II Course Manual 2 44 ni com Lesson 2 Designing Front Panels Place the Basic Averaged DC RMS VI located on the Functions ogri Analyze Waveform Measurements palette on the block diagram This VI takes the input waveform and calculates the DC and RMS values AT Place the Extract Single Tone Information VI located on the Pan Functions Analyze Waveform Measurements palette on the block diagram This VI takes the input waveform calculates the frequency response and returns the single tone with highest amplitude LabVIEW returns the amplitude frequency and phase values of that single tone a Save the VI under the same name Run the VI Move the cursors along the graph to select a subset of data to analyze and then click the Analyze Selected Subset button The results appear in the Analysis Results cluster When you have finished click the Return button 4 Close the VI when you are finished End of Exercise 2 7 National Instruments Corporation 2 45 LabVIEW Basics II Course Manual Lesson 2 Designing Front Panels E Control References In the previous two sections you used Property Nodes to programmatically change the characteristics of panel objects If you are building a large VI that contains many Property Nodes or if you are using the same property for many different controls and indicators you might want to consider placing the Property Node in a subVI and using Control References to access

Download Pdf Manuals

image

Related Search

Related Contents

ロスタテンショナー  TL-NDF10P  Istruzioni per l`uso  the Parry LPG 4 Round Pot Wet Bain    Indy X Chop Dispense Gun User ManualRevB1  Manual do utilizador do Auricular Bluetooth (HS-37W) da  

Copyright © All rights reserved.
Failed to retrieve file