Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Raspberry Pyusb资源繁忙_Python_Usb_Hid_Pyusb_Raspberry Pi2 - Fatal编程技术网

Python Raspberry Pyusb资源繁忙

Python Raspberry Pyusb资源繁忙,python,usb,hid,pyusb,raspberry-pi2,Python,Usb,Hid,Pyusb,Raspberry Pi2,我正在尝试通过USB将我的树莓PI连接到Pic4550。(Pic功能适用于windows c#程序!)。 因此,我安装了rpi 2和pyusb,并尝试在[ 我连接到USB设备,lsusb显示: 总线001设备006:ID 04d8:0080微芯片技术公司 python程序找到设备!获取正确的配置,但无法写入消息: usb.core.USBError:[Errno 16]资源正忙 我尝试以sudo的身份运行,我添加了以下规则: SUBSYSTEM==“usb”,ATTR{idVendor}==“0

我正在尝试通过USB将我的树莓PI连接到Pic4550。(Pic功能适用于windows c#程序!)。 因此,我安装了rpi 2和pyusb,并尝试在[

我连接到USB设备,lsusb显示:

总线001设备006:ID 04d8:0080微芯片技术公司

python程序找到设备!获取正确的配置,但无法写入消息:

usb.core.USBError:[Errno 16]资源正忙

我尝试以sudo的身份运行,我添加了以下规则:

SUBSYSTEM==“usb”,ATTR{idVendor}==“04d8”,ATTR{idProduct}==“0080”, MODE=“666”

不管怎样,我得到同样的资源忙

有胶水帮助链接吗?

我从这里(不远…)找到了解决方案:

驾驶员应按如下方式分离:

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

对于像我这样的新手,我会发布我的解决方案。 总结:仔细阅读文档

Python:3.2

pyusb1.0

端点是一个HID设备

这是我的代码正常工作

import usb.core
import usb.util
import sys
from time import gmtime, strftime
import time

print ("Meteo kezdés",strftime("%Y-%m-%d %H:%M:%S", gmtime()))


# find our device
dev = usb.core.find(idVendor=0x04d8, idProduct=0x0080)

# was it found?
if dev is None:
    raise ValueError('Device not found')
else:
    print ("meteo megvan!")

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

endpoint_in = dev[0][(0,0)][0]
endpoint_out = dev[0][(0,0)][1]
#print ("endpoint_out",endpoint_out)
#print ("endpoint_in",endpoint_in)

# write the data
msg = b'\x81'

while 1:
    try:
        endpoint_out.write(msg)

        # reading
        #print ("Waiting to read...")
        #print (endpoint.bEndpointAddress)
        data = dev.read(endpoint_in.bEndpointAddress, 64, 1000)
        DHT11_H = data[0]   # a tobbi helyiertek kimaradt!!
        DHT11_R = data[4]
        BMP180_H = data[8]
        BMP180_P = (data[12]+data[13]*256+data[14]*65536)/100

        print (strftime("%Y-%m-%d %H:%M:%S", gmtime()),
        "DHT t=" , str(DHT11_H) , "C| ",
        "DHT r=", DHT11_R, "%| " ,
        "BMP t=", BMP180_H, "C| " ,
        "BMP p=", BMP180_P, "HPa"
        )
        #print (data)
        time.sleep(10)
    except usb.core.USBError:
        print ("USB error")
    except:
        print ("write failed")
# end while

# This is needed to release interface, otherwise attach_kernel_driver fails
# due to "Resource busy"
usb.util.dispose_resources(dev)

# It may raise USBError if there's e.g. no kernel driver loaded at all
if reattach:
    dev.attach_kernel_driver(0)

我使用的是Raspberry 3B+、Python 2.7,并且有完全相同的错误消息:

usb.core.USBError:[Errno 16]资源正忙


对我来说,
dev.reset()。