def onInit(self): self.dev = InterfaceKit() self.setEventHandlers()
class PhidgetsKitService(Service): pmethods = [ 'getServiceLabel', 'getServiceName', 'getServiceType', 'getServiceVersion', 'getInputCount', 'getInputState', 'getLibraryVersion' , 'getOutputCount', 'getOutputState', 'getRatiometric', 'getSensorChangeTrigger', 'getSensorCount', 'getSensorRawValue', 'getSensorValue', 'getSerialNum', 'isAttached', 'setSensorChangeTrigger', 'setRadiometric', ] # ==== Implementation of Service base ==== def onInit(self): self.dev = InterfaceKit() self.setEventHandlers() def setThresholds(self): for k in [0,1,2,3,4,5,6,7]: val = None try: val = self.config.get('trigger%s' % k) except: pass if not val: continue self.dev.setSensorChangeTrigger(k, int(val)) def onStart(self): try: serial = self.config.get('serial') if serial: serial = int(serial) except KeyError: pass if not serial: serial = -1 try: log.info("Open Phidget with serial: %s" % serial) self.dev.openPhidget(serial) #self.dev.openPhidget() log.info("Waiting for Phidget to be attached...") self.dev.waitForAttach(100000) self.phidgetsId = self.dev.getSerialNum() log.info("Phidget with serial: %s attached" % self.phidgetsId) self.diginput = self.dev.getInputCount() log.info("Phidget %s has %s digital inputs" % (self.phidgetsId, self.diginput)) self.digoutput = self.dev.getOutputCount() log.info("Phidget %s has %s digital outputs" % (self.phidgetsId, self.digoutput)) self.analog = self.dev.getSensorCount() log.info("Phidget %s has %s analog inputs" % (self.phidgetsId, self.analog)) self.ifname = self.dev.getServiceName() log.info("Phidget %s has name: %s" % (self.phidgetsId, self.ifname)) self.setThresholds() # make sure dev is closed again if error except PhidgetException, e: self.close() self.phidgetsId = None # but still let the exception continue down the stack # (and set code|message that are not seen with tostring for PE) raise Exception("PhidgetsException, code: %s, msg: %s" % (e.code, e.message))
class PhidgetsKitService(Service): pmethods = [ 'getServiceLabel', 'getServiceName', 'getServiceType', 'getServiceVersion', 'getInputCount', 'getInputState', 'getLibraryVersion', 'getOutputCount', 'getOutputState', 'getRatiometric', 'getSensorChangeTrigger', 'getSensorCount', 'getSensorRawValue', 'getSensorValue', 'getSerialNum', 'isAttached', 'setSensorChangeTrigger', 'setRadiometric', ] # ==== Implementation of Service base ==== def onInit(self): self.dev = InterfaceKit() self.setEventHandlers() def setThresholds(self): for k in [0, 1, 2, 3, 4, 5, 6, 7]: val = None try: val = self.config.get('trigger%s' % k) except: pass if not val: continue self.dev.setSensorChangeTrigger(k, int(val)) def onStart(self): try: serial = self.config.get('serial') if serial: serial = int(serial) except KeyError: pass if not serial: serial = -1 try: log.info("Open Phidget with serial: %s" % serial) self.dev.openPhidget(serial) #self.dev.openPhidget() log.info("Waiting for Phidget to be attached...") self.dev.waitForAttach(100000) self.phidgetsId = self.dev.getSerialNum() log.info("Phidget with serial: %s attached" % self.phidgetsId) self.diginput = self.dev.getInputCount() log.info("Phidget %s has %s digital inputs" % (self.phidgetsId, self.diginput)) self.digoutput = self.dev.getOutputCount() log.info("Phidget %s has %s digital outputs" % (self.phidgetsId, self.digoutput)) self.analog = self.dev.getSensorCount() log.info("Phidget %s has %s analog inputs" % (self.phidgetsId, self.analog)) self.ifname = self.dev.getServiceName() log.info("Phidget %s has name: %s" % (self.phidgetsId, self.ifname)) self.setThresholds() # make sure dev is closed again if error except PhidgetException, e: self.close() self.phidgetsId = None # but still let the exception continue down the stack # (and set code|message that are not seen with tostring for PE) raise Exception("PhidgetsException, code: %s, msg: %s" % (e.code, e.message))