def AttachLED(databasepath, serialNumber): def onAttachHandler(event): logString = "LED Attached " + str(event.device.getSerialNum()) #print(logString) DisplayAttachedDeviceInfo(event.device) def onDetachHandler(event): logString = "LED Detached " + str(event.device.getSerialNum()) #print(logString) DisplayDetachedDeviceInfo(event.device) event.device.closePhidget() def onErrorHandler(event): logString = "LED Error " + str(event.device.getSerialNum()) + ", Error: " + event.description print(logString) DisplayErrorDeviceInfo(event) def onServerConnectHandler(event): logString = "LED Server Connect " + str(event.device.getSerialNum()) #print(logString) def onServerDisconnectHandler(event): logString = "LED Server Disconnect " + str(event.device.getSerialNum()) #print(logString) try: p = LED() p.setOnAttachHandler(onAttachHandler) p.setOnDetachHandler(onDetachHandler) p.setOnErrorhandler(onErrorHandler) p.setOnServerConnectHandler(onServerConnectHandler) p.setOnServerDisconnectHandler(onServerDisconnectHandler) p.openPhidget(serialNumber) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting...") exit(1)
detached = e.device print("LED %i Detached!" % (detached.getSerialNum())) def ledError(e): try: source = e.device print("LED %i: Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description)) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) # Main Program Code try: led.setOnAttachHandler(ledAttached) led.setOnDetachHandler(ledDetached) led.setOnErrorhandler(ledError) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) exit(1) print("Opening phidget object...") try: led.openPhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) exit(1) print("Waiting for attach....")
def ledDetached(e): detached = e.device print("LED %i Detached!" % (detached.getSerialNum())) def ledError(e): try: source = e.device print("LED %i: Phidget Error %i: %s" % (source.getSerialNum(), e.eCode, e.description)) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) #Main Program Code try: led.setOnAttachHandler(ledAttached) led.setOnDetachHandler(ledDetached) led.setOnErrorhandler(ledError) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) exit(1) print("Opening phidget object...") try: led.openPhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) exit(1) print("Waiting for attach....")