Windows的PyUSB问题

如何解决Windows的PyUSB问题

Pyusb在我的PC上无法正常工作。在这个论坛上没有关于我的问题的话题。详细信息如下。 我正在尝试运行一个简单的脚本,该脚本应显示USB设备信息:

import usb.core
import usb.util
for device in usb.core.find(find_all=True):
    print(device)

然后我收到2个错误: usb.core.USBError:[错误2]找不到实体 NotImplementedError:该平台不支持或未实现操作

日志

 DEVICE ID 8087:8008 on Bus 001 Address 003 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x200 USB 2.0
 bDeviceClass           :    0x9 Hub
 bDeviceSubClass        :    0x0
 bDeviceProtocol        :    0x1
 bMaxPacketSize0        :   0x40 (64 bytes)
 idVendor               : 0x8087
 idProduct              : 0x8008
 bcdDevice              :    0x5 Device 0.05
 iManufacturer          :    0x0
 iProduct               :    0x0
 iSerialNumber          :    0x0
 bNumConfigurations     :    0x1
  CONFIGURATION 1: 0 mA ====================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x19 (25 bytes)
   bNumInterfaces       :    0x1
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0
   bmAttributes         :   0xe0 Self Powered,Remote Wakeup
   bMaxPower            :    0x0 (0 mA)
    INTERFACE 0: Hub =======================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0x9 Hub
     bInterfaceSubClass :    0x0
     bInterfaceProtocol :    0x0
     iInterface         :    0x0
      ENDPOINT 0x81: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :    0x1 (1 bytes)
       bInterval        :    0xc
DEVICE ID 1c4f:0026 on Bus 003 Address 001 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x110 USB 1.1
 bDeviceClass           :    0x0 Specified at interface
 bDeviceSubClass        :    0x0
 bDeviceProtocol        :    0x0
 bMaxPacketSize0        :    0x8 (8 bytes)
 idVendor               : 0x1c4f
 idProduct              : 0x0026
 bcdDevice              :  0x110 Device 1.1
 iManufacturer          :    0x1 Error Accessing String
 iProduct               :    0x2 Error Accessing String
 iSerialNumber          :    0x0
 bNumConfigurations     :    0x1
  CONFIGURATION 1: 98 mA ===================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x3b (59 bytes)
   bNumInterfaces       :    0x2
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0
   bmAttributes         :   0xa0 Bus Powered,Remote Wakeup
   bMaxPower            :   0x31 (98 mA)
    INTERFACE 0: Human Interface Device ====================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0x3 Human Interface Device
     bInterfaceSubClass :    0x1
     bInterfaceProtocol :    0x1
     iInterface         :    0x0
      ENDPOINT 0x81: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :    0x8 (8 bytes)
       bInterval        :    0xa
    INTERFACE 1: Human Interface Device ====================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x1
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0x3 Human Interface Device
     bInterfaceSubClass :    0x0
     bInterfaceProtocol :    0x0
     iInterface         :    0x0
      ENDPOINT 0x82: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x82 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :    0x3 (3 bytes)
       bInterval        :    0xa
Traceback (most recent call last):
  File "f:\newpy\venv\lib\site-packages\usb\core.py",line 746,in __str__
    for configuration in self:
  File "f:\newpy\venv\lib\site-packages\usb\core.py",line 1128,in __iter__
    yield Configuration(self,i)
  File "f:\newpy\venv\lib\site-packages\usb\core.py",line 603,in __init__
    desc = backend.get_configuration_descriptor(
  File "f:\newpy\venv\lib\site-packages\usb\backend\libusb1.py",line 773,in get_configuration_descriptor
    _check(self.lib.libusb_get_config_descriptor(
  File "f:\newpy\venv\lib\site-packages\usb\backend\libusb1.py",line 604,in _check
    raise USBError(_strerror(ret),ret,_libusb_errno[ret])
usb.core.USBError: [Errno 2] Entity not found
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
  File "usbtesta.py",line 31,in <module>
    print(device)
  File "f:\newpy\venv\lib\site-packages\usb\core.py",line 750,in __str__
    configuration = self.get_active_configuration()
  File "f:\newpy\venv\lib\site-packages\usb\core.py",line 909,in get_active_configuration
    return self._ctx.get_active_configuration(self)
  File "f:\newpy\venv\lib\site-packages\usb\core.py",line 113,in wrapper
    return f(self,*args,**kwargs)
  File "f:\newpy\venv\lib\site-packages\usb\core.py",line 247,in get_active_configuration
    self.managed_open()
  File "f:\newpy\venv\lib\site-packages\usb\core.py",line 131,in managed_open
    self.handle = self.backend.open_device(self.dev)
  File "f:\newpy\venv\lib\site-packages\usb\backend\libusb1.py",line 804,in open_device
    return _DeviceHandle(dev)
  File "f:\newpy\venv\lib\site-packages\usb\backend\libusb1.py",line 652,in __init__
    _check(_lib.libusb_open(self.devid,byref(self.handle)))
  File "f:\newpy\venv\lib\site-packages\usb\backend\libusb1.py",line 600,in _check
    raise NotImplementedError(_strerror(ret))
NotImplementedError: Operation not supported or unimplemented on this platform

我在互联网上看到了类似的问题,但是在使用特定的USB设备时遇到了麻烦,可以通过安装Zadig并选择正确的驱动程序来解决。这样对我没有帮助,因为我不使用某些USB设备,而只使用试图查看设备列表的代码。问题不在PATH中。 我尝试使用以下配置运行脚本:win10,python 3.8.5,以及3.7.9,pyusb 1.1.0,libusb 1.0.23b1 / libusb-win32。 如果我使用libusb-win32(libusb0.dll)运行脚本,则什么也没有发生,python只是返回一个空行并等待新命令。如果我使用libusb运行脚本,则python将在本文上方显示这些错误。当我添加到脚本行set_configuration()

时,第一个错误消失
for device in usb.core.find(find_all=True):
    print(device)
    device.set_configuration()

但是如何解决第二个错误? 在Mac OS(pyusb,libusb 1.0,python 3.7.9)的相同配置中,该脚本成功运行

screen_mac

奇怪的是,此脚本运行成功:

for device in usb.core.find(find_all=True):
    print(device.bDeviceClass) # running only if i indicate parameter of variable "device" like here

奇怪的是,pyusb找到了一些USB设备(如您在日志中看到的),但最后出现了错误。在另一台我的脚本根本没有运行的PC上,启动后立即出现错误。 那么如何查看已连接设备的列表?我很高兴得到任何帮助

解决方法

enter image description result  here

    import sys
    import ctypes as ct
    import libusb as usb
    
    
    def print_devs(devs):
    
        path = (ct.c_uint8 * 8)()
    
        i = 0
        while devs[i]:
            dev = devs[i]
    
            desc = usb.device_descriptor()
            r = usb.get_device_descriptor(dev,ct.byref(desc))
            if r < 0:
                print("failed to get device descriptor",file=sys.stderr)
                return
    
            print("{:04x}:{:04x} (bus {:d},device {:d})".format(
                  desc.idVendor,desc.idProduct,usb.get_bus_number(dev),usb.get_device_address(dev)),end="")
    
            r = usb.get_port_numbers(dev,path,ct.sizeof(path))
            if r > 0:
                print(" path: {:d}".format(path[0]),end="")
                for j in range(1,r):
                    print(".{:d}".format(path[j]),end="")
    
            print()
            i += 1
    
    
    def main():
    
        r = usb.init(None)
        if r < 0:
            return r
    
        try:
            devs = ct.POINTER(ct.POINTER(usb.device))()
            cnt = usb.get_device_list(None,ct.byref(devs))
            if cnt < 0:
                return cnt
    
            print_devs(devs)
    
            usb.free_device_list(devs,1)
        finally:
            usb.exit(None)
    
        return 0
    
    
    sys.exit(main() or 0)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-