0

I'm trying to get value from a barcode scanner, this with pyusb on Ubuntu. After investigations, I found that the barcode scanner need to receive an activation data to be able to scan barcode. I found this data, modify my rules.d file in order to detect my device and then I ran this code to send the data through 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')

I get the following error:

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

But normally the following code must made the device available:

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

I tryed this code with another device (printer) and it's working.

Do you have any idea concerrning the problem?

Majonsi
  • 384
  • 1
  • 4
  • 17
  • First I have to say I am not familiar with PyUSB but only libusb. So I don't know if this works with exceptions instead but if not I wonder whether dev.detach_kernel_driver(0) is executed and if yes what it returns because it may return an error. Besides it would be interesting on which line the Errno16 occurs. – dryman Feb 26 '16 at 10:40

1 Answers1

1

I found the solution.

The problem was that usbhid driver use directly the device. So after desactivation of the drive I'm able to use it.

Majonsi
  • 384
  • 1
  • 4
  • 17