我无法通过 USB 连接树莓派和传感器

时间:2021-03-09 05:30:54

标签: python raspberry-pi usb pyusb

我用USB连接树莓派(CM3+)和传感器。 我下载并安装了pyusb。 我写了followig python代码。但是,出现错误消息。 不知道你能不能给我建议。

代码

import usb.core
import usb.util

# find our device
dev = usb.core.find(idVendor=0x0403, idProduct=0x6001)

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

错误

raise USBError(_strerror(ret), ret, _libusb_errno[ret])
   usb.core.USBError: [Errno 16] Resource busy

1 个答案:

答案 0 :(得分:0)

解决方案 1. :: 尝试使用

重置内核
dev.reset()

解决方案 2 :: 分离之前连接的任何使用缓存的设备

if dev.is_kernel_driver_active(0):
    reattach = True
    dev.detach_kernel_driver(0)