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
mngr.setOnErrorHandler(ManagerError) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Opening phidget manager....") try: mngr.openManager() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) attachedDevices = mngr.getAttachedDevices() print( "|------------|----------------------------------|--------------|------------|" ) print( "|- Attached -|- Type -|- Serial No. -|- Version -|" ) print( "|------------|----------------------------------|--------------|------------|" ) for attachedDevice in attachedDevices: print("|- %8s -|- %30s -|- %10d -|- %8d -|" % (attachedDevice.isAttached(), attachedDevice.getDeviceName(), attachedDevice.getSerialNum(), attachedDevice.getDeviceVersion()))
mngr.setOnErrorHandler(ManagerError) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("Opening phidget manager....") try: mngr.openManager() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) attachedDevices = mngr.getAttachedDevices() print("|------------|----------------------------------|--------------|------------|") print("|- Attached -|- Type -|- Serial No. -|- Version -|") print("|------------|----------------------------------|--------------|------------|") for attachedDevice in attachedDevices: print("|- %8s -|- %30s -|- %10d -|- %8d -|" % (attachedDevice.isAttached(), attachedDevice.getDeviceName(), attachedDevice.getSerialNum(), attachedDevice.getDeviceVersion())) print("|------------|----------------------------------|--------------|------------|") print("Press Enter to quit....") chr = sys.stdin.read(1) print("Closing...")
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
# else: param.appendData(ts,x,y,z) if len(param.getTimestamp()) == bufferSize: param.addIndex() #print("------------------------------------------") #Main Program Code #logging example, uncomment to generate a log file #spatial.enableLogging(PhidgetLogLevel.PHIDGET_LOG_VERBOSE, "phidgetlog.log") print("Opening phidget object....") numDevices = len(manager.getAttachedDevices()) params = {} for device in manager.getAttachedDevices(): try: spatial = Spatial() spatial.openPhidget(device.getSerialNum()) sensor = SensorParams(device.getSerialNum()) sensor.setBufferSize(bufferSize) sensor.setWindowSize(windowSize) params[device.getSerialNum()] = sensor spatial.setOnAttachHandler(SpatialAttached) spatial.setOnDetachHandler(SpatialDetached) spatial.setOnErrorhandler(SpatialError) spatial.setOnSpatialDataHandler(SpatialData) except PhidgetException as e: