1  """SpecCounter module 
 2   
 3  This module defines the classes for counter objects 
 4   
 5  Classes: 
 6  SpecCounter -- class representing a counter in Spec 
 7  SpecCounterA -- class representing a counter in Spec, to be used with a GUI 
 8  """ 
 9   
10  __author__ = 'Matias Guijarro' 
11  __version__ = '1.0' 
12   
13  import SpecConnectionsManager 
14  import SpecEventsDispatcher 
15  import SpecWaitObject 
16   
17  (COUNTING) = (3) 
18  (UNKNOWN, SCALER, TIMER, MONITOR) = (0, 1,2,3) 
19   
21      """SpecCounter class""" 
22 -    def __init__(self, specName = None, specVersion = None, timeout = None): 
 23          """Constructor 
24   
25          Keyword arguments: 
26          specName -- the name of the counter in Spec (defaults to None) 
27          specVersion -- 'host:port' string representing a Spec server to connect to (defaults to None) 
28          timeout -- optional timeout for connection (defaults to None) 
29          """ 
30          self.channelName = '' 
31          self.connection = None 
32          self.type = UNKNOWN 
33   
34          if specName is not None and specVersion is not None: 
35              self.connectToSpec(specName, specVersion, timeout) 
36          else: 
37              self.specName = None 
38              self.specVersion = None 
 39   
40   
67   
68   
70          """Count up to a certain time or monitor count 
71   
72          Arguments: 
73          time -- count time 
74          """ 
75          if self.connection is not None: 
76              c1 = self.connection.getChannel('scaler/.all./count') 
77              c2 = self.connection.getChannel('scaler/%s/value' % self.specName) 
78   
79              if self.type == MONITOR: 
80                  time = -time 
81   
82              c1.write(time) 
83   
84              w = SpecWaitObject.SpecWaitObject(self.connection) 
85              w.waitChannelUpdate('scaler/.all./count', waitValue = 0) 
86   
87              return c2.read() 
 88   
89   
91          """Return current counter value.""" 
92          if self.connection is not None: 
93              c = self.connection.getChannel('scaler/%s/value' % self.specName) 
94   
95              return c.read() 
  96