LIBUSB::ERROR_ACCESS in libusb_claim_interface
perryn opened this issue · 5 comments
whenever I try to claim an interface on my OSX machine I get the above error. Below is an irb log showing the problem. Any idea whats wrong? TIA.
> usb = LIBUSB::Context.new
=> #<LIBUSB::Context:0x007fcb428cb080 @ctx=#<FFI::Pointer address=0x007fcb4228a7a0>>
> device = usb.devices(:idVendor => 0x1294, :idProduct =>0x1320).first
=> #<LIBUSB::Device 250/6 1294:1320 MAIL MAIL ? (HID (00,00))>
> handle = device.open_interface(0)
LIBUSB::ERROR_ACCESS: LIBUSB::ERROR_ACCESS in libusb_claim_interface
from /Users/perrynfowler/.rvm/gems/ruby-1.9.3-p286/gems/libusb-0.2.2/lib/libusb/constants.rb:46:in `raise_error'
from /Users/perrynfowler/.rvm/gems/ruby-1.9.3-p286/gems/libusb-0.2.2/lib/libusb/dev_handle.rb:76:in `claim_interface'
from /Users/perrynfowler/.rvm/gems/ruby-1.9.3-p286/gems/libusb-0.2.2/lib/libusb/device.rb:77:in `block in open_interface'
from /Users/perrynfowler/.rvm/gems/ruby-1.9.3-p286/gems/libusb-0.2.2/lib/libusb/device.rb:62:in `open'
from /Users/perrynfowler/.rvm/gems/ruby-1.9.3-p286/gems/libusb-0.2.2/lib/libusb/device.rb:76:in `open_interface'
from (irb):5
from /Users/perrynfowler/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'
Using HID devices through libusb(x) is somewhat difficult on OSX. The device is usually already claimed by the hid kernel driver and detaching per detach_kernel_driver() is not possible on OSX. You may use a HID-specific API (as libhid or hidapi through a proper Ruby binding) or use libusb with a codeless kext kernel driver (seems to be an text file only). See also: https://github.com/libusbx/libusbx/wiki/FAQ#what-about-usb-hid-device-support
Unfortunately my OS-X knowledge is quite limited, so you should contact the libusbx team in case of further questions. I would be glad, if you could post your solution here, in case you found one.
hmmm, can I ask you a background question - I'm a bit confused.
So far I have managed to support all devices using libusb and usb_control_msg (with some magic numbers that apparently mean 'send data to a feature report'). I haven't needed to claim the interface to do this, so I haven't run into this problem.
With a particular device I was having trouble with this approach - and I saw something that suggested that what I needed to do was an 'interrupt write' so I tried using usb_interrupt_write. It seems to do this I do need to claim the interface.
Another thing I saw suggested that I need to send data to an 'output report' rather than a feature report.
My problem is that I don't understand the difference between any of these things- are they actually different, or are some just more low-level than others? How does HID vs non-HID fit in to this? I haven't been able to find anything to read that seems to explain this well - is there something you can point me at?
Thanks so much for any pointers you can give me
I hope this is solved, now.
I don't this is solved. I got the same error when recently trying to connect to a Extreme 3D Pro Joystick:
± irb -Ilib -rlibusb ruby-2.3.1
2.3.1 :001 > usb = LIBUSB::Context.new
=> #<LIBUSB::Context:0x007ff313800fa8 @ctx=#<FFI::Pointer address=0x007ff3114a5970>, @on_pollfd_added=nil, @on_pollfd_removed=nil, @hotplug_callbacks={}>
2.3.1 :002 > device = usb.devices(idVendor: 0x46D, idProduct: 0xC215).first
=> #<LIBUSB::Device 20/24 046d:c215 Logitech Logitech Extreme 3D ? (HID (00,00))>
2.3.1 :003 > device.open_interface(0)
LIBUSB::ERROR_ACCESS: LIBUSB::ERROR_ACCESS in libusb_claim_interface
from /Users/stefanahman/.rvm/gems/ruby-2.3.1/gems/libusb-0.5.1/lib/libusb/constants.rb:62:in `raise_error'
from /Users/stefanahman/.rvm/gems/ruby-2.3.1/gems/libusb-0.5.1/lib/libusb/dev_handle.rb:76:in `claim_interface'
from /Users/stefanahman/.rvm/gems/ruby-2.3.1/gems/libusb-0.5.1/lib/libusb/device.rb:77:in `block in open_interface'
from /Users/stefanahman/.rvm/gems/ruby-2.3.1/gems/libusb-0.5.1/lib/libusb/device.rb:62:in `open'
from /Users/stefanahman/.rvm/gems/ruby-2.3.1/gems/libusb-0.5.1/lib/libusb/device.rb:76:in `open_interface'
from (irb):3
from /Users/stefanahman/.rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>'
Also I have this problem when trying to connect to a Dymo S100 scale.