1 / 45

Workshop 3 of 7

Welcome!. Workshop 3 of 7. Today's Topics. Review of Workshop 2 Loops While For Auto-indexing Shift registers Case Structure. Review Question 1. True or False? Arrays can contain only one data type. An array must contain at least one element.

minda
Télécharger la présentation

Workshop 3 of 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome! Workshop 3 of 7

  2. Today's Topics Review of Workshop 2 Loops While For Auto-indexing Shift registers Case Structure

  3. Review Question 1 • True or False? • Arrays can contain only one data type. • An array must contain at least one element. • The Bundle function can be used to add elements to a cluster. • Clusters can contain both controls and indicators within the same shell; however, arrays cannot. • It is possible to have clusters containing arrays as well as arrays containing clusters.

  4. Review Question 1 • True or False? • Arrays can contain only one data type. TRUE • An array must contain at least one element. FALSE • The Bundle function can be used to add elements to a cluster. FALSE • Clusters can contain both controls and indicators within the same shell; however, arrays cannot. FALSE • It is possible to have clusters containing arrays as well as arrays containing clusters. TRUE

  5. Review Question 2 • The Error Cluster contains which of the following? • Boolean • Array • String • Numeric • Cluster

  6. Review Question 2 • The Error Cluster contains which of the following? • Boolean -status • Array • String - source • Numeric - code • Cluster

  7. Review Question 3 • An enumeration is a list of ___ and ___ pairs and acts like a ____ to the computer and ____ to the user. • integer, string, integer, string • Boolean, string, boolean, string • Boolean, integer, boolean, integer • integer, string, string, integer

  8. Review Question 3 • An enumeration is a list of ___ and ___ pairs and acts like a ____ to the computer and ____ to the user. • integer, string, integer, string • Boolean, string, boolean, string • Boolean, integer, boolean, integer • integer, string, string, integer

  9. Review Question 1 If I add a new element to an enum that is saved in a *.ctl file, how would the file need to be saved in order to update all of instances Custom control Strict Type Definition Type Definition

  10. Review Question 1 If I add a new element to an enum that is saved in a *.ctl file, how would the file need to be saved in order to update all of instances Custom control Strict Type Definition Type Definition

  11. Review Question 2 Which of the following always remain unique to each instance? Label Default value Size Data type Representation (numerics) Description

  12. Review Question 2 Which of the following always remain unique to each instance? Label Default value Size Data type Representation (numerics) Description

  13. Review Question 3 True or False? A custom control can only be used for the project within which it was created.

  14. Review Question 3 True or False? A custom control can only be used for the project within which it was created. FALSE

  15. Loops • Use loops when you want to repeat a section of code • Types: • While – repeats until a condition is met • For – repeats for X number of iterations

  16. While Loops • terminal counts the number of iterations; zero indexed • Always runs at least once (therefore, really a do-while loop) • Runs until stop condition is met • Stop if TRUE • Continue if TRUE While Loop Conditional terminal Iteration terminal

  17. For Loops • i Terminal counts iterations • Runs according to input Nof count terminal Count terminal For Loop Iteration terminal i = zero indexed N = one indexed

  18. Creating a Loop 2. Enclose code to be repeated 1. Select the structure 3. Drop or drag additional nodes and then wire

  19. Demonstration: Creating a Loop

  20. Building Arrays with Loops Auto-Indexing Enabled • Loops can accumulate arrays at their boundaries with auto-indexing • For loops auto-index by default • While loops output only the final value by default • Right-click tunnel and enable/disable auto-indexing Wire becomes thicker 1D Array 0 1 2 3 4 5 Auto-Indexing Disabled Wire remains the same size Only one value (last iteration) is passed out of the loop 5

  21. Auto-Indexing Input • If an array is passed into a For Loop and auto-indexing is enabled, the number of elements in the array determines the number of iterations of the For Loop (therefore, you are not required to wire the N terminal) • If the iteration count terminal is wired and arrays of different sizes are wired to auto-indexed tunnels, the actual number of iterations is the smallest of the choices.

  22. Shift Registers - Access Previous Loop Data “Up and around the loop” Left terminal provides stored data at beginning of next iteration Right terminal stores data on completion of current iteration • Come in pairs that are always aligned with each other • Available at left and right borders of loop structures • To create: • Right-click the border and select Add Shift Register • Right-click an existing tunnel, select Replace with Shift Register, and click the opposite loop border to create other half of pair

  23. Shift Registers in action Value 15 Initial Value Before Loop Begins First Iteration Second Iteration Last Iteration

  24. Stacked Shift Registers • Registers remember values from multiple previous iterations and carry those values to the next iterations • Values “bump down” with each iteration • To create: • Right-click » Add Element • Expand the left side register (down arrows) up or down by dragging the small square when the mouse is a double arrow Initial Value Note: Still only 1 register on right side

  25. Shift Registers - Uninitialized Run once VI finishes Run again

  26. Demonstration: Operation of a Shift Register

  27. Case Structure • Case Selector Label • Have two or more subdiagrams or cases • Execute and displays only one case at a time • An input value determines which subdiagram to execute • Similar to case statements or if...then...else statements in text-based programming languages • Selector Terminal

  28. Case Structure: Inputs • You can create multiple input tunnels • Inputs are available to all cases, but do not have to be used in all cases

  29. Case Structure: Outputs • You can create multiple output tunnels • You must define each output tunnel for each case, otherwise • Wire every case (2) • Right-click » Use Default If Unwired (3) (2) (3) (1)

  30. Case Structure

  31. Case Structure • If the error cluster is wired to the selector, the border of the case structure automatically turns red or green for the error and non-error cases, respectively Holy automatic coloring, Batman!

  32. Demonstration: Creating a Case Structure and Adding a Case

  33. Diagram Disable Structure • Use to disable a section of code on the block diagram • Multiple subdiagrams possible – maximum of one enabled • Disabled subdiagrams appear grayed out • Great tool for troubleshooting – don’t have to re-write code

  34. Conditional Disable Structure • Use 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.

  35. Events • Event — An asynchronous notification that something has occurred • Events originate from the user interface, external I/O, or other parts of the program • Example events: • Button click • Value change • Mouse over • Key press

  36. Event Structure • Event Structure — LabVIEW’s programmatic tool for handling events. • Therefore, execution of code can be dependent on whether or not an event has occurred • Waits for an event to occur indefinitely, unless configured to timeout.

  37. Parts of an Event Structure • Event Data Node Identifies the data LabVIEW provides when the event occurs; similar to the Unbundle By Name function • Event Filter Node Identifies the subset of data available in the Event Data node that the event case can modify Timeout Event Selector Label Event Data Node Event Filter Node

  38. Notify and Filter Events • Notify Events • User action has already occurred • LabVIEW has processed the event • Available only in the Event Data node • Filter Events • User action has already occurred • LabVIEW has NOT processed the event • Allows you to override default behavior for event • Available in the Event Filter node and Event Data node

  39. To Configure an Event Structure… Right-click the border and select Edit Events Handled by This Case

  40. Configuring Event Structures Configured Events Event Sources Events

  41. Notify and Filter Events in Config. Window Notify Events (green arrow) User action has already occurred Filter Events (red arrow) User performed action but event is not processed. Allows you to customize event handling.

  42. Using Event Structures • Normally used in a While Loop • Control/Indicator the event configured for is often placed inside that event case • Event structure handles exactly one event per iteration • Sleeps when no events occur

  43. Event Structures Tips • If no timeout is configured and an event never occurs – stuck waiting indefinitely, must abort VI; therefore, wire the timeout terminal with a value other than -1 (at least while developing) • “heavy” code within the Event Structure causes the front panel to lock up, often confusing the user – try to keep code in an event case to a minimum

  44. Demonstration: Configuring an Event

  45. Homework • Homework 3 is post at ni.com/mst • Create a Game • Student Zone has a lot of ideas • Email to mst.labview@gmail.com

More Related