コード例 #1
0
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)
コード例 #2
0
ファイル: TextLCD.py プロジェクト: Nyinc2830/SBCLogger
def AttachTextLCD(databasepath, serialNumber):
    def onAttachHandler(event):
        logString = "TextLCD Attached " + str(event.device.getSerialNum())
        #print(logString)
        DisplayAttachedDeviceInfo(event.device)

    def onDetachHandler(event):
        logString = "TextLCD Detached " + str(event.device.getSerialNum())
        #print(logString)
        DisplayDetachedDeviceInfo(event.device)

        event.device.closePhidget()

    def onErrorHandler(event):
        logString = "TextLCD Error " + str(
            event.device.getSerialNum()) + ", Error: " + event.description
        print(logString)

        DisplayErrorDeviceInfo(event)

    def onServerConnectHandler(event):
        logString = "TextLCD Server Connect " + str(
            event.device.getSerialNum())
        #print(logString)

    def onServerDisconnectHandler(event):
        logString = "TextLCD Server Disconnect " + str(
            event.device.getSerialNum())
        #print(logString)

    try:
        p = TextLCD()

        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)
コード例 #3
0
ファイル: TextLCD.py プロジェクト: njligames/SBCLogger
def AttachTextLCD(databasepath, serialNumber):
	def onAttachHandler(event):
		logString = "TextLCD Attached " + str(event.device.getSerialNum())
		#print(logString)
		DisplayAttachedDeviceInfo(event.device)

	def onDetachHandler(event):
		logString = "TextLCD Detached " + str(event.device.getSerialNum())
		#print(logString)
		DisplayDetachedDeviceInfo(event.device)

		event.device.closePhidget()

	def onErrorHandler(event):
		logString = "TextLCD Error " + str(event.device.getSerialNum()) + ", Error: " + event.description
		print(logString)

		DisplayErrorDeviceInfo(event)
		
	def onServerConnectHandler(event):
		logString = "TextLCD Server Connect " + str(event.device.getSerialNum())
		#print(logString)

	def onServerDisconnectHandler(event):
		logString = "TextLCD Server Disconnect " + str(event.device.getSerialNum())
		#print(logString)

	try:
		p = TextLCD()

		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)
コード例 #4
0
class csss_lcd:
	str_top = ""
	str_bottom = ""
	top_len = 0
	bot_len = 0
	textLCD = None
	
	def __init__(self):
		print("INIT: LCD")
		try:
			self.textLCD = TextLCD()
		except RuntimeError as e:
			print("RuntimeExceotion: %s" % e.details)
			print("Exiting....")
			exit(1)
		
		try:
			self.textLCD.setOnAttachHandler(TextLCDAttached)
			self.textLCD.setOnDetachHandler(TextLCDDetached)
			self.textLCD.setOnErrorhandler(TextLCDError)
		except PhidgetException as e:
			print("Phidget Exception %i: %s" % (e.code, e.details))
			print("Exiting....")
			exit(1)
		
		try:
			self.textLCD.openPhidget()
		except PhidgetException as e:
			print("Phidget Exception %i: %s" % (e.code, e.details))
			print("Exiting....")
			exit(1)	
		sleep(2)		
		return

	#Information Display Function
	def display(self, row, str):
			print("Displaying %s" % str)
			if len(str) > 20:
				self.scroll(row, str)
			try:
				if self.textLCD.getDeviceID()==PhidgetID.PHIDID_TEXTLCD_ADAPTER:
						self.textLCD.setScreenIndex(0)
						self.textLCD.setScreenSize(TextLCD_ScreenSize.PHIDGET_TEXTLCD_SCREEN_2x8)
				self.textLCD.setDisplayString(row, str)#bytes(str, 'utf-8'))
			except PhidgetException as e:
				print("Phidget Exception %i: %s" % (e.code, e.details))

	def displaySlow(self, row,str):
			self.display(row, str)
			sleep(0.75)

	def scroll(self, row, str):
			length = len(str)
			currIndex = 0
			endIndex = 20
			self.displaySlow(row, str[currIndex:endIndex])
			for currIndex in range (1,length):
				self.display(row,str[currIndex:endIndex])
				if endIndex < length:
					endIndex += 1
				sleep(0.22)
			self.clearRow(row)

	def clearRow(self, row):
			print("Clearing TextLCD")
			self.display(row, " ")

	def clearAll(self):
			self.clearRow(0)
			self.clearRow(1)

	def close(self):
		try:
			print("Closing TextLCD")
			self.textLCD.closePhidget()
		except PhidgetException as e:
			print("Phidget Exception &i: %s" % (e.code, e.details))
			print("Exiting....")
			exit(1)
コード例 #5
0
ファイル: thi2textlcd.py プロジェクト: kj1216/thi2textlcd
        textLCD.setOnAttachHandler(TextLCDAttached)
        textLCD.setOnDetachHandler(TextLCDDetached)
        textLCD.setOnErrorhandler(TextLCDError)
        interfaceKit.setOnAttachHandler(interfaceKitAttached)
        interfaceKit.setOnDetachHandler(interfaceKitDetached)
        interfaceKit.setOnErrorhandler(interfaceKitError)
        interfaceKit.setOnInputChangeHandler(interfaceKitInputChanged)
        interfaceKit.setOnOutputChangeHandler(interfaceKitOutputChanged)
        interfaceKit.setOnSensorChangeHandler(interfaceKitSensorChanged)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)

    try:
        textLCD.openPhidget()
        interfaceKit.openPhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")
        exit(1)

    print("Waiting for attach....")

    try:
        textLCD.waitForAttach(10000)
        interfaceKit.waitForAttach(10000)
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        try:
            interfaceKit.closePhidget()
              (source.getSerialNum(), e.eCode, e.description))
    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()
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

#Wait for the device to attach
try:
    textLCD.waitForAttach(10000)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    try:
        textLCD.closePhidget()
    except PhidgetException as e:
        print("Phidget Exception %i: %s" % (e.code, e.details))
        print("Exiting....")