You are on page 1of 28

Lesson 6

Using Decision-Making Structures


Learn to create different decision-making structures and be able to identify
applications where using these structures can be beneficial.

A. Case Structures
B. Event-Driven Programming

1
LESSON 6 Using Decision-Making Structures

A. Case Structures
Recognize and use the basic features and functionality of
Case Structures.

• Case Structures Review


• Creating and Configuring Case Structures
• Selector Terminal Data Types
• Input and Output Tunnels

2
LESSON 6 Using Decision-Making Structures

Activity 6-1
Case Structures Review
Case Selector Label

Selector Terminal 3
LESSON 6 Using Decision-Making Structures

Demonstration
Case Structures

Create and configure case structures.

4
A. Case Structures

Selector Terminal Data Types

5
A. Case Structures

Input and Output Tunnels


• Input tunnels are available to all cases if needed.
• You must define every output tunnel for each case.

6
LESSON 6 Using Decision-Making Structures

Demonstration
Selector Terminal Types and Tunnels

• Create Case structures using


different data type selectors.
• Create different types of
output tunnels.

7
LESSON 6 Using Decision-Making Structures

Exercise 6-1
Temperature Warnings with
Error Handling
Modify a VI to use Case structures to make a software decision.

8
LESSON 6 Using Decision-Making Structures

Exercise 6-1
Temperature Warnings with
Error Handling
• What happens if all the values are 10? How could you fix this?
• Are all output tunnels defined? What happens if an output is not defined?

9
LESSON 6 Using Decision-Making Structures

B. Event-Driven Programming
Recognize basic features and functionality of event
structures.

• Event-Driven Scenario • Configuring the Event


• Polling Versus Events Structure
• Event-Driven Programming • Caveats and
Recommendations

10
LESSON 6 Using Decision-Making Structures

Demonstration
Event-Driven Scenario

11
B. Event-Driven Programming

Polling Versus Events


Polling Events

12
LESSON 6 Using Decision-Making Structures

Multimedia Module
Event-Driven Programming

13
B. Event-Driven Programming

Configuring the Event Structure

14
B. Event-Driven Programming

Edit Events Dialog Box


Configured Events Events

Event Sources

15
B. Event-Driven Programming

Notify and Filter Events


Notify Events
(green arrow)

Filter Events (red arrow)

16
LESSON 6 Using Decision-Making Structures

Demonstration
Configure and Use Events

Demonstrate configuring and using


an Event structure.

17
LESSON 6 Using Decision-Making Structures

Exercise 6-2
Converting a Polling Design to
an Event Structure Design
Convert a polling-based application to an Event structure-based
application

18
LESSON 6 Using Decision-Making Structures

Exercise 6-2
Converting a Polling Design to
an Event Structure Design
• How many times did the loop run with polling?
• How many times did the loop run when you changed the VI to use an Event
structure?

19
B. Event-Driven Programming

Caveats and Recommendations


• Place only one Event structure in a loop.
• Use a Value Change event to detect value
changes.
• Keep event handling code short and quick.
• Place Boolean control terminals inside an event case
for latched operations to work properly.
• Avoid using an Event structure outside of a loop.
• Avoid configuring two Event structures for the same
event.
20
B. Event-Driven Programming

Think about the VIs that you will need to


develop at your job.
• Will you use event-based programming to implement
any of your VIs?
• Why or why not?

21
LESSON 6 Using Decision-Making Structures

Activity 6-2
Lesson Review

Refer to the participant guide to answer questions about what you have learned
in this lesson and then discuss the answers as a group.

22
Lesson Review

1. Which of the following can NOT be used


as the case selector input to a Case
structure?
a. Error cluster
b. Array
c. Enum
d. String

23
Lesson Review

1. Which of the following can NOT be used


as the case selector input to a Case
structure?
a. Error cluster
b. Array
c. Enum
d. String

24
Lesson Review

2. How many events can an Event structure


handle each time it executes?
a. As many as have occurred since the last time the
event structure executed
b. One per configured event case
c. One

25
Lesson Review

2. How many events can an Event structure


handle each time it executes?
a. As many as have occurred since the last time the
event structure executed
b. One per configured event case
c. One

26
Lesson Review

3. Which statements about event-driven


programming versus polling are true?
a. Events execute on demand.
b. Event-driven programming is less CPU-intensive.
c. Event structures handle all events in the order the
occur.
d. Polling may fail to detect a change.

27
Lesson Review

3. Which statements about event-driven


programming versus polling are true?
a. Events execute on demand.
b. Event-driven programming is less CPU-
intensive.
c. Event structures handle all events in the order
the occur.
d. Polling may fail to detect a change.

28

You might also like