Exemplo n.º 1
0
 def test_list_devices(self):
     """List FTDI devices."""
     devs = Ftdi.list_devices('ftdi:///?')
     self.assertEqual(len(devs), 6)
     devs = Ftdi.list_devices('ftdi://:232h/?')
     self.assertEqual(len(devs), 2)
     devs = Ftdi.list_devices('ftdi://:2232h/?')
     self.assertEqual(len(devs), 1)
     devs = Ftdi.list_devices('ftdi://:4232h/?')
     self.assertEqual(len(devs), 1)
     out = StringIO()
     Ftdi.show_devices('ftdi:///?', out)
     lines = [l.strip() for l in out.getvalue().split('\n')]
     lines.pop(0)  # "Available interfaces"
     while lines and not lines[-1]:
         lines.pop()
     self.assertEqual(len(lines), 10)
     portmap = defaultdict(int)
     reference = {'232': 1, '2232': 2, '4232': 4, '232h': 2, '230x': 1}
     for line in lines:
         url = line.split(' ')[0].strip()
         parts = urlsplit(url)
         self.assertEqual(parts.scheme, 'ftdi')
         self.assertRegex(parts.path, r'^/[1-4]$')
         product = parts.netloc.split(':')[1]
         portmap[product] += 1
     self.assertEqual(portmap, reference)
Exemplo n.º 2
0
def query_devices(ignored_devices):
    if ignored_devices is not None and not hasattr(ignored_devices, '__iter__'):
        raise ValueError("Invalid ignored devices variable")

    ignored_ids = list(map(lambda d: d.device_id, ignored_devices))
    def map_url(dev):
        usb: UsbDeviceDescriptor = dev[0]
        vid = usb.vid
        pid = usb.pid
        if vid == 0x0403:
            vid = "ftdi"
        if pid == 0x6001:
            pid = "232"
        interface = dev[1]
        return f"ftdi://{vid}:{pid}:{usb.sn}/{interface}"

    all_devices = list(map(map_url, Ftdi.list_devices()))

    def not_ignored(dev):
        return dev not in ignored_ids

    if ignored_devices is None:
        to_query = all_devices
    else:
        to_query = list(filter(not_ignored, all_devices))

    discovered_boards = []
    for t in to_query:
        try:
            qb = ReaderBoard(deviceid=t)
            discovered_boards.append(qb.__repr__())
            qb.shutdown()
        except:
            pass
    return discovered_boards
Exemplo n.º 3
0
 def test_descriptor_update(self):
     """Check EEPROM content overrides YaML configuration."""
     # this test is more about testing the virtual FTDI infrastructure
     # than a pure PyFtdi test
     devs = Ftdi.list_devices('ftdi:///?')
     self.assertEqual(len(devs), 1)
     desc = devs[0][0]
     # these values are not the ones defined in YaML, but stored in EEPROM
     self.assertEqual(desc.sn, 'FT3KMGTL')
     self.assertEqual(desc.description, 'LC231X')
Exemplo n.º 4
0
def scan_devices(sn):
    ftdi = Ftdi()
    devices = [d[0] for d in ftdi.list_devices()]

    # If the caller gave us a serial or a regex, keep only matching devices
    if sn:
        devices = [d for d in devices if re.search(sn, d.sn)]

    # Sorty devices by their serials so that the presentation order does not
    # depend on the order in which the devices were connected or reset.
    devices = sorted(devices, key=lambda d: d.sn)

    # Construct the FtdiEeprom object for each matching device
    devices = [load_eeprom(d.vid, d.pid, d.sn) for d in devices]

    return devices
Exemplo n.º 5
0
    def ftdiPorts(cls):
        # FIXME: for some reason, I can't get the Sutter URls with the
        # wildcard and I must handcode the following. It appears the wildcard
        # ftdi:///? does not work for some reason.
        vidpids = [(4930, 1)] # Must add custom pairs in the future.

        urls = []        
        for vid, pid in vidpids:
            pyftdidevices = Ftdi.list_devices(url="ftdi://{0}:{1}/1".format(vid, pid))
            for device, address in pyftdidevices:
                thePort = ListPortInfo(device="")
                thePort.vid = device.vid
                thePort.pid = device.pid
                thePort.serial_number = device.sn
                thePort.device = "ftdi://{0}:{1}:{2}/{3}".format(device.vid, device.pid, device.sn, address)
                urls.append(thePort)

        return urls
Exemplo n.º 6
0
def get_ftdi_devices(rtype=0):
 try:
  devs = Ftdi.list_devices()
 except:
  devs = []
 if rtype==0:
  return len(devs)
 elif rtype==1:
  return devs
 elif rtype==2:
  try:
   res = UsbTools.build_dev_strings(Ftdi.SCHEME,Ftdi.VENDOR_IDS,Ftdi.PRODUCT_IDS,devs)
  except:
   res = []
#  res.append( ('ftdi://ftdi:232h:3:9/1', '(Single RS232-HS)') ) # debug
#  res.append( ('ftdi://ftdi:232h:3:9/2', '(Single RS232-HS)') ) # debug
  res = sorted(res)
  return res