daily pastebin goal
80%
SHARE
TWEET

Circuits Example

a guest Dec 19th, 2013 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. """
  3.  
  4. from circuits import Event, Component, Timer
  5.  
  6. class rawdata(Event):
  7.     ''' New Raw Data
  8.    '''
  9.  
  10. class DataLog(Component):
  11.     ''' Data Logger '''
  12.     channel = "logger"    
  13.    
  14.     def rawdata(self, data):
  15.         print("Data Logger:")
  16.         print("\t" + str(data))
  17.        
  18.     def started(self, *args):
  19.         """started Event handler
  20.        
  21.        """
  22.         print('DataLog started')
  23.  
  24.  
  25. class CentralDispatch(Component):
  26.     ''' Central Dispatch '''
  27.     channel = "dispatch"
  28.    
  29.     def __init__(self):
  30.         super(CentralDispatch, self).__init__()
  31.  
  32.         self.rawdataacq = RawDataAcq().register(self)
  33.  
  34.     def started(self, *args):
  35.         """started Event handler
  36.        
  37.        """
  38.         print('CentralDispatch started')
  39.         self.stop()
  40.        
  41.     def rawdata(self, data):
  42.         print("Central Dispatch data:")
  43.         print("\t" + str(data))
  44.  
  45.  
  46. class RawDataAcq(Component):
  47.     def started(self, *args):
  48.         """started Event handler
  49.        
  50.        """
  51.         Timer(2, Event.create("rawdata", data=100), persist=True).register(self)
  52.         self.fire(rawdata(data=50))
  53.         self.fire(rawdata(data=45),"logger")
  54.         self.fire(rawdata(data=40),"dispatch")
  55.         self.fire(rawdata(data=35),"*")
  56.         Timer(4,rawdata(data=30), persist=True).register(self)
  57.    
  58. (DataLog() + CentralDispatch()).run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top