Lesson 2 Dataflow, data
types, For and While
loops
Use Express VIs to produce a project and simple VI that
acquires and analyzes data and then displays the results.
A. Dataflow
B. LabVIEW Data Types
C. Tools for Programming, Cleaning and Organizing Your VI
D. For and While Loops
1
LESSON 2 Dataflow, data types, For and
While loops
A. Dataflow
Recognize characteristics of dataflow on the block
diagram.
2
A. Dataflow
Key Points of Dataflow
Node executes only when all input
data are available.
Node supplies data to the output
terminals only when it is finished
executing.
3
LESSON 2 Dataflow, data types,
programming tools
Exploring Dataflow
Identify dataflow execution order in the following block diagrams.
4
A. Dataflow
Dataflow: Example A
5
A. Dataflow
Dataflow: Example B
?
6
A. Dataflow
Dataflow: Example C
7
A. Dataflow
Dataflow: Example D
8
LESSON 2 Dataflow, data types, For and
While loops
B. LabVIEW Data Types
Recognize the different data types and how they
relate to front panel objects.
• Accessing Object Properties • Strings
• Boolean Data • Enums
• Numeric Data • Other Data Types
Representations
9
B. LabVIEW Data Types
Terminals and LabVIEW Data Types
Terminals visually convey information about data
type.
10
LESSON 2 Dataflow, data types, programming tools
Demonstration
Accessing Object Properties
11
B. LabVIEW Data Types
Boolean Data
See example Mechanical Action.vi to learn about the different mechanical
actions of Boolean controls
12
B. LabVIEW Data Types
Strings
See example StringDisplay.vi to
learn about the display styles.
13
LESSON 2 Dataflow, data types, programming tools
Demonstration
Enums
14
B. LabVIEW Data Types
Other Data Types
Type Terminal Description
Dynamic Stores the information generated or
acquired by an Express VI
Path Stores the location of a file or directory
Waveform Carries the data, start time, and dt of a
waveform
15
LESSON 2 Dataflow, data types, For and While
loops
C. Tools for Programming,
Cleaning, and Organizing Your VI
Recognize tools for making clean, readable front
panels and block diagrams, and for documenting VIs.
• Programming Tools
• Wiring Tips
• Making Code Readable
16
LESSON 2 Dataflow, data types, programming tools
Demonstration
Programming Tools
Automatic tool selection
Tools Palette
17
LESSON 2 Dataflow, data types, programming tools
Demonstration
Wiring Tips
18
LESSON 2 Dataflow, data types, programming tools
Demonstration
Making Code Readable
19
LESSON 2 Dataflow, data types, programming tools
Questions for the audience
Ready?
20
Lesson Review
1. Which function executes first: Add
or Subtract?
a. Add
b. Subtract
c. Unknown
21
Lesson Review
1. Which function executes first: Add
or Subtract?
a. Add
b. Subtract
c. Unknown
22
Lesson Review
2. Which function executes first: Sine
or Divide?
a. Sine
b. Divide
c. Unknown
23
Lesson Review
2. Which function executes first: Sine
or Divide?
a. Sine
b. Divide
c. Unknown
24
Lesson Review
3. Which of the following functions executes
first: Random Number, Add or Divide?
a. Random Number
b. Divide
c. Add
d. Unknown
25
Lesson Review
3. Which of the following functions executes
first: Random Number, Add or Divide?
a. Random Number
b. Divide
c. Add
d. Unknown
26
Lesson Review
4. Which of the following
functions executes last: Random Number,
Subtract or Add?
a. Random Number
b. Subtract
c. Add
d. Unknown
27
Lesson Review
4. Which of the following
functions executes last: Random Number,
Subtract or Add?
a. Random Number
b. Subtract
c. Add
d. Unknown
28
Lesson Review
5. If an input to a function is marked with a red
dot (known as a coercion dot), what does the
dot indicate?
a. Data was transferred into a structure.
b. That input has not been wired
c. The wire is broken
d. The value passed into a node was converted to a
different representation.
29
Lesson Review
5. If an input to a function is marked with a red
dot (known as a coercion dot), what does the
dot indicate?
a. Data was transferred into a structure.
b. That input has not been wired
c. The wire is broken
d. The value passed into a node was converted
to a different representation.
30
Lesson Review
6. Which mechanical action causes a Boolean control in
the FALSE state to change to TRUE when you click it and
stay TRUE until LabVIEW has read the value?
a. Switch Until Released
b. Switch When Released
c. Latch When Pressed
d. Latch When Released
31
Lesson Review
6. Which mechanical action causes a Boolean control in
the FALSE state to change to TRUE when you click it and
stay TRUE until LabVIEW has read the value?
a. Switch Until Released
b. Switch When Released
c. Latch When Pressed
d. Latch When Released
32
LESSON 2 Dataflow, data types, For and While
loops
D. For and While Loops
Recognize loop structures and explain how to use
them.
• While Loops—Review
• For Loops—Review
• For Loop/While Loop Comparison
33
D. Loops Review
While Loops—Review
Continue If TRUE
iteration terminal conditional terminalStop If TRUE 34
D. Loops Review
For Loops—Review
count terminal
iteration terminal
35
D. Loops Review
For Loop/While Loop Comparison
Default
Default
tunnel mode
tunnel mode:
last value
indexing
array scalar
36
LESSON 2 Dataflow, data types, For and While
loops
D. While Loops
Recognize tunnels and explain their purpose on a
loop structure and demonstrate how to use error
checking and error handling inside a loop.
• Tunnels
• Error Checking and Error Handling
37
D. While Loops
Tunnels
38
D. While Loops
Error Checking and Error Handling
Stop the While Loop if an
error occurs.
39
LESSON 2 Dataflow, data types, For and While
loops
D. For Loops
Demonstrate how to add a conditional terminal to a For
Loop and describe how numeric conversion occurs on the
For Loop count terminal.
• Conditional Terminal
• Count Terminal Numeric Conversion
• Other tunnel modes: concatenating and conditional
40
D. For Loops
Conditional Terminal
41
D. For Loops
Count Terminal Numeric Conversion
42
D. For Loops
Other tunnel modes: concatenating
Build array
43
D. For Loops
Other tunnel modes: conditional
Only even numbers are selected
44
LESSON 2 Dataflow, data types, For and While
loops
D. Timing a VI
Identify scenarios that require loop timing and apply
the appropriate function.
• Reasons to Use Timing
• Wait Functions and Express VIs
45
D. Timing a VI
Why do you need timing in a VI?
46
D. Timing a VI
Wait Functions Inside a Loop
47
D. Timing a VI
Wait Function Timing
48
LESSON 2 Dataflow, data types, For and
While loops
D. Data Feedback in
Loops
Apply shift registers when appropriate and predict
the correct value at different iterations of the loop.
• Introduction to Shift
Registers
• Using Shift Registers
• Creating Shift Registers
49
D. Data Feedback in Loops
Introduction to Shift Registers
At every iteration, the value
is passed back from right to
left providing a feedback
mechanism
Uninitialized shift register: its
initial value is 0 the first time
the VI executes.
In this example, the second
time the VI executes, the The “output” indicator will be
initial value is 6. 6 after the first execution,
Can you explain why? and 12 after the second
execution
50
D. Data Feedback in Loops
What is the value of «Output» after
you run the VI a first time?
51
D. Data Feedback in Loops
What is the value of «Output» after
you run the VI a second time?
52
D. Data Feedback in Loops
Initialized shift registers: the value of
«Output» is the same after every run…
53
E. Data Feedback in Loops
Multiple shift registers in a loop
54
D. Data Feedback in Loops
Stacked shift registers
55
D. Data Feedback in Loops
What are the values in the left shift registers and the Output indicator after
three loop iterations?
56
LESSON 2 Dataflow, data types, For and
While loops
Examples
Use data feedback in a loop to calculate mathematical
sequences and to simulate physical problems. Use
waveform charts, waveform graphs and XY graphs to
plot data.
• Fibonacci sequence
• Brownian motion
57
The Fibonacci sequence and the golden ratio
0,1,1,2,3,5,8,13,21,34…
(see Fibonacci-
Spiral.vi)
58
Fibonacci: C++ vs LabVIEW
The loop executes N times
int N, t1 = 0, t2 = 1, next = 0;
double aurea;
for (int i = 0; i < N; i++)
{
next = t1 + t2;
t1 = t2;
t2 = next;
aurea=t2/t1;
}
The iteration terminal starts from 0
59
Fibonacci – LabVIEW program
(see Fibonacci.vi) 60
Brownian motion
2 k BT
x2 t
6r
61
Brownian motion – LabVIEW program
(see BrownianMotion.vi) 62
Milestone 2 – Brownian motion simulator
Build array
XY Graph
Build array
63
Esercizi
• Realizzare autonomamente un programma simile al Milestone 2 per
simulare il moto browniano in 2 dimensioni (soluzione in
BrownianMotion_RealTime.vi)
• CHALLENGE: calcolare e graficare il valore medio in funzione del
tempo per un insieme grande di «random walker» (soluzione in
BrownianMotion_MSD.vi)
64