On Mon, 22 Feb 2016 09:20:12 +0800
Post by Xiaofan ChenPost by John Coppens- In C, I have code that detaches the kernel driver if necessary. Is this necessary
here? I didn't find any reference in the tutorial.
Yes, if there is a kernel driver (except usbfs) bind to the device.
Thanks for the reply, Xiaofan.
I added:
if dev.is_kernel_driver_active(1):
dev.detach_kernel_driver(1)
print("Kernel detached")
but it didn't make much difference (see below)
Post by Xiaofan ChenYou can set LIBUSB_DEBUG=4 before running your pyusb program
and then post the verbose libusb debug info.
Here's the full debug output. Note that there is a 5 second wait before the set_configuration
times out (is this the default value?).
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000001] [000003da] libusb: debug [libusb_init] created default context
[ 0.000041] [000003da] libusb: debug [libusb_init] libusb v1.0.20.11004
[ 0.000062] [000003da] libusb: debug [find_usbfs_path] found usbfs at /dev/bus/usb
[ 0.000079] [000003da] libusb: debug [op_init] bulk continuation flag supported
[ 0.000088] [000003da] libusb: debug [op_init] zero length packet flag supported
[ 0.000103] [000003da] libusb: debug [op_init] sysfs can relate devices
[ 0.000112] [000003da] libusb: debug [op_init] sysfs has complete descriptors
[ 0.000354] [0000041b] libusb: debug [linux_udev_event_thread_main] udev event thread entering.
[ 0.000782] [000003da] libusb: debug [linux_get_device_address] getting address for device: usb3 detached: 0
[ 0.000803] [000003da] libusb: debug [linux_get_device_address] scan usb3
[ 0.000856] [000003da] libusb: debug [linux_get_device_address] bus=3 dev=1
[ 0.000869] [000003da] libusb: debug [linux_enumerate_device] busnum 3 devaddr 1 session_id 769
[ 0.000880] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 3/1 (session 769)
[ 0.000988] [000003da] libusb: debug [linux_get_device_address] getting address for device: 3-1 detached: 0
[ 0.001002] [000003da] libusb: debug [linux_get_device_address] scan 3-1
[ 0.001052] [000003da] libusb: debug [linux_get_device_address] bus=3 dev=2
[ 0.001064] [000003da] libusb: debug [linux_enumerate_device] busnum 3 devaddr 2 session_id 770
[ 0.001074] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 3/2 (session 770)
[ 0.001119] [000003da] libusb: debug [linux_get_parent_info] Dev 0x1d29300 (3-1) has parent 0x1d29240 (usb3) port 1
[ 0.001200] [000003da] libusb: debug [linux_get_device_address] getting address for device: usb4 detached: 0
[ 0.001212] [000003da] libusb: debug [linux_get_device_address] scan usb4
[ 0.001261] [000003da] libusb: debug [linux_get_device_address] bus=4 dev=1
[ 0.001274] [000003da] libusb: debug [linux_enumerate_device] busnum 4 devaddr 1 session_id 1025
[ 0.001284] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 4/1 (session 1025)
[ 0.001400] [000003da] libusb: debug [linux_get_device_address] getting address for device: usb1 detached: 0
[ 0.001413] [000003da] libusb: debug [linux_get_device_address] scan usb1
[ 0.001465] [000003da] libusb: debug [linux_get_device_address] bus=1 dev=1
[ 0.001487] [000003da] libusb: debug [linux_enumerate_device] busnum 1 devaddr 1 session_id 257
[ 0.001496] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 1/1 (session 257)
[ 0.001582] [000003da] libusb: debug [linux_get_device_address] getting address for device: 1-2 detached: 0
[ 0.001593] [000003da] libusb: debug [linux_get_device_address] scan 1-2
[ 0.001636] [000003da] libusb: debug [linux_get_device_address] bus=1 dev=3
[ 0.001644] [000003da] libusb: debug [linux_enumerate_device] busnum 1 devaddr 3 session_id 259
[ 0.001652] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 1/3 (session 259)
[ 0.001691] [000003da] libusb: debug [linux_get_parent_info] Dev 0x1d29f10 (1-2) has parent 0x1d29e50 (usb1) port 2
[ 0.001760] [000003da] libusb: debug [linux_get_device_address] getting address for device: 1-3 detached: 0
[ 0.001769] [000003da] libusb: debug [linux_get_device_address] scan 1-3
[ 0.001812] [000003da] libusb: debug [linux_get_device_address] bus=1 dev=4
[ 0.001820] [000003da] libusb: debug [linux_enumerate_device] busnum 1 devaddr 4 session_id 260
[ 0.001828] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 1/4 (session 260)
[ 0.001866] [000003da] libusb: debug [linux_get_parent_info] Dev 0x1d2b060 (1-3) has parent 0x1d29e50 (usb1) port 3
[ 0.001910] [000003da] libusb: debug [linux_get_device_address] getting address for device: 1-3.1 detached: 0
[ 0.001920] [000003da] libusb: debug [linux_get_device_address] scan 1-3.1
[ 0.001962] [000003da] libusb: debug [linux_get_device_address] bus=1 dev=6
[ 0.001970] [000003da] libusb: debug [linux_enumerate_device] busnum 1 devaddr 6 session_id 262
[ 0.001978] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 1/6 (session 262)
[ 0.002016] [000003da] libusb: debug [linux_get_parent_info] Dev 0x1d2b510 (1-3.1) has parent 0x1d2b060 (1-3) port 1
[ 0.002070] [000003da] libusb: debug [linux_get_device_address] getting address for device: 1-3.1.4 detached: 0
[ 0.002079] [000003da] libusb: debug [linux_get_device_address] scan 1-3.1.4
[ 0.002126] [000003da] libusb: debug [linux_get_device_address] bus=1 dev=10
[ 0.002134] [000003da] libusb: debug [linux_enumerate_device] busnum 1 devaddr 10 session_id 266
[ 0.002142] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 1/10 (session 266)
[ 0.002180] [000003da] libusb: debug [linux_get_parent_info] Dev 0x1d2b9c0 (1-3.1.4) has parent 0x1d2b510 (1-3.1) port 4
[ 0.002290] [000003da] libusb: debug [linux_get_device_address] getting address for device: 1-3.4 detached: 0
[ 0.002301] [000003da] libusb: debug [linux_get_device_address] scan 1-3.4
[ 0.002344] [000003da] libusb: debug [linux_get_device_address] bus=1 dev=7
[ 0.002353] [000003da] libusb: debug [linux_enumerate_device] busnum 1 devaddr 7 session_id 263
[ 0.002361] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 1/7 (session 263)
[ 0.002414] [000003da] libusb: debug [linux_get_parent_info] Dev 0x1d2be90 (1-3.4) has parent 0x1d2b060 (1-3) port 4
[ 0.002645] [000003da] libusb: debug [linux_get_device_address] getting address for device: usb5 detached: 0
[ 0.002657] [000003da] libusb: debug [linux_get_device_address] scan usb5
[ 0.002705] [000003da] libusb: debug [linux_get_device_address] bus=5 dev=1
[ 0.002716] [000003da] libusb: debug [linux_enumerate_device] busnum 5 devaddr 1 session_id 1281
[ 0.002726] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 5/1 (session 1281)
[ 0.002841] [000003da] libusb: debug [linux_get_device_address] getting address for device: usb6 detached: 0
[ 0.002853] [000003da] libusb: debug [linux_get_device_address] scan usb6
[ 0.002911] [000003da] libusb: debug [linux_get_device_address] bus=6 dev=1
[ 0.002923] [000003da] libusb: debug [linux_enumerate_device] busnum 6 devaddr 1 session_id 1537
[ 0.002933] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 6/1 (session 1537)
[ 0.003055] [000003da] libusb: debug [linux_get_device_address] getting address for device: usb2 detached: 0
[ 0.003068] [000003da] libusb: debug [linux_get_device_address] scan usb2
[ 0.003116] [000003da] libusb: debug [linux_get_device_address] bus=2 dev=1
[ 0.003129] [000003da] libusb: debug [linux_enumerate_device] busnum 2 devaddr 1 session_id 513
[ 0.003139] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 2/1 (session 513)
[ 0.003241] [000003da] libusb: debug [linux_get_device_address] getting address for device: 2-2 detached: 0
[ 0.003251] [000003da] libusb: debug [linux_get_device_address] scan 2-2
[ 0.003292] [000003da] libusb: debug [linux_get_device_address] bus=2 dev=2
[ 0.003300] [000003da] libusb: debug [linux_enumerate_device] busnum 2 devaddr 2 session_id 514
[ 0.003308] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 2/2 (session 514)
[ 0.003344] [000003da] libusb: debug [linux_get_parent_info] Dev 0x1d2d1b0 (2-2) has parent 0x1d2cce0 (usb2) port 2
[ 0.003428] [000003da] libusb: debug [linux_get_device_address] getting address for device: usb7 detached: 0
[ 0.003441] [000003da] libusb: debug [linux_get_device_address] scan usb7
[ 0.003482] [000003da] libusb: debug [linux_get_device_address] bus=7 dev=1
[ 0.003490] [000003da] libusb: debug [linux_enumerate_device] busnum 7 devaddr 1 session_id 1793
[ 0.003498] [000003da] libusb: debug [linux_enumerate_device] allocating new device for 7/1 (session 1793)
[ 0.003573] [000003da] libusb: debug [usbi_add_pollfd] add fd 6 events 1
[ 0.003585] [000003da] libusb: debug [usbi_io_init] using timerfd for timeouts
[ 0.003593] [000003da] libusb: debug [usbi_add_pollfd] add fd 9 events 1
[ 0.003670] [000003da] libusb: debug [libusb_get_device_list]
[ 0.003684] [000003da] libusb: debug [discovered_devs_append] need to increase capacity
[ 0.003745] [000003da] libusb: debug [libusb_get_device_descriptor]
[ 0.003888] [000003da] libusb: debug [libusb_get_device_descriptor]
[ 0.003993] [000003da] libusb: debug [libusb_get_device_descriptor]
[ 0.004058] [000003da] libusb: debug [libusb_get_device_descriptor]
[ 0.004123] [000003da] libusb: debug [libusb_get_device_descriptor]
[ 0.004187] [000003da] libusb: debug [libusb_get_device_descriptor]
[ 0.004252] [000003da] libusb: debug [libusb_get_device_descriptor]
[ 0.004330] [000003da] libusb: debug [libusb_get_config_descriptor] index 0
1
[ 0.004435] [000003da] libusb: debug [libusb_get_config_descriptor] index 0
0,0
[ 0.004545] [000003da] libusb: debug [libusb_get_config_descriptor] index 0
129
[ 0.004637] [000003da] libusb: debug [libusb_get_config_descriptor] index 0
1
[ 0.004726] [000003da] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.004783] [000003da] libusb: debug [libusb_open] open 1.10
[ 0.004810] [000003da] libusb: debug [usbi_add_pollfd] add fd 10 events 4
[ 0.004829] [000003da] libusb: debug [libusb_kernel_driver_active] interface 1
[ 0.004853] [000003da] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.004911] [000003da] libusb: debug [libusb_set_configuration] configuration 1
[ 5.004752] [000003da] libusb: error [op_set_configuration] failed, error -1 errno 110
Traceback (most recent call last):
File "./test_pyusb.py", line 82, in <module>
sys.exit(main(sys.argv))
File "./test_pyusb.py", line 73, in main
dev.set_configuration()
File "/usr/lib64/python2.7/site-packages/usb/core.py", line 819, in set_configuration
self._ctx.managed_set_configuration(self, configuration)
File "/usr/lib64/python2.7/site-packages/usb/core.py", line 129, in managed_set_configuration
self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
File "/usr/lib64/python2.7/site-packages/usb/backend/libusb1.py", line 786, in set_configuration
_check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
File "/usr/lib64/python2.7/site-packages/usb/backend/libusb1.py", line 592, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno None] Other error
[ 5.007842] [000003da] libusb: debug [libusb_close]
[ 5.007861] [000003da] libusb: debug [usbi_remove_pollfd] remove fd 10
[ 5.007894] [000003da] libusb: debug [libusb_exit]
[ 5.007904] [000003da] libusb: debug [libusb_exit] destroying default context
[ 5.007915] [000003da] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 5.007925] [000003da] libusb: debug [handle_events] poll fds modified, reallocating
[ 5.007937] [000003da] libusb: debug [handle_events] poll() 2 fds with timeout in 0ms
[ 5.007947] [000003da] libusb: debug [handle_events] poll() returned 0
[ 5.007957] [000003da] libusb: debug [libusb_unref_device] destroy device 7.1
[ 5.007967] [000003da] libusb: debug [libusb_unref_device] destroy device 2.2
[ 5.007975] [000003da] libusb: debug [libusb_unref_device] destroy device 2.1
[ 5.007984] [000003da] libusb: debug [libusb_unref_device] destroy device 6.1
[ 5.007992] [000003da] libusb: debug [libusb_unref_device] destroy device 5.1
[ 5.008002] [000003da] libusb: debug [libusb_unref_device] destroy device 1.7
[ 5.008011] [000003da] libusb: debug [libusb_unref_device] destroy device 1.10
[ 5.008019] [000003da] libusb: debug [libusb_unref_device] destroy device 1.6
[ 5.008028] [000003da] libusb: debug [libusb_unref_device] destroy device 1.4
[ 5.008037] [000003da] libusb: debug [libusb_unref_device] destroy device 1.3
[ 5.008047] [000003da] libusb: debug [libusb_unref_device] destroy device 1.1
[ 5.008056] [000003da] libusb: debug [libusb_unref_device] destroy device 4.1
[ 5.008065] [000003da] libusb: debug [libusb_unref_device] destroy device 3.2
[ 5.008074] [000003da] libusb: debug [libusb_unref_device] destroy device 3.1
[ 5.008083] [000003da] libusb: debug [usbi_remove_pollfd] remove fd 6
[ 5.008098] [000003da] libusb: debug [usbi_remove_pollfd] remove fd 9
[ 5.008129] [0000041b] libusb: debug [linux_udev_event_thread_main] udev event thread exiting