<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hello Everyone, <br><br>I am new to libhid and in USB device.<br><br>I have problem when I try to write and read data to the USB HID device, actually, I just want to read and write data to the USB.<br><br>When I use&nbsp; "hid_interrupt_write" and&nbsp; "hid_interrupt_read" to send and receive data, this error occured: error submitting URB: No such file or directory<br><br>But when I try to use "hid_set_output_report" and "hid_get_input_report" to write and read from the device, these error occured: error sending control message: Connection timed out. And error submitting URB: No such file or directory<br>and,&nbsp; I am not sure how to get the Usage_Path. <br>Could anyone help me in this problem? <br><br>Thanks for your help <br><br>With regards, <br><br>I Ketut Mustika Wiguna<br>Here are my source code and its result when executed:<br><br>#include
 &lt;hid.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;string.h&gt;<br><br><br>#define EP_HID_IN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x81
<br>#define EP_HID_OUT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x02<br>#define PACKET_INT_LEN&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 8<br><br>char command[8];<br>char answer[8];<br><br>const int PATHLEN = 2;<br>int const PATH_IN[2] = { 0xffff0001, 0xffff0003 };<br>int const PATH_OUT[2] = {0xffff0001, 0xffff0005 };<br><br>const int SEND_PACKET_LEN = 8;<br>const int RECV_PACKET_LEN = 8;<br><br>bool match_serial_number(struct usb_dev_handle* usbdev, void* custom, unsigned int len)<br>{<br>&nbsp; bool ret;<br>&nbsp; char* buffer = (char*)malloc(len);<br>&nbsp; usb_get_string_simple(usbdev, usb_device(usbdev)-&gt;descriptor.iSerialNumber,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buffer, len);<br>&nbsp; ret = strncmp(buffer, (char*)custom, len) == 0;<br>&nbsp; free(buffer);<br>&nbsp; return ret;<br>}<br><br>int main(void)<br>{<br>&nbsp; HIDInterface* hid;<br>&nbsp; hid_return ret;<br>&nbsp; int i = 0;<br><br>&nbsp;
 HIDInterfaceMatcher matcher = { 0x03eb, 0x4b4e, NULL, NULL, 0 };<br><br>&nbsp; /* see include/debug.h for possible values */<br>&nbsp; hid_set_debug(HID_DEBUG_ALL);<br>&nbsp; hid_set_debug_stream(stderr);<br>&nbsp; /* passed directly to libusb */<br>&nbsp; hid_set_usb_debug(1);<br>&nbsp; <br>&nbsp; ret = hid_init();<br>&nbsp; if (ret != HID_RET_SUCCESS) {<br>&nbsp;&nbsp;&nbsp; fprintf(stderr, "hid_init failed with return code %d\n", ret);<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp; }<br><br>&nbsp; hid = hid_new_HIDInterface();<br>&nbsp; if (hid == 0) {<br>&nbsp;&nbsp;&nbsp; fprintf(stderr, "hid_new_HIDInterface() failed, out of memory?\n");<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp; }<br><br>&nbsp; ret = hid_force_open(hid, 0, &amp;matcher, 3);<br>&nbsp; if (ret != HID_RET_SUCCESS) {<br>&nbsp;&nbsp;&nbsp; fprintf(stderr, "hid_force_open failed with return code %d\n", ret);<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp; }<br><br>&nbsp; ret =
 hid_write_identification(stdout, hid);<br>&nbsp; if (ret != HID_RET_SUCCESS) {<br>&nbsp;&nbsp;&nbsp; fprintf(stderr, "hid_write_identification failed with return code %d\n", ret);<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp; }<br><br>&nbsp; ret = hid_dump_tree(stdout, hid);<br>&nbsp; if (ret != HID_RET_SUCCESS) {<br>&nbsp;&nbsp;&nbsp; fprintf(stderr, "hid_dump_tree failed with return code %d\n", ret);<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp; }<br><br>&nbsp;&nbsp; // Set command,<br>&nbsp;&nbsp;&nbsp; command[0] = 0x03;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; command[1] = 0x01;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; command[2] = 0x31;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; command[3] = 0x31; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; command[4] = 0x04;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; command[5] = 0x00;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; command[6] = 0x00;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 command[7] = 0x00;<br>/*<br>&nbsp; <br>&nbsp; ret = hid_set_output_report(hid, PATH_IN, PATHLEN, command, SEND_PACKET_LEN);<br>&nbsp; if (ret != HID_RET_SUCCESS) {<br>&nbsp;&nbsp;&nbsp; fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret);<br>&nbsp; }<br>&nbsp; ret = hid_get_input_report(hid, PATH_OUT, PATHLEN, answer, RECV_PACKET_LEN);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (ret != HID_RET_SUCCESS) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(stderr, "hid_get_input_report failed with return code %d\n", ret);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; */<br>&nbsp; ret = hid_interrupt_write(hid, USB_ENDPOINT_OUT, command, PACKET_INT_LEN, 20);<br>&nbsp; if (ret &lt; 0) {<br>&nbsp; &nbsp;&nbsp;&nbsp; printf("error in interrupt write\n");<br>&nbsp; &nbsp;&nbsp;&nbsp; return 1;<br>&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; printf("Reading interrupt\n");<br>&nbsp;&nbsp;&nbsp; ret = hid_interrupt_read(hid,
 EP_HID_IN, answer, PACKET_INT_LEN, 4);<br>&nbsp;&nbsp;&nbsp; if(ret &lt; 0) {<br>&nbsp;&nbsp;&nbsp;&nbsp; printf("error interrupt read\n");<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; printf("Interrupt Transfer Loop Test Result:\n");<br>&nbsp;&nbsp;&nbsp; for(i = 0;i &lt; PACKET_INT_LEN; i++) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(i%8 == 0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("%02x; ",command[i]);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; printf("\n");<br>&nbsp;&nbsp;&nbsp; printf("\n");<br>&nbsp;&nbsp;&nbsp; for(i = 0;i &lt; PACKET_INT_LEN; i++) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(i%8 == 0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("\n");<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("%02x; ",answer[i]);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; printf("\n");<br>&nbsp;&nbsp;&nbsp;
 printf("\n");<br>&nbsp;&nbsp;&nbsp; <br>&nbsp; ret = hid_close(hid);<br>&nbsp; if (ret != HID_RET_SUCCESS) {<br>&nbsp;&nbsp;&nbsp; fprintf(stderr, "hid_close failed with return code %d\n", ret);<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp; }<br><br>&nbsp; hid_delete_HIDInterface(&amp;hid);<br><br>&nbsp; ret = hid_cleanup();<br>&nbsp; if (ret != HID_RET_SUCCESS) {<br>&nbsp;&nbsp;&nbsp; fprintf(stderr, "hid_cleanup failed with return code %d\n", ret);<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp; }<br>&nbsp; <br>&nbsp; return 0;<br>}<br><br><br>Result:<br># ./test_libhid <br>usb_set_debug: Setting debugging level to 1 (on)<br>&nbsp;NOTICE: hid_init(): libhid 0.2.15+20060325.0.0 is being initialized.<br>&nbsp; TRACE: hid_init(): initialising USB subsystem...<br>usb_os_init: Found USB VFS at /dev/bus/usb<br><br>...<br>...<br>device identification of HIDInterface 002/009[0]:<br>&nbsp; dev_handle:&nbsp;&nbsp;&nbsp; 0x09a52098<br>&nbsp;
 device:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x09a55068<br>&nbsp; location:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 002/009<br>&nbsp; manufacturer:&nbsp; ATMEL<br>&nbsp; product:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Firmware Demo<br>&nbsp; TRACE: hid_reset_parser(): resetting the HID parser for USB device 002/009[0]...<br>&nbsp; TRACE: hid_dump_tree(): iterating the parse tree for USB device 002/009[0]...<br>parse tree of HIDInterface 002/009[0]:<br>&nbsp; path: 0xffff0001.0xffff0002; type: 0x80<br>&nbsp; path: 0xffff0001.0xffff0003; type: 0x80<br>&nbsp; path: 0xffff0001.0x00000000; type: 0x80<br>&nbsp; path: 0xffff0001.0x00000000; type: 0x80<br>&nbsp; path: 0xffff0001.0x00000000; type: 0x80<br>&nbsp; path: 0xffff0001.0x00000000; type: 0x80<br>&nbsp; path: 0xffff0001.0x00000000; type: 0x80<br>&nbsp; path: 0xffff0001.0x00000000; type: 0x80<br>&nbsp; path: 0xffff0001.0xffff0004; type: 0x90<br>&nbsp; path: 0xffff0001.0xffff0005; type: 0x90<br>&nbsp; path:
 0xffff0001.0x00000000; type: 0x90<br>&nbsp; path: 0xffff0001.0x00000000; type: 0x90<br>&nbsp; path: 0xffff0001.0x00000000; type: 0x90<br>&nbsp; path: 0xffff0001.0x00000000; type: 0x90<br>&nbsp; path: 0xffff0001.0x00000000; type: 0x90<br>&nbsp; path: 0xffff0001.0x00000000; type: 0x90<br>&nbsp; path: 0xffff0001.0xffff0006; type: 0xb0<br>&nbsp; path: 0xffff0001.0xffff0007; type: 0xb0<br>&nbsp; path: 0xffff0001.0x00000000; type: 0xb0<br>&nbsp; path: 0xffff0001.0x00000000; type: 0xb0<br>&nbsp; TRACE: hid_reset_parser(): resetting the HID parser for USB device 002/009[0]...<br>&nbsp; TRACE: hid_set_output_report(): looking up report ID...<br>&nbsp; TRACE: hid_prepare_parse_path(): preparing search path of depth 2 for parse tree of USB device 002/009[0]...<br>&nbsp; TRACE: hid_prepare_parse_path(): search path prepared for parse tree of USB device 002/009[0].<br>&nbsp;NOTICE: hid_find_object(): found requested item.<br>&nbsp; TRACE: hid_set_output_report():
 sending report ID 0x00 (length: 8) to USB device 002/009[0]...<br>WARNING: hid_set_output_report(): failed to send report to USB device 002/009[0]:error sending control message: Connection timed out.<br>hid_set_output_report failed with return code 19<br>Reading interrupt<br>&nbsp; TRACE: hid_interrupt_read(): retrieving interrupt report from device 002/009[0] ...<br>WARNING: hid_interrupt_read(): failed to get interrupt read from device 002/009[0]: error submitting URB: No such file or directory<br>Interrupt Transfer Loop Test Result:<br><br>03; 01; 31; 31; 04; 00; 00; 00; <br><br><br>00; 00; 00; 00; 00; 00; 00; 00; <br><br>&nbsp; TRACE: hid_close(): closing USB device 002/009[0]...<br>&nbsp; TRACE: hid_close(): closing handle of USB device 002/009[0]...<br>&nbsp;NOTICE: hid_close(): successfully closed USB device 002/009[0].<br>&nbsp; TRACE: hid_reset_parser(): resetting the HID parser for USB device 002/009[0]...<br>&nbsp; TRACE: hid_close(): freeing
 memory allocated for HID parser...<br>&nbsp; TRACE: hid_close(): resetting HIDInterface...<br>&nbsp;NOTICE: hid_cleanup(): successfully deinitialised HID library.<br><br><br></td></tr></table><br>