Introduction to
State Notation Language (SNL)
Tatsuro NAKAMURA @ KEK
January 2009
January 2009
EPICS Seminar in Indore
1
Outline
• 1. Introduction
• 2. Basic Feature
• 3. Additional Feature
January 2009
EPICS Seminar in Indore
2
1. Introduction
SNL and Sequencer
• SNL (State Notation Language)
– A programming language like C
– Based on the State Transition Diagram
– SNC : State Notation Compiler
• Sequencer
– Programs produced by the SNL are executed
within the framework of the run-time
sequencer.
January 2009
EPICS Seminar in Indore
3
State Transition Diagram
State A
State C
State B
January 2009
EPICS Seminar in Indore
4
Where Sequencer runs ?
• Typical usage --- runs in IOC
– Sequencer is a software component of IOC.
OPI
network
Sequencer
CA
CA
process database
January 2009
IOC
EPICS Seminar in Indore
process database
5
• Another usage --- runs in OPI
– Sequencer (Ver. 2.0 or later) can run as a
stand-alone program in workstation.
OPI
Sequencer
network
Sequencer
CA
CA
process database
January 2009
IOC
EPICS Seminar in Indore
process database
6
Documents
• EPICS Sequencer Page
– http://www.slac.stanford.edu/comp/unix/package/epics/
sequencer/
• Manual is available.
• Tutorial Slides
– http://www.aps.anl.gov/epics/docs/USPAS2007.php
January 2009
EPICS Seminar in Indore
7
2. Basic Feature
• State Transition Diagram
state transition
event
state
Start
Light is off
v < 50
v > 60
Turn light off
Turn light on
action
January 2009
Light is on
EPICS Seminar in Indore
8
First Step of SNL Code
• Skeleton of the SNL code
Start
state light_off
{
when (v > 60.0) {
/* turn light on */
Light is off
v < 50
Turn light off
} state light_on
}
v > 60
Turn light on
state light_on
{
when (v < 50.0) {
/* turn light off */
Light is on
} state light_off
}
January 2009
EPICS Seminar in Indore
9
Variables assigned to a Channel
short light;
assign light to "sample:IndicatorLight";
/* turn light on */
light = TRUE;
pvPut(light);
/* turn light off */
light = FALSE;
pvPut(light);
January 2009
EPICS Seminar in Indore
10
Monitor a Channel
float v;
assign v to "sample:Vout";
monitor v;
when (v > 60.0) { …
January 2009
EPICS Seminar in Indore
11
A Complete State Program
program seqtest
float
v;
assign v to "sample:Vout";
monitor v;
short
light;
assign light to "sample:IndicatorLight";
ss volt_check
{
state light_off
{
when (v > 60.0)
{
/* turn light on */
light = TRUE;
pvPut(light);
} state light_on
}
}
January 2009
state light_on
{
when (v < 50.0)
{
/* turn light off */
light = FALSE;
pvPut(light);
} state light_off
}
EPICS Seminar in Indore
12
Structure of a State Program
program seqtest
float
v;
assign v to "sample:Vout";
monitor v;
short
light;
assign light to "sample:IndicatorLight";
ss volt_check
{
state light_off
{
when (v > 60.0)
{
/* turn light on */
light = TRUE;
pvPut(light);
} state light_on
}
}
January 2009
Program
Definition
State Set
state light_on
{
when (v < 50.0)
{
/* turn light off */
light = FALSE;
pvPut(light);
} state light_off
}
EPICS Seminar in Indore
13
Structure of a State Set
program seqtest
float
v;
assign v to "sample:Vout";
monitor v;
short
light;
assign light to "sample:IndicatorLight";
ss volt_check
{
state light_off
{
when (v > 60.0)
{
/* turn light on */
light = TRUE;
pvPut(light);
} state light_on
}
}
January 2009
State Set
State
Event Action
(State Transition)
state light_on
{
when (v < 50.0)
{
/* turn light off */
light = FALSE;
pvPut(light);
} state light_off
}
EPICS Seminar in Indore
14
Multiple State Sets
Each State Set runs concurrently.
State_set_1
State_set_2
State A
State C
State B
State D
January 2009
EPICS Seminar in Indore
program seqtest2
… declaration …
ss state_set_1
{
state A
{
…
}
state B
{
…
}
}
ss state_set_2
{
state C
{
…
}
state D
{
…
}
}
15
Declaration (1)
• Variable
int
variable_name;
short
variable_name;
long
variable_name;
char
variable_name;
float
variable_name;
double variable_name;
string variable_name;
January 2009
… fixed size char array
EPICS Seminar in Indore
16
Declaration (2)
• Assign
assign variable_name to "channel_name";
• Monitor
monitor variable_name;
January 2009
EPICS Seminar in Indore
17
Declaration (3)
• Array of Variables
int
variable_name[array_length];
int
variable_name[array_length][array_length];
int
Vin[4];
assign Vin to {"chan1", "chan2", "chan3"};
monitor Vin;
– int, short, long, char, float, double variable
can be array. (array of string is not available.)
January 2009
EPICS Seminar in Indore
18
Events
when ( expression )
• Typical expression:
– Change in value of a variable
when (v > 60.0)
– Time out
when (delay(10.0))
• The delay function returns a TRUE after a specified
time interval from when the state was entered.
• It should be used only within when expression.
• Its argument must contain a decimal point.
January 2009
EPICS Seminar in Indore
19
Actions (1)
• Most C statements are supported.
expression;
if (…) … else …
while (…) …
for (…, …, …) …
break;
January 2009
EPICS Seminar in Indore
20
Actions (2)
• C code may be escaped in the program.
%% escape one line of C code
%{
escape any number of lines of C code
}%
January 2009
EPICS Seminar in Indore
21
Actions (3)
• Built-in functions
pvPut(variable_name)
pvGet(variable_name)
…
– You can see many built-in functions in the
manual.
– In principle, the built-in functions cannot be
directly used in escaped C code.
January 2009
EPICS Seminar in Indore
22
Build an SNL program
• “make” automates the following steps.
SNC
test.stt
test.c
CPP
test.st
January 2009
CC
SNC
test.i
test.o
CC
test.c
EPICS Seminar in Indore
test.o
23
3. Additional Feature
• Variable Names using Macros
assign vin to "{unit}:ai1";
assign vout to "{unit}:ao1";
– Macro value is given at run-time.
January 2009
EPICS Seminar in Indore
24
• Dynamic Assignment
float Xmotor;
assign Xmotor to "";
…
pvAssign(Xmotor, "Motor_1_4");
January 2009
EPICS Seminar in Indore
25
• Status, Severity, Time stamp
pvStatus(Xmotor)
pvSeverity(Xmotor)
pvTimeStamp(Xmotor)
January 2009
EPICS Seminar in Indore
26
• Event Flag
– Synchronizing State Sets using Event Flag
evflag flag1;
…
efSet(flag1);
efClear(flag1);
…
when (efTestAndClear(flag1))
{ … }
January 2009
EPICS Seminar in Indore
27
• Event Flag associated to a Channel
– Event Flag is set whenever a monitor is delivered.
double
assign
monitor
evflag
sync
loLimit;
loLimit to "demo:loLimit";
loLimit;
loFlag;
loLimit loFlag;
…
when (efTestAndClear(loFflag))
{ … }
January 2009
EPICS Seminar in Indore
28
• Connection Management
when
{ …
when
{ …
(pvConnectedCount()!=pvChannelCount())
}
(pvConnected(Xmotor))
}
– SNC compiler option
• -c : don’t wait for channel connection
• +c : wait for channel connection (default)
January 2009
EPICS Seminar in Indore
29
• Asynchronous pvGet(), pvPut()
pvGet(vin, ASYNC)
pvPut(vout, ASYNC)
…
pvGetComplete(vin)
pvPutComplete(vout)
– SNC compiler option
• -a : synchronous pvGet() (default)
• +a : asynchronous pvGet()
January 2009
EPICS Seminar in Indore
30
• Reentrant Object Code
– SNC compiler option
• -r : Run-time code is not reentrant, thus saving
start-up time and memory (default)
• +r : Run-time code is reentrant. More than one
instance of the state program can run on an IOC.
January 2009
EPICS Seminar in Indore
31
• More features
– Look at the tutorial slides at APS.
– Read the manual.
January 2009
EPICS Seminar in Indore
32
© Copyright 2026 Paperzz