1 2009: Channel Access EPICS Channel Access Andy Foster Observatory Sciences Limited.

Slides:



Advertisements
Similar presentations
1 Symbian Client Server Architecture. 2 Client, who (a software module) needs service from service provider (another software module) Server, who provide.
Advertisements

MPI Message Passing Interface
1 1999/Ph 514: Channel Access Concepts EPICS Channel Access Concepts Bob Dalesio LANL.
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Virtual LANs.
Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
Remote Procedure Call (RPC)
Remote Procedure Call Design issues Implementation RPC programming
Channel Access Protocol Andrew Johnson Computer Scientist, AES Controls Group.
CS490T Advanced Tablet Platform Applications Network Programming Evolution.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Chapter 23: ARP, ICMP, DHCP IS333 Spring 2015.
CCNA Guide to Cisco Networking Fundamentals Fourth Edition Chapter 9 Network Services.
16: Distributed Systems1 DISTRIBUTED SYSTEM STRUCTURES NETWORK OPERATING SYSTEMS The users are aware of the physical structure of the network. Each site.
1 I/O Management in Representative Operating Systems.
PRASHANTHI NARAYAN NETTEM.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Fundamentals of Python: From First Programs Through Data Structures
資 管 Lee Application Layer and Client-Server Model A3.
Lecture 2 TCP/IP Protocol Suite Reference: TCP/IP Protocol Suite, 4 th Edition (chapter 2) 1.
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
Distributed Systems. Interprocess Communication (IPC) Processes are either independent or cooperating – Threads provide a gray area – Cooperating processes.
Channel Access Client Programming in C Advanced EPICS Training (This is going to be hard!)
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
EPICS devSNMP Extensions Euan Troup, CSIRO Australia Telescope National Facility ASKAP Project Paul Wild Observatory.
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
Problems with Send and Receive Low level –programmer is engaged in I/O –server often not modular –takes 2 calls to get what you want (send, followed by.
10/20/2015J-PARC1 Control Room Accelerator Physics Channel Access – Connection to Hardware Through EPICS Getting Information directly from the Control.
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.
Kazuro Furukawa, KEK, Jul Channel Access Clients EPICS Workshop 2006, VECC, India 1 Introduction to Channel Access Clients Kenneth Evans, Jr. September.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
1 Channel Access Concepts – EPICS Training – K.Furukawa – Mar EPICS Channel Access Concepts Kazuro Furukawa, KEK, ( ) (Bob Dalesio, LANL,
Introduction to the Channel Access Client Library Kenneth Evans, Jr. Kay Kasemir.
EPICS Access from Python Geoff Savage DØ Workshop Thursday June 22, 2000.
3.14 Work List IOC Core Channel Access. Changes to IOC Core Online add/delete of record instances Tool to support online add/delete OS independent layer.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
Client-Server Model of Interaction Chapter 20. We have looked at the details of TCP/IP Protocols Protocols Router architecture Router architecture Now.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
1 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Writing Channel Access Clients Kazuro Furukawa, KEK, ( ) (Marty.
EPICS Release 3.15 Bob Dalesio May 19, Features for 3.15 Support for large arrays - done for rsrv in 3.14 Channel access priorities - planned to.
1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Dynamic Host Configuration Protocol (DHCP)
Writing EPICS Channel Access Clients in Python Geoff Savage March 2003.
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
1 1999/Ph 514: Flow of Control EPICS Flow of Control Marty Kraimer APS.
GLOBAL EDGE SOFTWERE LTD1 R EMOTE F ILE S HARING - Ardhanareesh Aradhyamath.
The Mach System Silberschatz et al Presented By Anjana Venkat.
Virtual Local Area Networks (VLANs) Part II
Chapter 4 Version 1 Virtual LANs. Introduction By default, switches forward broadcasts, this means that all segments connected to a switch are in one.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
ERICSON BRANDON M. BASCUG Alternate - REGIONAL NETWORK ADMINISTRATOR HOW TO TROUBLESHOOT TCP/IP CONNECTIVITY.
EPICS Release 3.15 Bob Dalesio May 19, Features for 3.15 Support for large arrays Channel access priorities Portable server replacement of rsrv.
Advanced Photon Source Channel Access, CaSnooper, and CASW Kenneth Evans, Jr. Presented November 7, 2003 Argonne National Laboratory.
1 1999/Ph 514: Channel Access Configuration EPICS Channel Access Configuration Andrew Johnson APS.
Controls Zheqiao Geng Oct. 12, Autosave Additions/Upgrades and Experiences at SLAC Zheqiao Geng Controls Department SLAC National Accelerator Laboratory.
1 Channel Access Concepts – IHEP EPICS Training – K.F – Aug EPICS Channel Access Concepts Kazuro Furukawa, KEK (Bob Dalesio, LANL)
Introduction Contain two or more CPU share common memory and peripherals. Provide greater system throughput. Multiple processor executing simultaneous.
1 EPICS Flow of Control: EPICS Workshop at IHEP, Beijing, August 2001 EPICS Flow of Control Marty Kraimer APS.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
Control System Overview J. Frederick Bartlett Fermilab June 1,1999.
Monitoring Dynamic IOC Installations Using the alive Record Dohn Arms Beamline Controls & Data Acquisition Group Advanced Photon Source.
Net 431 D: ADVANCED COMPUTER NETWORKS
Channel Access, CaSnooper, and CASW
Issues in Client/Server Programming
Writing a Channel Access Client in EPICS
Channel Access Concepts
Channel Access Configuration
Channel Access Configuration
Channel Access Concepts
Exceptions and networking
Presentation transcript:

1 2009: Channel Access EPICS Channel Access Andy Foster Observatory Sciences Limited

2 2009: Channel Access EPICS Outline u What is Channel Access? u Channel Naming Convention u Features of Channel Access u Asynchronous nature of Channel Access u Client Library Functions u Create context u Create channel u Put u Get u Asynchronous Events u Exceptions u Flushing the send buffer u Error reporting u Channel Access configuration u Connection management u Examples of Channel Access client code u Software releases and documentation

3 2009: Channel Access EPICS What is Channel Access? u Channel Access (CA) is the EPICS communication protocol. u Based on a client-server architecture. u Clients are written using the CA client library. u The server is part of iocCore. u Note that an IOC is both a client and a server! u Clients make requests to the servers across the network. u A “Channel” is the communication path to a field within a record (process variable) in an IOC. u Integrates software modules into the control system i.e. Alarm Handler, Operator Interface.

4 2009: Channel Access EPICS The EPICS Software Bus Operator Interface Archive Tool Alarm Tool Application

5 2009: Channel Access EPICS Channel Naming Convention u CA requires that channels have a name. u The IOC database requires names of the form: u [. ] u rfhv01.LOPR” u rfhv01 u If the field name is omitted.VAL is assumed. u For large projects, record names usually follow a record naming convention. u Record field names and purposes are record type specific u A list of the field names available for each record can be obtained from the EPICS Record Reference Manual.

6 2009: Channel Access EPICS Features of Channel Access u The client library is easy to use (see later) u It is operating system transparent u It provides network transparency (i.e. access to remote and local channels is identical) u Handles data conversion between different CPU architectures u Asynchronous and efficient… u Small packet sizes, small headers, combined operations…

7 2009: Channel Access EPICS Channel Access Network Architecture IO Controller 2 Channel Access Server CAS Channel Access Client CAC CAS IO Controller 1... CAC Operator Interface 1 Operator Interface n... CAC CAS IEEE CAC

8 2009: Channel Access EPICS Asynchronous Nature of Channel Access u CA does not wait to gain access to the network prior to returning from each client library call. u Sometimes it is useful to perform labor on a local processor while several operations are completing on remote processors. u CA library calls are buffered and sent when either the buffer fills or a special CA library call is made. u Combined operations are more efficient when sharing a common resource such as the network. u Data fetched from a remote machine is generally not immediately available. u The plant, itself, is often asynchronous u All operations guaranteed to be executed in the order requested.

9 2009: Channel Access EPICS Client Library Functions Create CA Context u ca_context_create( enum ca_preemptive_callback_select SELECT ) u Should be called once from each thread prior to making any other CA calls. u The SELECT argument specifies non-preemptive mode or preemptive mode. u In non-preemptive mode, a user’s callback functions will only be called when the thread which made this call is inside a CA library function. The CA client library always waits for the current callback to complete before invoking a new one. This means the user does not have to worry about multiple, simultaneous, accesses to data structures. u In pre-emptive mode, a user’s callback functions can be called when the thread which made this call is not inside a CA library function. In this case the user is responsible for mutex locking of private data structures. u EPICS 3.14 CA client libraries are fully thread safe on all OS’s. u Registers this client with the CA repeater. u This is a daemon (under Unix) which fans out UDP broadcasts received on the CA UDP port to all CA processes running on the machine. Solves the problem of the O/S only allowing one process to have access to the port.

: Channel Access EPICS Client Library Functions Create Channel u ca_create_channel( “name”, userFunc, &user, priority, &channelID ) u Causes a UDP broadcast to be sent to all CA servers on the client’s local subnet. u Only a server which recognizes “name” will respond to the client u If identical record names exist in two IOCs, the first to reply “wins” the connection u The client library then opens a TCP connection with the server and establishes a “virtual circuit” to access the channel u Note that there is only one TCP connection between any particular client and a server. All data about all channels (PV’s) on that IOC pass through this connection. u Connections between individual channels in the IOC and the client are referred to as “virtual circuits”.

: Channel Access EPICS Client Library Functions Create Channel (contd.) u userFunc is an optional user function to call when the connection state changes. u user is an optional pointer to user data which will be associated with this channel. u priorit y is the priority level for servicing requests within the server (range is 0 – 99 with 0 the lowest). u channelID is an identifier, returned from the client library, for this channel. It will be used to communicate with this channel in all future CA calls made by the users application.

: Channel Access EPICS Client Library Functions Create Channel (contd.) u Potential problems: u Not all LANs support broadcasting u Ethernet does, Token Ring doesn’t u Some sites don’t allow broadcasting u Bridges/hubs will not forward packets u Broadcasts are local to the machine’s subnet u Sites can span more than a single subnet

: Channel Access EPICS Client Library Functions Put u There are many CA PUT functions: u ca_put( field_type, channelId, &val ) u ca_put_callback ( field_type, channelId, &val, usrFunc, usrArg ) u field_type : u All channels have a “native” data storage type in the IOC. u Native data storage types are “atomic” and include: integer, floating point, string, enumerated etc. u field_type is the data format we will use to write to the channel. Often referred to as the external data type. u The external data type can be different from the native type if conversion is possible. u Conversion between types are done in the server so ask for native types for better performance at the real-time end! u All use “channel ID” from Create to communicate with record field u usrFunc is called after all records in the processing chain in the database have been processed.

: Channel Access EPICS Client Library Functions Get u There are many CA GET functions: u ca_get( field_type, channelId, &val ) u ca_get_callback (field_type, channelId, usrFunc, usrArg) u Arguments similar to the PUT functions. u Notice that ca_get_callback does not get the value directly. It is available to the user defined function (see example).

: Channel Access EPICS Client Library Functions Asynchronous Events u How can we write a client which will react to asynchronous events in the database? u Use: ca_create_subscription( field_type, count, channelId, mask, usrFunc, usrArg, &evid ) u usrFunc will be called when the “events” we have subscribed to, occur in the database. We define these “events” by the mask parameter. u mask will be a logical OR of: DBE_VALUE: Channel value changes by more than the monitor deadband. DBE_LOG: Channel value changes by more than the archival deadband. DBE_ALARM: Alarm status or severity changes. u evid is a returned pointer to this event. It can be used as an argument to ca_clear_event to cancel the subscription to these event(s). u Events are placed in a queue and handled in the order that they occurred. u For analogue channels, the rate at which events occur should be minimized so that we do not saturate the network. This rate is managed by adjusting the channel’s dead band and scan rate.

: Channel Access EPICS Client Library Functions Exceptions u Since the CA client library does not wait to gain access to the network before returning from each call, it does not know if the operation was successful in the server. u Therefore, error codes returned from CA library calls only check the validity of the request NOT the success of the operation. u Status of unsuccessful operations are returned from the server to the client’s exception handler. u The default exception handler prints a message for each unsuccessful operation and aborts the client if the condition is severe. u We can install our own exception handler by using: ca_add_exception_event (pCallback userFunc, void *usrArg); where: typedef void (*pCallback) (struct exception_handler_args hArgs); u Operations which fail in the server are nearly always caused by programming errors e.g. trying to convert between two incompatible types (string to double).

: Channel Access EPICS Flushing the Send Buffer u Vital for the CA client to work!! u All CA client calls are buffered until either the send buffer is full or one of these is explicitly called: u ca_pend_io( timeout ) Flushes the send buffer and waits until the shorter of: u All outstanding calls to ca_get complete u The timeout expires (Note a timeout of 0 means wait forever) u ca_pend_event( timeout ) Flushes the send buffer and always waits “timeout” seconds for asynchronous events (timeout of 0 means wait forever)

: Channel Access EPICS Error Reporting u For portability reasons CA functions do not return status following the UNIX convention. u Do not test return status against “0”. u Useful macro for testing return status: u SEVCHK( status, “user string” );

: Channel Access EPICS Channel Access Configuration u CA clients and servers can be configured by setting environment variables u On Unix/Linux:  csh, tcsh — setenv VARNAME value  sh, bash, ksh — export VARNAME=value  printenv displays all variables from any shell u On vxWorks:  putenv "VARNAME=value"  envShow displays all variable values  EPICS soft IOC shell iocsh: u epicsEnvSet name value u Environment variables are inherited when you start a new program, not afterwards u Unix: Set the variables, then start the client u vxWorks: Set variables in the startup script  Default values for a site are set at build-time in /base/config/CONFIG_ENV and /base/config/CONFIG_SITE_ENV

: Channel Access EPICS Connection Management u Network connections are inherently transient. u A channel’s connection state is either not found, connected, or disconnected. u CA allows you to specify a handler to be run when a channel’s connection state changes. u Connection requires a server for the channel and a valid network path to the server. u CA automatically restores connection upon notification from the server. This is a very strong feature of CA!

: Channel Access EPICS Connection Health u By default, CA servers send out an “I’m still here” UDP broadcast beacon ever 15 seconds. This is known as the server beacon period. u If a server is quiet for 30 seconds (the client connection timeout), any connected clients will u send it an “echo” packet (not broadcast) u allow 5 seconds for it to reply u mark all channels to this server disconnected u Potential problems: u Slow or busy links might introduce random delays, some longer than 15 seconds u Busy sites may want to reduce broadcast rates u Clients take 35 seconds to recognize when a server has died

: Channel Access EPICS Configuring Connection Health u How to change the server beacon period?  putenv "EPICS_CA_BEACON_PERIOD=30.0" u Default value is 15.0 seconds u How to change the client connection timeout?  setenv EPICS_CA_CONN_TMO 60.0 u Default value is 30.0 seconds u This value determines how long a client takes to notice that a server has died (+5 seconds) u The client connection timeout must be longer than the server beacon period. For efficient operation it is recommended to be set to at least twice as long.

: Channel Access EPICS Configuring Name Resolution u How to disable all broadcasts?  EPICS_CA_AUTO_ADDR_LIST = NO u Default value = YES u IOCs are also clients, so generate broadcasts u How to find channels without broadcast?  EPICS_CA_ADDR_LIST u List of IP addresses, separated by spaces setenv EPICS_CA_ADDR_LIST " " u This list is used in addition to broadcasts if these are enabled u A port number may optionally be specified after a trailing colon. u How to search other subnets as well?  Use a broadcast address in EPICS_CA_ADDR_LIST setenv EPICS_CA_ADDR_LIST " " u Some routers will not pass broadcast addresses

: Channel Access EPICS Configuring Port Numbers u Channel Access uses two IP port numbers for its communication  EPICS_CA_SERVER_PORT u Default is 5064 u UDP used for name resolution u TCP used for channel requests  EPICS_CA_REPEATER_PORT u Default is 5065 u UDP used for receiving server beacons u Both should be > 5000, check with sys-admins u The settings for a server and all its clients must be the same u Using different port numbers can allow independent projects to share a subnet without any danger of CA name clashes u Can also be used for application testing u No interaction is possible between projects

: Channel Access EPICS Configuring Maximum Array Size u Channel Access has a default maximum array size of bytes. This is the size of the largest array that can be passed through CA in a single transfer.  This value may be changed using the environment variable EPICS_CA_MAX_ARRAY_BYTES u A value > bytes will allocate more buffer space. u The settings for a server and all its clients must be the same

: Channel Access EPICS Example Client caPut.c #include #include /* Structures and data types used by CA */ int main( int argc, char *argv[] ) { int status; chid channelId; double val; val = atof( argv[1] ); status = ca_context_create( ca_disable_preemptive_callback ); SEVCHK(status, “ “); status = ca_create_channel( “test:ai”, 0, 0, 0, &channelId ); SEVCHK(status, “ “); status = ca_pend_io(0.0); SEVCHK(status, “ “); status = ca_put( DBR_DOUBLE, channelId, &val ); SEVCHK(status, “ “); status = ca_pend_io(0.0); SEVCHK(status, “ “); return(0); }

: Channel Access EPICS Example Client caGet.c (main) int main( int argc, char *argv[] ) { int status; chid channelId; info_t info; info.project = “Diamond”; info.numIoc = 167; info.current = 3.45; status = ca_context_create( ca_disable_preemptive_callback ); SEVCHK(status, “ “); status = ca_create_channel( “test:ai”, 0, 0, 0, &channelId ); SEVCHK(status, “ “); status = ca_pend_io(0.0); SEVCHK(status, “ “); status = ca_get_callback( DBR_DOUBLE, channelId, (void (*)())usrFunc, &info ); SEVCHK(status, “ “); status = ca_pend_event(0.1); /* This is different! */ SEVCHK(status, “ “); return(0); }

: Channel Access EPICS Example Client caGet.c (contd.) #include typedef struct info { char *project; int numIoc; double current; } info_t; void usrFunc( struct event_handler_args args ) /* cadef.h */ { info_t *t = (info_t *)args.usr; if( args.status == ECA_NORMAL ) { printf(“UsrFunc called: Value = %f\n”, *(double *)args.dbr); printf(“User Argument Name = %s\n”, t->project); printf(“User Argument NumIoc = %d\n”, t->numIoc); printf(“User Argument Current = %f\n”, t->current); printf(“Channel Name = %s\n”, ca_name(args.chid) ); printf(“Number of Elements = %d\n”, ca_element_count(args.chid) ); printf(“Host Name = %s\n”, ca_host_name(args.chid) ); }

: Channel Access EPICS Example Client caMonitor.c (main) int main( int argc, char *argv[] ) { int status; chid channelId; status = ca_context_create( ca_disable_preemptive_callback ); SEVCHK(status, “ “); status = ca_create_channel( “test:ai”, (void (*)())connectFunc, 0, 0, &channelId ); SEVCHK(status, “ “); status = ca_pend_io(0.0); SEVCHK(status, “ “); status = ca_create_subscription( DBR_DOUBLE, 0, channelId, DBE_VALUE|DBE_LOG|DBE_ALARM, (void (*)())monitorFunc, NULL, NULL ); SEVCHK(status, “ “); status = ca_pend_event(0.0); /* Wait forever */ SEVCHK(status, “ “); return(0); }

: Channel Access EPICS Example Client caMonitor.c (contd.) #include void connectFunc( struct connection_handler_args args ) { if( ca_state(args.chid) != cs_conn ) printf(“%s” has just Disconnected\n”, ca_name(args.chid)); else printf(“%s” has just Connected\n”, ca_name(args.chid)); } void monitorFunc( struct event_handler_args args ) { printf(“Monitor on %s, new value = %f\n”, ca_name(args.chid), *(double *)args.dbr); }

: Channel Access EPICS Compound Data Types u Compound data types contain a channel value combined with additional status or configuration information. u Value u Alarm Status u Alarm Severity u Alarm Limits u Precision u Engineering units u Time Stamp u Display Limits u Compound types involve the database record as a whole. u Compound types can currently only be used with gets and monitors. u Data types are described in db_access.h. (DBR_XXXX)

: Channel Access EPICS Example Client caGetCompound.c (main) int main( int argc, char *argv[] ) { int status; chid channelId; struct dbr_ctrl_double data; struct dbr_time_double tdata; char timeString[64]; status = ca_context_create( ca_disable_preemptive_callback ); SEVCHK(status, “ “); status = ca_create_channel( “test:ai”, 0, 0, 0, &channelId ); SEVCHK(status, “ “); status = ca_pend_io(0.0); SEVCHK(status, “ “); status = ca_get( DBR_CTRL_DOUBLE, channelId, &data ); SEVCHK(status, “ “); status = ca_get( DBR_TIME_DOUBLE, channelId, &tdata ); status = ca_pend_io(0.0); SEVCHK(status, “ “); epicsTimeToStrftime( timeString, sizeof(timeString), “%a %b %d %Y %H:%M:%S.%f”, &tdata.stamp ); printResults( data, timeString ); return(0); }

: Channel Access EPICS Example Client caGetCompound.c (contd.) #include void printResults( struct dbr_ctrl_double data, char *timeString ) { printf(“Channel Value = %f\n”, data.value); printf(“Alarm Status = %d\n”, data.status); /* see alarm.h */ printf(“Alarm Severity = %d\n”, data.severity); /* see alarm.h */ printf(“Precision = %d\n”, data.precision); printf(“Engineering Units = %s\n”, data.units); printf(“Upper Display Limit = %d\n”, data.upper_disp_limit); printf(“Lower Display Limit = %d\n”, data.lower_disp_limit); printf(“Upper Alarm Limit = %d\n”, data.upper_alarm_limit); printf(“Lower Alarm Limit = %d\n”, data.lower_alarm_limit); printf(“Upper Warning Limit = %d\n”, data.upper_warning_limit); printf(“Lower Warning Limit = %d\n”, data.lower_warning_limit); printf(“Last Processed on: %s\n”, timeString); }

: Channel Access EPICS Software Releases & Documentation u IOC core and CA client library EPICS major release number must match, or client will not find server. u This is due to potential CA protocol redesign between major releases. u CA protocol is upwardly compatible within a major release. u When new features are added to the client, older versions of the server won’t support them. u Documentation: u EPICS 3.14 Channel Access Reference Manual (