Review Question 1

advertisement
Welcome!
Workshop
4 of 7
Today's Topics

Review of Workshop 3

Sequence Structure

Timing

State Machine
Review Question 1
How many times must a For Loop iterate? A While Loop?
a) 0,0
b) 1,0
c) 0,1
d) 1,1
Review Question 1
How many times must a For Loop iterate? A While Loop?
a) 0,0
b) 1,0
c) 0,1
d) 1,1
Review Question 2
True or False?
The value passed to the case selector terminal
determines which case will execute.
Review Question 2
True or False?
The value passed to the case selector terminal
determines which case will execute.
TRUE
Review Question 3
A “hollow” output tunnel will appear on the edge of a case
structure because…?
a) the wrong data type is wired to it
b) there is not a wire leading away from it
c) one or more cases do not have a wire leading to it
Review Question 3
A “hollow” output tunnel will appear on the edge of a case
structure because…?
a) the wrong data type is wired to it
b) there is not a wire leading away from it
c) one or more cases do not have a wire leading to it
Review Question 4
Which of the following statements about Auto-indexing are
true? (multiple answers possible)
a) When auto-indexing is enabled on an output tunnel, only
one element can be passed out of the tunnel.
b) When auto-indexing is enabled on an input tunnel, only
one element can be passed out of the tunnel
c) When auto-indexing is enabled on an output tunnel, the
entire array is passed out of the tunnel
d) When auto-indexing is enabled on an input tunnel, the
entire array is passed out of the tunnel
Review Question 4
Which of the following statements about Auto-indexing are
true? (multiple answers possible)
a) When auto-indexing is enabled on an output tunnel, only
one element can be passed out of the tunnel.
b) When auto-indexing is enabled on an input tunnel,
only one element can be passed out of the tunnel
c) When auto-indexing is enabled on an output tunnel,
the entire array is passed out of the tunnel
d) When auto-indexing is enabled on an input tunnel, the
entire array is passed out of the tunnel
Review Question 5
The value of Result when the VI below finishes will be:
a) 15
b) 18
c) 22
d) 28
Review Question 5
The value of Result when the VI below finishes will be:
a) 15
b) 18
c) 22
d) 28
Review Question 1
True or False?
You must have at least one case in a Disable Diagram that
is enabled.
Review Question 1
True or False?
You must have at least one case in a Disable Diagram that
is enabled.
TRUE
Review Question 2
Match the following:
a) Event Filter Node
b) Notify Event
c) Filter Event
d) Event Data Node
• attached to the inside left border of each
event case; identifies the data LabVIEW
provides when an event occurs.
• attached to the inside right border of
filter event cases; identifies the subset
of data available that the event case
can modify
• an indication that a user action has
already occurred, such as when the
user has changed the value of a control
• inform you that the user has performed
an action before LabVIEW processes it,
which allows you to customize how the
program responds to interactions with
the user interface
Review Question 2
Match the following:
• attached to the inside left border of each
event case; identifies the data LabVIEW
provides when an event occurs.
a) Event Filter Node
• attached to the inside right border of
filter event cases; identifies the subset
of data available that the event case
can modify
b) Notify Event
c) Filter Event
d) Event Data Node
• an indication that a user action has
already occurred, such as when the
user has changed the value of a control
• Informs you that the user has performed
an action before LabVIEW processes it,
which allows you to customize how the
program responds to interactions with
the user interface
Review Question 3
Which of the following is true about the Event Structure?
a) An event structure will sleep while waiting for an event
to occur
b) An even structure can process multiple events
simultaneously
c) It is a good idea multiple event structures within a block
diagram
d) Event structures are often used within a while loop
Review Question 3
Which of the following is true about the Event Structure?
a) An event structure will sleep while waiting for an event
to occur TRUE
b) An even structure can process multiple events
simultaneously FALSE
c) It is a good idea multiple event structures within a block
diagram FALSE
d) Event structures are often used within a while loop
TRUE
Flat Sequence Structure


Executes each frame beginning with the left-most frame
and ending with the right-most frame
The previous frame must complete before the next frame
executes

Data can be passed out of or between frames using tunnels

Once the sequence begins, it cannot be stopped
1st
2nd
3rd
Stacked Sequence Structure




Stacks each frame so you see only one frame at a time
Executes frame 0, then frame 1, etc. until the last frame
executes
Returns data only after the
last frame executes
To transfer data from frame
to frame, a Sequence Local
must be created (right-click
» Add Sequence Local)
• Once the sequence begins,
it cannot be stopped
Sequence
Local
Timing Functions
• Control or measure 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
Wait Function
• Waits the specified number of milliseconds.
• If 0 is wired to it, the current thread is forced to yield
control of the CPU
• Uses the operating system millisecond clock
Wait Function- example cases
• Loop would go to next iteration
after 10 ms or more depending
on amount of time the subVI
takes.
• If subVI takes >10 ms, loop
goes as soon as subVI is done
• If subVI takes <10 ms , loop
goes at 10 ms mark.
• Loop would go on to
next iteration after
10 ms, because the
only thing that
happens in each
iteration is wait 10
ms
Moment next loop
iteration can begin
10 ms
20 ms
30 ms
Wait
Other code
(running in
parallel with
Wait VI)
Wait Until Next Millisecond Multiple Function
• Waits until a multiple of the millisecond value wired in
• Provide the processor with time to complete other
tasks, such as processing the user interface
• Uses the operating system millisecond clock
Wait Until Next Millisecond Multiple Function
• Loop would go to next iteration
after 10 , 20, 30, or a greater
multiple of 10 ms depending on
amount of time the subVI takes.
• If subVI takes <10 ms , loop
goes at 10 ms mark.
• If subVI takes 16 ms, then
the loop goes at 20 ms.
• Loop would go on to
next iteration after
10 ms, because the
only thing that
happens in each
iteration is wait 10
ms and 10ms is the
first multiple of 10
• If subVI takes 22 ms, then
the subVI goes at 30 ms.
Wait
10 ms
20 ms
30 ms
Other code
(subVI)
Comparison of Timing Functions
Red represents
times when Wait
functions are NOT
restricting
Moment next loop
iteration can begin
Other code
(running in
parallel with
waits)
10 ms
20 ms
30 ms
Demonstration:
Comparing the Timing Functions
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
VI Timing
Execution Timing
Software Control Timing
29
State Machine Intro: 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.
Programming Designs: Sequential
Sequential Programming
Sequential Programming
Sequential Programming
Sequential Programming
• 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?
State Machines
• Implements a state
diagram.
• Programmatically
determine which state
is next
- Different action if a
quarter was inserted
compared to return
change requested
State Machine
• 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
Enum
Shift Register
Case Structure
State Machine: Transition Code
• State Functionality Code:
• this state was entered to
perform what function?
• Transition Code:
• which state is next?
Demonstration:
Execution of a State Machine
Design Patterns: Single Loop
General VI
Three phases: Start-up, Main Application, and Shutdown
40
Single Loop Design Pattern: in LabVIEW
General VI
41
Single Loop Design Pattern
State Machine
Usually has a start-up and shut-down state, but also
contains other states
42
Single Loop Design Pattern
State Machine
43
Parallelism
Parallelism: executing multiple tasks at the same time
Use case:
• Need to acquire data very quickly, process it and save it to file.
• If you do each step in a linear fashion and try to acquire all the data
before processing, then you may run out of memory before
processing begins.
• If you do “sets” of steps (acquire, process, save, repeat), then you
are missing the data points when the processing and saving are
going on.
• If only you could acquire, process, and save in parallel….good
news, you can!
44
Multiple Loop Design Pattern
Parallel Loop
45
Multiple Loop Design Pattern
Producer/Consumer
46
Multiple Loop Design Pattern
Master/Slave: a type of Producer/Consumer
• uses notifiers
to allow loops
to run at
different rates
47
Notifiers
Pros:
• Both loops are synchronized to the master loop—the slave loop only
executes when the master loop sends a notification
• You can use notifiers to create globally available data, making it possible
to send data with a notification
• Using notifiers creates efficient code—there is no need to poll to
determine when data is available from the master loop
Cons:
• Notifiers do not buffer data.
• If the master loop sends another piece of data before the first piece of
data has been read by the slave loops, that data is overwritten and lost.
48
Queues
• Queues are similar to notifiers, except that a queue
can store multiple pieces of data
• By default, queues work in a FIFO (first in, first out)
manner
• Use a queue when you want to process all data
placed in the queue
• Use a notifier if you only want to process the current
data
• Use the Queue Operations functions to create a
queue for communicating data between sections of a
block diagram or from another VI.
49
Producer/Consumer with Queues
Data type here
determines the
data type that
can be placed
in the queue
50
Demonstration:
Queues in Action
Producer/Consumer with Queues and Events
• Efficiently responds
asynchronously to the
user interface
52
Notifier vs. Queue Review
Tool
Function
When to use
Notifier
- sends alert to helps control
timing of parallel loops
- can transfer data between
loops
- data NOT buffered (lossy)
- have a parallel loops that are
running at different rates and 1+ loop
is dependent on another
- want to transfer data from one loop
to another
Queue
- helps control timing of parallel
loops
- transfers data between loops
- buffers data to be transferred
(FIFO)
- have a parallel loops that are
running at different rates and 1+ loop
is dependent on another
- want to transfer ALL data from one
loop to another
Homework
Work on a Game!
Complete Homework 4
CLAD Questions 4
Email to mst.labview@gmail.com
Download