当前位置: 首页>>代码示例>>Python>>正文


Python hid.enumerate方法代码示例

本文整理汇总了Python中hid.enumerate方法的典型用法代码示例。如果您正苦于以下问题:Python hid.enumerate方法的具体用法?Python hid.enumerate怎么用?Python hid.enumerate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hid的用法示例。


在下文中一共展示了hid.enumerate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open_device

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def open_device(vendor_id, product_id, interface_number):
    """Opens and returns the HID device (file-like object). Raise IOError if
    the device or interface is not available.

    Arguments:
    vendor_id -- the mouse vendor id (e.g. 0x1038)
    product_id -- the mouse product id (e.g. 0x1710)
    interface_number -- the interface number (e.g. 0x00)
    """
    # Dry run
    if debug.DEBUG and debug.DRY and is_device_plugged(vendor_id, product_id):
        device = BytesIO()  # Moke the device
        device.send_feature_report = device.write
        return device

    # Real device
    for interface in hid.enumerate(vendor_id, product_id):
        if interface["interface_number"] != interface_number:
            continue
        device = hid.device()
        device.open_path(interface["path"])
        return device

    raise IOError("Unable to find the requested device: %04X:%04X:%02X" % (
        vendor_id, product_id, interface_number)) 
开发者ID:flozz,项目名称:rivalcfg,代码行数:27,代码来源:usbhid.py

示例2: find_devices

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def find_devices(self, vendor=None, product=None, bus=None, address=None,
                     usb_port=None, **kwargs):
        """ Find compatible regular USB devices."""
        drivers = sorted(find_all_subclasses(UsbDriver), key=lambda x: x.__name__)
        LOGGER.debug('searching %s (drivers=[%s])', self.__class__.__name__,
                     ', '.join(map(lambda x: x.__name__, drivers)))
        for handle in PyUsbDevice.enumerate(vendor, product):
            if bus and handle.bus != bus:
                continue
            if address and handle.address != address:
                continue
            if usb_port and handle.port != usb_port:
                continue
            LOGGER.debug('probing drivers for device %04x:%04x', handle.vendor_id,
                         handle.product_id)
            for drv in drivers:
                yield from drv.probe(handle, vendor=vendor, product=product, **kwargs) 
开发者ID:jonasmalacofilho,项目名称:liquidctl,代码行数:19,代码来源:usb.py

示例3: __init__

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def __init__(self, vendor_id=9583, product_id=50735):
        """Initialize a SpaceMouse handler.

        Args:
            vendor_id: HID device vendor id
            product_id: HID device product id

        Note:
            Use hid.enumerate() to view all USB human interface devices (HID).
            Make sure SpaceMouse is detected before running the script.
            You can look up its vendor/product id from this method.
        """

        print("Opening SpaceMouse device")
        self.device = hid.device()
        self.device.open(vendor_id, product_id)  # SpaceMouse

        print("Manufacturer: %s" % self.device.get_manufacturer_string())
        print("Product: %s" % self.device.get_product_string())

        self._display_controls()

        self.single_click_and_hold = False

        self._control = [0., 0., 0., 0., 0., 0.]
        self._reset_state = 0
        self.rotation = np.array([[-1., 0., 0.], [0., 1., 0.], [0., 0., -1.]])
        self._enabled = False

        # launch a new listener thread to listen to SpaceMouse
        self.thread = threading.Thread(target=self.run)
        self.thread.daemon = True
        self.thread.start() 
开发者ID:StanfordVL,项目名称:robosuite,代码行数:35,代码来源:spacemouse.py

示例4: new_packet

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def new_packet(fill, *args):
        pkt = bytearray([fill] * 65)
        pkt[0] = 0  # Report ID
        for i, v in enumerate(args):
            pkt[i + 1] = v
        return pkt

    # 52 get / 51 SET - looks like even numbers are getters and odd setters 
开发者ID:gfduszynski,项目名称:cm-rgb,代码行数:10,代码来源:ctrl.py

示例5: __init_hid_device

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def __init_hid_device(self):
        device_list = [x for x in hid.enumerate(self.VENDOR_ID, self.PRODUCT_ID)
                       if x['interface_number'] == self.IFACE_NUM]
        if len(device_list) == 0:
            raise Exception("No devices found. See: https://github.com/gfduszynski/cm-rgb/issues/9")

        self.device = hid.device()

        try:
            self.device.open_path(device_list[0]["path"])
        except OSError as err:
            print("Failed to access usb device. See: https://github.com/gfduszynski/cm-rgb/wiki/1.-Installation-&-Configuration#3-configuration")
            print("Also check if other process is not using the device.\n")
            raise 
开发者ID:gfduszynski,项目名称:cm-rgb,代码行数:16,代码来源:ctrl.py

示例6: detect

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def detect(cls):
        if cls.mock_address is not None:
            from shadowlands.credstick.mock_ethdriver import MockEthDriver
            return MockEthDriver

        def handle_trezor(hidDevice):
            from shadowlands.credstick.trezor_ethdriver import TrezorEthDriver
            TrezorEthDriver.manufacturerStr = hidDevice['manufacturer_string']
            if hidDevice['release_number'] == 256:
                TrezorEthDriver.productStr = 'Trezor One' 
                sleep(1)
            elif hidDevice['release_number'] == 512:
                TrezorEthDriver.productStr = 'Trezor T' 
            return TrezorEthDriver
 
        for hidDevice in hid.enumerate(0, 0):
            if hidDevice['path'] is not None:
                if hidDevice['vendor_id'] == 0x2c97:
                    from shadowlands.credstick.ledger_ethdriver import LedgerEthDriver
                    LedgerEthDriver.manufacturer = hidDevice['manufacturer_string']
                    LedgerEthDriver.product = hidDevice['product_string']
                    return LedgerEthDriver
                elif hidDevice['vendor_id'] == 0x534c:
                    return handle_trezor(hidDevice)
                elif hidDevice['vendor_id'] == 0x1209:
                    return handle_trezor(hidDevice)

        raise NoCredstickFoundError("Could not identify any supported credstick") 
开发者ID:kayagoban,项目名称:shadowlands,代码行数:30,代码来源:__init__.py

示例7: enumerate

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def enumerate(password=''):
    results = []
    devices = []
    for device_id in LEDGER_DEVICE_IDS:
        devices.extend(hid.enumerate(LEDGER_VENDOR_ID, device_id))
    devices.append({'path': SIMULATOR_PATH.encode(), 'interface_number': 0, 'product_id': 1})

    for d in devices:
        if ('interface_number' in d and d['interface_number'] == 0
                or ('usage_page' in d and d['usage_page'] == 0xffa0)):
            d_data = {}

            path = d['path'].decode()
            d_data['type'] = 'ledger'
            d_data['model'] = 'ledger_nano_x' if d['product_id'] == 0x0004 else 'ledger_nano_s'
            d_data['path'] = path

            if path == SIMULATOR_PATH:
                d_data['model'] += '_simulator'

            client = None
            with handle_errors(common_err_msgs["enumerate"], d_data):
                try:
                    client = LedgerClient(path, password)
                    d_data['fingerprint'] = client.get_master_fingerprint_hex()
                    d_data['needs_pin_sent'] = False
                    d_data['needs_passphrase_sent'] = False
                except BTChipException:
                    # Ignore simulator if there's an exception, means it isn't there
                    if path == SIMULATOR_PATH:
                        continue
                    else:
                        raise

            if client:
                client.close()

            results.append(d_data)

    return results 
开发者ID:bitcoin-core,项目名称:HWI,代码行数:42,代码来源:ledger.py

示例8: enumerate

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def enumerate(cls, debug: bool = False) -> Iterable["HidTransport"]:
        devices = []
        for dev in hid.enumerate(0, 0):
            usb_id = (dev["vendor_id"], dev["product_id"])
            if usb_id != DEV_TREZOR1 and usb_id != DEV_KEEPKEY:
                continue
            if debug:
                if not is_debuglink(dev):
                    continue
            else:
                if not is_wirelink(dev):
                    continue
            devices.append(HidTransport(dev))
        return devices 
开发者ID:bitcoin-core,项目名称:HWI,代码行数:16,代码来源:hid.py

示例9: find_debug

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def find_debug(self) -> "HidTransport":
        if self.protocol.VERSION >= 2:
            # use the same device
            return self
        else:
            # For v1 protocol, find debug USB interface for the same serial number
            for debug in HidTransport.enumerate(debug=True):
                if debug.device["serial_number"] == self.device["serial_number"]:
                    return debug
            raise TransportException("Debug HID device not found") 
开发者ID:bitcoin-core,项目名称:HWI,代码行数:12,代码来源:hid.py

示例10: __init__

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def __init__(self, idVendor=0x16c0, idProduct=0x05df, idSerial=None):
     self.compdevs = []
     firstdev = ""
     self.relaynum = 0
     self.serialnum = ""
     try:
      for d in hid.enumerate(idVendor, idProduct):
       tarr = []
       if (d["product_string"][:-1] == "USBRelay"):
         tarr.append(d["product_string"][-1:]) 
         tarr.append(d["path"])
         hidevice = hid.device()
         hidevice.open_path(d["path"]) 
         result = hidevice.get_feature_report(1,9)
         hidevice.close()
         if len(result) > 5:
          resstr = ""
          for i in range(5):
           resstr += chr(result[i])
         #print(resstr)
         tarr.append(resstr)
         if firstdev == "":
          if idSerial == None:
           firstdev = d["path"]
           self.relaynum = int(tarr[0])
           self.serialnum = resstr
          elif idSerial == resstr:
           firstdev = d["path"]
           self.relaynum = int(tarr[0])
           self.serialnum = resstr
         self.compdevs.append(tarr)
     except:
      pass
     try:
      self.h = hid.device()
      self.h.open_path(d["path"])
      self.h.set_nonblocking(1)
     except:
      pass 
开发者ID:enesbcs,项目名称:rpieasy,代码行数:41,代码来源:lib_vusb.py

示例11: is_device_plugged

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def is_device_plugged(vendor_id, product_id):
    """Returns True if the given HID device is plugged to the computer.

    Arguments:
    vendor_id -- the mouse vendor id (e.g. 0x1038)
    product_id -- the mouse product id (e.g. 0x1710)
    """
    if debug.DEBUG:
        mouse_id = debug.get_debug_profile()
        if mouse_id:
            return (mouse_id.vendor_id == vendor_id
                    and mouse_id.product_id == product_id)
    return len(hid.enumerate(vendor_id, product_id)) > 0 
开发者ID:flozz,项目名称:rivalcfg,代码行数:15,代码来源:usbhid.py

示例12: __init__

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def __init__(self, device, description, **kwargs):
        # compatibility with v1.1.0 drivers, which could be directly
        # instantiated with a usb.core.Device
        if isinstance(device, usb.core.Device):
            LOGGER.warning('deprecated: device must be HidapiDevice, not PyUSB handle')
            LOGGER.warning('deprecated: PyUSB no longer supported for HID devices')
            LOGGER.warning('deprecated: switch to find_supported_devices or pass HidapiDevice')
            usbdev = device
            hidinfo = next(info for info in hid.enumerate(usbdev.idVendor, usbdev.idProduct)
                           if info['serial_number'] == usbdev.serial_number)
            assert hidinfo, 'Could not find device in HID bus'
            device = HidapiDevice(hid, hidinfo)
        super().__init__(device, description, **kwargs) 
开发者ID:jonasmalacofilho,项目名称:liquidctl,代码行数:15,代码来源:usb.py

示例13: enumerate

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def enumerate(cls, vid=None, pid=None):
        args = {}
        if vid:
            args['idVendor'] = vid
        if pid:
            args['idProduct'] = pid
        for handle in usb.core.find(find_all=True, **args):
            yield cls(handle) 
开发者ID:jonasmalacofilho,项目名称:liquidctl,代码行数:10,代码来源:usb.py

示例14: enumerate_devices

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def enumerate_devices() -> List[bytes]:
        devices: List[bytes] = []

        for hid_device in hid.enumerate(LEDGER_VENDOR_ID, 0):
            if (hid_device.get("interface_number") == 0 or
                    hid_device.get("usage_page") == 0xffa0):
                devices.append(hid_device["path"])

        assert (len(devices) != 0,
                f"Can't find HID device with vendor id {LEDGER_VENDOR_ID}")

        return devices 
开发者ID:LedgerHQ,项目名称:app-monero,代码行数:14,代码来源:hid_device.py

示例15: getDongles

# 需要导入模块: import hid [as 别名]
# 或者: from hid import enumerate [as 别名]
def getDongles(dev_class=None, scrambleKey="", debug=False):
    dev_class = dev_class or HIDDevice
    devices = []
    for d in hid.enumerate(0, 0):
        usage_page = d['usage_page']
        if usage_page == 0xf1d0 and d['usage'] == 1:
            devices.append(U2FTunnelDongle(dev_class(d['path']),scrambleKey, debug=debug))
        # Usage page doesn't work on Linux
        # well known devices
        elif (d['vendor_id'], d['product_id']) in DEVICES:
            device = HIDDevice(d['path'])
            try:
                device.open()
                device.close()
                devices.append(U2FTunnelDongle(dev_class(d['path']),scrambleKey, debug=debug))
            except (exc.DeviceError, IOError, OSError):
                pass
        # unknown devices
        else:
            device = HIDDevice(d['path'])
            try:
                device.open()
                # try a ping command to ensure a FIDO device, else timeout (BEST here, modulate the timeout, 2 seconds is way too big)
                device.ping()
                device.close()
                devices.append(U2FTunnelDongle(dev_class(d['path']),scrambleKey, debug=debug))
            except (exc.DeviceError, IOError, OSError):
                pass
    return devices 
开发者ID:LedgerHQ,项目名称:blue-loader-python,代码行数:31,代码来源:commU2F.py


注:本文中的hid.enumerate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。