You are on page 1of 26

Short Term Course on

PEC Deemed University
DAY- 6 (4th DEC, 2006)


PEC Deemed University

Basic Programming Architecture

Introduction to State Machine
Simple State Selector
String Functions
Parsing of strings
LabVIEW String Formats
Basic Programming Architecture
Simple VI Architecture
General VI Architecture
Parallel Loops Architecture
Multiple Case Structures Architecture
State Machine Architecture
Simple VI Architecture
Functional VI that produces results when run
No start or stop options
Suitable for lab tests, calculations
Example: Convert C to
General VI Architecture

Three main steps:

(1) Startup
2) Main application
(3) Shutdown
Parallel Loops Architecture

+ Handles
Data exchange
Multiple Case Structures

+ Synchronization and
data exchange are
Loop can get large and
difficult to view
Handling one event can
block other events
All events are handled
at the same rate
State Machine Architecture
0: Startup
1: Idle
2: Event 1
3: Event 2
4: Shutdown

+ Can go to any state from any other
+ Easier to modify and debug
Can lose events if two occur at same time
The State Machine
State Machine architecture can be used to implement
complex decision-making algorithms.
The State Machine is one of the fundamental
architectures LabVIEW developers frequently use to
build applications quickly.
State Machines are used in applications where
distinguishable states exist.
Each state can lead to one or multiple states, and can
also end the process flow.
A State Machine relies on user input or in-state
calculation to determine which state to go to next.
The State Machine contd

Many applications require an initialize state, followed

by a default state where many different actions can be
The actions performed can depend on user input or
previous results.
A shutdown state . to perform clean up actions.
When creating a user interface, different user actions
send the user interface into different processing
Each of these segments will act as states.
These segments can either lead to another segment for
further processing or wait for another user event.
Example - Coke Machine
This application has the following requirements:
All Coke products are sold for 50 cents.
The machine only accepts nickels, dimes, and quarters.
Exact change is not needed.
Change can be returned.
Our first step will be to create a state diagram.
There are quite a few ways this can be done, but
remember that more states equals less efficiency.
For this example, our state diagram will have eight
The states we will be using are:

1.) INIT initialize our Coke Machine

2.) WAIT FOR EVENT where the machine waits for
3.) RETURN CHANGE where the machine returns
4.) COKE PRODUCT when the machine has received
50 or more cents it will dispense the beverage
5.) QUARTER when the customer enters a quarter
6.) DIME when the customer enters a dime
7.) NICKLE when the customer enters a nickel
8.) EXIT after the change is returned and/or beverage
dispensed, the machine will power down (application will
Creating Simple User Menus
Cluster of labeled buttons (mechanical action is
latch when released)
Cluster Order:
(0) Configure button
(1) Test 1 button
(2) Test 2 button

You must set the cluster size

Mechanical Action of Booleans
Change state on a button press. Switch action:
Remain there until another button
Switch When Pressed press. Control is toggled
Change state on a button release. until changed by
Remain there until another button
Switch When Released release. hand
Change state on a button press.
Change back when the button is
Switch Until Released released.
Latch action:
Change state on a button press.
Change back when the control is read Control reverts to
Latch When Pressed by LabVIEW.
Change state on a button release.
default state when
Latch When Released
Change back when the control is read
by LabVIEW.
read by diagram
Change state on a button press.
Change back when released and read
Latch Until Released by LabVIEW.
State Machine Programming
Useful in
programming user
interface VIs
One case for each
state in the machine
Relatively easy to
State Machine Programming
Value State Description Next State
1 No Event Monitor Depends on
Boolean Boolean button
menu to pressed. If no
select next button is
state. pressed, next
state is No
0 Login Log in user No Event (1)
1 Configure Configure Acquire (2)
2 Acquire Acquire Data No Event (1)
State Machine Programming
Select and display the button selection
through a single dialogue box.
Enter username if authenticated then allow
to acquire the data.
Make a simple calculator using state
machine architecture.
Make a simple state machine to calculate
|x-y| using state selector.
Waveform generator.
A string is a sequence of displayable or
nondisplayable characters (ASCII)
Many uses displaying messages, instrument
control, file I/O
String control/indicator is in the Controls >>
String subpalette
String Display Modes
Normal display \ code display

Password display Hex display

String Functions

String Length

Length = 20

Concatenate Strings
spaces here
The quick brown fox jumped over the lazy dog.
Concatenated String
String Functions
String Functions
Converting numbers to strings

Converting strings to numbers

Edit Format String
Format Into String & Scan From String Functions
Complete the exercise set in part (a) and
part (b).