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()
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)
(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)
def LibraryErrorHandler(event): try: errorDevice = event.device serialNumber = errorDevice.getSerialNum() print("Error with Serial Number " + str(serialNumber)) 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: #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....") try: