def getDevices(): ports = DriverSerial.findSerialDevices(hardwareID="16C0:0483") devs = [] print "Available Devices:" count = 0 for port in ports: id = DriverSerial.getDeviceID(port) devs.append((id, port)) print "{}: {} - ID {}".format(count, port, id) count += 1 return devs
import sys from bibliopixel.drivers.serial_driver import DriverSerial run = True print "Press Ctrl+C any time to exit." try: while run: ignored = raw_input( "\nConnect just one Serial device (AllPixel) and press enter...") ports = DriverSerial.findSerialDevices() if len(ports): try: id = DriverSerial.getDeviceID(ports[0]) print "Device ID of {}: {}".format(ports[0], id) newID = raw_input("Input new ID (enter to skip): ") if newID != '': try: newID = int(newID) if newID < 0 or newID > 255: raise ValueError() try: DriverSerial.setDeviceID(ports[0], newID) print "Device ID set to: {}".format( DriverSerial.getDeviceID(ports[0])) except: pass except ValueError: print "Please enter a valid number between 0 and 255." except Exception, e: print e
import sys from bibliopixel.drivers.serial_driver import DriverSerial run = True print "Press Ctrl+C any time to exit." try: while run: ignored = raw_input( "\nConnect just one Serial device (AllPixel) and press enter...") ports = DriverSerial.findSerialDevices() if len(ports): try: id = DriverSerial.getDeviceID(ports[0]) print "Device ID of {}: {}".format(ports[0], id) newID = raw_input("Input new ID (enter to skip): ") if newID != '': try: newID = int(newID) if newID < 0 or newID > 255: raise ValueError() try: DriverSerial.setDeviceID(ports[0], newID) print "Device ID set to: {}".format(DriverSerial.getDeviceID(ports[0])) except: pass except ValueError: print "Please enter a valid number between 0 and 255." except Exception, e: print e else:
except: print "Invalid choice!" continue dev = devs[choice] print "{} - Current ID: {}".format(dev[1], dev[0]) newID = raw_input("Input new ID: ") if newID != '': try: newID = int(newID) if newID < 0 or newID > 255: raise ValueError() try: DriverSerial.setDeviceID(dev[1], newID) print "Device ID set to: {}".format(DriverSerial.getDeviceID(dev[1])) except: pass except ValueError: print "Please enter a valid number between 0 and 255." except Exception, e: print e else: print "No serial devices found. Please connect one." else: args = sys.argv[1:] if len(args) % 2 != 0: print "Must provide device and ID for each device!" sys.exit(1) devs = getDevices()