def init(): deviceDescriptions = d2xx.listDevices(d2xx.OPEN_BY_DESCRIPTION) deviceSerials = d2xx.listDevices(d2xx.OPEN_BY_SERIAL_NUMBER) for i, description in enumerate(deviceDescriptions): serial = deviceSerials[i] if description[:6] != "monome" and description[:2] != "mk": print "ignoring non-monome device id " + str(i) + ": " + description + " [" + serial + "]" continue device = d2xx.open(i) print "opened device id " + str(i) + ": " + description + " [" + serial + "]" type = description[7:] grids = 0 prefix = "/" + type initOscCallbacks(prefix) deviceInfo = { "description": description, "serial": deviceSerials[i], "prefix": prefix, "type": type, "device": device, "cable": "left", "offsetX": 0, "offsetY": 0, "tiltmode": 0, "grids": 0, } if debugMode == 1: print deviceInfo devices.insert(i, deviceInfo) clearHandler(prefix, "i", (0,), 0) thread = MonomeThread(deviceInfo, oscClient) thread.start() deviceInfo["thread"] = thread
def init(): deviceDescriptions = d2xx.listDevices(d2xx.OPEN_BY_DESCRIPTION) deviceSerials = d2xx.listDevices(d2xx.OPEN_BY_SERIAL_NUMBER) for i, description in enumerate(deviceDescriptions): serial = deviceSerials[i] if description[:6] != "monome" and description[:2] != "mk": print "ignoring non-monome device id " + str( i) + ": " + description + " [" + serial + "]" continue device = d2xx.open(i) print "opened device id " + str( i) + ": " + description + " [" + serial + "]" type = description[7:] grids = 0 prefix = "/" + type initOscCallbacks(prefix) deviceInfo = { 'description': description, 'serial': deviceSerials[i], 'prefix': prefix, 'type': type, 'device': device, 'cable': "left", 'offsetX': 0, 'offsetY': 0, 'tiltmode': 0, 'grids': 0 } if debugMode == 1: print deviceInfo devices.insert(i, deviceInfo) clearHandler(prefix, 'i', (0, ), 0) thread = MonomeThread(deviceInfo, oscClient) thread.start() deviceInfo['thread'] = thread
def open(self, devicenum, portlist): """Open an FT232R device with devicenum and initialize with the portlist""" if self.handle is not None: self.close() if devicenum is None: self._log("Opening first available device...") devices = d2xx.listDevices() available_device = False for num, serial in enumerate(devices): try: h = d2xx.open(num) h.close() available_device = True break except: pass if available_device: devicenum = num if devicenum is not None: self.handle = d2xx.open(devicenum) if self.handle is not None: self._log("Opened device %i" % devicenum) self.devicenum = devicenum self.portlist = portlist self.serial = self.handle.getDeviceInfo()['serial'] self._setBaudRate(DEFAULT_FREQUENCY) self._setSyncMode() self._purgeBuffers() return True else: return False
def __init__(self,port): #List of FTDI Devices Available devAvail = d2xx.listDevices() if not devAvail: print("Error - Check your Connection to FTDI Device") else: self.port=d2xx.open(port) print("Connection to Port %d established"%port)
def autodetect(self, core): return #Disabled in favor of FTDIJTAG module try: found = False try: import usb for bus in usb.busses(): for dev in bus.devices: if dev.idVendor == 0x0403 and dev.idProduct == 0x6001: try: handle = dev.open() manufacturer = handle.getString( dev.iManufacturer, 100).decode("latin1") product = handle.getString( dev.iProduct, 100).decode("latin1") serial = handle.getString( dev.iSerialNumber, 100).decode("latin1") if (manufacturer == "FTDI" and product == "FT232R USB UART") or ( manufacturer == "FPGA Mining LLC" and product == "X6500 FPGA Miner"): try: configuration = dev.configurations[0] interface = configuration.interfaces[ 0][0] handle.setConfiguration( configuration.value) handle.claimInterface( interface.interfaceNumber) handle.releaseInterface() handle.setConfiguration(0) found = True break except: pass except: pass if found: break except: pass if not found: try: import d2xx devices = d2xx.listDevices() for devicenum, serial in enumerate(devices): try: handle = d2xx.open(devicenum) handle.close() found = True break except: pass except: pass if found: core.add_worker(self(core)) except: pass
def __init__(self,port): #List of FTDI Devices Available devAvail = d2xx.listDevices() if not devAvail: print("Error - Check your Connection to FTDI Device") else: self.port=d2xx.open(port) self.port.resetDevice() dataToRead=self.port.getQueueStatus() while dataToRead: dataRBuff=self.port.read(dataToRead) dataToRead=self.port.getQueueStatus() print("Connection to Port %d established"%port)
def __init__(self, deviceid): import d2xx self.handle = None self.serial = deviceid devices = d2xx.listDevices() for devicenum, serial in enumerate(devices): if deviceid != "" and deviceid != serial: continue try: self.handle = d2xx.open(devicenum) self.serial = serial break except: pass if self.handle == None: raise Exception("Can not open the specified device") self.handle.setBaudRate(3000000)
def autodetect(self, core): return #Disabled in favor of FTDIJTAG module try: found = False try: import usb for bus in usb.busses(): for dev in bus.devices: if dev.idVendor == 0x0403 and dev.idProduct == 0x6001: try: handle = dev.open() manufacturer = handle.getString(dev.iManufacturer, 100).decode("latin1") product = handle.getString(dev.iProduct, 100).decode("latin1") serial = handle.getString(dev.iSerialNumber, 100).decode("latin1") if (manufacturer == "FTDI" and product == "FT232R USB UART") or (manufacturer == "FPGA Mining LLC" and product == "X6500 FPGA Miner"): try: configuration = dev.configurations[0] interface = configuration.interfaces[0][0] handle.setConfiguration(configuration.value) handle.claimInterface(interface.interfaceNumber) handle.releaseInterface() handle.setConfiguration(0) found = True break except: pass except: pass if found: break except: pass if not found: try: import d2xx devices = d2xx.listDevices() for devicenum, serial in enumerate(devices): try: handle = d2xx.open(devicenum) handle.close() found = True break except: pass except: pass if found: core.add_worker(self(core)) except: pass
def _mGetHandle(self): d = d2xx.listDevices() comindex = -1 counter = 0 if d != 0: for j in d: try: hl = d2xx.open(counter) a = hl.getComPortNumber() a = 'COM' + str(a) if self.sComPort == a: return hl hl.close() except Exception as e: self.logger.debug( 'Exception communicating with FTDI device (%s)' % str(e)) else: counter += 1 return
def main(self): # Loop until we are shut down while not self.shutdown: if self.useftd2xx: import d2xx if not self.useftd2xx or self.settings.takeover: import usb try: boards = {} if self.useftd2xx: devices = d2xx.listDevices() for devicenum, serial in enumerate(devices): try: handle = d2xx.open(devicenum) handle.close() available = True except: availabale = False boards[serial] = available else: for bus in usb.busses(): for dev in bus.devices: if dev.idVendor == 0x0403 and dev.idProduct == 0x6001: try: handle = dev.open() manufacturer = handle.getString(dev.iManufacturer, 100).decode("latin1") product = handle.getString(dev.iProduct, 100).decode("latin1") serial = handle.getString(dev.iSerialNumber, 100).decode("latin1") if (manufacturer == "FTDI" and product == "FT232R USB UART") or (manufacturer == "FPGA Mining LLC" and product == "X6500 FPGA Miner"): try: configuration = dev.configurations[0] interface = configuration.interfaces[0][0] handle.setConfiguration(configuration.value) handle.claimInterface(interface.interfaceNumber) handle.releaseInterface() handle.setConfiguration(0) available = True except: available = False boards[serial] = available except: pass for serial in boards.keys(): if self.settings.blacklist: if serial in self.settings.boards: del boards[serial] else: if serial not in self.settings.board: del boards[serial] for serial, child in self.childmap.items(): if not serial in boards: try: self.core.log("%s: Shutting down worker %s...\n" % (self.settings.name, child.settings.name), 800) child.stop() except Exception as e: self.core.log("%s: Could not stop worker %s: %s\n" % (self.settings.name, child.settings.name, traceback.format_exc()), 100, "rB") childstats = child.get_statistics() fields = ["ghashes", "jobsaccepted", "jobscanceled", "sharesaccepted", "sharesrejected", "sharesinvalid"] for field in fields: self.stats[field] += childstats[field] try: self.child.destroy() except: pass del self.childmap[serial] try: self.children.remove(child) except: pass for serial, available in boards.items(): if serial in self.childmap: continue if not available and self.settings.takeover: try: for bus in usb.busses(): if available: break for dev in bus.devices: if available: break if dev.idVendor == 0x0403 and dev.idProduct == 0x6001: handle = dev.open() manufacturer = handle.getString(dev.iManufacturer, 100).decode("latin1") product = handle.getString(dev.iProduct, 100).decode("latin1") _serial = handle.getString(dev.iSerialNumber, 100).decode("latin1") if ((manufacturer == "FTDI" and product == "FT232R USB UART") or (manufacturer == "FPGA Mining LLC" and product == "X6500 FPGA Miner")) and _serial == serial: handle.reset() time.sleep(1) configuration = dev.configurations[0] interface = configuration.interfaces[0][0] handle.setConfiguration(configuration.value) handle.claimInterface(interface.interfaceNumber) handle.releaseInterface() handle.setConfiguration(0) handle.reset() time.sleep(1) available = True except: pass if available: child = X6500Worker(self.core) child.settings.name = "X6500 board " + serial child.settings.serial = serial fields = ["takeover", "useftd2xx", "uploadfirmware", "firmware", "initialspeed", "maximumspeed", "tempwarning", "tempcritical", "invalidwarning", "invalidcritical", "speedupthreshold", "jobinterval", "pollinterval"] for field in fields: child.settings[field] = self.settings[field] child.apply_settings() self.childmap[serial] = child self.children.append(child) try: self.core.log("%s: Starting up worker %s...\n" % (self.settings.name, child.settings.name), 800) child.start() except Exception as e: self.core.log("%s: Could not start worker %s: %s\n" % (self.settings.name, child.settings.name, traceback.format_exc()), 100, "rB") except: self.core.log("Caught exception: %s\n" % traceback.format_exc(), 100, "rB") with self.wakeup: self.wakeup.wait(self.settings.scaninterval)
#!/usr/bin/python import os os.system('rmmod ftdi_sio') import d2xx devices = d2xx.listDevices() for devicenum, serial in enumerate(devices): try: h = d2xx.open(devicenum) h.close() isopen = True except: isopen = False print "%2d %s %s" % (devicenum, serial, '*' if isopen else '') print "* means this device is currently available"
# ---------- # import the PyUSB module import d2xx # list devices by description, returns tuple of attached devices description strings d = d2xx.listDevices(d2xx.OPEN_BY_DESCRIPTION) print d # list devices by serial, returns tuple of attached devices serial strings d = d2xx.listDevices() # implicit d2xx.OPEN_BY_SERIAL_NUMBER print d h = d2xx.open(0) print h # read eeprom print h.eeRead() # get queue status print h.getQueueStatus() # set RX/TX timeouts h.setTimeouts(1000, 1000) # write bytes (serial mode) print h.write("Hello world!\r\n") # read bytes (serial mode) print h.read(5)
# ---------- # import the PyUSB module import d2xx # list devices by description, returns tuple of attached devices description strings d = d2xx.listDevices(d2xx.OPEN_BY_DESCRIPTION) print d # list devices by serial, returns tuple of attached devices serial strings d = d2xx.listDevices() # implicit d2xx.OPEN_BY_SERIAL_NUMBER print d h = d2xx.open(0) print h # read eeprom print h.eeRead() # get queue status print h.getQueueStatus() # set RX/TX timeouts h.setTimeouts(1000,1000) # write bytes (serial mode) print h.write('Hello world!\r\n') # read bytes (serial mode) print h.read(5)
def get_device_list(): device_list = dict([(__key, __d2xx.listDevices(__d2xx.OPEN_BY_DESCRIPTION)[__n]) for __n, __key in enumerate(__d2xx.listDevices())]) return device_list
import d2xx
def main(self): if self.useftd2xx: import d2xx if not self.useftd2xx or self.takeover: import usb while True: try: for child in self.children: if child.dead: with self.statlock: stats = child.getstatistics(self.miner.collectstatistics(child.children)) self.children.remove(child) self.mhashes = self.mhashes + stats["mhashes"] self.jobsaccepted = self.jobsaccepted + stats["jobsaccepted"] self.accepted = self.accepted + stats["accepted"] self.rejected = self.rejected + stats["rejected"] self.invalid = self.invalid + stats["invalid"] boards = [] if self.useftd2xx: devices = d2xx.listDevices() for devicenum, serial in enumerate(devices): try: handle = d2xx.open(devicenum) handle.close() available = True except: available = False boards.append((serial, available)) else: for bus in usb.busses(): for dev in bus.devices: if dev.idVendor == 0x0403 and dev.idProduct == 0x6001: try: handle = dev.open() manufacturer = handle.getString(dev.iManufacturer, 100).decode("latin1") product = handle.getString(dev.iProduct, 100).decode("latin1") serial = handle.getString(dev.iSerialNumber, 100).decode("latin1") if (manufacturer == "FTDI" and product == "FT232R USB UART") or product == "X6500 FPGA Miner" or product == "X6500r3 FPGA Miner": try: configuration = dev.configurations[0] interface = configuration.interfaces[0][0] handle.setConfiguration(configuration.value) handle.claimInterface(interface.interfaceNumber) handle.releaseInterface() handle.setConfiguration(0) available = True except: available = False boards.append((serial, available)) except: pass for deviceid, available in boards: found = False for child in self.children: if child.deviceid == deviceid: found = True break if found: continue if not available and self.takeover: try: for bus in usb.busses(): if available: break for dev in bus.devices: if available: break if dev.idVendor == 0x0403 and dev.idProduct == 0x6001: handle = dev.open() manufacturer = handle.getString(dev.iManufacturer, 100).decode("latin1") product = handle.getString(dev.iProduct, 100).decode("latin1") serial = handle.getString(dev.iSerialNumber, 100).decode("latin1") if ((manufacturer == "FTDI" and product == "FT232R USB UART") or product == "X6500 FPGA Miner" or product == "X6500r3 FPGA Miner") and serial == deviceid: handle.reset() configuration = dev.configurations[0] interface = configuration.interfaces[0][0] handle.setConfiguration(configuration.value) handle.claimInterface(interface.interfaceNumber) handle.releaseInterface() handle.setConfiguration(0) handle.reset() available = True except: pass if available: config = { \ "deviceid": deviceid, \ "firmware": self.firmware, \ "jobinterval": self.jobinterval, \ "pollinterval": self.pollinterval, \ "useftd2xx": self.useftd2xx, \ "takeover": False, \ "uploadfirmware": self.uploadfirmware, \ "clockspeed": self.clockspeed, \ "errorwarning": self.errorwarning, \ "errorcritical": self.errorcritical, \ "tempwarning": self.tempwarning, \ "tempcritical": self.tempcritical, \ } self.children.append(worker.fpgamining.x6500.X6500Worker(self.miner, config, True)) except Exception as e: self.miner.log("Caught exception: %s\n" % e, "r") time.sleep(self.scaninterval)
def newspeed(bps=9600): ser.baudrate = 9600 resetavr() # wait for AVR to boot sleep(1) # switch to fast mode setbaud(bps) stats() # main program twocan = -1 usb = -1 ser = -1 # list devices by description, returns tuple of attached devices description strings dl = d2xx.listDevices(d2xx.OPEN_BY_DESCRIPTION) for num, name in enumerate(dl): print "Found device " + str(num) + " named " + name if name == "2CAN": twocan = num break if twocan < 0: print "2CAN not found" raise BaseException def usbopen(): global usb usb = d2xx.open(twocan)
def get_device_list(): device_list = dict([(__key, __d2xx.listDevices(__d2xx.OPEN_BY_DESCRIPTION)[__n]) for __n,__key in enumerate(__d2xx.listDevices())]) return device_list
def main(self): if self.useftd2xx: import d2xx if not self.useftd2xx or self.takeover: import usb while True: try: for child in self.children: if child.dead: with self.statlock: stats = child.getstatistics(self.miner.collectstatistics(child.children)) self.children.remove(child) self.mhashes = self.mhashes + stats["mhashes"] self.jobsaccepted = self.jobsaccepted + stats["jobsaccepted"] self.accepted = self.accepted + stats["accepted"] self.rejected = self.rejected + stats["rejected"] self.invalid = self.invalid + stats["invalid"] boards = [] if self.useftd2xx: devices = d2xx.listDevices() for devicenum, serial in enumerate(devices): try: handle = d2xx.open(devicenum) handle.close() available = True except: availabale = False boards.append((serial, available)) else: for bus in usb.busses(): for dev in bus.devices: if dev.idVendor == 0x0403 and dev.idProduct == 0x6001: try: handle = dev.open() manufacturer = handle.getString(dev.iManufacturer, 100).decode("latin1") product = handle.getString(dev.iProduct, 100).decode("latin1") serial = handle.getString(dev.iSerialNumber, 100).decode("latin1") if (manufacturer == "FTDI" and product == "FT232R USB UART") or (manufacturer == "FPGA Mining LLC" and product == "X6500 FPGA Miner"): try: configuration = dev.configurations[0] interface = configuration.interfaces[0][0] handle.setConfiguration(configuration.value) handle.claimInterface(interface.interfaceNumber) handle.releaseInterface() handle.setConfiguration(0) available = True except: available = False boards.append((serial, available)) except: pass for deviceid, available in boards: found = False for child in self.children: if child.deviceid == deviceid: found = True break if found: continue if not available and self.takeover: try: for bus in usb.busses(): if available: break for dev in bus.devices: if available: break if dev.idVendor == 0x0403 and dev.idProduct == 0x6001: handle = dev.open() manufacturer = handle.getString(dev.iManufacturer, 100).decode("latin1") product = handle.getString(dev.iProduct, 100).decode("latin1") serial = handle.getString(dev.iSerialNumber, 100).decode("latin1") if manufacturer == "FTDI" and product == "FT232R USB UART" and serial == deviceid: handle.reset() configuration = dev.configurations[0] interface = configuration.interfaces[0][0] handle.setConfiguration(configuration.value) handle.claimInterface(interface.interfaceNumber) handle.releaseInterface() handle.setConfiguration(0) handle.reset() available = True except: pass if available: config = { \ "deviceid": deviceid, \ "firmware": self.firmware, \ "jobinterval": self.jobinterval, \ "pollinterval": self.pollinterval, \ "useftd2xx": self.useftd2xx, \ "takeover": False, \ "uploadfirmware": self.uploadfirmware, \ "clockspeed": self.clockspeed, \ "errorwarning": self.errorwarning, \ "errorcritical": self.errorcritical, \ "tempwarning": self.tempwarning, \ "tempcritical": self.tempcritical, \ } self.children.append(worker.fpgamining.x6500.X6500Worker(self.miner, config, True)) except Exception as e: self.miner.log("Caught exception: %s\n" % e, "r") time.sleep(self.scaninterval)
def main(self): # Loop until we are shut down while not self.shutdown: if self.useftd2xx: import d2xx if not self.useftd2xx or self.settings.takeover: import usb try: boards = {} if self.useftd2xx: devices = d2xx.listDevices() for devicenum, serial in enumerate(devices): try: handle = d2xx.open(devicenum) handle.close() available = True except: availabale = False boards[serial] = available else: for bus in usb.busses(): for dev in bus.devices: if dev.idVendor == 0x0403 and dev.idProduct == 0x6001: try: handle = dev.open() manufacturer = handle.getString( dev.iManufacturer, 100).decode("latin1") product = handle.getString( dev.iProduct, 100).decode("latin1") serial = handle.getString( dev.iSerialNumber, 100).decode("latin1") if (manufacturer == "FTDI" and product == "FT232R USB UART" ) or (manufacturer == "FPGA Mining LLC" and product == "X6500 FPGA Miner"): try: configuration = dev.configurations[ 0] interface = configuration.interfaces[ 0][0] handle.setConfiguration( configuration.value) handle.claimInterface( interface.interfaceNumber) handle.releaseInterface() handle.setConfiguration(0) available = True except: available = False boards[serial] = available except: pass for serial in boards.keys(): if self.settings.blacklist: if serial in self.settings.boards: del boards[serial] else: if serial not in self.settings.board: del boards[serial] for serial, child in self.childmap.items(): if not serial in boards: try: self.core.log( "%s: Shutting down worker %s...\n" % (self.settings.name, child.settings.name), 800) child.stop() except Exception as e: self.core.log( "%s: Could not stop worker %s: %s\n" % (self.settings.name, child.settings.name, traceback.format_exc()), 100, "rB") childstats = child.get_statistics() fields = [ "ghashes", "jobsaccepted", "jobscanceled", "sharesaccepted", "sharesrejected", "sharesinvalid" ] for field in fields: self.stats[field] += childstats[field] try: self.child.destroy() except: pass del self.childmap[serial] try: self.children.remove(child) except: pass for serial, available in boards.items(): if serial in self.childmap: continue if not available and self.settings.takeover: try: for bus in usb.busses(): if available: break for dev in bus.devices: if available: break if dev.idVendor == 0x0403 and dev.idProduct == 0x6001: handle = dev.open() manufacturer = handle.getString( dev.iManufacturer, 100).decode("latin1") product = handle.getString( dev.iProduct, 100).decode("latin1") _serial = handle.getString( dev.iSerialNumber, 100).decode("latin1") if ((manufacturer == "FTDI" and product == "FT232R USB UART") or (manufacturer == "FPGA Mining LLC" and product == "X6500 FPGA Miner") ) and _serial == serial: handle.reset() time.sleep(1) configuration = dev.configurations[ 0] interface = configuration.interfaces[ 0][0] handle.setConfiguration( configuration.value) handle.claimInterface( interface.interfaceNumber) handle.releaseInterface() handle.setConfiguration(0) handle.reset() time.sleep(1) available = True except: pass if available: child = X6500Worker(self.core) child.settings.name = "X6500 board " + serial child.settings.serial = serial fields = [ "takeover", "useftd2xx", "uploadfirmware", "firmware", "initialspeed", "maximumspeed", "tempwarning", "tempcritical", "invalidwarning", "invalidcritical", "speedupthreshold", "jobinterval", "pollinterval" ] for field in fields: child.settings[field] = self.settings[field] child.apply_settings() self.childmap[serial] = child self.children.append(child) try: self.core.log( "%s: Starting up worker %s...\n" % (self.settings.name, child.settings.name), 800) child.start() except Exception as e: self.core.log( "%s: Could not start worker %s: %s\n" % (self.settings.name, child.settings.name, traceback.format_exc()), 100, "rB") except: self.core.log( "Caught exception: %s\n" % traceback.format_exc(), 100, "rB") with self.wakeup: self.wakeup.wait(self.settings.scaninterval)