f Fermilab Python Channel Access Interface Ca Channel

f. Fermilab Python Channel Access Interface (Ca. Channel) Geoff Savage EPICS Collaboration Meeting 16 November 2000

Why Python? · “Python is an interpreted, interactive, object-oriented programming language” · Fermilab experience Reduced development time u Portable (Linux, NT, OSF 1) u Graphics (Tcl/Tk) u Powerful extension library u Easy to extend (SWIG) u Short learning curve u · www. python. org 11/16/00 Python/CA 2

Introduction · Implement channel access in a Python class for use in control system applications · First the channel access library must be wrapped Each Python function wraps a CA “C” function u Additional C functions are needed to complete the wrap u § Internal functions – callbacks – file descriptor manager § Helper functions – ca macros – db macros 11/16/00 Python/CA 3

Software Layers Ca. Channel u Python class u Implemented using ca. Python functions and SWIG pointer library ca. Python u Python wrapper around the C library u Collection of python functions u Software wrapper and interface generator (SWIG) EPICS channel access C library u C functions u Macros u Data structures u Constants 11/16/00 Python/CA 4

Examples Interactive >>> from Ca. Channel import * >>> ch = Ca. Channel() >>> ch. searchw('catest') >>> ch. putw(123. 456) >>> ch. getw() 123. 456 Script from Ca. Channel import * def main(): try: catest = Ca. Channel() catest. searchw('catest') catest. putw(123. 456) print catest. getw() except Ca. Channel. Exception, status: print ca. message(status) main() 11/16/00 Python/CA 5

Ca. Channel Methods · Connection to a process variable (PV) search_and_connect u clear_channel u · Write to a PV array_put u array_put_callback u · Read from a PV array_get u array_get_callback u · Monitoring a PV add_masked_array_event u clear_event u 11/16/00 Python/CA 6

Ca. Channel Methods · Send the requests (search, get, put) to an IOC (server) u pend_io, pend_event, flush_io · PV information u field_type, element_count, name, state, host_name, read_access, write_access · Convenient PV access Added by us to make PV access easier u searchw = search + pend_io u putw = array_put + pend_io u getw = array_get + pend_io u 11/16/00 Python/CA 7

Callbacks · Users write callback functions in Python · The standard set of EPICS callbacks is supported Connection u Put u Get u § Value, Status, Time, Graphic, Control u Monitors § Value, Log, Alarm u Internal functions move data from C to Python 11/16/00 Python/CA 8
![Monitor Callback def event. Cb(epics_args, user_args): print ca. message(epics_args['status']) print "new value = ", Monitor Callback def event. Cb(epics_args, user_args): print ca. message(epics_args['status']) print "new value = ",](http://slidetodoc.com/presentation_image_h2/bc4c525ccd03dc525bcc1915cc6741fd/image-9.jpg)
Monitor Callback def event. Cb(epics_args, user_args): print ca. message(epics_args['status']) print "new value = ", epics_args['pv_value'] print ca. alarm. Severity. String( epics_args['pv_severity']) print ca. alarm. Status. String( epics_args['pv_status']) try: ch = Ca. Channel() ch. searchw('catest') ch. add_masked_array_event( ca. dbf_type_to_DBR_STS(ch. field_type()), None, ca. DBE_VALUE | ca. DBE_ALARM, event. Cb) ch. pend_io() except Ca. Channel. Exception, status: print ca. message(status) 11/16/00 Python/CA 9

CA Functions Not Wrapped · ca_change_connection_event u use ca_search_and_connect · ca_add_exception_event · ca_replace_printf_handler · ca_replace_access_rights_ev ent · ca_puser macro u not used · ca_test_event 11/16/00 Python/CA 10

Issues and Plans · Issues Scan groups included but not tested u fd manager implementation appears to have a memory leak (Janousch Markus) u · Plans Complete the wrap u Suitability of next CA version for use in Python u 11/16/00 Python/CA 11

Summary · Extensive experience using Ca. Channel used in all control and monitoring GUIs at DZero · Easy for novices to use Python and Ca. Channel 11/16/00 Python/CA 12

Downloading Ca. Channel www. aps. anl. gov/epics/ ->host software->Ca. Python 11/16/00 Python/CA 13
- Slides: 13