Changeset 725


Ignore:
Timestamp:
Dec 18, 2011 8:52:41 AM (14 years ago)
Author:
jemian
Message:

better comments, example code, streamline the callback

Location:
moxy/trunk/src/moxy
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified moxy/trunk/src/moxy/m_axis.py

    r724 r725  
    8383   
    8484    def connect(self, ext_handler = None):
    85         '''connect all the PVs with EPICS'''
     85        '''
     86        connect all the PVs with EPICS
     87       
     88        :param meth ext_handler: external callback routine to be called, see _local_callback() for example
     89        '''
    8690        cb_method = self._local_callback
    8791        self.val.connect(suppliedname=self.val.pvname, callback=cb_method, field='VAL')
     
    111115   
    112116    def _local_callback(self, **kw):
    113         """
     117        '''
    114118        PyEPICS PV callback handler.
    115119       
     
    119123        * value
    120124        * char_value
    121         * field
     125        * field (custom field, identifies VAL, RBV, DMOV, EGU, STOP, DESC, ...)
    122126       
    123         Pass the entire ``kw`` dictionary to the ext_handler() method
    124         """
    125         if kw['field'] in ('VAL', 'RBV', 'DMOV', ):
    126             value = kw['value']
    127             if kw['field'] == 'VAL':
    128                 self.target = value
    129             elif kw['field'] == 'RBV':
    130                 self.readback = value
    131             elif kw['field'] == 'DMOV':
    132                 self.moving = not value
     127        Pass the entire ``kw`` dictionary to the ext_handler() method.
     128        The ext_handler() method is something such as::
     129       
     130            def handler(**kw):
     131                "PyEPICS callback handler to describe moving state in GUI"
     132                if kw['field'] == 'DMOV':
     133                    moving = not kw['value']
     134                    color = {False: NOT_MOVING_COLOR,
     135                             True: MOVING_COLOR}[ moving ]
     136                    SetWidgetBackgroundColor(color)
     137        '''
     138        value = kw['value']
     139        if kw['field'] == 'RBV':
     140            # most common case comes first
     141            self.readback = value
     142        elif kw['field'] == 'DMOV':
     143            # next most common (twice as many as VAL updates)
     144            self.moving = not value
     145        elif kw['field'] == 'VAL':
     146            # almost as common as DMOV updates
     147            self.target = value
     148
     149        # external callback handler
    133150        if self.ext_handler is not None:
    134151            self.ext_handler(**kw)
     
    139156
    140157def waitmove(pv, position, seconds):
     158    '''move this axis and wait for a fixed time (showing EPICS CA monitors)'''
    141159    from time import sleep
    142160    print "moving", pv.val.channel.pvname, " to ", position
     
    149167
    150168def handler(**kw):
    151     '''callback handler'''
     169    '''trivial example callback handler'''
    152170    print kw['pvname'], kw['field'], kw['value']
    153171
  • TabularUnified moxy/trunk/src/moxy/m_pv.py

    r723 r725  
    9191
    9292def waitmove(pv, position, seconds):
     93    '''move this motor pv and wait for a fixed time'''
    9394    from time import sleep
    9495    print "moving", pv, " to ", position
Note: See TracChangeset for help on using the changeset viewer.