Presentation is loading. Please wait.

Presentation is loading. Please wait.

Quiz Which types of folders are available in a LabVIEW Project?

Similar presentations


Presentation on theme: "Quiz Which types of folders are available in a LabVIEW Project?"— Presentation transcript:

0

1 Quiz Which types of folders are available in a LabVIEW Project?
Virtual folder Logical folder Auto-updating folder Auto-populating folder 1

2 Quiz Answer Which types of folders are available in a LabVIEW Project?
Virtual folder Logical folder Auto-updating folder Auto-populating folder You can add auto-populating folders to a project and create virtual folders in it. Auto-populating folder has exactly the same contents as a directory on the disc. Virtual folder is a way to group files in one place in your project even if physically they are placed in different directories in the file system. 2

3 Quiz Match the data types with wires that represent them on the block diagram. String Boolean Integer Numeric Floating-Point Numeric 3

4 Quiz Answer Match the data types with wires that represent them on the block diagram. String Boolean Integer Numeric Floating-Point Numeric 4

5 Quiz What is the value in XOR Result after the following code has executed? 1 True False

6 Quiz Answer What is the value in XOR Result after the following code has executed? 1 True False LabVIEW follows a dataflow model for running VIs. A block diagram node executes when it receives all required inputs. When a node executes, it produces output data and passes the data to the next node in the dataflow path. As a result, 1 and 0 are passed to the or and the and nodes simultaneously. 1 or’ed with 0 equals 1 and 1 and’ed with 0 equals 0; therefore 1 and 0 are passed to the exclusive or node. 1 exclusive or’ed with 0 equals 1. The answer is an integer value (0/1) and not a Boolean value (False/True) because the code operates on integers – you can see the „1” and „0” constants and blue wires indicating integer data. Boolean data would be passed on green dotted wires and the constants would then be „T” (True) and „F” (False).

7 Quiz In the following VI, what is the execution order of functions?

8 Quiz Answer In the following VI, what is the execution order of functions? LabVIEW follows a dataflow model for running VIs. A block diagram node executes when it receives all required inputs. When a node executes, it produces output data and passes the data to the next node in the dataflow path. As a result, the decrement (-1) node executes and passes data to the division node giving it the second input it needs to execute. The data from the division node is passed to the multiplication node also giving it the second input it needs to execute. The data from the multiplication node is passed to the addition node giving it the second input it needs to execute. The data from the addition node is passed to the Round Toward +Infinity node giving it the input it needs to execute.

9 Implementing a VI Designing Controls and Indicators LabVIEW Data Types
While Loop For Loop Timing a VI Data Feedback in Loops Case Structure Disable Structures

10 A. Designing Controls and Indicators

11 Labels & Options Make sure to label controls and indicators clearly and set a default value if necessary. Front panel controls and indicators create terminals on the block diagram. The front panel is the user interface. Usually you start a VI with inputs and outputs on the front panel. The block diagram is the programming behind the user interface. After you build the front panel, you add code on the block diagram to control the front panel objects. The labels of the front panel objects become the identifying labels for the terminals on the block diagram. You can also set default values for controls and indicators.

12 B. LabVIEW Data Types Shortcut Menu and Properties Dialog Box
Numeric Types Boolean Types String Types Enums and Other Types

13 LabVIEW Data Types Terminals visually communicate information about the data type represented. Terminal colors, text, arrow direction, and border thickness all provide visual information about the terminal. For example, orange represents floating point numbers. DBL indicates a double-precision floating point number. Terminals with thick borders with arrows on the right are control terminals. Terminals with thin borders and arrows on the left are indicator terminals.

14 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

15 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. Instructor Demo: Demonstrate both shortcut menus and the Properties dialog box. Show how to multi-select and configure multiple objects through the Properties dialog box. For example, show and hide labels for multiple controls. 15

16 Numerics Various data type representations: Floating-point
Unsigned integers Signed integers Integers represent whole numbers. Unsigned integers are non-negative values. Signed integers can be positive, negative, or zero. Students learned about the numeric, Boolean and string data types in Lesson 1. Now, they learn about implementing these data types, such as representation, Boolean action, and string display type. They also learn a couple new data types: Enum and dynamic.

17 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. If you use two numbers of the same type with different bit widths, LabVIEW coerces the smaller to the larger of the two bit widths – e.g. when using 32- and 16-bit integers, the shorter one is coerced to 32-bit. Examples: If you use a signed integer with an unsigned integer, LabVIEW coerces the signed integer to the unsigned integer. If you use an integer with a floating point, LabVIEW coerces the integer to the floating point. If you use a floating point with a complex integer, LabVIEW coerces the floating point to the complex integer.

18 Booleans Behavior of Boolean controls is specified by the mechanical action. Boolean have only TRUE/FALSE values. Use Boolean controls and indicators to enter and display Boolean (TRUE/FALSE) values. For example, if you are monitoring the temperature of an experiment, you can place a Boolean warning light (LED) on the front panel to indicate when the temperature exceeds a certain level. Note the difference between the label name and Boolean text. The label matches the block diagram terminal label. Boolean text is cosmetic and appears only on the front panel.

19 Mechanical Action of Booleans
In everyday life we interface with many Boolean switches and buttons. These switches and buttons have different mechanical behaviors. Light switches change state when the switch is flipped. The state stays the same until you flip the switch again. Buzzers and door bells change state on a button press. They change back when the button is released. Mouse clicks and keyboard presses have a latch behavior. They change state on a button release. Furthermore, the key press or mouse click only takes effect when read by the system. When your computer system is sluggish, we sometimes see a delay in processing a mouse click or key press.

20 Mechanical Action of Booleans
Use the Properties»Operations tab of a Boolean control to learn about the different switch and latch actions. Drop a Boolean control. Right-click the control to bring up the Properties dialog box. Switch to Operations tab. Experiment with different mechanical actions. (When you write a VI, alternatively to setting the mechanical action in the Operations tab of Properties window, you can change it via the shortcut menu: right-click the control and select Mechanical Action»desired option.) In a VI, you may test the latch actions on a Stop button wired to the conditional terminal of a While loop. Switch actions may be tested on a button wired to an LED indicator and placed in a while loop (or you may omit the loop and press Run Continuously button instead). Try pressing the buttons for a longer period, e.g. a second, before releasing the mouse and observe the differences between the variants of switch and latch actions.

21 Strings A string is a sequence of ASCII characters.
Strings have various display styles. Backslash codes Password Hex Uses for strings: Creating simple text messages. Controlling instruments by sending text commands to the instrument and returning data values in the form of either ASCII or binary strings which you then convert to numeric values. Storing numeric data to disk. To store numeric data in an ASCII file, you must first convert numeric data to strings before writing the data to a disk file. Instructing or prompting the user with dialog boxes.

22 Enums Enums give users a list of items from which to select.
Each item represents a pair of values. String Unsigned integer Each enum value is presented as string to the user (and programmer) and as number to the processor. Enums are useful because they make strings equivalent to numbers, and it is easier to manipulate numbers than strings on the block diagram. The data type of the enum terminal is blue, showing that the enum is passing an integer value. You can configure which type of integer you want your enum to be represented by, just as you do it with numeric controls, indicators and constants (right-click the enum and go to Representation or right-click, go to Properties and switch to Data Type tab). You can choose from 8-, 16- and 32-bit unsigned integer. s

23 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. Ask students how a Path data type might differ from a String data type? Although it is easy to convert a Path to a String, it is best to use a Path data type when working with a location of a file or directory. Using the Path data type, LabVIEW can handle the folder specifiers (for example, a backslash on Windows).

24 Searching Help for Data Types
Use LabVIEW Help to learn about LabVIEW data types. Display the LabVIEW Help. (Select Help»LabVIEW Help.) Switch to the Index tab. Search for “data types” to view the Control and Indicator Data Types help topic. Show the complete list of data types with terminal colors and usage details. Point out the Default Values column. Indicate that students should learn the default value of common data types (numerics, string, Boolean) as this will be important for later lessons.

25 C. While Loop Iteration and Conditional Terminals Tunnels
Error Checking

26 While Loop LabVIEW While Loop Flowchart Pseudo Code Repeat (code);
Until Condition met; End; Demonstrate the creation of a While Loop. To create a While Loop complete the following: Select the While Loop from the palette. Use the cursor to drag a selection rectangle around the section of the block diagram you want to repeat. When you release the mouse button, a While Loop boundary encloses the section you selected. Add block diagram objects to the While Loop by dragging and dropping them inside the While Loop. LabVIEW While Loop Flowchart Pseudo Code

27 While Loop Iteration terminal Conditional terminal
Returns number of times loop has executed. Is zero-indexed. Conditional terminal Defines when the loop stops. Has two options: Stop if True Continue if True. Iteration Terminal Conditional Terminal By default the iteration terminal is in lower right corner of the While Loop and the conditional terminal is in the lower left corner. The conditional terminal defaults to Stop if True. Most applications use this option. However, you can also modify it to use Continue if True. Just click the conditional terminal when the cursor has a shape of white hand.

28 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.

29 While Loop – Error Checking and Error Handling
Use an error cluster in a While Loop to stop the While Loop if an error occurs.

30 Auto Match VI Use a While Loop and the iteration terminal and pass data through a tunnel. Example - Auto Match VI is attached to the slides.

31 Auto Match VI How many times is the Number of Iterations indicator updated? Why? How many times is the Number of Iterations updated? Why? Once, because the output tunnel on the While Loop will output only a single value once the While Loop has finished executing. Place a control inside a loop if you want it to be read at each loop iteration. Place a control outside a loop and wire its content through an input tunnel if you want to read the value of the control only once and then use the same value in each loop iteration. Place an indicator inside the loop if you want it to be updated in every loop iteration (first, consider if it makes sense to update it so often). Place an indicator outside the loop and wire a value from the loop through an output tunnel to the indicator if you want its value to be updated only once, after the loop finishes execution.

32 D. For Loop Conditional Terminals Comparison with While Loop
Numeric Conversion for Count Terminal

33 For Loop LabVIEW For Loop Flowchart Pseudo Code N=100; i=0; Until i=N:
Repeat (code;i=i+1); End; LabVIEW For Loop Flowchart Pseudo Code

34 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.

35 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.

36 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.

37 For Loop / While Loop Comparison
Executes a set number of times unless a conditional terminal is added. Can execute zero times. Tunnels automatically output an array of data. 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.

38 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. The For Loop count terminal always coerces to a 32-bit signed integer. Typically, LabVIEW coerces numerics to the format with more bit representation. However, the For Loop count terminal works in the opposite manner. If you wire a double-precision, floating-point numeric value to the 32-bit count terminal, LabVIEW coerces the larger numeric value to a 32-bit signed integer. Although the conversion is contrary to normal conversion standards, it is necessary, because a For Loop can only execute an integer number of times. The For Loop count terminal will always coerce to a 32-bit signed integer data type.

39 Group Exercise Concept: While Loops versus For Loops
When to use a While Loop and when to use a For Loop? Use a For Loop if you know the necessary number of iterations in advance. Use a While Loop if you don’t know the number of iterations in advance but you want to stop the loop when a certain condition occurs. Sometimes it is possible to use any of these loops and then you may just choose which one is more convenient to use for you in this situation.

40 E. Timing a VI Reasons To Use Timing Wait Functions and Express VIs

41 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.

42 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.

43 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.

44 Wait Chart VI Compare and contrast using a Wait function and the Elapsed Time Express VI for software timing. Open both Wait Chart example VIs or write them from scratch. Run the VIs and compare the results that they produce – when the wait times are equal in both VIs, the resulting graphs on the front panel are identical. Then compare the CPU usage when running these VIs: notice that Wait function makes the VI sleep and does not consume CPU time, while Elapsed Time Express VI does not do it and causes high CPU usage. ‘Iteration terminal’ indicators on the front panels also give insight to what is happening to the loops in both VIs – observe how often do the indicators increment their value.

45 F. Data Feedback in Loops
Shift Registers Initializing Shift Registers Default for Unwired Values Compound Shift Registers

46 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. Cover mechanics of using shift registers in later slides; here just talk about why you need them.

47 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.

48 Initializing Shift Registers
Run once VI finishes Run again Block Diagram 1st run 2nd run Initialized Shift Register Output = 5 Not Initialized Shift Register Output = 4 Output = 8

49 Default Value if Unwired
Default values vary by data type: Uninitialized shift registers use default values for the first run. At the beginning of next runs, they remember the last value they stored. Data Type Default Value Numeric Boolean FALSE String Empty

50 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.

51 G. Case Structures Parts of a Case Structure Enum Case Structures
Error Case Structures Input and Output Tunnels

52 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.

53 Case Structures Case Selector Label Selector Terminal
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

54 Case Structures Selector terminal data types: Boolean Error Cluster
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 Boolean input to the selector terminal creates two cases: True and False. Error cluster input to the selector terminal creates two cases: No Error and Error. Integer or string input to the selector terminal creates multiple cases. - Developer must add a case for each integer or string as necessary. If an undefined integer or strings is wired to the terminal, LabVIEW uses the Default case. - You can create one single case with label eg. 0..5, 7 – such a case is executed if a value of 0, 1, 2, 3, 4, 5 or 7 is passed to the selector terminal. Enums - Gives users a list of items from which to select a case. The case selector can display a case for each item in the enumerated type control; or, as with integers and strings, you may define single cases which handle multiple values of enum. One of the cases is the Default case – even if a separate case was defined for each value of enum, one of them still has to be marked as Default. To edit the case selector label, you may click it and start typing.

55 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.

56 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.

57 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.

58 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. Point out difference between tunnels that have been wired for all cases, tunnels that have not, and tunnels marked as Use Default If Unwired. Point out that the unwired output tunnel will result in a broken Run arrow. The other two options will not cause a broken Run arrow. Zoom in on the tunnels so that students can clearly see the differences. Demonstrate how to enable or disable the Use Default If Unwired option. Tell students to avoid using the Use Default If Unwired option on Case structure tunnels for the following reasons. Adds a level of complexity to the code. Complicates debugging your code.

59 Case Structures Create case structures using different data type selectors. Add, remove and duplicate cases. Create different types of output tunnels. Below are the key items to note: Show how the Case structure defaults to a Boolean Case structure with only two cases – True and False. Show how wiring different types of data types to the selector terminal changes the case selector label. Emphasize to students that they should wire the selector terminal BEFORE trying to change the selector label. Show the shortcut menu. Add, remove and duplicate a case. Show how deleting a case is different than removing the Case structure. Show how the Run arrow is broken if an output tunnel is not wired in each case.

60 H. Disable Structures Diagram Disable Structure
Conditional Disable Structure

61 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. Disable structures contain multiple subdiagrams of which exactly one compiles and executes. Code within the inactive subdiagrams does not compile or execute at run time. You can use disable structures to make sections of code on the block diagram inactive. Disable structures are similar to #if … #endif preprocessor directives in C-type programming languages. When LabVIEW loads a VI with user-defined objects - such as subVIs and typedefs - in the Disabled subdiagram of a Diagram Disable structure or in the inactive subdiagrams of a Conditional Disable structure, LabVIEW does not load these objects into memory. However, when you display the block diagram of the VI, LabVIEW attempts to load those objects. If LabVIEW cannot find the objects, LabVIEW returns a warning, but the VI does not break because LabVIEW does not include the code when compiling and executing the VI. Note LabVIEW does check the syntax of code in inactive subdiagrams. However, broken code within the inactive subdiagrams does not prevent the VI from compiling and executing. Use the Diagram Disable structure to disable specific code on the block diagram. Use the Conditional Disable structure to define conditions that indicate which code on the block diagram executes.

62 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. Use the Conditional Disable structure to define conditions that indicate which code on the block diagram executes. The Conditional Disable structure, shown as follows, has one or more subdiagrams, or cases, exactly one of which LabVIEW uses for the duration of execution, depending on the configuration of the conditions of the subdiagram. When compiling, LabVIEW does not include any code in the inactive subdiagrams of the Conditional Disable structure. Note LabVIEW does check the syntax of code in inactive subdiagrams. However, broken code within the inactive subdiagrams does not prevent the VI from compiling and executing. Use the Conditional Disable structure to define conditions in which specific code compiles and executes. For example, if one section of the VI is target-specific, you can put this code in a Conditional Disable structure and configure it to run on the specific target. Targets you might configure a Conditional Disable structure for include Windows, Mac, Unix systems and FPGA targets. Browse LV Help for more details on types of conditions (symbols) and valid values for them. Some symbols are available only if the VI is a part of a LV project. You can define your own Conditional Disable Symbols for VIs in a project. To do this, right-click a target (for example, My Computer) in the project tree and select Properties>>Conditional Disable Symbols. You can define a new symbol by writing its name in New Symbol field and its current value in New Value field.

63 Homework: Blinking LED
Use a While Loop a timing function to blink an LED. Version 1: with shift register Create a While loop with Boolean shift register. Inside the loop, connect the shift register with an LED. To make the LED blink, negate the Boolean value taken from the left part of the shift register and wire it to the right part of the shift register. Version 2: with checking if iteration number (i) is even or odd Create a While loop. Wire the iteration number (the „i” terminal) to Quotient and Remainder function and check the remainder of dividing the number by 2. Compare the remainder (which is 0 or 1) with constant 0 and wire the result to an LED. In both versions Control the blinking rate by adding a Wait or Wait Until Next ms Multiple function. The ms input to the function may be a constant or you might make it a control to allow the user to adjust the blinking rate. Do not forget to add a Stop button to finish execution of the loop. Sample front panel for the VI is presented in the slide.

64 Homework: Average Temperature VI
You are taking temperature measurements using temperature.vi (available on the webpage) which simulates reading a temperature sensor. Use this subVI in a While Loop to take continuous measurements and display them on a Waveform Chart. Do not forget about timing! Set a reasonable loop period, using for example Wait or Wait Until Next ms Multiple function. Calculate the moving average of 5 measurements (use a stacked shift register) and display the averaged temperature on a chart as well. Do not forget to initialize the shift register, for example with a temperature reading from temperature.vi. Sample front panel for the VI is presented on the slide. Use a While Loop and stacked shift registers to average data.

65 Homework: Temperature Limits VI
Use a Case Structure to output a string indicating if the temperature is OK or outside the limits. You may use the VI created as the previous homework and modify it. Add two numeric controls: High Limit and Low Limit, in which the user specifies allowable temperature limits. Add a string indicator where a message is displayed: Temperature OK if the current readings are within these limits, Too hot or Too cold if the temperature is above or below the limits. To select the proper string to be displayed, use Case Structures or Select function (available in Functions>>Programming>>Comparison palette). Sample front panel for the VI is presented on the slide.


Download ppt "Quiz Which types of folders are available in a LabVIEW Project?"

Similar presentations


Ads by Google