示例#1
0
文件: usbdev.py 项目: abeck70/pycs
def find(vps, sn = None):
  """lookup a usb device based on vid, pid and serial number"""
  devices = UsbTools.find_all(vps)
  # do we have any devices?
  if len(devices) == 0:
    return None, 'no device found'
  if sn is not None:
    # filter using the serial number
    devices_sn = [d for d in devices if d[2] == sn]
    if len(devices_sn) == 0:
      # we have devices, but none with this serial number
      s = []
      s.append('no device with this serial number')
      s.append('devices found:')
      for d in devices:
        s.append('%04x:%04x sn %r' % (d[0], d[1], d[2]))
      return None, '\n'.join(s)
    else:
      devices = devices_sn
  # no devices
  if len(devices) == 0:
    return None, 'no device found'
  # multiple devices
  if len(devices) > 1:
    s = []
    s.append('multiple devices found:')
    for d in devices:
      s.append('%04x:%04x sn %r' % (d[0], d[1], d[2]))
    return None, '\n'.join(s)
  # 1 device
  return devices[0], None
示例#2
0
文件: usbdev.py 项目: deadsy/pycs
def find(vps, sn=None):
    """lookup a usb device based on vid, pid and serial number"""
    devices = UsbTools.find_all(vps)
    # do we have any devices?
    if len(devices) == 0:
        return None, "no device found"
    if sn is not None:
        # filter using the serial number
        devices_sn = [d for d in devices if d[2] == sn]
        if len(devices_sn) == 0:
            # we have devices, but none with this serial number
            s = []
            s.append("no device with this serial number")
            s.append("devices found:")
            for d in devices:
                s.append("%04x:%04x sn %r" % (d[0], d[1], d[2]))
            return None, "\n".join(s)
        else:
            devices = devices_sn
    # no devices
    if len(devices) == 0:
        return None, "no device found"
    # multiple devices
    if len(devices) > 1:
        s = []
        s.append("multiple devices found:")
        for d in devices:
            s.append("%04x:%04x sn %r" % (d[0], d[1], d[2]))
        return None, "\n".join(s)
    # 1 device
    return devices[0], None
示例#3
0
文件: usbdev.py 项目: abeck70/pycs
 def open(self, vendor, product, interface=1, index=0, serial=None, description=None):
   """open a new interface to the specified device"""
   self.usb_dev = UsbTools.get_device(vendor, product, index, serial, description)
   config = self.usb_dev.get_active_configuration()
   # check for a valid interface
   if interface > config.bNumInterfaces:
     raise usbdev_error('invalid interface: %d' % interface)
   self._set_interface(config, interface)
示例#4
0
文件: usbdev.py 项目: deadsy/pycs
 def open(self, vendor, product, interface=1, index=0, serial=None, description=None):
     """open a new interface to the specified device"""
     self.usb_dev = UsbTools.get_device(vendor, product, index, serial, description)
     config = self.usb_dev.get_active_configuration()
     # check for a valid interface
     if interface > config.bNumInterfaces:
         raise usbdev_error("invalid interface: %d" % interface)
     self._set_interface(config, interface)
示例#5
0
文件: usbdev.py 项目: mistsys/pycs
 def open(self, vid, pid, itf=0, idx=0, sn=None, descr=None):
     """open a new interface to the specified device"""
     self.usb_dev = UsbTools.get_device(vid, pid, idx, sn, descr)
     cfg = self.usb_dev.get_active_configuration()
     # check for a valid interface
     if itf >= cfg.bNumInterfaces:
         raise usbdev_error('invalid interface: %d' % itf)
     self._set_interface(cfg, itf)
示例#6
0
文件: ft2232.py 项目: deadsy/espdbg
 def open_ft2232(self, vps, itf, sn):
     # find the device on USB
     devices = UsbTools.find_all(vps)
     if sn is not None:
         # filter based on device serial number
         devices = [dev for dev in devices if dev[2] == sn]
     if len(devices) == 0:
         raise IOError("No such device")
     self.vid = devices[0][0]
     self.pid = devices[0][1]
     self.sn = devices[0][2]
     self.ftdi = Ftdi()
     self.freq = self.ftdi.open_mpsse(self.vid,
                                      self.pid,
                                      itf,
                                      serial=self.sn,
                                      frequency=_FREQ)
     self.wrbuf = array.array('B')
     self.gpio_init()
     self.state_reset()
     self.sir_end_state = 'IDLE'
     self.sdr_end_state = 'IDLE'
示例#7
0
文件: usbdev.py 项目: abeck70/pycs
 def close(self):
   """close the interface"""
   UsbTools.release_device(self.usb_dev)
示例#8
0
文件: usbdev.py 项目: deadsy/pycs
 def close(self):
     """close the interface"""
     UsbTools.release_device(self.usb_dev)