Experimental Physics and Industrial Control System (EPICS) Sequencer and State Notation Language Tutorial Slides Bob Dalesio, Deb Kerstiens, Rozelle Wright.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 1.
Advertisements

January 2009EPICS Seminar in Indore1 Introduction to State Notation Language (SNL) Tatsuro KEK January 2009.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
1 1999/Ph 514: Channel Access Concepts EPICS Channel Access Concepts Bob Dalesio LANL.
Chapter 8 Improving the User Interface
Simulation executable (simv)
Programming Languages and Paradigms The C Programming Language.
1 MODULE name (parameters) “Ontology” “Program” “Properties” The NuSMV language A module can contain modules Top level: parameters less module Lower level.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
1 CS 161 Introduction to Programming and Problem Solving Chapter 9 C++ Program Components Herbert G. Mayer, PSU Status 10/20/2014.
Programming Logic and Design Fourth Edition, Introductory
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Chapter 10.
VBA Modules, Functions, Variables, and Constants
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Guide To UNIX Using Linux Third Edition
Denso Training Using WINCAPS III
Guide To UNIX Using Linux Third Edition
Chapter 1 Program Design
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Experimental Physics and Industrial Control System (EPICS) Alarm Handler (ALH) Bob Dalesio, August 14, 1999.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
ORNL is managed by UT-Battelle for the US Department of Energy EPICS State Notation Language (SNL), “Sequencer” Kay Kasemir, SNS/ORNL Many slides from.
Python Programming Fundamentals
SNL and Sequencer 1 Controls EPICS Training Class EPICS Collaboration Meeting SLAC State Notation Language (SNL) and Sequencer April 23, 2012 Kukhee.
Reusable Code For Your Appx Processes Presented By: Gary Rogers.
1 1999/Ph 514: State Notation Language EPICS State Notation Language (SNL) Ned D. Arnold APS.
1 2001: Beijing State Notation Language EPICS State Notation Language (SNL) Ned D. Arnold APS (Ron Chestnut SLAC)
Introduction to Shell Script Programming
Designing For Testability. Incorporate design features that facilitate testing Include features to: –Support test automation at all levels (unit, integration,
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
By Sidhant Garg.  C was developed between by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
1 SNL Current State (in transition state) By Matthias Clausen Ron Chestnut.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
Managed by UT-Battelle for the Department of Energy EPICS Sequencer Kay Kasemir, SNS/ORNL Many slides from Andrew Johnson, APS/ANL Feb
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
EPICS sequencer update Greg White / William Lupton / EPICS ‘99 SLAC, May 27, 1999.
Reliability/ Secure IOC / Outlook M. Clausen / DESY 1 CA-Put Logging BurtSave Warm Reboot Matthias Clausen DESY/ MKS.
Stanford Linear Accelerator Center New SNL Ideas Possible Next Steps Ron Chestnut – PSI, May, 2001 With ideas from B. Dalesio and M. Clausen.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
1 1999/Ph 514: Lab #3A : SNL Lab#3B : Development Environment EPICS Lab #3a State Notation Language.
Scion Macros How to make macros for Scion The Fast and Easy Guide.
1 Channel Access Concepts – IHEP EPICS Training – K.F – Aug EPICS Channel Access Concepts Kazuro Furukawa, KEK (Bob Dalesio, LANL)
Extra Recitations Wednesday 19:40-22:30 FENS L055 (tomorrow!) Friday 13:40-16:30 FENS L063 Friday 17: :30 FENS L045 Friday 19:40-22:30 FENS G032.
1 EPICS Flow of Control: EPICS Workshop at IHEP, Beijing, August 2001 EPICS Flow of Control Marty Kraimer APS.
Expressions and Data Types Professor Robin Burke.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
State Notation Language and the Sequencer Andrew Johnson APS Engineering Support Division October 2008 INFN EPICS Training.
Chapter Topics The Basics of a C++ Program Data Types
User-Written Functions
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
State Notation Language (SNL) and Sequencer
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
PHP.
Channel Access Concepts
Presentation transcript:

Experimental Physics and Industrial Control System (EPICS) Sequencer and State Notation Language Tutorial Slides Bob Dalesio, Deb Kerstiens, Rozelle Wright Oct 1, 2001

Sequencer Version These slides describe SNL/SEQ version This version is available for downloading at Documentation for Version which is being distributed with EPICS 3.14 is available at this same site. Version has all the functionality of Version except that SEQ does not run on UNIX.

Outline What is state notation and what function does it serve Components of a state notation program Building, running and debugging a state notation program Additional Features Some Notes on the Runtime Sequencer

Purpose A language to facilitate sequential programming in the EPICS real- time environment Fast execution - compiled code Programming interface to extend EPICS in the real-time environment Easy for first-time user to learn and apply

Common Uses of the State Notation Language Provide automated start-up sequences like vacuum or RF where subsystems need coordination Provide fault recovery or transition to a safe state Provide access to the Unix file system for save/restore or restoration of parameters on reboot Provide automatic calibration of equipment

State Transition Diagram State A State B Event Action Transition A to B Start Low vacuum High vacuum pressure < Torr Open the valve pressure > Torr Close the valve

SNL: General Structure and Syntax program program_name declarations ss state_set_name { state state_name { enter{ action statements } when (event) { action_statements } state new_state_name when(event) … exit{ action statements } state state_name {.... }

SNL: General Structure and Syntax program nameA Program contains many state sets. The program name is used as the handle to the sequencer manager for state programs. ss name{A state set becomes a task in the vxWorks environment. state name{A state is an area where the task waits for events. The related task waits until one of the events occurs and then checks to see which it should execute. The first state defined in a state set is the initial state. option flag;A state specific option when (event) {Is used to define the events for which this state waits. } state statenameIs used to define the new state after the actions are taken. entry{Do these actions on entry to this state from another state (using option -e; will do these actions even if it enters from the same state) } exit{Do these actions before exiting this state to another state. (using option -x; will do these actions even if it exits to the same state.) }

Declarations Occur before a state set and have a scope of the entire program. Scalar types intvariableIname; short variableSname; long variableLname; char variableCname; float variableFname; double variableDname; string variableStrname; /* currently limited to 40 characters*/ Vector types intarrayIname[array_length]; shortarraySname[array_length]; long arrayLname[array_length]; chararrayCname[array_length]; floatarrayFname[array_length]; double arrayDname[array_length];

Declarations - continued Assignment to channel access server channels floatpressure; assignpressure to “Tank1CouplerPressureRB1”; doublepressures[2]; assignpressures to {“Tank1CouplerPressureRB1”, ”Tank1CouplerPressureRB2”,”Tank1CouplerPressureRB3”}; To use these channel in when clauses they must be monitored monitor pressure; monitor pressures; Declaring Event Flags evflagevent_flag_name;/* event for state sets to set, clear, /* and test syncpressure flag_monitor;/* flag monitor is set when pressure /* changes (posts a monitor)

Events An event is the condition on which statements following a when are executed and a state transition is made Possible events: Change in value of a variable that is being monitored example: when(achan < 10.0) A timed event (not a task delay!) example: when(delay(1.5)) The delay value is in seconds. It is delclared internally as a double and constant arguments to the delay function must contain a decimal point. A delay is normally reset whenever the state containing it is exited. Use the state specific option -t to keep it from being reset when exiting to the same state..

Events (continued) An internally generated event (event flag) examples: when(efTestAndClear(myflag)) when(efTest(myflag)) efTest does not clear the flag. efClear must be called sometime later to avoid an infinite loop. The event flag can be set internally by efSet(event_flag_name) or if the flag is synced to a monitored channel it will be set when the channel changes. Change in the channel access connection status. examples: when(pvConnectCount() < pvChannelCount()) when(pvConnected(mychan) )

Actions almost any C expression switch is not implemented and code using it must be escaped. % escape one line of C code %{ escape any number of lines of C code }% Built-in action function: pvPut (variable_name); pvGet (variable_name); efSet (event_flag_name); efClear (event_flag_name);

State Definitions and State Transitions Low Vacuum pressure > RoughPump on CryoPump off Valve closed pressure <= RoughPump off CryoPump on Valve open InitalState High Vacuum pressure <= RoughPump off CryoPump on Valve open pressure > RoughPump on CryoPump off Valve closed Fault 10 minutes RoughPump off CryoPump off Valve closed

Declarations for Example double pressure; assign pressure to “Tank1Coupler1PressureRB”; monitor pressure; shortRoughPump; assignRoughPump to “Tank1Coupler1RoughPump”; shortCryoPump; assignCryoPump to “Tank1Coupler1CryoPump”; shortValve; assignValve to “Tank1Coupler1IsolationValve”; stringCurrentState; assignCurrentState to “Tank1Coupler1VacuumState”;

State Transitions for the Example program vacuum_control ss coupler_control { state init{ when(pressure > ){ } state low_vacuum when(pressure <= ){ } state high_vacuum } state high_vacuum{ when(pressure > ){ } state low_vacuum } state low_vacuum{ when(pressure <= ){ }state high_vacuum when(delay(600.0)){ }state fault } state fault{ }

States for the Example - Init state init{ entry{ strcpy(CurrentState,”Init”); pvPut(CurrentState); } when(pressure > ){ RoughPump = 1; pvPut(RoughPump); CryoPump = 0; pvPut(CryoPump); Valve = 0; pvPut(Valve); } state low_vacuum when(pressure <= ){ RoughPump = 0; pvPut(RoughPump); CryoPump = 1; pvPut(CryoPump); Valve = 1; pvPut(Valve); } state high_vacuum }

States for the Example state high_vacuum{ entry{ strcpy(CurrentState,”High Vacuum”); pvPut(CurrentState); } when(pressure > ){ RoughPump = 1; pvPut(RoughPump); CryoPump = 0; pvPut(CryoPump); Valve = 0; pvPut(Valve); } state low_vacuum } state low_vacuum{ entry{ strcpy(CurrentState,”Low Vacuum”); pvPut(CurrentState); } when(pressure <= ){ RoughPump = 0; pvPut(RoughPump); CryoPump = 1; pvPut(CryoPump); Valve = 1; pvPut(Valve); }state high_vacuum when(delay(600.0)){ }state fault } state fault{ entry{ strcpy(CurrentState,”Vacuum Fault”); pvPut(CurrentState); }

Building a state program 1. Use editor to build the source file: file name must end with ".st", e.g. "example.st". 2. “gmake” automates these steps: Runs the C preprocessor Compiles the state program with SNC to produce C code: snc example.st -> example.c Compiles the resultant C code with the C compiler: cc example.c -> example.o The file "example.o” becomes part of the application library, which is ready to be loaded by VxWorks. 3. Note: For class purposes, we will be reloading the object code as a module instead of rebooting to reload the library.

The Run-Time Sequencer 1. The sequencer executes the state program in the VxWorks environment. 2. The sequencer supports the event-driven execution; no polling needed. 3. Each state set becomes a VxWorks task. 4. The sequencer manages connections to database channels through "channel access". 5. The sequencer provides support for channel access (put, get, and monitor). 6. The sequencer supports asynchronous execution of delay and event flag functions. 7. Only one copy (object module) of the sequencer is required on each IOC. 8. Query commands display information about executing state programs.

Executing a state program Assume that VxWorks is running in an IOC and the proper database is loaded. 1. Telnet to the IOC: telnet ts1 log in ts1>you should get a prompt 2. Load the object module:( ts1> ld /example.o 3. Execute the state program: ts1> seq &example this is the program name This will create one task for each state set. 4. Exercise the program. 5. Print a summary of state programs ts1> seqShow 6. If it doesn’t work properly: Delete the tasks that were created in step 3. ts1> td "example” Go back to step 2.

Hints for debugging a state program 1. Use printf statements in program: printf("entering state: light_on"); 2. Manually enter database values using CAU: cau: put hv03:temp Print database values using CAU: cau: get hv03:temp Use special state program query commands: seqShow displays information on all running state programs seqShow "example" displays detailed information on program seqChanShow "example" /* all channels */ seqChanShow "example”,”-”/* disconnected */ displays information on all channels 5. Use spy to find a sequence with an infinite loop with no delays

Example of seqShow output -> seqShow Program Name Task ID Task Name SS Name lights lights ss lights_1 switch_to_auto

Example of seqShow output(continued) ->seqShow "lights” State Program: "lights” initial task id= =0x1b87e78 task priority=100 number of state sets=2 number of syncQ queues=0 number of channels=16 number of channels assigned=16 number of channels connected=16 options: async=0, debug=0, newef=1, reent=0, conn=1 log file fd=8 log file name="/pty/telnet.S” State Set: "ss1” task name=lights; task id= =0x1b87e78 First state = "init” Current state = "auto” Previous state = "auto” Elapsed time since state was entered = 0.0 seconds)

Example of seqShow output (continued) State Set: "switch_to_auto” task name=lights_1; task id= =0x1b855d4 First state = "man” Current state = "auto” Previous state = "man” Elapsed time since state was entered = seconds)

Additional Features Connection management: –when ( pvConnectCount() != pvChannelCount() ) –when ( pvConnected(Vin) ) Macros: –assign Vout to "{unit}:OutputV"; –(must use the +r compiler options for this if more than one copy of the sequence is running on the same ioc) –ts1> seq &example, "unit=HV01" Compiler options: –+r make program reentrant (default is -r) –-c don't wait for all channel connections (default is +c) –+a asynchronous pvGet() (default is -a) –-w don't print compiler warnings (default is +w) –+e eftest automatically clears flag (default is -e)

Additional Features(continued) Pass parameters to programs at run time: –#----- this line is executed in the st.cmd file –ts1> seq &example, "bias = 2.55" –pStr = macValueGet("bias"); /* this statement in the.st file gets value */ Access to alarm status and severity: –pvStatus(var_name) –pvSeverity(var_name) Queueable monitors -- saves monitors in queue in the order they come in -- no missing monitors. –syncQ variableName to eventFlagname [optionally the length of the queue] –pvGetQ( variableName ) removes oldest value from variables monitor queue. Remains true until queue is empty. –pvFreeQ( variable Name)