Changeset 731


Ignore:
Timestamp:
Dec 20, 2011 4:46:55 PM (12 years ago)
Author:
jemian
Message:

needs more testing - threading?

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

Legend:

Unmodified
Added
Removed
  • moxy/trunk/src/moxy/m_pv.py

    r727 r731  
    3030# - - - - - - - - - - - - - - - - - - class
    3131
    32 class PvConnection:
     32class PvConnection():
    3333    '''
    3434    A single EPICS Process Variable connection
     
    4040    :param bool connected: Is PV connected with EPICS now?
    4141    :param str connectedText: describes connection state for humans
    42     :param str str_value: most recent value of EPICS PV
    4342    '''
    4443   
     
    4948        self.connected = False
    5049        self.connectedText = 'not connected'
    51         self.str_value = ''
     50        self.ext_callback = None
    5251   
    5352    def connect(self, callback = None, suppliedname = None, **kw):
     
    6867                    char_value = repr(value)
    6968                print("%.32s %s %s" % (pvname, epics.pv.fmt_time(), char_value))
    70                 self.str_value = str(value)
    7169
    7270        if len(pvname) > 0:    # PV name must not be an empty string
    7371            self.channel = epics.PV(pvname, connection_callback=self.connection_cb)
    7472            if callback is not None:
     73                self.ext_callback = callback
    7574                self.cb_index = self.channel.add_callback(callback, **kw)
    7675   
     
    8281        self.connected = False
    8382        self.channel = None
     83        self.ext_callback = None
    8484
    8585    def connection_cb(self, **metadata):
    8686        "PV connection callback"
    8787        self.connected = metadata['conn']       # connection state
     88        self.connectedText = {True: 'connected',
     89                              False: 'not connected'}[self.connected]
     90        if self.ext_callback is not None:
     91            self.ext_callback(**metadata)
    8892
    8993
  • moxy/trunk/src/moxy/vc_pv.py

    r730 r731  
    184184        self.w_value.SetValue( self.value )
    185185   
     186    def ColorSelector(self, index):
     187        clut = [ COLOR_NOT_MOVING, COLOR_MOVING,
     188                 COLOR_PALE_PURPLE, COLOR_LIGHTGREEN, COLOR_LIGHTRED, ]
     189        return clut[index % len(clut)]
     190   
    186191    def callback(self, **kw):
    187192        "generic monitor callback"
    188193        print kw
    189         self.SetRemarks(kw['cb_info'])
    190         self.SetValue(kw['value'])
    191         self._cb_counter += 1
    192         color = self.ColorSelector(self._cb_counter)
    193         print self._cb_counter, color
    194         self.w_value.SetBackgroundColour(color)
    195    
    196     def ColorSelector(self, index):
    197         clut = [ COLOR_NOT_MOVING, COLOR_MOVING, COLOR_PALE_PURPLE, COLOR_LIGHTGREEN, COLOR_LIGHTRED, ]
    198         return clut[index % len(clut)]
     194        if 'conn' in kw.keys():
     195            self.SetState({False: 'not connected', True: 'connected'}[kw['conn']])
     196            if kw['conn']:
     197                print "before...", kw['conn']
     198                value = self.pv.channel.get()
     199                self.SetValue( value )
     200                print "HERE WE ARE...", value
     201        else:
     202            self.SetRemarks(kw['cb_info'])
     203            self.SetValue(kw['value'])
     204            self._cb_counter += 1
     205            color = self.ColorSelector(self._cb_counter)
     206            print self._cb_counter, color
     207            self.w_value.SetBackgroundColour(color)
    199208
    200209
Note: See TracChangeset for help on using the changeset viewer.