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)
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #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)
Beispiel #5
0
    textLCD.setDisplayString(0, tmp)
    textLCD.setDisplayString(1, hmd)
    print("InterfaceKit %i: Sensor %i: %i" %
          (source.getSerialNum(), e.index, e.value))


def interfaceKitOutputChanged(e):
    source = e.device
    print("InterfaceKit %i: Output %i: %s" %
          (source.getSerialNum(), e.index, e.state))


if __name__ == '__main__':
    # Main Program Code
    try:
        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()
Beispiel #6
0
def TextLCDError(e):
    try:
        source = e.device
        print("TextLCD %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:
    #logging example, uncomment to generate a log file
    #textLCD.enableLogging(PhidgetLogLevel.PHIDGET_LOG_VERBOSE, "phidgetlog.log")

    textLCD.setOnAttachHandler(TextLCDAttached)
    textLCD.setOnDetachHandler(TextLCDDetached)
    textLCD.setOnErrorhandler(TextLCDError)
except PhidgetException as e:
    print("Phidget Exception %i: %s" % (e.code, e.details))
    print("Exiting....")
    exit(1)

print("Opening phidget object....")

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