Implementing a VI


TOPICS
0
ni.com/training
Implementing a VI
TOPICS
A. Designing Controls and E. Timing a VI
Indicators
F. Data Feedback in Loops
B. LabVIEW Data Types
G. Case Structure
C. While Loop
H. Disable Structures
D. For Loop
1
ni.com/training
A. Designing Controls
and Indicators
2
ni.com/training
Labels & Options
Make sure to label controls and indicators clearly
and set a default value if necessary.
ni.com/training
B. LabVIEW Data Types
Shortcut Menu and Properties Dialog Box
Numeric Types
Boolean Types
String Types
Enums and Other Types
4
ni.com/training
LabVIEW Data Types
Terminals visually communicate information about
the data type represented.
5
ni.com/training
Shortcut Menus
" All LabVIEW objects
have associated
shortcut menus.
" Use shortcut menu
items to change the
look or behavior of
objects.
" To access the shortcut
menu, right-click the
object.
6
ni.com/training
6
Properties Dialog Box
" All LabVIEW objects
have properties.
" To access properties,
right-click the object
and select Properties.
" Property options are
similar to shortcut
menu options.
" Select multiple objects
to simultaneously
configure their
common properties.
7
ni.com/training
7
Numerics
Various data type
representations:
" Floating-point
" Unsigned integers
" Signed integers
8
ni.com/training
Numeric Conversion Coercion Dot
" Coercion dots indicate that
LabVIEW converted the value
passed into a node to a different
representation.
- Occurs when a node expects an input
with a different representation.
" LabVIEW chooses the
representation that uses more bits.
" Avoid coercion by
programmatically converting
to a matching data type.
9
ni.com/training
Booleans
" Behavior of Boolean
controls is specified by
the mechanical action.
" Boolean have only
TRUE/FALSE values.
10
ni.com/training
Mechanical Action of Booleans
11
ni.com/training
Mechanical Action of Booleans
Use the PropertiesOperations tab of a Boolean
control to learn about the different switch and latch
actions.
DEMONSTRATION
Strings
" A string is a sequence of
ASCII characters.
" Strings have various
display styles.
- Backslash codes
- Password
- Hex
13
ni.com/training
Enums
" Enums give users
a list of items from
which to select.
" Each item represents
a pair of values.
- String
- Unsigned integer
14
ni.com/training
Other Data Types
Refer to LabVIEW Help for complete list of terminal
symbols for different types of controls and indicators.
" Dynamic
- Stores the information generated or acquired by an
Express VI.
" Path
- Stores the location of a file or directory using the
standard syntax for the platform you are using.
" Waveform
- Carries the samples, start time, and dt of a waveform.
15
ni.com/training
Searching Help for Data Types
Use LabVIEW Help to learn about LabVIEW data
types.
DEMONSTRATION
C. While Loop
Iteration and Conditional Terminals
Tunnels
Error Checking
17
ni.com/training
While Loop
Repeat (code);
Until Condition met;
End;
LabVIEW While Loop Flowchart Pseudo Code
18
ni.com/training
While Loop
Conditional terminal
Iteration terminal
" Defines when the loop stops.
" Returns number of times
" Has two options:
loop has executed.
- Stop if True
" Is zero-indexed.
- Continue if True.
Iteration Terminal
Conditional Terminal
19
ni.com/training
While Loop  Tunnels
" Tunnels transfer data into and out of structures.
" When a tunnel passes data into a loop, the loop
executes only after data arrive at the tunnel
(at all tunnels,
if there is more
than one).
" Data pass out of
a loop after the
loop terminates.
20
ni.com/training
While Loop  Error Checking and Error
Handling
Use an error cluster in a While Loop to stop the
While Loop if an error occurs.
21
ni.com/training
Auto Match VI
Use a While Loop and the iteration terminal and
pass data through a tunnel.
DEMONSTRATION
Auto Match VI
How many times is the Number of Iterations
indicator updated? Why?
DISCUSSION
D. For Loop
Conditional Terminal
Comparison with While Loop
Numeric Conversion for Count Terminal
24
ni.com/training
For Loop
N=100;
i=0;
Until i=N:
Repeat (code;i=i+1);
End;
LabVIEW For Loop Flowchart Pseudo Code
25
ni.com/training
For Loop
" Create a For Loop the same way you create
a While Loop.
" You can replace a While Loop with a For Loop
by right-clicking the border of the While Loop
and selecting Replace with For Loop from the
shortcut menu.
" The value in the count terminal (an input
terminal) indicates how many times to repeat
the subdiagram in the For Loop.
26
ni.com/training
For Loop  Conditional Terminal
You can add a conditional terminal to configure a For
Loop to stop when a Boolean condition is true or an
error occurs.
This is similar
to a  break
statement in
text-based
programming
languages.
27
ni.com/training
For Loop  Conditional Terminal
For Loops configured with a conditional terminal have:
" A red glyph next to the count terminal
" A conditional terminal in the lower right corner.
28
ni.com/training
For Loop / While Loop Comparison
For Loop While Loop
" Executes a set number of " Stops executing only if the
times unless a conditional value at the conditional
terminal is added. terminal meets the condition.
" Can execute zero times. " Must execute at least once.
" Tunnels automatically " Tunnels automatically output
output an array of data. the last value.
29
ni.com/training
For Loop  Numeric Conversion
" The number of iterations a For Loop executes must be
specified in non-negative integers.
" If you wire a double-precision, floating-point numeric
value to the count terminal, LabVIEW converts the
numeric value to a 32-bit signed integer.
30
ni.com/training
Group Exercise
Concept: While Loops versus For Loops
When to use a While Loop and when to use a For
Loop?
DISCUSSION
E. Timing a VI
Reasons To Use Timing
Wait Functions and Express VIs
32
ni.com/training
Timing a VI
Why do you need timing in a VI?
" To control the frequency at
which a loop executes.
" To provide the processor with
time to complete other tasks,
such as processing the user
interface or running other
applications.
33
ni.com/training
Wait Functions
A wait function inside a loop:
" Allows the VI to sleep for a set amount of time.
" Allows the processor to address other tasks
during the wait time.
" Uses the operating system millisecond clock.
34
ni.com/training
Elapsed Time Express VI
" Determines how much time elapses after some
point in your VI.
" Keeps track of time while
the VI continues to execute.
" Does not provide the processor
with time to complete other tasks.
35
ni.com/training
Wait Chart VI
Compare and contrast using a Wait function and
the Elapsed Time Express VI for software timing.
DEMONSTRATION
F. Data Feedback in Loops
Shift Registers
Initializing Shift Registers
Default for Unwired Values
Compound Shift Registers
37
ni.com/training
Data Feedback in Loops
" When programming with loops, you often need to
know the values of data from previous iterations of
the loop.
" Shift registers transfer values from one loop iteration
to the next.
38
ni.com/training
Shift Registers
" Right-click the border and select Add Shift
Register from the shortcut menu.
" Right part of shift register stores data on
completion of an iteration.
" Left part of shift
register provides
stored data at
the beginning
of the next
iteration.
39
ni.com/training
Initializing Shift Registers
Run once VI finishes Run again
Block Diagram 1st run 2nd run
Initialized
Shift
Output = 5 Output = 5
Register
Not
Initialized
Output = 4 Output = 8
Shift
Register
40
ni.com/training
Default Value if Unwired
Default values vary by data type:
Data Type Default Value
Numeric 0
Boolean FALSE
String Empty
Uninitialized shift registers use default values for
the first run. At the beginning of next runs, they
remember the last value they stored.
41
ni.com/training
Multiple Previous Iterations
" Stacked shift registers remember values from
multiple previous iterations and carry those
values to the next iterations.
" Right-click the left shift register and select Add
Element from the shortcut menu to stack a shift
register.
42
ni.com/training
G. Case Structures
Parts of a Case Structure
Enum Case Structures
Error Case Structures
Input and Output Tunnels
43
ni.com/training
Case Structures
" Have two or more subdiagrams (cases).
" Use an input value to determine which case to
execute.
" Execute and display only one case at a time.
" Are similar to case statements or if...then...else
statements in text-based programming languages.
44
ni.com/training
Case Structures
" Case Selector Label
- Contains the name of the current case.
- Has decrement and increment arrows.
" Selector Terminal
Case Selector Label
- Lets you wire an input
value, or selector, to
determine which case
executes.
Selector Terminal
45
ni.com/training
Case Structures
Selector terminal data
types:
" Boolean
- True case and False Case
" Error Cluster
- Error Case and No Error
Case
" Integer, string or enum
- Structure can have any
number of cases
- Include a Default diagram
to avoid listing every
possible input value
46
ni.com/training
Shortcut Menu
Use the shortcut
menu of a Case
structure to:
- Customize the structure
and diagrams.
- Remove or replace the
structure.
- Add, duplicate, remove
or rearrange cases.
- Specify the Default case.
- Switch cases.
47
ni.com/training
Enum Case Structure
" Gives users a list of items from which to select.
" The case selector displays a case for each item
in the enumerated type control.
48
ni.com/training
Error Case Structure
Use Case structures inside VIs to execute the
code if there is no error and skip the code if there
is an error.
49
ni.com/training
Input and Output Tunnels
You can create multiple input and output tunnels.
" Inputs tunnels are available to all cases if needed.
" You must define each output tunnel for each case.
50
ni.com/training
Case Structures
" Create case structures using different data type
selectors.
" Add, remove and duplicate cases.
" Create different types of output tunnels.
DEMONSTRATION
H. Disable Structures
Diagram Disable Structure
Conditional Disable Structure
52
ni.com/training
Diagram Disable Structure
lð Use it to disable a section of code on the block
diagram.
lð Multiple subdiagrams are possible  one is enabled.
lð Disabled subdiagrams appear grayed out.
lð Great tool for troubleshooting  no need to re-write
code.
ni.com/training
Conditional Disable Structure
" Use it 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.
ni.com/training
Homework:
Blinking LED
Use a While Loop with shift register and a timing
function to blink an LED.
ni.com/training
Homework: Average Temperature VI
Use a While Loop and stacked shift registers to
average data.
ni.com/training
Homework: Temperature Limits VI
Use a Case
Structure to output
a string indicating
if the temperature
is OK or outside
the limits.
ni.com/training


Wyszukiwarka

Podobne podstrony:
Cw 4 Implementacja VI Materiały dodatkowe
Cw 4 Implementacja VI Instrukcja
Nauka o materiałach 2 VI
Fiz pol VI 2014
EKO VI Promocja jako proces komunikacji
Streszczenie Pieśni VI Iliady
Prezentacja VI dzia
Capítulo VI
vi tutorial QWERTY Gray
The?vil s Lover The Resurrect
The Pacific Pt VI PROPER HDTV XviD NoTV
Paradies Sonata VI
R4 VI(1)
implementation view?73E3B6

więcej podobnych podstron