Exemple #1
0
 def get_urls(key: Optional[Callable] = None):
     devspec = ftdi.Ftdi.list_devices()
     urls = UsbTools.build_dev_strings(PyFTDIDevice.URLS,
                                       ftdi.Ftdi.VENDOR_IDS,
                                       ftdi.Ftdi.PRODUCT_IDS, devspec)
     urls = filter(key, urls)
     return urls
Exemple #2
0
 def test_list_devices(self):
     """List FTDI devices."""
     vid = 0x403
     vids = {'ftdi': vid}
     pids = {
         vid: {
             '230x': 0x6015,
             '232r': 0x6001,
             '232h': 0x6014,
             '2232h': 0x6010,
             '4232h': 0x6011,
         }
     }
     devs = UsbTools.list_devices('ftdi:///?', vids, pids, vid)
     self.assertEqual(len(devs), 6)
     ifmap = {0x6001: 1, 0x6010: 2, 0x6011: 4, 0x6014: 1, 0x6015: 1}
     for dev, desc in devs:
         strings = UsbTools.build_dev_strings('ftdi', vids, pids,
                                              [(dev, desc)])
         self.assertEqual(len(strings), ifmap[dev.pid])
         for url, _ in strings:
             parts, _ = UsbTools.parse_url(url, 'ftdi', vids, pids, vid)
             self.assertEqual(parts.vid, dev.vid)
             self.assertEqual(parts.pid, dev.pid)
             self.assertEqual(parts.bus, dev.bus)
             self.assertEqual(parts.address, dev.address)
             self.assertEqual(parts.sn, dev.sn)
     devs = UsbTools.list_devices('ftdi://:232h/?', vids, pids, vid)
     self.assertEqual(len(devs), 2)
     devs = UsbTools.list_devices('ftdi://:2232h/?', vids, pids, vid)
     self.assertEqual(len(devs), 1)
Exemple #3
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