Pyusb:Ressource busy / USB条形码扫描仪

时间:2016-02-24 09:18:48

标签: python usb reverse-engineering libusb pyusb

我正试图从条形码扫描仪获得价值,这与Ubuntu上的pyusb有关。经过调查,我发现条形码扫描仪需要接收激活数据才能扫描条形码。我找到了这个数据,修改了我的rules.d文件以便检测我的设备,然后运行这段代码通过USB发送数据:

import usb.core
import usb.util

# find our device
dev = usb.core.find(idVendor=0x05f9, idProduct=0x1203)

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

# Attach and detach the usb
if dev.is_kernel_driver_active(0):
    dev.detach_kernel_driver(0)

# 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('\x0b')

我收到以下错误:

usb.core.USBError: [Errno 16] Resource busy

但通常以下代码必须使设备可用:

# Attach and detach the usb
    if dev.is_kernel_driver_active(0):
        dev.detach_kernel_driver(0)

我用其他设备(打印机)试用了这个代码,它正在运行。

你有任何关于这个问题的想法吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。

问题是usbhid驱动程序直接使用该设备。因此,在停用驱动器后,我可以使用它。

相关问题