Ejemplo n.º 1
0
	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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
    def __init__(self, master):
        """
        Start the GUI and the asynchronous threads. We are in the main
        (original) thread of the application, which will later be used by
        the GUI. We spawn a new thread for the worker.
        """
        try:
            d = d2xx.open(0)
            d.purge(0)
            d.purge(1)
            d.resetPort()
            d.close()
        except:
            print 'resetport'

        self.master = master

        # Create the queue
        self.queue = Queue.Queue()

        # Set up the thread to do asynchronous I/O
        # More can be made if necessary
        self.running = 1
        self.thread1 = threading.Thread(target=self.workerThread1)
        self.thread1.start()

        # Set up the GUI part
        self.gui = GuiPart(master, self.queue, self.endApplication, self.send)

        
        # Start the periodic call in the GUI to check if the queue contains
        # anything
        self.periodicCall()
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
	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)
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
	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)
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 def __init__(self, interface):
     # Switching between USB and RS232C interfaces
     if interface == "USB":
         import d2xx
         self.ctrlif = d2xx.open(0)
     else:
         # Here, interface is expected to be like "COM1"
         # In this case, port number for pySecial should be 0
         import serial
         portNum = int(interface[3:]) - 1
         try:
             self.ctrlif = serial.Serial(port=portNum, baudrate=19200,timeout=1)
         except serial.serialutil.SerialException:
             import sys
             sys.exit("Cannot open port: " + interface)
     self.cipher_list = rev1_cipher_list
     self.addr_list = rev1_addr_list
Ejemplo n.º 12
0
    def workerThread1(self):
        """
        This is where we handle the asynchronous I/O. For example, it may be
        a 'select()'.
        One important thing to remember is that the thread has to yield
        control.
        """

        time.sleep(1)  # cheat the program to let UI finish loading

        try:
            self.d = d2xx.open(0)
            self.d.setBaudRate(115200)
            self.d.setTimeouts(1, 0)
        except:
            self.queue.put("exit")
            self.running = 0
            return

        buffer = ''
        try:
            while self.running:
                time.sleep(0.01)
                b = self.d.read(1)

                # if b == '':
                #     continue

                # if not (ord(b) == 13 or (ord(b) in range(48, 58)) or (ord(b) in range(65, 91))):
                #     print b
                #     continue

                if b != '' and b != '\r':
                    buffer += b

                if b == '\r':
                    print "Receive:", buffer, len(buffer)
                    self.queue.put(buffer)
                    buffer = ''

        except:
            print 'Closed', sys.exc_info()[0]

            self.d.close()
Ejemplo n.º 13
0
    def workerThread1(self):
        """
        This is where we handle the asynchronous I/O. For example, it may be
        a 'select()'.
        One important thing to remember is that the thread has to yield
        control.
        """

        time.sleep(1) # cheat the program to let UI finish loading

        try:
            self.d = d2xx.open(0)
            self.d.setBaudRate(115200)
            self.d.setTimeouts(1, 0)
        except:
            self.queue.put("exit")
            self.running = 0
            return
        
        buffer = ''
        try:
            while self.running:
                time.sleep(0.01)
                b = self.d.read(1)

                # if b == '':
                #     continue

                # if not (ord(b) == 13 or (ord(b) in range(48, 58)) or (ord(b) in range(65, 91))):
                #     print b
                #     continue

                if b != '' and b != '\r':
                    buffer += b

                if b == '\r':
                    print "Receive:", buffer, len(buffer)
                    self.queue.put(buffer)
                    buffer = ''
                    
        except:
            print 'Closed', sys.exc_info()[0]

            self.d.close()
 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
Ejemplo n.º 15
0
 def __init__(self, interface="USB"):
     # Switching between USB and RS232C interfaces
     if interface == "USB":
         import d2xx
         self.ctrlif = d2xx.open(0)
         # setTimeouts(Read timeout, write timeout)
         self.ctrlif.setTimeouts(5000, 5000) 
     else:
         # Here, interface is expected to be like "COM1"
         # In this case, port number for pySecial should be 0
         import serial
         portNum = int(interface[3:]) - 1
         try:
             # Default baud rate is 19200.
             self.ctrlif = serial.Serial(port=portNum, baudrate=115200,timeout=1)
         except serial.serialutil.SerialException:
             import sys
             sys.exit("Cannot open port: " + interface)
     self.cipher_list = rev1_cipher_list
     self.addr_list = rev1_addr_list
Ejemplo n.º 16
0
        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
Ejemplo n.º 17
0
##
##
##ins.write('DATA:SOU CH1')
##ins.write('DATA:WIDTH 1')
##ins.write('DATA:ENC RPB')
##ins.write('DATA:STOP 10000')
##
##ymult=float(ins.query('WFMPRE:YMULT?'))
##yzero=float(ins.query('WFMPRE:YZERO?'))
##yoff=float(ins.query('WFMPRE:YOFF?'))
##xincr=float(ins.query('WFMPRE:XINCR?'))
##ins.write("ACQ:STATE ON")
####ins.write("ACQ:STOPA SEQ")

d=d2xx.listDevices()
h=d2xx.open(0)
h.setBitMode(0xff,0x40)
h.setUSBParameters(0x32000,0x320000)
h.setLatencyTimer(3)
h.purge()
wr_cmd='01'
rd_cmd='00'
rd_data=[]
##rd_val=None
key_raw='00000000000000000000000000000000'
data_raw='0000000000000000000000000fffffff'
key=key_raw[-1::-1]
data=data_raw[-1::-1]


for i in range(0,8):
Ejemplo n.º 18
0
# THE SOFTWARE.

import d2xx
import time


def safe_read(handle, count):
    while handle.getQueueStatus() < count:
        time.sleep(1)
        print "Waiting to read..."

    return handle.read(count)


print "Opening"
handle = d2xx.open(0)
handle.setBitMode(0x0F, 0)
handle.setBitMode(0x0F, 4)
handle.setBaudRate(3000000)

print "Write and read?"
handle.write("\x00" * 100)
safe_read(handle, 100)

handle.setBitMode(0x0F, 0)
handle.setBitMode(0x0F, 1)

print "Writing"
CHUNK_SIZE = 4096 * 4
for i in range(16000000 / CHUNK_SIZE):
    print "Wrote: ", handle.write("\x00" * CHUNK_SIZE)
Ejemplo n.º 19
0
def open(lowByteValue=MASK.SPI_S, lowByteDirection=MASK.SPI_O):
    return Mpsse(d2xx.open(0), lowByteValue, lowByteDirection)
Ejemplo n.º 20
0
def open(lowByteValue = MASK.SPI_S, lowByteDirection = MASK.SPI_O):
    return Mpsse(d2xx.open(0), lowByteValue, lowByteDirection)
Ejemplo n.º 21
0
  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)
Ejemplo n.º 22
0
import d2xx
Ejemplo n.º 23
0
def usbopen():
    global usb
    usb = d2xx.open(twocan)
Ejemplo n.º 24
0
Archivo: 2con.py Proyecto: cmgt/2can
def usbopen():
    global usb
    usb = d2xx.open(twocan)
Ejemplo n.º 25
0
#!/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"
Ejemplo n.º 26
0
# ----------
# 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)
Ejemplo n.º 27
0
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import d2xx
import time

def safe_read(handle, count):
	while handle.getQueueStatus() < count:
		time.sleep(1)
		print "Waiting to read..."
	
	return handle.read(count)


print "Opening"
handle = d2xx.open(0)
handle.setBitMode(0x0F, 0)
handle.setBitMode(0x0F, 4)
handle.setBaudRate(3000000)

print "Write and read?"
handle.write("\x00"*100)
safe_read(handle, 100)

handle.setBitMode(0x0F, 0)
handle.setBitMode(0x0F, 1)


print "Writing"
CHUNK_SIZE = 4096*4
for i in range(16000000/CHUNK_SIZE):
Ejemplo n.º 28
0
  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)
Ejemplo n.º 29
0
#!/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"
Ejemplo n.º 30
0
    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)
  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)
Ejemplo n.º 32
0
    def __init__(self, name, serial='UM245R', reset=False):
        """
        Creates an interface to Raymond's RF Multiplexer, allowing each RF relais to be switched
        on or off. The manual overide switch should be in the down position, thereby turining the 
        LED off. The LED then indicates if any of the relais are switched on. 
        Note that 8 bits can be set, but currently only relays 1-5 are connected.

        Requires pyusb package (http://bleyer.org/pyusb/), and the FTDI usb drivers (http://www.ftdichip.com/Drivers/D2XX.htm) installed.

        Arguments:
        - serial: FTDI serial id. To see available devices, run:
        
        import d2xx
        for i in d2xx.createDeviceInfoList():
            print d2xx.getDeviceInfoDetail(i)
        
        """
        Instrument.__init__(self, name)

        self._serial = serial

        self.add_parameter('state',
                           type=types.IntType,
                           flags=Instrument.FLAG_GETSET,
                           minval=0,
                           maxval=255)

        self.add_function('set_state_bitstring')
        self.add_function('get_state_bitstring')
        self.add_function('turn_on_relay')
        self.add_function('turn_off_relay')
        self.add_function('toggle_relay')
        self.add_function('get_dev')

        dev_list_len = d2xx.createDeviceInfoList()
        dev_id = -1
        for i in range(dev_list_len):
            dev_info = d2xx.getDeviceInfoDetail(i)
            if dev_info['serial'] == self._serial:
                dev_id = i
                break
        if dev_id == -1:
            error_str = 'Device address serial {} not found in device list'.format(
                self._serial)
            logging.error(error_str)
            raise Exception(error_str)

        self._dev = d2xx.open(dev_id)
        self._dev.setBitMode(0xFF, 1)  #BitBangMode!

        self._state = 0

        # override from config
        cfg_fn = os.path.abspath(
            os.path.join(qt.config['ins_cfg_path'], name + '.cfg'))
        if not os.path.exists(cfg_fn):
            _f = open(cfg_fn, 'w')
            _f.write('')
            _f.close()

        self.ins_cfg = config.Config(cfg_fn)
        self.load_cfg()
        self.save_cfg()