简体   繁体   English

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

[英]I can't connect raspberry pi and sensor by USB

I connect raspberry Pi(CM3+) with sensor by USB.我通过 USB 将树莓派(CM3+)与传感器连接起来。 I download and install pyusb.我下载并安装pyusb。 I write the followig python codes.But, error massage appear.我写了以下 python 代码。但是,出现错误消息。 I wonder if you could give me advices.我想知道你是否可以给我一些建议。

codes代码

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

error错误

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

Solution 1. :: Try to Reset the kernel using解决方案 1. :: 尝试使用重置 kernel

dev.reset()

Solution 2 :: Detach if any devices previously attached that are cached using解决方案 2 :: 如果之前连接的任何设备使用缓存,则分离

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM