def attach(self): m = Manager() m.openManager() time.sleep(1) # print 'There are', len(m.getAttachedDevices()), 'device(s) attached' try: d = m.getAttachedDevices()[0] self.ir = IR() self.ir.openPhidget(d.getSerialNum()) except IndexError as e: print 'No devices attached!' raise e
def _init(): global _log, _serial2phidgets, _manager, _encoderHistory, _encoderAsAxis, _lastPollDevices, _sync _log = logging.getLogger("phidgets") _serial2phidgets = dict() _encoderHistory = dict() _encoderAsAxis = dict() _lastPollDevices = 0 _sync = 0 try: _manager = Manager() _manager.openManager() except Exception as e: _manager = None _log.warning("Cannot initialize support for Phidgets (%s)", e) _log.debug(traceback.format_exc()) all()
motorC.closePhidget() elif serial == config.servoSerial: print(' - Disconnecting servo | ' + str(serial)) global servoC servoC.closePhidget() elif serial == config.interSerial: print(' - Disconnecting inter | ' + str(serial)) global interC interC.closePhidget() def ConnectHandler(e): print('[C+] Connected to Server!') def DisconnectHandler(e): print('[C-] Disconnected from Server') manager = Manager() manager.setOnAttachHandler(AttachHandler) manager.setOnDetachHandler(DetachHandler) manager.setOnServerConnectHandler(ConnectHandler) manager.setOnServerDisconnectHandler(DisconnectHandler) manager.openRemoteIP(config.SBCIP, 5001) print("phidAPI @ :"+str(config.myPort)) try: s = zerorpc.Server(rpc()) s.bind("tcp://" + str(config.myIP) + ":" + str(config.myPort)) s.run()
except PhidgetException as e: LocalErrorCatcher(e) # =========== Python-specific Exception Handler ========== def LocalErrorCatcher(event): print("Phidget Exception: " + str(e.code) + " - " + str(e.details) + ", Exiting...") exit(1) # ========= Main Code ========== try: manager = Manager() except RuntimeError as e: print("Runtime Error " + e.details + ", Exiting...\n") exit(1) try: manager.setOnAttachHandler(AttachHandler) manager.setOnDetachHandler(DetachHandler) manager.setOnErrorHandler(LibraryErrorHandler) except PhidgetException as e: LocalErrorCatcher(e) print("Opening....") try: # This would be openPhidget for a specific device object manager.openManager()
(attached.getSerialNum(), attached.getDeviceName())) def ManagerDeviceDetached(e): detached = e.device print("Manager - Device %i: %s Detached!" % (detached.getSerialNum(), detached.getDeviceName())) def ManagerError(e): print("Manager Phidget Error %i: %s" % (e.eCode, e.description)) #Create an interfacekit object try: mngr = Manager() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") exit(1) #Main Program Code try: mngr.setOnAttachHandler(ManagerDeviceAttached) mngr.setOnDetachHandler(ManagerDeviceDetached) mngr.setOnErrorHandler(ManagerError) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1)
#Event Handler Callback Functions def ManagerDeviceAttached(e): attached = e.device print("Manager - Device %i: %s Attached!" % (attached.getSerialNum(), attached.getDeviceName())) def ManagerDeviceDetached(e): detached = e.device print("Manager - Device %i: %s Detached!" % (detached.getSerialNum(), detached.getDeviceName())) def ManagerError(e): print("Manager Phidget Error %i: %s" % (e.eCode, e.description)) #Create an interfacekit object try: mngr = Manager() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") exit(1) #Main Program Code try: mngr.setOnAttachHandler(ManagerDeviceAttached) mngr.setOnDetachHandler(ManagerDeviceDetached) mngr.setOnErrorHandler(ManagerError) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1)
def setup_phidgets(): global interfaceKits interfaceKits = InterfaceKits() "Print Creating phidget manager" try: manager = Manager() except RuntimeError as e: output("Runtime Exception: %s" % e.details) output("Exiting....") exit(1) try: manager.setOnAttachHandler(ManagerDeviceAttached) manager.setOnDetachHandler(ManagerDeviceDetached) manager.setOnErrorHandler(ManagerError) except PhidgetException as e: output("Phidget Exception %i: %s" % (e.code, e.details)) output("Exiting....") exit(1) output("Opening phidget manager....") logging.info("Opening phidget manager....") try: manager.openManager() #manager.openRemote("hydropi","hydropi") except PhidgetException as e: output("Phidget Exception %i: %s" % (e.code, e.details)) logging.error("Phidget Exception %i: %s" % (e.code, e.details)) output("Exiting....") logging.error("Exiting....") exit(1) # Wait a moment for devices to attache...... output("\nWaiting one sec for devices to attach....\n\n") logging.info("Waiting one sec for devices to attach....") time.sleep(1) output("Phidget manager opened.") attachedDevices = manager.getAttachedDevices() for attachedDevice in attachedDevices: output("Found %30s - SN %10d" % (attachedDevice.getDeviceName(), attachedDevice.getSerialNum())) if attachedDevice.getDeviceClass() == PhidgetClass.INTERFACEKIT: output(" %s/%d is an InterfaceKit" % ( attachedDevice.getDeviceName(),attachedDevice.getSerialNum())) #Create an interfacekit object try: newInterfaceKit = InterfaceKit() except RuntimeError as e: output("Runtime Exception: %s" % e.details) output("Exiting....") exit(1) output(" Opening...") try: newInterfaceKit.openPhidget() except PhidgetException as e: output("Phidget Exception %i: %s" % (e.code, e.details)) output("Exiting....") output(" Setting handlers...") try: newInterfaceKit.setOnAttachHandler(interfaceKitAttached) newInterfaceKit.setOnDetachHandler(interfaceKitDetached) newInterfaceKit.setOnErrorhandler(interfaceKitError) except PhidgetException as e: output("Phidget Exception %i: %s" % (e.code, e.details)) output("Exiting....") exit(1) output(" Attaching...") try: newInterfaceKit.waitForAttach(5000) except PhidgetException as e: output("Phidget Exception %i: %s" % (e.code, e.details)) try: newInterfaceKit.closePhidget() except PhidgetException as e: output("Phidget Exception %i: %s" % (e.code, e.details)) output("Exiting....") exit(1) output("Exiting....") exit(1) output(" Setting the data rate for each sensor index to 1000ms....") for i in range(newInterfaceKit.getSensorCount()): try: newInterfaceKit.setDataRate(i, 1000) except PhidgetException as e: output("Phidget Exception %i: %s" % (e.code, e.details)) interfaceKits.kitList.append(newInterfaceKit) display_device_info(manager) return manager
mutex = Condition() i = 0 j = windowSize spatialList = [] #Create an accelerometer object # try: # spatial = Spatial() # except RuntimeError as e: # print("Runtime Exception: %s" % e.details) # print("Exiting....") # exit(1) try: manager = Manager() manager.openManager() except PhidgetException as e: print ("PhidgetException: %s" % e.details) print ("Exiting") exit(1) def animate(e, serialNum): global params param = params[serialNum] if len(param.getTimestamp()) < windowSize: return #mutex.acquire() # while len(dataBuffer[0]) < bufferSize or len(subBuffer[0]) < windowSize: # mutex.wait() # transferToBuffer(dataBuffer,subBuffer)
LocalErrorCatcher(e) # =========== Python-specific Exception Handler ========== def LocalErrorCatcher(event): print("Phidget Exception: " + str(e.code) + " - " + str(e.details) + ", Exiting...") exit(1) # ========= Main Code ========== try: manager = Manager() except RuntimeError as e: print("Runtime Error " + e.details + ", Exiting...\n") exit(1) try: #logging example, uncomment to generate a log file #manager.enableLogging(PhidgetLogLevel.PHIDGET_LOG_VERBOSE, "phidgetlog.log") manager.setOnAttachHandler(AttachHandler) manager.setOnDetachHandler(DetachHandler) manager.setOnErrorHandler(LibraryErrorHandler) except PhidgetException as e: LocalErrorCatcher(e) print("Opening....")
def main(): createDB() try: manager = Manager() except RuntimeError as e: print("RuntimeException: %s" % e.details) print("Exiting...") exit(1) try: manager.setOnAttachHandler(managerDeviceAttached) manager.setOnDetachHandler(managerDeviceDetached) manager.setOnErrorHandler(managerErrorHandler) manager.setOnServerConnectHandler(managerServerConnect) manager.setOnServerDisconnectHandler(managerServerDisconnect) manager.openManager() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting...") exit(1) try: manager.openManager() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting...") exit(1) print("Press Enter to quit...") chr = sys.stdin.read(1) print("Closing...") try: manager.closeManager() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting...") exit(1) print("Done.") exit(0)
servoC.closePhidget() elif serial == config.interSerial: print(' - Disconnecting inter | ' + str(serial)) global interC interC.closePhidget() def ConnectHandler(e): print('[C+] Connected to Server!') def DisconnectHandler(e): print('[C-] Disconnected from Server') manager = Manager() manager.setOnAttachHandler(AttachHandler) manager.setOnDetachHandler(DetachHandler) manager.setOnServerConnectHandler(ConnectHandler) manager.setOnServerDisconnectHandler(DisconnectHandler) manager.openRemoteIP(config.SBCIP, 5001) print("phidAPI @ :" + str(config.myPort)) try: s = zerorpc.Server(rpc()) s.bind("tcp://" + str(config.myIP) + ":" + str(config.myPort)) s.run()