#!/usr/bin/env python #Basic imports from ctypes import * import sys #Phidget specific imports from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs from Phidgets.Devices.LED import LED, LEDCurrentLimit, LEDVoltage from time import sleep from Phidgets.Phidget import PhidgetLogLevel #Create an LED object try: led = LED() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") 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....") try: led.waitForAttach(1000)
__version__ = "2.1.8" __date__ = "May 17 2010" # Basic imports from ctypes import * import sys # Phidget specific imports from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs from Phidgets.Devices.LED import LED, LEDCurrentLimit, LEDVoltage from time import sleep # Create an LED object try: led = LED() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") exit(1) # Information Display Function def displayDeviceInfo(): print("|------------|----------------------------------|--------------|------------|") print("|- Attached -|- Type -|- Serial No. -|- Version -|") print("|------------|----------------------------------|--------------|------------|") print( "|- %8s -|- %30s -|- %10d -|- %8d -|" % (led.isAttached(), led.getDeviceName(), led.getSerialNum(), led.getDeviceVersion()) ) print("|------------|----------------------------------|--------------|------------|")
from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs from Phidgets.Devices.LED import LED, LEDCurrentLimit, LEDVoltage from time import sleep from Phidgets.Phidget import PhidgetLogLevel limit_to_string = { LEDCurrentLimit.CURRENT_LIMIT_20mA: '20mA', LEDCurrentLimit.CURRENT_LIMIT_40mA: '40mA', LEDCurrentLimit.CURRENT_LIMIT_60mA: '60mA', LEDCurrentLimit.CURRENT_LIMIT_80mA: '80mA', } string_to_limit = {v: k for k, v in limit_to_string.items()} #Create an LED object try: led = LED() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") 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....") try:
__author__ = 'Adam Stelmack' __version__ = '2.1.8' __date__ = 'May 17 2010' #Basic imports from ctypes import * import sys #Phidget specific imports from Phidgets.PhidgetException import PhidgetErrorCodes, PhidgetException from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs from Phidgets.Devices.LED import LED, LEDCurrentLimit, LEDVoltage from time import sleep #Create an LED object try: led = LED() except RuntimeError as e: print("Runtime Exception: %s" % e.details) print("Exiting....") exit(1) #Information Display Function def displayDeviceInfo(): print("|------------|----------------------------------|--------------|------------|") print("|- Attached -|- Type -|- Serial No. -|- Version -|") print("|------------|----------------------------------|--------------|------------|") print("|- %8s -|- %30s -|- %10d -|- %8d -|" % (led.isAttached(), led.getDeviceName(), led.getSerialNum(), led.getDeviceVersion())) print("|------------|----------------------------------|--------------|------------|") #Event Handler Callback Functions def ledAttached(e):
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)