RPi Cant通过PyUSB连接到USB设备

时间:2020-10-09 04:19:58

标签: python pyusb libusb-1.0 pyvisa

我正在尝试与树莓派(32位raspbian 10内核:5.4.51-v7 +)上的设备进行一些基本的USB通信。

我正在逐字运行PyUSB代码:

# find our device
dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001)

# was it found?
if dev is None:
    raise ValueError('Device not found')

# 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')

我收到以下错误:

Traceback (most recent call last):
  File "USB Testing.py", line 36, in <module>
    ep.write('test')
  File "/usr/lib/python3/dist-packages/usb/core.py", line 387, in write
    return self.device.write(self, data, timeout)
  File "/usr/lib/python3/dist-packages/usb/core.py", line 948, in write
    self.__get_timeout(timeout)
  File "/usr/lib/python3/dist-packages/usb/backend/libusb1.py", line 824, in bulk_write
    timeout)
  File "/usr/lib/python3/dist-packages/usb/backend/libusb1.py", line 920, in __write
    _check(retval)
  File "/usr/lib/python3/dist-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error

我可以看到设备/接口/端点:

DEVICE ID 1ab1:0641 on Bus 001 Address 006 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x200 USB 2.0
 bDeviceClass           :    0x0 Specified at interface
 bDeviceSubClass        :    0x0
 bDeviceProtocol        :    0x0
 bMaxPacketSize0        :   0x40 (64 bytes)
 idVendor               : 0x1ab1
 idProduct              : 0x0641
 bcdDevice              :  0x101 Device 1.01
 iManufacturer          :    0x1 Rigol Technologies  
 iProduct               :    0x2 DG4102
 iSerialNumber          :    0x3 DG4E191300534
 bNumConfigurations     :    0x1
  CONFIGURATION 1: 2 mA ====================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x27 (39 bytes)
   bNumInterfaces       :    0x1
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0 
   bmAttributes         :   0xc0 Self Powered
   bMaxPower            :    0x1 (2 mA)
    INTERFACE 0: Application Specific ======================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x3
     bInterfaceClass    :   0xfe Application Specific
     bInterfaceSubClass :    0x3
     bInterfaceProtocol :    0x1
     iInterface         :    0x0 
      ENDPOINT 0x88: Interrupt IN ==========================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x88 IN
       bmAttributes     :    0x3 Interrupt
       wMaxPacketSize   :   0x40 (64 bytes)
       bInterval        :    0xb
      ENDPOINT 0x2: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x2 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x86: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x86 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0

我尝试了一些额外的操作,包括分离内核驱动程序和显式声明接口,以及显式使用libusb1后端。所有人都给管道带来了问题,所以我假设我缺少一些简单的东西或与硬件有关的东西。

我可以在Windows VISA上看到它并打开/对话,但是pi的PyVISA抛出:

Found a device whose serial number cannot be read. The partial VISA resource name is: USB0::6833::1601::???::0::INSTR

我收到ValueError:尝试通过PyVISA打开设备时,设备没有出现兰蒂德错误。

看一下pi的Wireshk捕获,GET DESCRIPTOR Request DEVICE的URB状态为-EINPROGRESS -115,这似乎是错误的。如果有帮助,我可以提供完整的Wireshk捕获。

小修改: 这不是特定于测试设备的

0 个答案:

没有答案