january 2009epics seminar in indore1 introduction to state notation language (snl) tatsuro nakamura...

32
January 2009 EPICS Seminar in Indore 1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

Upload: nicholas-borow

Post on 01-Apr-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

January 2009 EPICS Seminar in Indore 1

Introduction toState Notation Language (SNL)

Tatsuro NAKAMURA @ KEK

January 2009

Page 2: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

January 2009 EPICS Seminar in Indore 2

Outline

• 1. Introduction

• 2. Basic Feature

• 3. Additional Feature

Page 3: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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.

Page 4: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

January 2009 EPICS Seminar in Indore 4

State Transition Diagram

State A

State B

State C

Page 5: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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

Page 6: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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

Page 7: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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

Page 8: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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

Page 9: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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

Page 10: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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);

Page 11: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

January 2009 EPICS Seminar in Indore 11

Monitor a Channel

float v;

assign v to "sample:Vout";

monitor v;

when (v > 60.0) { …

Page 12: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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}

}

Page 13: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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

Page 14: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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}

}

Page 15: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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.

Page 16: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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

Page 17: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

January 2009 EPICS Seminar in Indore 17

Declaration (2)

• Assign

• Monitor

assign variable_name to "channel_name";

monitor variable_name;

Page 18: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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;

Page 19: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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))

Page 20: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

January 2009 EPICS Seminar in Indore 20

Actions (1)

• Most C statements are supported.

expression;

if (…) … else …

while (…) …

for (…, …, …) …

break;

Page 21: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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

}%

Page 22: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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.

Page 23: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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

Page 24: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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.

Page 25: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

January 2009 EPICS Seminar in Indore 25

• Dynamic Assignment

float Xmotor;

assign Xmotor to "";

pvAssign(Xmotor, "Motor_1_4");

Page 26: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

January 2009 EPICS Seminar in Indore 26

• Status, Severity, Time stamp

pvStatus(Xmotor)

pvSeverity(Xmotor)

pvTimeStamp(Xmotor)

Page 27: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

January 2009 EPICS Seminar in Indore 27

• Event Flag– Synchronizing State Sets using Event Flag

evflag flag1;… efSet(flag1); efClear(flag1);… when (efTestAndClear(flag1)) { … }

Page 28: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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))

{ … }

Page 29: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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)

Page 30: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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()

Page 31: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

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.

Page 32: January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro NAKAMURA @ KEK January 2009

January 2009 EPICS Seminar in Indore 32

• More features

– Look at the tutorial slides at APS.

– Read the manual.