From: Brian N. <br...@tw...> - 2005-05-23 00:17:53
|
Still having the same issues, here's a little more detail: I'm running a recent Linux 2.6 kernel. I have a HID device, shows up as a joystick (which it should). I need to send a short two-byte control message to the device for configuration. The problem I'm having is the usb_claim_interface call fails because it's already claimed by the usbhid driver. I can disconnect it from the driver and the code works fine, but that's not what I want to do, because I want to maintain the joystick functionality that I already have. I've attached my code and the output from it below. Is this going to be possible? Do I need to investigate other methods of communicating with the device, like hiddev or perhaps something on an even lower level? I haven't done a ton of research, but I understand it might be possible to write to the device directly thorough the /proc/bus/usb/XXX/YYY file? This process works fine under Windows, so I'm not sure where to go from here under Linux. Thanks for any suggestions that anyone can offer. -Brian Program output (as root): usb_set_debug: Setting debugging level to 8 (on) usb_os_find_busses: Found 004 usb_os_find_busses: Found 003 usb_os_find_busses: Found 002 usb_os_find_busses: Found 001 usb_os_find_busses: Skipping non bus directory devices usb_os_find_devices: Found 001 on 004 usb_os_find_devices: Found 001 on 003 usb_os_find_devices: Found 001 on 002 usb_os_find_devices: Found 002 on 001 skipped 1 class/vendor specific interface descriptors usb_os_find_devices: Found 001 on 001 Check that you have permissions to write to 001/002 and, if you don't, that you set up hotplug (http://linux-hotplug.sourceforge.net/) correctly. USB error: could not claim interface 0: Device or resource busy USB error: error sending control message: Device or resource busy usb_claim_interface error: could not claim interface 0: Device or resource busy msg return: -16 | error sending control message: Device or resource busy The code: #include <usb.h> int main(void) { struct usb_bus *busses; struct usb_bus *bus; struct usb_device *dev; usb_dev_handle *usb_handle; int ret; unsigned char command[2] = {0xCC, 0x03}; usb_init(); usb_set_debug(8); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for (bus = busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if (dev->descriptor.idVendor == 0xFAFA) { usb_handle = usb_open(dev); if(usb_handle) { if (usb_set_configuration(usb_handle, dev->config->bConfigurationValue)) { printf("usb_set_configuration error: %s\n", usb_strerror()); } usb_set_altinterface(usb_handle, 0); if (usb_claim_interface(usb_handle, 0) < 0) { printf("usb_claim_interface error: %s\n", usb_strerror()); } ret = usb_control_msg(usb_handle, 0x21, // Set_Report request (page 52 HID Spec) 0x09, // SET_REPORT (Top Remarks page 51) 0x200, // (Bottom Remarks section page 51) 0x00, // Interface 0 command, // Buffer for characters to transmit 0x02, // Size of message 10); // Milliseconds of timeout printf("msg return: %d | %s\n", ret, ret < 0 ? usb_strerror() : "<no error>"); usb_close(usb_handle); } else { printf("Error opening device.\n"); } } } } } |