Writing EPICS Channel Access Clients in Python Geoff Savage March 2003.

Slides:



Advertisements
Similar presentations
Network II.5 simulator ..
Advertisements

Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
1 1999/Ph 514: Channel Access Concepts EPICS Channel Access Concepts Bob Dalesio LANL.
A component- and message-based architectural style for GUI software
Remote Procedure Call (RPC)
Remote Procedure Call Design issues Implementation RPC programming
Channel Access Protocol Andrew Johnson Computer Scientist, AES Controls Group.
9-12 Oct 2000PCaPAC 2000, DESY Hamburg Epics to TINE translator Matthias Clausen, DESY Hamburg Phil Duval, DESY Hamburg Zoltan Kakucs, DESY Hamburg.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
OCT 1 Master of Information System Management Organizational Communications and Distributed Object Technologies Lecture 5: Distributed Objects.
WSN Simulation Template for OMNeT++
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 1 Let’s get started. Let’s start by selecting an architecture from among.
1 I/O Management in Representative Operating Systems.
C++ fundamentals.
Fundamentals of Python: From First Programs Through Data Structures
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.
NETWORK CENTRIC COMPUTING (With included EMBEDDED SYSTEMS)
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Understanding the CORBA Model. What is CORBA?  The Common Object Request Broker Architecture (CORBA) allows distributed applications to interoperate.
Imperial College Tracker Slow Control & Monitoring.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
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.
BLU-ICE and the Distributed Control System Constraints for Software Development Strategies Timothy M. McPhillips Stanford Synchrotron Radiation Laboratory.
(Business) Process Centric Exchanges
10/20/2015J-PARC1 Control Room Accelerator Physics Channel Access – Connection to Hardware Through EPICS Getting Information directly from the Control.
1 Cisco Unified Application Environment Developers Conference 2008© 2008 Cisco Systems, Inc. All rights reserved.Cisco Public Introduction to Etch Scott.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
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.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
Wir schaffen Wissen – heute für morgen PSI,30. Oktober 2015 Paul Scherrer Institut Python Channel Access Client/Server Extension Xiaoqiang Wang EPICS Spring.
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.
X-WindowsP.K.K.Thambi The X Window System Module 5.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
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.
Chapter 5: Distributed objects and remote invocation Introduction Remote procedure call Events and notifications.
EPICS EPICS Limitations Bob Dalesio Marty Kraimer.
Apr. 8, 2002Calibration Database Browser Workshop1 Database Access Using D0OM H. Greenlee Calibration Database Browser Workshop Apr. 8, 2002.
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 1999/Ph 514: Flow of Control EPICS Flow of Control Marty Kraimer APS.
1. LabVIEW and EPICS Workshop EPICS Collaboration Meeting Fall 2011.
Python Applications for Beamline Control Mark Rivers.
Channel Access Client Coding 2006
New IP Drivers using drvIpac Module Driver:CANopen Carrier Driver:GPFC drvIpac ?? CANopen Tip810 CAN Tip810 mv162GPFCatc40vipc310vipc616 Module driver.
EPICS Release 3.15 Bob Dalesio May 19, Features for 3.15 Support for large arrays Channel access priorities Portable server replacement of rsrv.
B. Dalesio, N. Arnold, M. Kraimer, E. Norum, A. Johnson EPICS Collaboration Meeting December 8-10, 2004 Roadmap for IOC.
PvaPy: Python API for EPICS PV Access Siniša Veseli Scientific Software Engineering & Data Management Advanced Photon Source EPICS Meeting October 2015.
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
F Fermilab Python Channel Access Interface (CaChannel) Geoff Savage EPICS Collaboration Meeting 16 November 2000.
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.
16th Oct 08 Tom Cobb - Python at DLS 1 Uses of Python at Diamond Light Source.
Updates to CaPython/CaChannel John Hammonds Beamline Controls and Data Acquisition Group APS Engineering Support Division EPICS Collaboration Meeting INFN.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
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.
JavaIOC Overview and Update
Writing Channel Access Clients
Topics Introduction to File Input and Output
Writing a Channel Access Client in EPICS
Channel Access Concepts
Topics Introduction to File Input and Output
Channel Access Concepts
Presentation transcript:

Writing EPICS Channel Access Clients in Python Geoff Savage March 2003

27 March 2003Python CA Clients2 Contents  EPICS concepts  EPICS architecture  Channel access (CA)  EPICS CA and Python  Motivation  Examples  Software architecture  CaChannel  caPython

27 March 2003Python CA Clients3 EPICS Architecture Input Output Controller Host Network Operating systems: VxWorks Linux WindowsNT Hardware and Software Devices Data Bus Control and monitor devices

27 March 2003Python CA Clients4 Channel Access Input Output Controller Host Network The EPICS Software Bus – Client-server protocol Network or local communication path CASCAC CASCAC CAS CAC Channel Access Server Channel Access Client

27 March 2003Python CA Clients5 CA Communication Input Output Controller Host Network CA Client – Connects with a record by name Access individual fields in a record Read/write, post events on value change, … CAS CAC CA Server – A record connects data with a name Fields in each record specify how to manipulate the data Fields for conversions, alarm limits, …

27 March 2003Python CA Clients6 CA Services  Dynamic channel creation  Automatic channel reconnect  Read  Write  Monitoring  Generates callbacks  Events  Access control  Connection  Data type conversions  Composite data structures

27 March 2003Python CA Clients7 Channel Creation IOC Host Who has channel ‘XXXX’? (udp broadcast) IOC Host I have channel ‘XXXX’. IOC Host Negotiate connection. (point-to-point tcp)

27 March 2003Python CA Clients8 CA Buffering  “All requests which require interaction with a CA server are accumulated (buffered) and not forwarded to the IOC until one of ca_flush_io(), ca_pend_io(), ca_pend_event(), ca_sg_pend() are called allowing several operation to be efficiently sent over the network in one message.”  Read/write transactions can not be in the same message as the connection request

27 March 2003Python CA Clients9 CA Request Status  “If the server for a channel is located in a different node than the client then the operations that communicate with the server return status indicating the validity of the request.”  “In other words, success returned from the client library routine indicates that it checked your request, it appeared to be valid, and it forwarded it to the server.”  Check the status when the transactions have completed

27 March 2003Python CA Clients10 CA Transaction Status  “Any process variable values written into your program’s variables by ca_get() should not be referenced by your program until ECA_NORMAL has been receied from ca_pend_io().”  Upon receipt of a callback the transaction is complete and the transaction status is available from within the callback.

27 March 2003Python CA Clients11 CA Operation  “For proper operation CA must periodically be allowed to take care of background activity. This requires that your application must either wait in one of ca_pend_event(), ca_pend_io(), or ca_sg_block(), or it must call ca_pend_event() at least every 15 seconds.”

27 March 2003Python CA Clients12 EPICS CA Summary  EPICS software bus  Client-server architecture  Library functionality  Create and maintain connections  Synchronous transactions  Asynchronous transactions  Transaction status reporting  Buffering for efficiency Details follow in the discussion of CaChannel.

27 March 2003Python CA Clients13 Why Python?  “Python is an interpreted, interactive, object-oriented programming language”  Fermilab experience  Reduced development time  Portable (Linux, NT, OSF1)  Graphics (Tcl/Tk)  Powerful extension library  Easy to extend (SWIG)  Short learning curve 

27 March 2003Python CA Clients14 Using CA from Python  Maintain full CA functionality  Callbacks  Data types  Map each connection to an object  Two step process  caPython – make the CA library callable from Python (wrapping)  CaChannel – use the wrapped functions in caPython to create channel objects

27 March 2003Python CA Clients15 ~]$ setup d0online ~]$ python Python 2.1 (#3, May , 15:15:15) [GCC (release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> from CaChannel import * >>> ch = CaChannel('catest') >>> ch.searchw() >>> ch.putw( ) >>> ch.getw() Simple Interpreter Example Make a connection via a name. Create the connection. Write a value. Read a value.

27 March 2003Python CA Clients16 Simple Script Example #! /bin/env python from CaChannel import * def main(): try: catest = CaChannel('catest') catest.searchw() catest.putw( ) print catest.getw() except CaChannelException, status: print ca.message(status) main() Print the error string.

27 March 2003Python CA Clients17 Graphical Interfaces

27 March 2003Python CA Clients18 Architecture EPICS channel access C library  Collection of C functions and macros  Distributed with EPICS caPython  Python wrapper around the C library  Collection of python functions CaChannel  Python class  Calls caPython functions Move from C functions to a Python class interface.

27 March 2003Python CA Clients19 CaChannel  Methods  Data types  Synchronous I/O  Asynchronous I/O  Monitoring  Use with Tkinter

27 March 2003Python CA Clients20 CaChannel Construction  CaChannel is constructed from caPython and the SWIG pointer library  “SWIG is an interface compiler that connects programs written in C and C++ with scripting languages such as Perl, Python, Ruby, and Tcl.”  caPython – CA functions, macros, and helper functions wrapped using SWIG  SWIG pointer library – manipulation of C pointers from Python

27 March 2003Python CA Clients21 CaChannel Methods …  Connection  search  search_and_connect  clear_channel  Synchronization  pend_io  pend_event  poll  flush_io  Write  array_put  array_put_callback  Read  array_get  array_get_callback  getValue  Monitors  add_masked_array_event  clear_event

27 March 2003Python CA Clients22 … CaChannel Methods  Simple and slow  searchw = search + pend_io  getw = array_get + pend_io  putw = array_put + pend_io  Information  field_type  element_count  name  state  host_name  read_access  write_access

27 March 2003Python CA Clients23 Synchronous I/O  pend_io = flush request buffer and wait for CA requests to complete for all CaChannel objects  Multiple requests can be issued before each pend_io  All connections must be made before get or put  On a get a value is not valid until pend_io has returned with no errors >>> >>> ch.search() >>> ch.pend_io() >>> >>> ch.array_put( ) >>> ch.pend_io() >>> >>> ch.array_get() >>> ch.pend_io() >>> ch.getValue()

27 March 2003Python CA Clients24 >>> ch.getw() >>> ch.getw(ca.DBR_INT) 123 >>> ch.getw(ca.DBR_STRING) '123' >>> ch.field_type() 6 >>>ca.dbr_text(ch.field_type()) 'DBR_DOUBLE‘ >>> Data Types …  Each PV has a native type  Different data types can be requested  Requests using the native type are most efficient Not all caPython functions are implemented as methods of CaChannel.

27 March 2003Python CA Clients25 … Data Types … >>> scan = CaChannel('catest.SCAN') >>> scan.searchw() >>> scan.getw() 6 >>> scan.getw(ca.DBR_STRING) '1 second' >>> scan.putw(5) >>> scan.getw(ca.DBR_STRING) '2 second‘ >>> ca.dbr_text(scan.field_type()) 'DBR_ENUM' >>>  The SCAN field of a record identifies how often the record is processed  There is an enumerated list of possible SCAN field values

27 March 2003Python CA Clients26 … Data Types >>> scan.putw('1 second') Traceback (innermost last): File " ", line 1, in ? File "CaChannel.py", line 383, in putw count, pval = self.__setup_put(value, req_type) File "CaChannel.py", line 131, in __setup_put CaChannel.dbr_d[req_type]['convert'](value), ValueError: invalid literal for int(): 1 second >>> scan.putw('1 second', ca.DBR_STRING) >>> scan.getw(ca.DBR_STRING) '1 second' Writing the enumerated identifier (5) works on the previous slide and writing a value (‘1 second’) fails.

27 March 2003Python CA Clients27 Request Data Types Request typePython typeComments DBR_STRINGString DBR_ENUMIntegerEnumerated DBR_CHARInteger8 bits DBR_INTInteger16 bits DBR_LONGInteger32 bits DBR_FLOATFloat DBR_DOUBLEFloat Array of DBRList of type

27 March 2003Python CA Clients28 Asynchronous I/O …  No waiting for CA requests to complete  A user written callback function is executed when the request has completed  ca_pend_event = flush the request buffer and wait for timeout or until all CA background activity is processed  ca_poll = ca_pend_event with a short timeout  ca_flush_io = flush the request buffer

27 March 2003Python CA Clients29 … Asynchronous I/O  Asynchronous callbacks do not preempt the main thread  Instead ca_pend_io, ca_pend_event, or ca_poll must be called at least every 15 seconds to allow background activity to process

27 March 2003Python CA Clients30 Connection Callback ch.search_and_connect('catest', connectCb) while 1: ch.pend_event() def connectCb(epics_args, user_args): print ‘name =‘, ca.name(epics_args[0]) print ‘state =‘, epics_args[1]  epics_args = 2 element tuple  epics_args[0] = channel identifier, used to get the channels name  epics_args[1] = connection state  ca.OP_CONN_UP  ca.OP_CONN_DOWN  user_args = tuple containing all python objects specified after the callback in the method

27 March 2003Python CA Clients31 Put Callback  epics_args is a dictionary with keys:  chid = channel identifier  type = request type (DBR_XXXX)  count = element count  status = transaction status code from server ch.array_put_callback(3.3, None, None, putCb) while 1: ch.pend_event() def putCb(epics_args, user_args): print ca.name(epics_args['chid']) print ca.dbr_text(epics_args['type']) print epics_args['count'] print ca.message(epics_args['status']) print user_args Native data type Default element count

27 March 2003Python CA Clients32 Get Callback  value(s) = data returned by the server. Multiple data elements are returned in a tuple. ch.array_get_callback(None, None, getCb1) while 1: ch.pend_event() def getCb1(epics_args, user_args): print "pvName = ", ca.name(epics_args['chid']) print "type = ", ca.dbr_text(epics_args['type']) print "count = ", epics_args['count'] print "status = ", ca.message(epics_args['status']) print "user args = ", user_args print "value(s) = ", epics_args['pv_value'] Native data type Default element count

27 March 2003Python CA Clients33 Compound Data Types  Only supported in asynchronous mode  Extra information with the value  Status – alarm values  Time – status + timestamp  Graphics – status + alarm limits + display limits  Control – graphics + control limits  Routines are provided to convert DBR type to compound type

27 March 2003Python CA Clients34 Get Status Callback  pv_severity = alarm severity  pv_status = alarm status ch.array_get_callback(ca.dbf_type_to_DBR_STS(ch.field_type()), None, getCb2) while 1: ch.pend_event() def getCb2(epics_args, user_args): print "pvName = ", ca.name(epics_args['chid']) print "type = ", ca.dbr_text(epics_args['type']) print "count = ", epics_args['count'] print "status = ", ca.message(epics_args['status']) print "user args = ", user_args print "value(s) = ", epics_args['pv_value'] print ca.alarmSeverityString(epics_args['pv_severity']) print ca.alarmStatusString(epics_args['pv_status']) Default element count

27 March 2003Python CA Clients35 Monitoring …  Asynchronous I/O originated at the server  Client requests notification from the server when  the channel’s value changes by more than the value dead band or alarm dead band  the channel’s alarm state changes  Monitor callbacks match those described under asynchronous I/O

27 March 2003Python CA Clients36 … Monitoring … def eventCb(epics_args, user_args): print ca.message(epics_args['status']) print "new value = ", epics_args['pv_value'] print ca.alarmSeverityString(epics_args['pv_severity']) print ca.alarmStatusString(epics_args['pv_status']) try: chan = CaChannel() chan.searchw('catest') chan.add_masked_array_event( ca.dbf_type_to_DBR_STS(chan.field_type()), None, ca.DBE_VALUE | ca.DBE_ALARM, eventCb) except CaChannelException, status: print ca.message(status)

27 March 2003Python CA Clients37 … Monitoring Monitor maskNotification condition ca.DBE_VALUE when the channel’s value changes by more than MDEL ca.DBE_LOG when the channel’s value changes by more than ADEL ca.DBE_ALARM when the channel’s alarm state changes

27 March 2003Python CA Clients38 Functions Not Implemented  ca_change_connection_event  use ca_search_and_connect  ca_add_exception_event  ca_replace_printf_handler  ca_replace_access_rights_event  ca_puser macro  not used  ca_test_event  Scan groups

27 March 2003Python CA Clients39 Tkinter and CaChannel  EPICS CA is not thread safe  All CaChannel activity must be performed in the main thread  Use the Tkinter after method to interrupt the mainloop at regular intervals to allow CA backgroud activity to execute  Execute CaChannel calls from the update function called by after

27 March 2003Python CA Clients40 caPython  Maintain full CA functionality  SWIG handles the wrapping of functions not associated with callbacks without intervention  Label the functions with the C function name minus the ca_ prefix  ca_pend_io -> pend_io  Additional C functions were added to handle callbacks  Access to constants in the header files  Macros are wrapped in functions

27 March 2003Python CA Clients41 caPython Initialization  Provide access to constants in header files  DBF_XXXX types – native field types  DBR_XXXX types – transaction request types  ECA_XXXX – transaction status codes  Connection states  Event masks  When the ca module is imported into python execute ca_task_initialize()

27 March 2003Python CA Clients42 caPython Callbacks 1. Python callback function 2. Register the callback 3. Synchronize with pend_event 4. Execute C function 5. Execute callback function 6. Cleanup reference counts 7. Resume python code Python script C function Key:

27 March 2003Python CA Clients43  When ca_search_and_connect() completes it calls USERFUNC with one argument of type struct connection_handler_args  connectCallback is the C function always called  The python callback function and user data are combined and passed in through PUSER Callback Example int ca_search_and_connect( char *CHANNEL_NAME, chid *PCHID, void (*USERFUNC)(struct connection_handler_args ARGS), void *PUSER);

27 March 2003Python CA Clients44 Callback Functions  Convert the channel access C data for return to the Python callback function  Separate the python callback function and user data found in PUSER  Call the Python function with two arguments  CA data  User data - if no user data is specified then the user data tuple is empty  Cleanup reference counts