Jesse Roberts & Craig Jones Acoustic Models for …€“SNL-Delft3D-CEC, SNL-EFDC
January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA...
-
Upload
nicholas-borow -
Category
Documents
-
view
216 -
download
1
Transcript of January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA...
January 2009 EPICS Seminar in Indore 1
Introduction toState Notation Language (SNL)
Tatsuro NAKAMURA @ KEK
January 2009
January 2009 EPICS Seminar in Indore 2
Outline
• 1. Introduction
• 2. Basic Feature
• 3. Additional Feature
January 2009 EPICS Seminar in Indore 3
1. IntroductionSNL 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 4
State Transition Diagram
State A
State B
State C
January 2009 EPICS Seminar in Indore 5
Where Sequencer runs ?
• Typical usage --- runs in IOC– Sequencer is a software component of IOC.
process database
Sequencer
CA
IOC
OPI
process database
CA
network
January 2009 EPICS Seminar in Indore 6
• Another usage --- runs in OPI– Sequencer (Ver. 2.0 or later) can run as a
stand-alone program in workstation.
process database
Sequencer
CA
IOC
OPI
process database
CA
Sequencer
network
January 2009 EPICS Seminar in Indore 7
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 8
2. Basic Feature
• State Transition Diagram
Start
Light is off
Light is on
v > 60
Turn light on
v < 50
Turn light off
event
action
statestate transition
January 2009 EPICS Seminar in Indore 9
First Step of SNL Code
• Skeleton of the SNL codestate light_off
{
when (v > 60.0) {
/* turn light on */
} state light_on
}
state light_on
{
when (v < 50.0) {
/* turn light off */
} state light_off
}
Start
Light is off
Light is on
v > 60
Turn light on
v < 50
Turn light off
January 2009 EPICS Seminar in Indore 10
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 11
Monitor a Channel
float v;
assign v to "sample:Vout";
monitor v;
when (v > 60.0) { …
January 2009 EPICS Seminar in Indore 12
A Complete State Programprogram seqtestfloat 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}
state light_on{
when (v < 50.0){
/* turn light off */light = FALSE;pvPut(light);
} state light_off}
}
January 2009 EPICS Seminar in Indore 13
Structure of a State Programprogram seqtestfloat 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}
state light_on{
when (v < 50.0){
/* turn light off */light = FALSE;pvPut(light);
} state light_off}
}
Program
Definition
State Set
January 2009 EPICS Seminar in Indore 14
Structure of a State Set
Event Action(State Transition)
State
State Set
program seqtestfloat 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}
state light_on{
when (v < 50.0){
/* turn light off */light = FALSE;pvPut(light);
} state light_off}
}
January 2009 EPICS Seminar in Indore 15
program seqtest2 … declaration …ss state_set_1{
state A{ …}state B{ …}
}ss state_set_2{
state C{ …}state D{ …}
}
Multiple State Sets
State C
State D
State_set_2
State A
State B
State_set_1
Each State Set runs concurrently.
January 2009 EPICS Seminar in Indore 16
Declaration (1)
• Variable
int variable_name;
short variable_name;
long variable_name;
char variable_name;
float variable_name;
double variable_name;
string variable_name; … fixed size char array
January 2009 EPICS Seminar in Indore 17
Declaration (2)
• Assign
• Monitor
assign variable_name to "channel_name";
monitor variable_name;
January 2009 EPICS Seminar in Indore 18
Declaration (3)
• Array of Variables
– int, short, long, char, float, double variable can be array. (array of string is not available.)
int variable_name[array_length];
int variable_name[array_length][array_length];
int Vin[4];
assign Vin to {"chan1", "chan2", "chan3"};
monitor Vin;
January 2009 EPICS Seminar in Indore 19
Events
• Typical expression:– Change in value of a variable
– Time out
• 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.
when (v > 60.0)
when ( expression )
when (delay(10.0))
January 2009 EPICS Seminar in Indore 20
Actions (1)
• Most C statements are supported.
expression;
if (…) … else …
while (…) …
for (…, …, …) …
break;
January 2009 EPICS Seminar in Indore 21
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 22
Actions (3)
• Built-in functionspvPut(variable_name)
pvGet(variable_name)
…– You can see many built-in functions in the ma
nual. – In principle, the built-in functions cannot be dir
ectly used in escaped C code.
January 2009 EPICS Seminar in Indore 23
Build an SNL program
• “make” automates the following steps.
CPP
test.st test.ctest.i test.o
SNC CC
test.stt test.c test.o
SNC CC
January 2009 EPICS Seminar in Indore 24
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 25
• Dynamic Assignment
float Xmotor;
assign Xmotor to "";
…
pvAssign(Xmotor, "Motor_1_4");
January 2009 EPICS Seminar in Indore 26
• Status, Severity, Time stamp
pvStatus(Xmotor)
pvSeverity(Xmotor)
pvTimeStamp(Xmotor)
January 2009 EPICS Seminar in Indore 27
• Event Flag– Synchronizing State Sets using Event Flag
evflag flag1;… efSet(flag1); efClear(flag1);… when (efTestAndClear(flag1)) { … }
January 2009 EPICS Seminar in Indore 28
• Event Flag associated to a Channel– Event Flag is set whenever a monitor is delivered.
double loLimit;
assign loLimit to "demo:loLimit";
monitor loLimit;
evflag loFlag;
sync loLimit loFlag;
…
when (efTestAndClear(loFflag))
{ … }
January 2009 EPICS Seminar in Indore 29
• Connection Management
when (pvConnectedCount()!=pvChannelCount())
{ … }
when (pvConnected(Xmotor))
{ … }
– SNC compiler option•-c : don’t wait for channel connection•+c : wait for channel connection (default)
January 2009 EPICS Seminar in Indore 30
• 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 31
• 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 32
• More features
– Look at the tutorial slides at APS.
– Read the manual.