I'm trying to use libusb, but I am get the following error message:
usbfs: process 24665 (myprogram) did not claim interface 0 before use
I don't really understand why, because as far as I can tell, I'm doing it according to the description found in the library. Here's my code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <libusb.h>
int main(void)
{
int result;
struct libusb_device_descriptor desc;
libusb_device **list;
libusb_device *my_device = NULL;
result = libusb_init(NULL);
libusb_set_debug(NULL, 3);
ssize_t count = libusb_get_device_list(NULL, &list);
for (int i = 0; i < count; i++) {
libusb_device *device = list[i];
result = libusb_get_device_descriptor(device, &desc);
if((desc.idVendor == 0x03f0) && (desc.idProduct == 0x241d)) {
my_device = device;
break;
}
}
if(my_device != NULL) {
libusb_device_handle *handle;
result = libusb_open(my_device, &handle);
int kernelActive = libusb_kernel_driver_active(handle, 0);
if(kernelActive == 1) {
result = libusb_detach_kernel_driver(handle, 0);
}
result = libusb_claim_interface (handle, 0);
result = libusb_control_transfer(handle,0x21,34,0x0003,0,NULL,0,0);
result = libusb_release_interface (handle, 0);
if(kernelActive == 1) {
result = libusb_attach_kernel_driver(handle, 0);
}
libusb_close(handle);
}
libusb_free_device_list(list, 1);
libusb_exit(NULL);
return EXIT_SUCCESS;
}
As you can see, I do claim the interface before the transfer. (I have tried the same code with other USB devices as well, just in case that would have something to do with it.)
I'm using libusb-1.0.9, which is the latest release I could find. I'm running this thing on Ubuntu 12.04_64 (Precise Pangolin).
sudo
? – Cesena