1 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar.2004. EPICS Writing Channel Access Clients Kazuro Furukawa, KEK, (2000-2004) (Marty.

Slides:



Advertisements
Similar presentations
MPI Message Passing Interface
Advertisements

1 1999/Ph 514: Channel Access Concepts EPICS Channel Access Concepts Bob Dalesio LANL.
Channel Access Protocol Andrew Johnson Computer Scientist, AES Controls Group.
Exception Handling Introduction Exception handling is a mechanism to handle exceptions. Exceptions are error like situations. It is difficult to decide.
9-12 Oct 2000PCaPAC 2000, DESY Hamburg Epics to TINE translator Matthias Clausen, DESY Hamburg Phil Duval, DESY Hamburg Zoltan Kakucs, DESY Hamburg.
CSCI 4550/8556 Computer Networks Comer, Chapter 3: Network Programming and Applications.
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
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.
Guide To UNIX Using Linux Third Edition
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
File System. NET+OS 6 File System Architecture Design Goals File System Layer Design Storage Services Layer Design RAM Services Layer Design Flash Services.
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
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.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Kazuro Furukawa, KEK, Jul Jacva and JCA / CAJ EPICS Workshop 2006, VECC, India 1 Java and JCA / CAJ Kenneth Evans, Jr. October 12, 2004 Part of the.
HOW WEB SERVER WORKS? By- PUSHPENDU MONDAL RAJAT CHAUHAN RAHUL YADAV RANJIT MEENA RAHUL TYAGI.
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.
Specview 32 Release 2.5 Enhancements
JavaIOC EPICS Meeting SSRF March Presented by: Marty Kraimer.
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.
Making LabVIEW look like an IOC Kay-Uwe Kasemir, LANL May 2002.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
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.
1 Channel Access Concepts – EPICS Training – K.Furukawa – Mar EPICS Channel Access Concepts Kazuro Furukawa, KEK, ( ) (Bob Dalesio, LANL,
1 2009: Channel Access EPICS Channel Access Andy Foster Observatory Sciences Limited.
Final Review of ITER PBS 45 CODAC – PART 1 – 14 th, 15 th and 16 th of January CadarachePage 1 FINAL DESIGN REVIEW OF ITER PBS 45 CODAC – PART 1.
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.
OS2014 PROJECT 2 Supplemental Information. Outline Sequence Diagram of Project 2 Kernel Modules Kernel Sockets Work Queues Synchronization.
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.
FTP Server API Implementing the FTP Server Registering FTP Command Callbacks Data and Control Port Close Callbacks Other Server Calls.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
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.
Writing EPICS Channel Access Clients in Python Geoff Savage March 2003.
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.
Channel Access Client Coding 2006
How to write a MSGQ Transport (MQT) Overview Nov 29, 2005 Todd Mullanix.
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.
Argonne National Laboratory is managed by The University of Chicago for the U.S. Department of Energy ICALEPCS 2005: EPICS Workshop EPICS V4 : Runtime.
B. Dalesio, N. Arnold, M. Kraimer, E. Norum, A. Johnson EPICS Collaboration Meeting December 8-10, 2004 Roadmap for IOC.
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)
EPICS and LabVIEW Tony Vento, National Instruments
1 EPICS Flow of Control: EPICS Workshop at IHEP, Beijing, August 2001 EPICS Flow of Control Marty Kraimer APS.
Control System Overview J. Frederick Bartlett Fermilab June 1,1999.
1 Writing Channel Access Clients–EPICS Training – K.F – Jul EPICS Writing Channel Access Clients Kazuro Furukawa, KEK (Marty Kraimer, APS, USPAS1999)
LonWorks Introduction Hwayoung Chae.
IPEmotion License Management PM (V1.2).
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Monitoring Dynamic IOC Installations Using the alive Record Dohn Arms Beamline Controls & Data Acquisition Group Advanced Photon Source.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
Managed by UT-Battelle for the Department of Energy LabVIEW Channel Access Implementaion Alexander Zhukov SNS.
JavaIOC Overview and Update
Writing Channel Access Clients
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Topics Introduction to File Input and Output
Issues in Client/Server Programming
Writing a Channel Access Client in EPICS
Channel Access Concepts
EPICS: Experimental Physics and Industrial Control System
Writing Channel Access Clients
Writing Channel Access Clients
Topics Introduction to File Input and Output
Channel Access Concepts
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

1 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Writing Channel Access Clients Kazuro Furukawa, KEK, ( ) (Marty Kraimer, APS, USPAS1999) (Bob Dalesio, LANL, USPAS2003)

2 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS References u EPICS R3.12 / R3.14 Channel Access Reference Manual are the Detailed Documents u cadef.h caerr.h Description of Basic Channel Access Interface u db_access.h Definition of data, difficult to understand but important to write robust software u Tutorials on LANL Web Pages Links from EPICS Web Pages

3 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS CA between IOC and OPI IOC instrumentation and control hardware DATABASE database access library device drivers Channel Access client Channel Access client user program C program WORKSTATION SNL sequence Channel Access server record support device support database library Channel Access Repeater

4 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Overview of Talk u Introduction of Channel Access Client Software Demonstrate Simplified Usage of CA API/Macro Demonstrate Flavors of CA Callback (without details of db_access.h) SEVCHK SEVCHK(,”message”) Macro to test the return code, it display message and abort, on error Used in sample software, convenient in test software Should not be used in production applications u CA Client Library slightly Changed between EPICS 3.13 and 3.14 u In this talk, example codes are based on EPICS 3.13, And they can be used still on EPICS u There exists newer API to support more functionalities, eg. ca_context_create() instead of ca_task_initialize(). Please read the documentation, or look in example codes. u On the other hand, it is assumed to build them on EPICS 3.14 in order to test them on Linux easily. On 3.13, you may need slightly different commands to build them.

5 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Very Simple Example /*caSimpleExample.c*/ #include #include "cadef.h" main(int argc,char **argv) { doubledata; chidmychid; if(argc != 2) { fprintf(stderr,"usage: caExample pvname\n"); exit(1); } SEVCHK(ca_task_initialize(),"ca_task_initialize"); SEVCHK(ca_search(argv[1],&mychid),"ca_search failure"); SEVCHK(ca_pend_io(5.0),"ca_pend_io failure"); SEVCHK(ca_get(DBR_DOUBLE,mychid,(void *)&data),"ca_get failure"); SEVCHK(ca_pend_io(5.0),"ca_pend_io failure"); printf("%s %f\n",argv[1],data); return(0); }

6 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS caExample /*from stdin read list of PVs to monitor*/ #include #define MAX_PV 1000 #define MAX_PV_NAME_LEN 40 typedef struct{ charvalue[20]; chidmychid; evidmyevid; } MYNODE; u Declarations/Definitions for Channel Access u A piece of software to accept a list of Process Variable (Record) names from stdin, then to process them

7 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS CA macros static void printChidInfo(chid chid, char *message) { printf("\n%s\n",message); printf("pv: %s type(%d) nelements(%d) host(%s)", ca_name(chid),ca_field_type(chid), ca_element_count(chid), ca_host_name(chid)); printf(" read(%d) write(%d) state(%d)\n", ca_read_access(chid),ca_write_access(chid), ca_state(chid)); } u Various information available for given chid (Channel ID) u ca_name - name u ca_field_type - type as defined in db_access.h u ca_element_count - array size (1 for scalars) u ca_host_name - INET name of host u ca_read_access - Is read access allowed u ca_write_access - Is write access allowed u ca_state - connected, not connected, etc.

8 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS exception/connection callbacks static void exceptionCallback( struct exception_handler_args args) { chidchid = args.chid; MYNODE*pnode = (MYNODE *)ca_puser(chid); longtype = args.type;/*type of value returned*/ longcount = args.count; longstat = args.stat; printChidInfo(chid,"exceptionCallback"); printf("type(%d) count(%d) stat(%d)\n",type,count,stat); } static void connectionCallback(struct connection_handler_args args) { chidchid = args.chid; MYNODE*pnode = (MYNODE *)ca_puser(chid); printChidInfo(chid,"connectionCallback"); } u exceptionCallback u Called on events other than following callbacks u Errors detected at IOC, etc. u connectionCallback u Called on each connect/disconnect

9 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS accessRightsCallback static void accessRightsCallback( struct access_rights_handler_args args) { chidchid = args.chid; MYNODE*pnode = (MYNODE *)ca_puser(chid); printChidInfo(chid,"accessRightsCallback"); } u Called on connect u Called whenever access rights change

10 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS eventCallback static void eventCallback( struct event_handler_args eha) { chidchid = eha.chid; MYNODE*pnode = (MYNODE *)ca_puser(chid); longtype = eha.type; longcount = eha.count; if(eha.status!=ECA_NORMAL) { printChidInfo(chid,"eventCallback"); } else { char *pdata = (char *)eha.dbr; printf("Event Callback: %s = %s\n", ca_name(eha.chid),pdata); } u Called on Monitored event

11 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS main - start main() { intnpv = 0; MYNODE*pnode; MYNODE*pmynode[MAX_PV]; char*pname[MAX_PV]; inti, status; chartempStr[MAX_PV_NAME_LEN]; char*pstr; while(1) { if(npv >= MAX_PV ) break; pstr = fgets(tempStr,MAX_PV_NAME_LEN,stdin); if(!pstr) break; if(strlen(pstr) <=1) continue; pstr[strlen(pstr)-1] = '\0'; /*strip off newline*/ pname[npv] = calloc(1,strlen(pstr) + 1); strcpy(pname[npv],pstr); pmynode[npv] = (MYNODE *)calloc(1,sizeof(MYNODE)); npv++; } u Read a list of Process Variable (Record) Names caExample < file

12 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Actual CA calls SEVCHK(ca_task_initialize(), "ca_task_initialize"); SEVCHK(ca_add_exception_event( exceptionCallback,NULL), "ca_add_exception_event"); for(i=0; i<npv; i++) { SEVCHK(ca_search_and_connect( pname[i],&pmynode[i]->mychid, connectionCallback,&pmynode[i]), "ca_search_and_connect"); SEVCHK(ca_replace_access_rights_event( pmynode[i]->mychid, accessRightsCallback), "ca_replace_access_rights_event"); SEVCHK(ca_add_event(DBR_STRING, pmynode[i]->mychid,eventCallback, pmynode[i],&pmynode[i]->myevid), "ca_add_event"); } SEVCHK(ca_pend_event(0.0),"ca_pend_event"); /* does not reach here */ ca_task_exit(); }

13 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Start and End  ca_task_initialize initialize the interface to ca_repeater, etc (connection management) ca_context_create() is recommended in 3.14  ca_add_exception_event Specify a Callback routine for an anomaly in CA u {Body of the Code}  ca_task_exit Release resources allocated to CA ca_context_destroy() is recommended in 3.14.

14 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Search u ca_search_and_connect(name,pchid, connectionCallback,userarg) ca_replace_access_rights_event(chid, accessRightsCallback) u Requests are buffered till the buffer is full, or ca_pend or ca_flush are called u Search Process Variable via UDP broadcast  (if EPICS_CA_AUTO_ADDR_LIST is YES or not set ) u An IOC in the subnet responds, if it contains the Process Variable u Establish a TCP connection with the IOC which contains the Process Variable u connectionCallback is called when the connection status changes u accessRightsCallback is called when the Access Right changes u Given a chid we can always retrieve userarg  ca_create_channel() is recommended in 3.14.

15 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS I/O u Puts - Many flavors  ca_array_put(type,count,chid,pvalues)... ca_flush_io() Calls are buffered until: buffer full, ca_flush, or ca_pend.  ca_put_callback(type,count,chid, pvalue,putCallback,userarg) putCallback called after all records processed because of put complete processing. u Gets - Many flavors u ca_array_get(type,count,chid,pvalues)... ca_pend_io(timeout) u ca_array_get_callback(type,count,chid,getCallback,user arg)... ca_pend_event(timeout)

16 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS I/O continued u Monitors - Many flavors  ca_add_masked_array_event(type,count, chid,eventCallback,userarg, pevid,mask) Call this once for each channel to be monitored. Mask allows value changes, alarm changes, archival changes …  ca_pend_event(timeout) Waits at least timeout seconds

17 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Waiting  ca_flush_io() Normally called by ca_pend routines Sends any udp/tcp buffers that are not empty  ca_pend_io(timeout) Calls ca_flush_io. Waits until timeout OR until all outstanding ca_gets complete. Also waits until ca_search with no callback are satisfied  ca_pend_event(timeout) Processes incoming events for at least timeout seconds u timeout u 0 means wait forever u Short time, e.g means poll

18 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS CA with X u Channel Access uses select() to wait. u File Descriptor Manager can be used. u Channel access provides ca_add_fd_registration u X provides similar facility

19 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS db_access.h u Describes the data CA can transfer u Hard to understand and use u Provides access to u data types: string, char, short, long, float, double u status, severity, time stamp u arrays u enums (in ioc both menus and DBF_ENUM fields) u complete set of enum choices u control, display, alarm limits u Alarm Acknowledgment

20 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS ezCa - Easy Channel Access u Goals u Easy to use. u Provide non-callback synchronous model. u Data Types u ezcaByte, ezcaString, ezcaShort, ezcaLong, ezcaFloat, ezcaDouble u Basic Calls u int ezcaGet(pvname, type, nelem, buff) u int ezcaPut(pvname, type, nelem, buff) u int ezcaGetWithStatus(pvname,type, nelem,buff,time,stat,sevr) u Synchronous Groups u int ezcaStartGroup(void) u any combination of get and put u int ezcaEndGroup(void)

21 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS ezCa continued u Error Handling u ezcaPerror(message) u ezcaGetErrorString(message,errorstring) u ezcaFreeErrorString(errorstring) u Other Groupable Functions u int ezcaGetControlLimits(pvname,type,low,high) u int ezcaGetGraphicLimits(pvname,type,low,high) u int ezcaGetNelem(pvname,nelem) u int ezcaGetPrecision(pvname,precision) u int ezcaGetStatus(pvname,time,stat,sevr)  int ezcaGetUnits(pvname,units) u Monitor Functions u int ezcaSetMonitor(pvname,type) u int ezcaClearMonitor(pvname,type) u int ezcaNewMonitor(pvname,type) u Others

22 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Starting Your Practice u mkdir mytest u cd mytest u setenv EPICS_HOST_ARCH \ `$EPICS_BASE/startup/EpicsHostArch.pl` u (HOST_ARCH=`$EPICS_BASE/startup/EpicsHostArch.pl`; export HOST_ARCH)  setenv PATH ${PATH}:$EPICS_BASE/bin/$EPICS_HOST_ARCH u (USER=`whoami` ; export USER) u makeBaseApp.pl –t caClient test1 u cd test1App  create source code, or use examples there  edit Makefile if necessary u cd.. u make (gmake) u gmake caExample u caExample ffred

23 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Practice Explanation 1 u EPICS_HOST_ARCH=\ `$EPICS_BASE/startup/EpicsHostArch.pl` export EPICS_HOST_ARCH assigning a platform name for EPICS software (backquotes around “$EPICS … HostArch.pl” mean “execute it and use the result”) u USER=`whoami` ; export USER (you don’t need this, since normal Unix initializes this variable automatically) assigning a user name for EPICS software u mkdir mytest ; cd mytest making directory for your test, and going into it u makeBaseApp.pl –t caClient test1 creating environment (directory and config files) for a new EPICS application see the manual “EPICS IOC Applications Developers Guide”

24 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS u cd test1App Create a Simple sample code or use a sample code there u make (gmake) build the application with gnu-make based on the Makefile made by makeBaseApp.pl  If you wrote a code and if you don’t want to modify Makefile u cd O.linux ; make xxxx if you modifed Makefile, you don’t need this step u./xxxx Execute the application Practice Explanation 2

25 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Data Type Conversions in Channel Access DBR _STRING, _DOUBLE, _FLOAT, _LONG, _CHAR, _ENUM Data type conversions are performed in the server Endian and floating point conversions are done in the client Polite clients requests data in native type and perform necessary conversion on the client side

26 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Accessing Composite Data Structures Many fields are fetched from the data store in one access: struct dbr_ctrl_floatdata; struct dbr_ctrl_float*pdata = &data; ca_get(DBR_CTRL_FLOAT,mychid,(void *)pdata); printf(“%d %d\n”,pdata->status, pdata->severity); printf(“%d %d\n”,pdata->stamp.secPastEpoch, pdata->stamp.nsec); printf(“%f %f\n”,pdata->high_display_limit,pdata->low_display_limit); printf(“%f %f\n”,pdata->high_warning_limit,pdata->low_warning_limit); printf(“%f %f\n”,pdata->high_alarm_limit,pdata->low_alarm_limit); printf(“%f %f\n”,pdata->high_control_limit,pdata->low_control_limit); printf(“%f %s\n”,pdata->value, pdata->units); *Refer to db_access.h for structures...

27 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Error Checking u Error codes and error related macros are in caerr.h u SEVCHK will exit on errors it deems irrecoverable u ECA_NORMAL means the exchange was initiated successfully u SEVCHK exit behavior can be replaced with your own exception handler ca_add_exception_event(…..) u example: status = ca_array_put(data_type,channel_id,pvalue); SEVCHK(status,”additional info in error message”);

28 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Caching vs. Queuing u An event handler can either take its actions in the event handler - queuing all data is handled degradation mode is longer delays u Place data into an intermediate buffer and have an alternate thread handle the data caching data can be overwritten degradation mode is intermediate data is discarded u note that buffer in IOC will overwrite the last monitor on the queue when a buffer overflows in the IOC

29 Writing Channel Access Clients–EPICS Training – K.Furukawa – Mar EPICS Channel Access Notes u ca_repeater needs to be run once on each workstation u in the database, u a deadband of 0 posts a monitor on any change u a deadband of -1 posts monitors on every scan u R3.15 is hoped to provide an ability to limit the monitor event rates u read cadef.h, caerr.h and db_access.h before writing a channel access client u it is most efficient to use native data types and handle data conversions in the client program