• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.find_descriptor函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中usb.util.find_descriptor函数的典型用法代码示例。如果您正苦于以下问题:Python find_descriptor函数的具体用法?Python find_descriptor怎么用?Python find_descriptor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: __plugDevice

def __plugDevice(flag, dom, usbmap):              
        for dev in core.find(find_all=True):
            for cfg in dev:
                intf = util.find_descriptor(cfg, find_all=True)
                intf0 = util.find_descriptor(cfg, bInterfaceClass=0)
                intf3 = util.find_descriptor(cfg, bInterfaceClass=3)
                intf9 = util.find_descriptor(cfg, bInterfaceClass=9)
                if intf != None and intf0 == None and intf3 == None and intf9 == None:
                    idVendor = str(hex(dev.idVendor))
                    if len(idVendor) < 6:
                        idVendor = '0x' + '0' * (6 - len(idVendor)) + idVendor[2:]
                     
                    idProduct = str(hex(dev.idProduct))
                    if len(idProduct) < 6:
                        idProduct = '0x' + '0' * (6 - len(idProduct)) + idProduct[2:]

                    xml = __generateUSBXML(idVendor, idProduct)
                    if dom != None and dom.isActive() == True:
                        if flag:
                            dom.attachDevice(xml)
                            syspath=__getSysPath(idVendor, idProduct)
                            if syspath != None:
                                usbmap[syspath]=idProduct+idVendor
                        else:
                            dom.detachDevice(xml)
                            syspath=__getSysPath(idVendor, idProduct)
                            if syspath != None:
                                usbmap.pop(syspath)
                    else:
                        pass 
开发者ID:siwenhu,项目名称:test_client_broadcast,代码行数:30,代码来源:usbplug.py


示例2: clearHalt

    def clearHalt(self, endpoint):
        r"""Clears any halt status on the specified endpoint.

        Arguments:
            endpoint: endpoint number.
        """
        cfg = self.dev.get_active_configuration()
        intf = util.find_descriptor(cfg, bInterfaceNumber = self.__claimed_interface)
        e = util.find_descriptor(intf, bEndpointAddress = endpoint)
        control.clear_feature(self.dev, control.ENDPOINT_HALT, e)
开发者ID:RoboticMayhem,项目名称:pyusb,代码行数:10,代码来源:legacy.py


示例3: get_interface

 def get_interface(self, device, intf):
     # TODO: check the viability of issuing a GET_INTERFACE
     # request when we don't have a alternate setting cached
     if intf is None:
         cfg = self.get_active_configuration(device)
         return cfg[(0, 0)]
     elif isinstance(intf, Interface):
         return intf
     else:
         cfg = self.get_active_configuration(device)
         if intf in self._alt_set:
             return util.find_descriptor(cfg, bInterfaceNumber=intf, bAlternateSetting=self._alt_set[intf])
         else:
             return util.find_descriptor(cfg, bInterfaceNumber=intf)
开发者ID:storm9789,项目名称:pyalienfx,代码行数:14,代码来源:core.py


示例4: managed_set_interface

 def managed_set_interface(self, device, intf, alt):
     if isinstance(intf, Interface):
         i = intf
     else:
         cfg = self.get_active_configuration(device)
         if intf is None:
             intf = cfg[(0,0)].bInterfaceNumber
         if alt is not None:
             i = util.find_descriptor(cfg, bInterfaceNumber=intf, bAlternateSetting=alt)
         else:
             i = util.find_descriptor(cfg, bInterfaceNumber=intf)
     self.managed_claim_interface(device, i)
     if alt is None:
         alt = i.bAlternateSetting
     self.backend.set_interface_altsetting(self.handle, i.bInterfaceNumber, alt)
     self._alt_set[i.bInterfaceNumber] = alt
开发者ID:jaseg,项目名称:pyusb,代码行数:16,代码来源:core.py


示例5: managed_set_configuration

    def managed_set_configuration(self, device, config):
        if config is None:
            cfg = device[0]
        elif isinstance(config, Configuration):
            cfg = config
        elif config == 0:  # unconfigured state

            class FakeConfiguration(object):
                def __init__(self):
                    self.index = None
                    self.bConfigurationValue = 0

            cfg = FakeConfiguration()
        else:
            cfg = util.find_descriptor(device, bConfigurationValue=config)
        self.managed_open()
        self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
        # cache the index instead of the object to avoid cyclic references
        # of the device and Configuration (Device tracks the _ResourceManager,
        # which tracks the Configuration, which tracks the Device)
        self._active_cfg_index = cfg.index
        # after changing configuration, our alternate setting and endpoint type caches
        # are not valid anymore
        self._ep_type_map.clear()
        self._alt_set.clear()
开发者ID:storm9789,项目名称:pyalienfx,代码行数:25,代码来源:core.py


示例6: test_config_switch_2

 def test_config_switch_2(self):
     """
     Uses the API if you're interested in the cfg block
     """
     cfg = uu.find_descriptor(self.dev, bConfigurationValue=2)
     self.assertIsNotNone(cfg, "Config 2 should exist")
     self.dev.set_configuration(cfg)
开发者ID:UweBonnes,项目名称:libopencm3,代码行数:7,代码来源:test_gadget0.py


示例7: managed_set_configuration

    def managed_set_configuration(self, device, config):
        if config is None:
            cfg = device[0]
        elif isinstance(config, Configuration):
            cfg = config
        elif config == 0: # unconfigured state
            class MockConfiguration(object):
                def __init__(self):
                    self.index = None
                    self.bConfigurationValue = 0
            cfg = MockConfiguration()
        else:
            cfg = util.find_descriptor(device, bConfigurationValue=config)

        if cfg is None:
            raise ValueError("Invalid configuration " + str(config))

        self.managed_open()
        self.backend.set_configuration(self.handle, cfg.bConfigurationValue)

        # cache the index instead of the object to avoid cyclic references
        # of the device and Configuration (Device tracks the _ResourceManager,
        # which tracks the Configuration, which tracks the Device)
        self._active_cfg_index = cfg.index

        self._ep_info.clear()
开发者ID:mull3rcw,项目名称:python_mt_unitTest,代码行数:26,代码来源:core.py


示例8: setUp

    def setUp(self):
        self.dev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID, custom_match=find_by_serial(DUT_SERIAL))
        self.assertIsNotNone(self.dev, "Couldn't find locm3 gadget0 device")

        self.cfg = uu.find_descriptor(self.dev, bConfigurationValue=2)
        self.assertIsNotNone(self.cfg, "Config 2 should exist")
        self.dev.set_configuration(self.cfg)
开发者ID:ChuckM,项目名称:libopencm3-stm32f429-changes,代码行数:7,代码来源:test_gadget0.py


示例9: get_active_configuration

 def get_active_configuration(self, device):
     if self._active_cfg_index is None:
         cfg = util.find_descriptor(device, bConfigurationValue=self.backend.get_configuration(self.handle))
         if cfg is None:
             raise USBError("Configuration not set")
         self._active_cfg_index = cfg.index
         return cfg
     return device[self._active_cfg_index]
开发者ID:storm9789,项目名称:pyalienfx,代码行数:8,代码来源:core.py


示例10: setUp

    def setUp(self):
        self.dev = usb.core.find(idVendor=0xcafe, idProduct=0xcafe, custom_match=find_by_serial(DUT_SERIAL))
        self.assertIsNotNone(self.dev, "Couldn't find locm3 gadget0 device")

        self.cfg = uu.find_descriptor(self.dev, bConfigurationValue=2)
        self.assertIsNotNone(self.cfg, "Config 2 should exist")
        self.dev.set_configuration(self.cfg);
        self.req = uu.CTRL_IN | uu.CTRL_TYPE_VENDOR | uu.CTRL_RECIPIENT_INTERFACE
开发者ID:AbuShaqra,项目名称:libopencm3,代码行数:8,代码来源:test_gadget0.py


示例11: __call__

 def __call__(self, device):
     if device.bDeviceClass == self.__class:
         return True
     for cfg in device:
         intf = find_descriptor(cfg, bInterfaceClass=self.__class)
         if intf is not None:
             return True
     return False
开发者ID:jj1bdx,项目名称:gnuk,代码行数:8,代码来源:card_reader.py


示例12: get_endpoint_type

 def get_endpoint_type(self, device, address, intf):
     intf = self.get_interface(device, intf)
     key = (address, intf.bInterfaceNumber, intf.bAlternateSetting)
     try:
         return self._ep_type_map[key]
     except KeyError:
         e = util.find_descriptor(intf, bEndpointAddress=address)
         etype = util.endpoint_type(e.bmAttributes)
         self._ep_type_map[key] = etype
         return etype
开发者ID:jaseg,项目名称:pyusb,代码行数:10,代码来源:core.py


示例13: setUp

    def setUp(self):
        self.dev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID, custom_match=find_by_serial(DUT_SERIAL))
        self.assertIsNotNone(self.dev, "Couldn't find locm3 gadget0 device")

        self.cfg = uu.find_descriptor(self.dev, bConfigurationValue=2)
        self.assertIsNotNone(self.cfg, "Config 2 should exist")
        self.dev.set_configuration(self.cfg)
        self.intf = self.cfg[(0, 0)]
        # heh, kinda gross...
        self.ep_out = [ep for ep in self.intf if uu.endpoint_direction(ep.bEndpointAddress) == uu.ENDPOINT_OUT][0]
        self.ep_in = [ep for ep in self.intf if uu.endpoint_direction(ep.bEndpointAddress) == uu.ENDPOINT_IN][0]
开发者ID:UweBonnes,项目名称:libopencm3,代码行数:11,代码来源:test_gadget0.py


示例14: get_interface_and_endpoint

    def get_interface_and_endpoint(self, device, endpoint_address):
        try:
            return self._ep_info[endpoint_address]
        except KeyError:
            for intf in self.get_active_configuration(device):
                ep = util.find_descriptor(intf, bEndpointAddress=endpoint_address)
                if ep is not None:
                    self._ep_info[endpoint_address] = (intf, ep)
                    return intf, ep

            raise ValueError('Invalid endpoint address ' + hex(endpoint_address))
开发者ID:mull3rcw,项目名称:python_mt_unitTest,代码行数:11,代码来源:core.py


示例15: isPassthroughUsbDevice

def isPassthroughUsbDevice(interfaceClass, idP, idV):              
        for dev in core.find(find_all=True):
            for cfg in dev:
                intf = util.find_descriptor(cfg, bInterfaceClass=interfaceClass)
                if intf is not None:
                    idVendor = str(hex(dev.idVendor))
                    if len(idVendor) < 6:
                        idVendor = '0x' + '0' * (6 - len(idVendor)) + idVendor[2:]
                     
                    idProduct = str(hex(dev.idProduct))
                    if len(idProduct) < 6:
                        idProduct = '0x' + '0' * (6 - len(idProduct)) + idProduct[2:]

                    if idVendor !=None and idProduct != None and idVendor == idV and idProduct == idP:
                        return True

        return False
开发者ID:siwenhu,项目名称:test_client_broadcast,代码行数:17,代码来源:usbplug.py


示例16: __init__

    def __init__(self, dev):
        """
        __init__(dev) -> None
        Initialize the DEV of CCID.
        device: usb.core.Device object.
        """

        cfg = dev.get_active_configuration()
        intf = find_descriptor(cfg, bInterfaceClass=CCID_CLASS,
                               bInterfaceSubClass=CCID_SUBCLASS,
                               bInterfaceProtocol=CCID_PROTOCOL_0)
        if intf is None:
            raise ValueError("Not a CCID device")

        claim_interface(dev, intf)

        for ep in intf:
            if endpoint_type(ep.bmAttributes) == ENDPOINT_TYPE_BULK and \
               endpoint_direction(ep.bEndpointAddress) == ENDPOINT_OUT:
               self.__bulkout = ep.bEndpointAddress
            if endpoint_type(ep.bmAttributes) == ENDPOINT_TYPE_BULK and \
               endpoint_direction(ep.bEndpointAddress) == ENDPOINT_IN:
               self.__bulkin = ep.bEndpointAddress

        assert len(intf.extra_descriptors) == 54
        assert intf.extra_descriptors[1] == 33

        if (intf.extra_descriptors[42] & 0x02):
            # Short APDU level exchange
            self.__use_APDU = True
        elif (intf.extra_descriptors[42] & 0x04):
            # Short and extended APDU level exchange
            self.__use_APDU = True
        elif (intf.extra_descriptors[42] & 0x01):
            # TPDU level exchange
            self.__use_APDU = False
        else:
            raise ValueError("Unknown exchange level")

        # Check other bits???
        #       intf.extra_descriptors[40]
        #       intf.extra_descriptors[41]

        self.__dev = dev
        self.__timeout = 10000
        self.__seq = 0
开发者ID:jj1bdx,项目名称:gnuk,代码行数:46,代码来源:card_reader.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.get_string函数代码示例发布时间:2022-05-27
下一篇:
Python util.endpoint_type函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap