搜索
bottom↓
回复: 7

用pyusb模块 dev.get_active_configuration()错误

[复制链接]

出0入0汤圆

发表于 2016-2-19 10:13:18 | 显示全部楼层 |阅读模式
源代码为:
import usb.core
import usb.util
import sys
dev =  usb.core.find(idVendor= 0x0781, idProduct= 0x5567)
if dev is None:
    raise ValueError('Device not found')
print(dev)
# set the active configuration. With no arguments, the first
# configuration will be the active one

cfg = dev.get_active_configuration()

结果为:
<usb.core.Device object at 0x01155AD0>
Traceback (most recent call last):
  File "C:\Documents and Settings\Administrator\桌面\新建文件夹 (3)\123.py", line 11, in <module>
    cfg = dev.get_active_configuration()
  File "C:\Python33\lib\site-packages\usb\core.py", line 558, in get_active_configuration
    return self._ctx.get_active_configuration(self)
  File "C:\Python33\lib\site-packages\usb\core.py", line 163, in get_active_configuration
    self.managed_open()
  File "C:\Python33\lib\site-packages\usb\core.py", line 70, in managed_open
    self.handle = self.backend.open_device(self.dev)
  File "C:\Python33\lib\site-packages\usb\backend\libusb1.py", line 494, in open_device
    _check(_lib.libusb_open(dev.devid, byref(handle)))
  File "C:\Python33\lib\site-packages\usb\backend\libusb1.py", line 403, in _check
    raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno 40] Operation not supported or unimplemented on this platform
>>>
请问是什么问题?

阿莫论坛20周年了!感谢大家的支持与爱护!!

你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。

出0入0汤圆

发表于 2016-2-19 14:01:55 | 显示全部楼层
沒看到你做dev.set_configuration()

出0入0汤圆

 楼主| 发表于 2016-2-19 14:45:45 | 显示全部楼层
Jach 发表于 2016-2-19 14:01
沒看到你做dev.set_configuration()

dev.set_configuration()加之后还是同样的错误
import usb.core
import usb.util
import sys

dev =  usb.core.find(idVendor= 0x0781, idProduct= 0x5567)   
if dev is None:
    raise ValueError('Device not found')
print(dev)
# set the active configuration. With no arguments, the first
# configuration will be the active one

dev.set_configuration()

# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]

ep = usb.util.find_descriptor(
    intf,
    # match the first OUT endpoint
    custom_match = \
    lambda e: \
        usb.util.endpoint_direction(e.bEndpointAddress) == \
        usb.util.ENDPOINT_OUT)

assert ep is not None

# write the data
ep.write('test')


<usb.core.Device object at 0x01142AF0>
Traceback (most recent call last):
  File "C:\Documents and Settings\Administrator\桌面\新建文件夹 (3)\123.py", line 12, in <module>
    dev.set_configuration()
  File "C:\Python33\lib\site-packages\usb\core.py", line 554, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "C:\Python33\lib\site-packages\usb\core.py", line 91, in managed_set_configuration
    self.managed_open()
  File "C:\Python33\lib\site-packages\usb\core.py", line 70, in managed_open
    self.handle = self.backend.open_device(self.dev)
  File "C:\Python33\lib\site-packages\usb\backend\libusb1.py", line 494, in open_device
    _check(_lib.libusb_open(dev.devid, byref(handle)))
  File "C:\Python33\lib\site-packages\usb\backend\libusb1.py", line 403, in _check
    raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno 40] Operation not supported or unimplemented on this platform

出0入0汤圆

发表于 2016-2-19 15:41:46 | 显示全部楼层
楼主是PYTHON3,看看第三方的是否支持?
有的是支持2.7,里面数据ASCII,不是UTF-8

出0入0汤圆

发表于 2016-2-19 16:20:21 | 显示全部楼层
你用的pyusb是哪個版本? 怎麼core.py裏的那些line number位置和我差的蠻多的.

出0入0汤圆

 楼主| 发表于 2016-2-19 16:24:43 | 显示全部楼层
本帖最后由 pll19840511 于 2016-2-19 16:25 编辑
Jach 发表于 2016-2-19 16:20
你用的pyusb是哪個版本? 怎麼core.py裏的那些line number位置和我差的蠻多的.


用的1.0.0,python3.3,windowxp ,刚重装了最新的beta测试版本pyusb,发现好像设备信息都出来了,你用的什么版本,python版本,平台是linux还是windowsxp什么的?
DEVICE ID 0ac8:0345 on Bus 008 Address 001 =================
bLength                :   0x12 (18 bytes)
bDescriptorType        :    0x1 Device
bcdUSB                 :  0x200 USB 2.0
bDeviceClass           :   0xef Miscellaneous
bDeviceSubClass        :    0x2
bDeviceProtocol        :    0x1
bMaxPacketSize0        :   0x40 (64 bytes)
idVendor               : 0x0ac8
idProduct              : 0x0345
bcdDevice              : 0x2032 Device 32.32
iManufacturer          :    0x1 Error Accessing String
iProduct               :    0x2 Error Accessing String
iSerialNumber          :    0x0
bNumConfigurations     :    0x1
  CONFIGURATION 1: 500 mA ==================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :  0x1c5 (453 bytes)
   bNumInterfaces       :    0x2
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0
   bmAttributes         :   0x80 Bus Powered
   bMaxPower            :   0xfa (500 mA)
    INTERFACE 0: Video =====================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0xe Video
     bInterfaceSubClass :    0x1
     bInterfaceProtocol :    0x0
     iInterface         :    0x4 Error Accessing String
      ENDPOINT 0x81: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x81 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x10 (16 bytes)
       bInterval        :    0x7
    INTERFACE 1: Video =====================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x1
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x0
     bInterfaceClass    :    0xe Video
     bInterfaceSubClass :    0x2
     bInterfaceProtocol :    0x0
     iInterface         :    0x4 Error Accessing String
    INTERFACE 1, 1: Video ==================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x1
     bAlternateSetting  :    0x1
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0xe Video
     bInterfaceSubClass :    0x2
     bInterfaceProtocol :    0x0
     iInterface         :    0x4 Error Accessing String
      ENDPOINT 0x82: Isochronous IN ========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x82 IN
       bmAttributes     :    0x5 Isochronous
       wMaxPacketSize   : 0x1400 (5120 bytes)
       bInterval        :    0x1
    INTERFACE 1, 2: Video ==================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x1
     bAlternateSetting  :    0x2
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0xe Video
     bInterfaceSubClass :    0x2
     bInterfaceProtocol :    0x0
     iInterface         :    0x4 Error Accessing String
      ENDPOINT 0x82: Isochronous IN ========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x82 IN
       bmAttributes     :    0x5 Isochronous
       wMaxPacketSize   :  0xc00 (3072 bytes)
       bInterval        :    0x1
    INTERFACE 1, 3: Video ==================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x1
     bAlternateSetting  :    0x3
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0xe Video
     bInterfaceSubClass :    0x2
     bInterfaceProtocol :    0x0
     iInterface         :    0x4 Error Accessing String
      ENDPOINT 0x82: Isochronous IN ========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x82 IN
       bmAttributes     :    0x5 Isochronous
       wMaxPacketSize   :  0x400 (1024 bytes)
       bInterval        :    0x1
    INTERFACE 1, 4: Video ==================================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x1
     bAlternateSetting  :    0x4
     bNumEndpoints      :    0x1
     bInterfaceClass    :    0xe Video
     bInterfaceSubClass :    0x2
     bInterfaceProtocol :    0x0
     iInterface         :    0x4 Error Accessing String
      ENDPOINT 0x82: Isochronous IN ========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x82 IN
       bmAttributes     :    0x5 Isochronous
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x1
Traceback (most recent call last):
  File "C:\Documents and Settings\Administrator\桌面\新建文件夹 (3)\123.py", line 13, in <module>
    dev.set_configuration()
  File "C:\Python33\lib\site-packages\usb\core.py", line 799, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "C:\Python33\lib\site-packages\usb\core.py", line 128, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "C:\Python33\lib\site-packages\usb\backend\libusb1.py", line 730, in set_configuration
    _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
  File "C:\Python33\lib\site-packages\usb\backend\libusb1.py", line 552, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 2] Entity not found

出0入0汤圆

发表于 2016-2-19 17:56:44 | 显示全部楼层
我(也)是1.0.0 (beta2), Python 3.4.3, Win7.

有進步了, 過了open()這一關.
但是, 怎麼印出來的裝置和你要的不合? 你的裝置是自己做的嗎?

出0入0汤圆

发表于 2019-11-16 09:28:53 | 显示全部楼层
这个问题解决了么 因为什么啊
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-9-28 15:23

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表