class PHIDGET_TEXTLCD(object): """ Phidget TextLCD with integrated InterfaceKit """ def __init__(self, serialNumber=None, waitForAttach=1000, **kargs): self.textLCD = TextLCD() if 'remoteHost' in kargs: self.textLCD.openRemote(kargs['remoteHost'], serialNumber) else: self.textLCD.openPhidget(serialNumber) h = [ 'onAttachHandler', 'onDetachHandler', 'onErrorhandler' ] for event in h: self.__dict__[event] = None if event in kargs: self.__dict__[event] = kargs[event] self.textLCD.setOnAttachHandler(self.attached) self.textLCD.setOnDetachHandler(self.detached) if waitForAttach > 0: try: self.textLCD.waitForAttach(waitForAttach) except PhidgetException as e: #print("Phidget Exception %i: %s" % (e.code, e.details)) try: self.textLCD.closePhidget() except PhidgetException as e2: pass raise e def attached(self, e): from Phidgets.Phidget import PhidgetID if e.device.getDeviceID()==PhidgetID.PHIDID_TEXTLCD_ADAPTER: e.device.setScreenIndex(0) e.device.setScreenSize(TextLCD.TextLCD_ScreenSize.PHIDGET_TEXTLCD_SCREEN_2x20) if self.onAttachHandler: self.onAttachHandler(e) def detached(self, e): if self.onDetachHandler: self.onDetachHandler(e) def error(self, e): error = {'code': e.eCode, 'description': e.description} if self.onErrorhandler: self.onErrorhandler(error, e)
print("Phidget Exception %i: %s" % (e.code, e.details)) #Connect the event handlers try: textLCD.setOnErrorhandler(TextLCDError) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) #Open the textLCD try: # textLCD.openPhidget() # interfaceKitLCD.openPhidget(serial=120517) textLCD.openRemote('odroid',serial=120517) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) if not textLCD.isAttachedToServer(): sleep(2) print('textLCD webservice status: %s' % textLCD.isAttachedToServer()) #Wait for the device to attach try: textLCD.waitForAttach(10000) # interfaceKitLCD.waitForAttach(10000) except PhidgetException as e:
print("Phidget Exception %i: %s" % (e.code, e.details)) #Connect the event handlers try: textLCD.setOnErrorhandler(TextLCDError) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) #Open the textLCD try: # textLCD.openPhidget() # interfaceKitLCD.openPhidget(serial=120517) textLCD.openRemote('odroid', serial=120517) except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) if not textLCD.isAttachedToServer(): sleep(2) print('textLCD webservice status: %s' % textLCD.isAttachedToServer()) #Wait for the device to attach try: textLCD.waitForAttach(10000) # interfaceKitLCD.waitForAttach(10000) except PhidgetException as e: