(Windows) PyUSB & libusb 产生 NotImplementedError

问题描述

我确实有一个 USB 温度传感器,可能有制造商自己的软件驱动程序。他们的软件不适合我的需求,所以我试图自己收集数据,并在以后需要时与他们合作。

我刚刚遇到的问题是 NotImplementedError。 错误本身:

发生异常:NotImplementedError Operation not supported or 未在此平台上实现

在处理上述异常的过程中,又发生了一个异常:

文件“C:\Users\NAME\OneDrive - NAME\Documents\Senzor Python\recv_usb_push_db.py”,第 183 行,在 ret = dev.read(ep_in.bEndpointAddress,REPLY_BYTES_LENGTH,timeout=REPLY_TIMEOUT_MS)

考虑以下代码

import usb.core
import usb.util
import usb.backend.libusb1

def find_device_usb():
    backend = usb.backend.libusb1.get_backend(find_library=lambda x: 'C:\\Users\\NAME\\AppData\\Local\\Programs\\Python\\python39\\Lib\\site-packages\\libusb\\_platform\\_windows\\x64\\libusb-1.0.dll')
    return usb.core.find(idvendor = IDvendOR,idProduct = IDPRODUCT,backend=backend)
    
def find_ep(intf,direction):
    ep = usb.util.find_descriptor(
        intf,# match the first OUT endpoint
        custom_match = \
        lambda e: \
            usb.util.endpoint_direction(e.bEndpointAddress) == \
            direction)
    return ep

# find our device
dev = find_device_usb()

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

# if dev.is_kernel_driver_active(0): # -> error here
#     dev.detach_kernel_driver(0) # -> error here
# dev.set_configuration() # -> error here

cfg = dev[0]
intf = cfg[(0,0)]

# direction relevant from the pc POV (out - write to USB,in - read from USB)
ep_out = find_ep(intf,usb.util.ENDPOINT_OUT)
ep_in = find_ep(intf,usb.util.ENDPOINT_IN)
assert ep_out is not None
assert ep_in is not None

ret = dev.read(ep_in.bEndpointAddress,timeout=REPLY_TIMEOUT_MS) # -> error here

我怀疑 dev 中的每个函数变量(attach_kernel_driver、clear_halt、configuration、ctrl_transfer、detach_kernel_driver、finalize、get_active_configuration、is_kernel_driver_active、read、reset、set_configuration、set_interface_altsetting、write)都会产生相同的错误

>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)