source: moxy/trunk/src/moxy/paxis.py @ 780

Last change on this file since 780 was 780, checked in by jemian, 11 years ago

consistency

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision Url
File size: 4.5 KB
Line 
1#!/usr/bin/env python
2
3########### SVN repository information ###################
4# $Date: 2012-02-02 20:36:47 +0000 (Thu, 02 Feb 2012) $
5# $Author: jemian $
6# $Revision: 780 $
7# $URL$
8# $Id: paxis.py 780 2012-02-02 20:36:47Z jemian $
9########### SVN repository information ###################
10
11'''
12Pseudo-motor (axis, positioner, whatever) object.
13Provides abstraction for an EPICS motor record and
14a more generic "axis" positioner, defined by individual EPICS PVs.
15
16The methods to start and stop EPICS CA callbacks are different in the
17PyEpics objects of epics.motor.Motor and epics.device.Device.
18Here, new methods are created in the paxis.Motor and paxis.PAxis
19objects so that the client may call with the same signature.
20
21
22To start EPICS CA monitoring, invoke with a call, such as::
23   
24    cb = some_axis_object.start_callback('VAL', handler, {'field': 'VAL'})
25
26where the ``handler()`` method might be defined as::
27
28    def handler(**kw):
29        """trivial example callback handler"""
30        print kw['pvname'], kw['field'], kw['value']
31'''
32
33
34# - - - - - - - - - - - - - - - - - - Imports
35
36
37import epics
38
39
40# - - - - - - - - - - - - - - - - - - Global
41
42
43__svnid__ = "$Id: paxis.py 780 2012-02-02 20:36:47Z jemian $"
44
45
46# - - - - - - - - - - - - - - - - - - classes
47
48
49class Motor(epics.Motor):
50    '''minor customizations'''
51   
52    def stop(self):
53        '''Provide a stop() method, PyEpics uses SPMG field in StopNow()'''
54        self.STOP = 1
55   
56    def start_callback(self, attr, handler, kws):
57        '''start EPICS CA monitoring'''
58        return self.add_callback(attr, handler, **kws)
59   
60    def stop_callback(self, attr, index):
61        '''terminate EPICS CA monitoring'''
62        self.get_pv(attr).remove_callback(index=index)
63
64
65class PAxis(epics.device.Device):
66    '''
67    Define a pseudo-motor object with support for a few select
68    fields coming from different, unrelated, EPICS PVs.
69    Meet the interface of the PyEpics.motor.Motor object.
70   
71    :see: http://cars9.uchicago.edu/software/python/pyepics3/devices.html
72    '''
73   
74    def __init__(self, val, rbv, desc, egu, dmov, stop, timeout=3.0, **kws):
75        '''
76        EPICS PV names are required for these fields:
77       
78        ===========  ========================================================
79        field        description
80        ===========  ========================================================
81        ``VAL``      [float] (commanded) target value for this axis
82        ``RBV``      [float] current (readback) value for this axis
83        ``DESC``     [str] description of this axis
84        ``EGU``      [str] engineering units
85        ``DMOV``     [bool] done moving = 1
86        ``STOP``     [int] send 1 to stop this axis
87        ===========  ========================================================
88       
89        :param str val:  PV for VAL field
90        :param str rbv:  PV for RBV field
91        :param str desc:  PV for DESC field
92        :param str egu:  PV for EGU field
93        :param str dmov:  PV for DMOV field
94        :param str stop:  PV for STOP field
95        :param float timeout: seconds to wait for EPICS reply
96        :param dict kws: other optional arguments for the superclass
97        '''
98        epics.Device.__init__(self)
99        self.add_pv(val, 'VAL')
100        self.add_pv(rbv, 'RBV')
101        self.add_pv(desc, 'DESC')
102        self.add_pv(egu, 'EGU')
103        self.add_pv(dmov, 'DMOV')
104        self.add_pv(stop, 'STOP')
105
106    def within_limits(self, val, dial=False):
107        """Tests whether a target value is within drive limits.
108        Always returns True (since no PVs for limits are specified).
109        Ignores the dial attribute.
110        (This method meets same interface as PyEpics.Motor() object.)
111        """
112        return True
113   
114    def move(self, position):
115        '''Provide a stop() method'''
116        self.VAL = position
117   
118    def stop(self):
119        '''Provide a stop() method'''
120        self.STOP = 1
121   
122    def get_pv(self, attr):
123        '''return the PV object for the attr'''
124        return self._pvs[attr]
125   
126    def start_callback(self, attr, handler, kws = {}):
127        '''start EPICS CA monitoring'''
128        return self.add_callback(attr, handler, **kws)
129   
130    def stop_callback(self, attr, index):
131        '''terminate EPICS CA monitoring'''
132        self.remove_callbacks(attr, index)
133
134
135# - - - - - - - - - - - - - - - - - - methods
136
137
138# - - - - - - - - - - - - - - - - - - main
139
140
141if __name__ == '__main__':
142    '''show how to use this class'''
143    s = 'prj:m2.'
144    m1 = PAxis(s+'VAL', s+'RBV', s+'DESC', s+'EGU', s+'DMOV', s+'STOP')
145    print m1
146    print m1.VAL
147    print m1.RBV
148    print m1.DESC
149    import pprint
150    pprint.pprint( m1._pvs )
151    print m1._nonpvs
152    print m1._init
Note: See TracBrowser for help on using the repository browser.