New Python EPICS Interface
Motivation
History
Geoff Savage created
caPython(CaChannel) and Mark Rivers extended it to
epicsPV and upon that created device support modules, epicsMotor, epicsLogger, epicsScaler, epicsMed, epicsMca. In today's point of view, it has the following limitations:
- Based on EPICS 3.13. Using APIs obsoleted in EPICS 3.14.
- For the same reason, no thread support.
- It is not actively maintained.
- The code is wrapped by SWIG-1.1 and requires extra work to be used by SWIG-1.3.
On the other hand, Noboru Yamamoto created and still maintains
PythonCA. It has been brought update to date with EPICS 3.14. It has the following advantages:
- With thread support.
- Preemptive callback is enabled by default, which does not require periodical call of poll() to process background CA activities.
- Wrapped with Python/C API, no SWIG dependence.
Indeed there is a third development from Matthew Newville, formerly known as Ezca and has evolved into
EpicsCA.
- EPICS 3.14 compatible.
- Lacks thread support and disables preemptive callback.
- Caches all connected PV channels in the C extension level.
- Wrapped with SWIG 1.3.
What is in SLS
Our Approach
PythonCA is chosen as the basic layer to provide Python EPICS interface. After a thorough
analysis of the API of both CaPython and PythonCA, we rebuild the CaChannel interfaces. The results are the following files:
- _ca_fnal.py: holds all namespace from
_ca and add necessary functions(mostly data type related) not directly implemented in _ca but existing in CaPython.
- CaChannel.py: CaChannel Class interface
Our modification of PythonCA has been kindly accepted into the main release, since
1.20.1.beta2.
Regression Test
ca_cb_gr.py and
ca_wf.py are two unmodified test programs from CaPython. The new interface passes all test.
However there are subtle differences, see blow.
How to Convert Old Codes
If you only use searchw(), getw(), putw() function calls either using CaChannel or epicsPV classes, then you can safely skip the following discussions. Continue reading if you worry about the internals.
- In CaPython one needs to call poll() periodically for CA library to process callback functions. This is not needed in PythonCA because preemptive callback is enabled by default.
- In CaPython, CaChannelException has a member variable status to hold the integer CA error code, ECA_NORMAL etc. In PythonCA, it has been used to hold the string message. But in both cases,
print will show the error message.
- In PythonCA, add_masked_array_event ignores the req_type parameter, which means only native field type is supported.
Test Suite
Here we demonstrate two typical usage, one is for command line based program and one is for graphical based program with multithread capability.
- Before Start
- Load CVS:/G/EPICS/extensions/src/PythonCA/test/test.db to an IOC:
iocsh> dbLoadRecords("test.db") It provides the following records,
- catest - ao
- castr - stringout
- cabo - bo
- cawave - waveform of double
- cawavec - waveform of char
- cawaves - waveform of string
- Point your Python package search path to the new module,
export PYTHONPATH=/somewhere/to/be/decided:$PYTHONPATH
- CVS:G/EPICS/extensions/src/PythonCA/test/test.py is a command line program doing synchronous CA get/put calls.
- CVS:G/EPICS/extensions/src/PythonCA/test/thread.py is a multithread GUI program using asynchronous CA calls. It spawns a thread to calculate the Fibonacci numbers and put it to PV catest. In the main thread PV catest is monitored and displayed in a Tkinter Label widget.
- CaChannel has doctest built in. See the test results with command,
python CaChannel.py -v
Documentation
Basically the API is the same as CaPython, so the documentation of
CaChannel is still valid.
Install
The releases can be downloaded from
https://sourceforge.net/project/showfiles.php?group_id=249697&package_id=312334.
Binary:
CaChannel_bin.tar.gz
| OS | Python | EPICS | GCC |
| Windows | 2.5 | 3.14.9 | MinGW 3.4.5 |
| Linux | 2.4 | 3.14.8.2 | GCC 4.1.2 |
Sources:
CaChannel_src.tar.gz
- Download PythonCA from http://www-acc.kek.jp/EPICS_Gr/products.html and untar it, resulting a directory like
PythonCA-1.20.1.
- Download
CaChannel_src.tar.gz and extract the contents to PythonCA-1.20.1.
- Edit
EPICS_config_XXX.py to setup your EPICS environment variables.
- Edit
ca.py, at the bottom of the file, replace from _ca_kek import * with from _ca_fnal import *
- Run
python setup.py build.
--
XiaoqiangWang - 22 Aug 2008
keywords: Python