TOPICS 0 ni.com/training Quiz Which types of folders are available in a LabVIEW Project? a) b) c) d) 1 Virtual folder Logical folder Auto-updating folder Auto-populating folder ni.com/training 1 Quiz Answer Which types of folders are available in a LabVIEW Project? a) b) c) d) 2 Virtual folder Logical folder Auto-updating folder Auto-populating folder ni.com/training 2 Quiz Match the data types with wires that represent them on the block diagram. a) b) c) d) 3 String Boolean Integer Numeric Floating-Point Numeric ni.com/training 3 Quiz Answer Match the data types with wires that represent them on the block diagram. a) b) c) d) 4 String Boolean Integer Numeric Floating-Point Numeric ni.com/training 4 Quiz What is the value in XOR Result after the following code has executed? a) b) c) d) 0 1 True False ni.com/training Quiz Answer What is the value in XOR Result after the following code has executed? a) b) c) d) 0 1 True False ni.com/training Quiz In the following VI, what is the execution order of functions? ni.com/training Quiz Answer In the following VI, what is the execution order of functions? ni.com/training Implementing a VI TOPICS A. Designing Controls and Indicators B. LabVIEW Data Types C. While Loop D. For Loop 9 E. F. G. H. Timing a VI Data Feedback in Loops Case Structure Disable Structures ni.com/training A. Designing Controls and Indicators 10 ni.com/training Labels & Options Make sure to label controls and indicators clearly and set a default value if necessary. ni.com/training B. LabVIEW Data Types Shortcut Menu and Properties Dialog Box Numeric Types Boolean Types String Types Enums and Other Types 12 ni.com/training LabVIEW Data Types Terminals visually communicate information about the data type represented. 13 ni.com/training Shortcut Menus • All LabVIEW objects have associated shortcut menus. • Use shortcut menu items to change the look or behavior of objects. • To access the shortcut menu, right-click the object. 14 ni.com/training 14 Properties Dialog Box • All LabVIEW objects have properties. • To access properties, right-click the object and select Properties. • Property options are similar to shortcut menu options. • Select multiple objects to simultaneously configure their common properties. 15 ni.com/training 15 Numerics Various data type representations: • Floating-point • Unsigned integers • Signed integers 16 ni.com/training Numeric Conversion Coercion Dot • Coercion dots indicate that LabVIEW converted the value passed into a node to a different representation. − Occurs when a node expects an input with a different representation. • LabVIEW chooses the representation that uses more bits. • Avoid coercion by programmatically converting to a matching data type. 17 ni.com/training Booleans • Behavior of Boolean controls is specified by the mechanical action. • Boolean have only TRUE/FALSE values. 18 ni.com/training Mechanical Action of Booleans 19 ni.com/training Mechanical Action of Booleans Use the Properties»Operations tab of a Boolean control to learn about the different switch and latch actions. DEMONSTRATION Strings • A string is a sequence of ASCII characters. • Strings have various display styles. − Backslash codes − Password − Hex 21 ni.com/training Enums • Enums give users a list of items from which to select. • Each item represents a pair of values. − String − Unsigned integer 22 ni.com/training Other Data Types Refer to LabVIEW Help for complete list of terminal symbols for different types of controls and indicators. • Dynamic − Stores the information generated or acquired by an Express VI. • Path − Stores the location of a file or directory using the standard syntax for the platform you are using. • Waveform − Carries the samples, start time, and dt of a waveform. 23 ni.com/training Searching Help for Data Types Use LabVIEW Help to learn about LabVIEW data types. DEMONSTRATION C. While Loop Iteration and Conditional Terminals Tunnels Error Checking 25 ni.com/training While Loop Repeat (code); Until Condition met; End; LabVIEW While Loop 26 Flowchart Pseudo Code ni.com/training While Loop Iteration terminal Conditional terminal • Returns number of times loop has executed. • Is zero-indexed. • Defines when the loop stops. • Has two options: − Stop if True − Continue if True. Iteration Terminal 27 Conditional Terminal ni.com/training While Loop – Tunnels • Tunnels transfer data into and out of structures. • When a tunnel passes data into a loop, the loop executes only after data arrive at the tunnel (at all tunnels, if there is more than one). • Data pass out of a loop after the loop terminates. 28 ni.com/training While Loop – Error Checking and Error Handling Use an error cluster in a While Loop to stop the While Loop if an error occurs. 29 ni.com/training Auto Match VI Use a While Loop and the iteration terminal and pass data through a tunnel. DEMONSTRATION Auto Match VI How many times is the Number of Iterations indicator updated? Why? DISCUSSION D. For Loop Conditional Terminals Comparison with While Loop Numeric Conversion for Count Terminal 32 ni.com/training For Loop N=100; i=0; Until i=N: Repeat (code;i=i+1); End; LabVIEW For Loop 33 Flowchart Pseudo Code ni.com/training For Loop • Create a For Loop the same way you create a While Loop. • You can replace a While Loop with a For Loop by right-clicking the border of the While Loop and selecting Replace with For Loop from the shortcut menu. • The value in the count terminal (an input terminal) indicates how many times to repeat the subdiagram in the For Loop. 34 ni.com/training For Loop – Conditional Terminal You can add a conditional terminal to configure a For Loop to stop when a Boolean condition is true or an error occurs. This is similar to a ‘break’ statement in text-based programming languages. 35 ni.com/training For Loop – Conditional Terminal For Loops configured with a conditional terminal have: • A red glyph next to the count terminal • A conditional terminal in the lower right corner. 36 ni.com/training For Loop / While Loop Comparison For Loop • Executes a set number of times unless a conditional terminal is added. • Can execute zero times. • Tunnels automatically output an array of data. 37 While Loop • Stops executing only if the value at the conditional terminal meets the condition. • Must execute at least once. • Tunnels automatically output the last value. ni.com/training For Loop – Numeric Conversion • The number of iterations a For Loop executes must be specified in non-negative integers. • If you wire a double-precision, floating-point numeric value to the count terminal, LabVIEW converts the numeric value to a 32-bit signed integer. 38 ni.com/training Group Exercise Concept: While Loops versus For Loops When to use a While Loop and when to use a For Loop? DISCUSSION E. Timing a VI Reasons To Use Timing Wait Functions and Express VIs 40 ni.com/training Timing a VI Why do you need timing in a VI? • To control the frequency at which a loop executes. • To provide the processor with time to complete other tasks, such as processing the user interface or running other applications. 41 ni.com/training Wait Functions A wait function inside a loop: • Allows the VI to sleep for a set amount of time. • Allows the processor to address other tasks during the wait time. • Uses the operating system millisecond clock. 42 ni.com/training Elapsed Time Express VI • Determines how much time elapses after some point in your VI. • Keeps track of time while the VI continues to execute. • Does not provide the processor with time to complete other tasks. 43 ni.com/training Wait Chart VI Compare and contrast using a Wait function and the Elapsed Time Express VI for software timing. DEMONSTRATION F. Data Feedback in Loops Shift Registers Initializing Shift Registers Default for Unwired Values Compound Shift Registers 45 ni.com/training Data Feedback in Loops • When programming with loops, you often need to know the values of data from previous iterations of the loop. • Shift registers transfer values from one loop iteration to the next. 46 ni.com/training Shift Registers • Right-click the border and select Add Shift Register from the shortcut menu. • Right part of shift register stores data on completion of an iteration. • Left part of shift register provides stored data at the beginning of the next iteration. 47 ni.com/training Initializing Shift Registers Run once Block Diagram VI finishes Run again 1st run 2nd run Initialized Shift Register Output = 5 Output = 5 Not Initialized Shift Register Output = 4 Output = 8 48 ni.com/training Default Value if Unwired Default values vary by data type: Data Type Default Value Numeric 0 Boolean FALSE String Empty Uninitialized shift registers use default values for the first run. At the beginning of next runs, they remember the last value they stored. 49 ni.com/training Multiple Previous Iterations • Stacked shift registers remember values from multiple previous iterations and carry those values to the next iterations. • Right-click the left shift register and select Add Element from the shortcut menu to stack a shift register. 50 ni.com/training G. Case Structures Parts of a Case Structure Enum Case Structures Error Case Structures Input and Output Tunnels 51 ni.com/training Case Structures • Have two or more subdiagrams (cases). • Use an input value to determine which case to execute. • Execute and display only one case at a time. • Are similar to case statements or if...then...else statements in text-based programming languages. 52 ni.com/training Case Structures • Case Selector Label − Contains the name of the current case. − Has decrement and increment arrows. • Selector Terminal − Lets you wire an input value, or selector, to determine which case executes. Case Selector Label Selector Terminal 53 ni.com/training Case Structures Selector terminal data types: • Boolean − True case and False case • Error Cluster − Error case and No Error case • Integer, string or enum − Structure can have any number of cases − Include a Default diagram to avoid listing every possible input value 54 ni.com/training Shortcut Menu Use the shortcut menu of a Case Structure to: − Customize the structure and diagrams. − Remove or replace the structure. − Add, duplicate, remove or rearrange cases. − Specify the Default case. − Switch cases. 55 ni.com/training Enum Case Structure • Gives users a list of items from which to select. • The case selector displays a case for each item in the enumerated type control. 56 ni.com/training Error Case Structure Use Case structures inside VIs to execute the code if there is no error and skip the code if there is an error. 57 ni.com/training Input and Output Tunnels You can create multiple input and output tunnels. • Inputs tunnels are available to all cases if needed. • You must define each output tunnel for each case. 58 ni.com/training Case Structures • Create case structures using different data type selectors. • Add, remove and duplicate cases. • Create different types of output tunnels. DEMONSTRATION H. Disable Structures Diagram Disable Structure Conditional Disable Structure 60 ni.com/training Diagram Disable Structure Use it to disable a section of code on the block diagram. Multiple subdiagrams are possible – one is enabled. Disabled subdiagrams appear grayed out. Great tool for troubleshooting – no need to re-write code. ni.com/training Conditional Disable Structure • Use it to define conditions that indicate which code on the block diagram executes. • Examples: – – If running as an executable, then programmatically close LabVIEW when VI finishes. If running on Windows, look for file here; if running on Mac OSX, then look here. ni.com/training Homework: Blinking LED Use a While Loop a timing function to blink an LED. ni.com/training Homework: Average Temperature VI Use a While Loop and stacked shift registers to average data. ni.com/training Homework: Temperature Limits VI Use a Case Structure to output a string indicating if the temperature is OK or outside the limits. ni.com/training
© Copyright 2026 Paperzz