Presentation is loading. Please wait.

Presentation is loading. Please wait.

Workshop 2 of 4 Welcome!. Survey While You Wait ni.com/duke >> Recent Documents >> LabVIEW Workshop Participation Survey.

Similar presentations


Presentation on theme: "Workshop 2 of 4 Welcome!. Survey While You Wait ni.com/duke >> Recent Documents >> LabVIEW Workshop Participation Survey."— Presentation transcript:

1 Workshop 2 of 4 Welcome!

2 Survey While You Wait ni.com/duke >> Recent Documents >> LabVIEW Workshop Participation Survey

3 Today's Topics Review of Workshop 1 More Structures Sequence, Disable, Conditional, Case Enumerations State Machine – Activity: build a state machine Timing Event Structure

4 Review Question 1 Which of the following are the three parts of a VI? a)Front Panel b)Project c)Block Diagram d)Connector Pane/Icon

5 Review Question 1 Which of the following are the three parts of a VI? a)Front Panel b)Project c)Block Diagram d)Connector Pane/Icon

6 Use LabVIEW Projects to: Group LabVIEW files and non-LabVIEW files Create build specifications (i.e. stand-alone applications) Deploy or download files to targets (i.e. FPGA target) 6 Project Explorer Right Click!

7 Answer: a LabVIEW program 1. Front Panel User interface (UI) – Controls = inputs – Indicators = outputs 2. Block Diagram Graphical source code – Data travels on wires from control terminals through functions to indicator terminals – Blocks execute by data flow 3. Icon/Connector Pane Graphical representation of a VI Means of connecting VIs (subVIs) What is a Virtual Instrument (VI)? * Conn. pane available from FP only

8 Review Question 2 1.Which identifies the control or indicator on the block diagram? a)Caption b)Location c)Label d)Value

9 Review Question 2 1.Which identifies the control or indicator on the block diagram? a)Caption b)Location c)Label d)Value

10 Review Question 3 Which of the following are not a nodes? a)Terminals b)Structures (while loop, for loop) c)subVIs d)Wires e)Functions

11 Review Question 3 Which of the following are not a nodes? a)Terminals b)Structures (while loop, for loop, etc.) c)subVIs d)Wires e)Functions

12 Block Diagram Nodes Objects on the block diagram that have inputs and/or outputs and perform operations when a VI runs Analogous to statements, operators, functions, and subroutines in text-based programming languages Functions Fundamental operating elements of LabVIEW Do not have front panels or block diagrams, but do have connector panes Double-clicking a function only selects the function – does not open it like a VI Has a pale yellow background on its icon subVIs VIs that you build to use inside of another VI Any VI has potential to become a subVI Double-clicking a subVI will open it (exception: Express VIs – config. window opens) Icon represents subVI in main VI Structures While loops, for loops, event structures More discussion later

13 Which function executes first: Add or Subtract? a)Add b)Subtract c)Unknown 13 Review Question 4

14 Which function executes first: Add or Subtract? a)Add b)Subtract c)Unknown 14 Review Question 4

15 Data Flow Block diagram execution is dependent on the flow of data Block diagram does NOT execute left to right Node executes when data is available to ALL input terminals Nodes supply data to all output terminals when done If the computer running this code had multiple processors, these two pieces of code could run independently without additional coding

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

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

18 Clusters differ from arrays in that they are a fixed size Clusters can contain mixed data types; arrays contain only one data type Like an array, a cluster is either a control or an indicator and cannot contain a mixture of controls and indicators 18 Clusters vs. Arrays

19 Match the icon with its name and description. 1.Iteration terminal – tells how many time the loop has executed. 2.Count terminal – receives value to tell how of times a for loop will execute 3.Conditional terminal – tells the loop to stop if the condition is met 19 Review Question 6

20 Match the icon with its name and description. 1.Iteration terminal – tells how many time the loop has executed. 2.Count terminal – receives value to tell how of times a for loop will execute 3.Conditional terminal – tells the loop to stop if the condition is met 20 Review Question 6

21 Loops  While Loop  Terminal counts iterations  Always runs at least once  Runs until stop condition is met  For Loop  Terminal counts iterations  Runs according to input N of count terminal While Loop For Loop i = zero indexed N = one indexed

22 What will be the value in output once this VI finishes? a)11 b)9 c)3 d)4 22 Review Question 7

23 What will be the value in output once this VI finishes? a)11 b)9 c)3 d)4 23 Review Question 7

24 Shift Registers - Access Previous Loop Data Available at left or right border of loop structures Right-click the border and select Add Shift Register Right terminal stores data on completion of iteration Left terminal provides stored data at beginning of next iteration - stacked: registers remember values from multiple previous iterations and carry those values to the next iterations (right-click -> Add Element) Before Loop Begins First Iteration Second Iteration Last Iteration Value 15 Initial Value

25 New Stuff

26 Sequence Structures Flat Sequence Structure Executes frames from left to right and when all data values wired to a frame are available The input of one frame can depend on the output of another frame Stacked Sequence Structure Stacks each frame so you see only one frame at a time and executes frame 0, then frame 1, and so on until the last frame executes Returns data only after the last frame executes

27 Diagram Disable & Conditional Structures Use the Diagram Disable structure to disable specific code on the block diagram Multiple subdiagrams possible – only one enabled Use the Conditional Disable structure to define conditions that indicate which code on the block diagram executes

28 Case Structure 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 Case Selector Label Selector Terminal

29 You can create multiple input and output tunnels Inputs are available to all cases if needed You must define each output tunnel for each case Case Structure: Inputs & Outputs Data TypeDefault Value Numeric0 BooleanFALSE StringEmpty

30 Case Structure

31 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 Case Structure Holy automatic coloring, Batman!

32 Enumeration An enum represents a pair of values, a string and a numeric, where the enum can be one of a defined list of values

33 Custom Controls & Type Definitions Control No connection between the one you saved and the instance in the VI Update the file, but the instances are not updated Type Def Connection between the saved file and all instances Forces the data type of each instance to be identical (clusters, enum) Changes made to file will populate throughout each instance Strict Type Def Connection between saved file and all instances Forces everything about an instance to be identical to the strict type definition, except: label description default value - Use custom controls and indicators to extend the available set of front panel objects

34 Custom Controls & Type Definitions How to create: -Right click on the control; select Advanced >> Customize -Select Type Def or Strict Type Def in the menu before saving

35 Let’s put it all together…

36 Scenario Want to create a program that does the following: 1.Reads a voltage 2.Tells user to turn on power supply 3.Read the voltage again now that power is on 4.Tell the user to turn off the power.

37 Programming Designs: Sequential

38 Sequential Programming

39

40

41 What if you need to change the order of the sequence? What if you need to repeat one item in the sequence more often than the other items? What if some items in the sequence execute only when certain conditions are met? What if you need to stop the program immediately, rather than waiting until the end of the sequence?

42 A state machine consists of a set of states and a transition function that maps to the next state Each state can lead to one or multiple states or end the process flow While Loop Case Structure Shift Register State Machine Enum

43 State Functionality Code: this state was entered to perform what function? Transition Code: which state is next? State Machine: Transition Code

44 Activity 1: Creating a state machine 1.Start a project 2.Create a new VI 3.Create a cluster on the front panel with 3 buttons: -“Do This” -“Do That” -“Stop” 4. Create a state machine Make a type def. enum for the selector input -Initialize -Idle -Do this -Do that -Stop 5. Run the VI Functions for each state: -Initialize: turn on an LED that is labeled “Running?” -Idle: read button values, choose state based on button values -Do this: send dialog to user that “This is Done” -Do that: send dialog to user that “That is Done” -Stop: end VI execution and turn “Running?” LED off

45 Timing Functions Control the frequency at which a loop executes Provide the processor with time to complete other tasks, such as processing the user interface Uses the operating system millisecond clock 10 ms20 ms30 ms

46 VI Timing Types Execution Timing Provides the design pattern with a function that specifically allows the processor time to complete other tasks In some cases, a Wait function is not necessary Use of Timeout inputs can provide execution timing Software Control Timing Timing (pauses, waits, time checks) you put in place to make the code execute after a certain amount of time. Example: If you must acquire data for 5 minutes, you could remain in the acquisition state until the 5 minutes elapses. However, during that time you cannot process any user interface actions such as stopping the VI. To process user interface actions, you must implement timing (checking if 5 min has passed since the start of acquisition) so that the VI continually executes for the specified time

47 47 Software Control Timing Execution Timing VI Timing

48 Events and Event Structure Event — An asynchronous notification that something has occurred 48 Timeout Event Selector Label Event Data Node Event Filter Node 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

49 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 Notify and Filter Events

50 Events Event Sources Configured Events Right-click the border and select Edit Events Handled by This Case Normally used in a While Loop Event structure handles exactly one event per iteration Sleeps when no events occur Using and Configuring Event Structures

51 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. Notify and Filter Events in Config. Window

52 Better State Machine Update your state machine to include: -An event structure in the Idle state to monitor button presses instead of polling the value -Add execution timing in the while loop so the processor can be free to update the front panel -Add software timing in the Do This state so that it stays in the Do This state for 5 seconds. -Bonus: display the 5 second wait on the front panel


Download ppt "Workshop 2 of 4 Welcome!. Survey While You Wait ni.com/duke >> Recent Documents >> LabVIEW Workshop Participation Survey."

Similar presentations


Ads by Google