<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 "hid_interrupt_write" and "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, 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
<hid.h><br>#include <stdio.h><br>#include <string.h><br><br><br>#define EP_HID_IN 0x81
<br>#define EP_HID_OUT 0x02<br>#define PACKET_INT_LEN 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> bool ret;<br> char* buffer = (char*)malloc(len);<br> usb_get_string_simple(usbdev, usb_device(usbdev)->descriptor.iSerialNumber,<br> buffer, len);<br> ret = strncmp(buffer, (char*)custom, len) == 0;<br> free(buffer);<br> return ret;<br>}<br><br>int main(void)<br>{<br> HIDInterface* hid;<br> hid_return ret;<br> int i = 0;<br><br>
HIDInterfaceMatcher matcher = { 0x03eb, 0x4b4e, NULL, NULL, 0 };<br><br> /* see include/debug.h for possible values */<br> hid_set_debug(HID_DEBUG_ALL);<br> hid_set_debug_stream(stderr);<br> /* passed directly to libusb */<br> hid_set_usb_debug(1);<br> <br> ret = hid_init();<br> if (ret != HID_RET_SUCCESS) {<br> fprintf(stderr, "hid_init failed with return code %d\n", ret);<br> return 1;<br> }<br><br> hid = hid_new_HIDInterface();<br> if (hid == 0) {<br> fprintf(stderr, "hid_new_HIDInterface() failed, out of memory?\n");<br> return 1;<br> }<br><br> ret = hid_force_open(hid, 0, &matcher, 3);<br> if (ret != HID_RET_SUCCESS) {<br> fprintf(stderr, "hid_force_open failed with return code %d\n", ret);<br> return 1;<br> }<br><br> ret =
hid_write_identification(stdout, hid);<br> if (ret != HID_RET_SUCCESS) {<br> fprintf(stderr, "hid_write_identification failed with return code %d\n", ret);<br> return 1;<br> }<br><br> ret = hid_dump_tree(stdout, hid);<br> if (ret != HID_RET_SUCCESS) {<br> fprintf(stderr, "hid_dump_tree failed with return code %d\n", ret);<br> return 1;<br> }<br><br> // Set command,<br> command[0] = 0x03;<br> command[1] = 0x01; <br> command[2] = 0x31;<br> command[3] = 0x31; <br> command[4] = 0x04;<br> command[5] = 0x00;<br> command[6] = 0x00;<br>
command[7] = 0x00;<br>/*<br> <br> ret = hid_set_output_report(hid, PATH_IN, PATHLEN, command, SEND_PACKET_LEN);<br> if (ret != HID_RET_SUCCESS) {<br> fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret);<br> }<br> ret = hid_get_input_report(hid, PATH_OUT, PATHLEN, answer, RECV_PACKET_LEN);<br> if (ret != HID_RET_SUCCESS) {<br> fprintf(stderr, "hid_get_input_report failed with return code %d\n", ret);<br> }<br> */<br> ret = hid_interrupt_write(hid, USB_ENDPOINT_OUT, command, PACKET_INT_LEN, 20);<br> if (ret < 0) {<br> printf("error in interrupt write\n");<br> return 1;<br> }<br> printf("Reading interrupt\n");<br> ret = hid_interrupt_read(hid,
EP_HID_IN, answer, PACKET_INT_LEN, 4);<br> if(ret < 0) {<br> printf("error interrupt read\n");<br> return 1;<br> }<br> <br> printf("Interrupt Transfer Loop Test Result:\n");<br> for(i = 0;i < PACKET_INT_LEN; i++) {<br> if(i%8 == 0)<br> printf("\n");<br> printf("%02x; ",command[i]);<br> }<br> printf("\n");<br> printf("\n");<br> for(i = 0;i < PACKET_INT_LEN; i++) {<br> if(i%8 == 0)<br> printf("\n");<br> printf("%02x; ",answer[i]);<br> }<br> printf("\n");<br>
printf("\n");<br> <br> ret = hid_close(hid);<br> if (ret != HID_RET_SUCCESS) {<br> fprintf(stderr, "hid_close failed with return code %d\n", ret);<br> return 1;<br> }<br><br> hid_delete_HIDInterface(&hid);<br><br> ret = hid_cleanup();<br> if (ret != HID_RET_SUCCESS) {<br> fprintf(stderr, "hid_cleanup failed with return code %d\n", ret);<br> return 1;<br> }<br> <br> return 0;<br>}<br><br><br>Result:<br># ./test_libhid <br>usb_set_debug: Setting debugging level to 1 (on)<br> NOTICE: hid_init(): libhid 0.2.15+20060325.0.0 is being initialized.<br> 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> dev_handle: 0x09a52098<br>
device: 0x09a55068<br> location: 002/009<br> manufacturer: ATMEL<br> product: Firmware Demo<br> TRACE: hid_reset_parser(): resetting the HID parser for USB device 002/009[0]...<br> TRACE: hid_dump_tree(): iterating the parse tree for USB device 002/009[0]...<br>parse tree of HIDInterface 002/009[0]:<br> path: 0xffff0001.0xffff0002; type: 0x80<br> path: 0xffff0001.0xffff0003; type: 0x80<br> path: 0xffff0001.0x00000000; type: 0x80<br> path: 0xffff0001.0x00000000; type: 0x80<br> path: 0xffff0001.0x00000000; type: 0x80<br> path: 0xffff0001.0x00000000; type: 0x80<br> path: 0xffff0001.0x00000000; type: 0x80<br> path: 0xffff0001.0x00000000; type: 0x80<br> path: 0xffff0001.0xffff0004; type: 0x90<br> path: 0xffff0001.0xffff0005; type: 0x90<br> path:
0xffff0001.0x00000000; type: 0x90<br> path: 0xffff0001.0x00000000; type: 0x90<br> path: 0xffff0001.0x00000000; type: 0x90<br> path: 0xffff0001.0x00000000; type: 0x90<br> path: 0xffff0001.0x00000000; type: 0x90<br> path: 0xffff0001.0x00000000; type: 0x90<br> path: 0xffff0001.0xffff0006; type: 0xb0<br> path: 0xffff0001.0xffff0007; type: 0xb0<br> path: 0xffff0001.0x00000000; type: 0xb0<br> path: 0xffff0001.0x00000000; type: 0xb0<br> TRACE: hid_reset_parser(): resetting the HID parser for USB device 002/009[0]...<br> TRACE: hid_set_output_report(): looking up report ID...<br> TRACE: hid_prepare_parse_path(): preparing search path of depth 2 for parse tree of USB device 002/009[0]...<br> TRACE: hid_prepare_parse_path(): search path prepared for parse tree of USB device 002/009[0].<br> NOTICE: hid_find_object(): found requested item.<br> 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> 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> TRACE: hid_close(): closing USB device 002/009[0]...<br> TRACE: hid_close(): closing handle of USB device 002/009[0]...<br> NOTICE: hid_close(): successfully closed USB device 002/009[0].<br> TRACE: hid_reset_parser(): resetting the HID parser for USB device 002/009[0]...<br> TRACE: hid_close(): freeing
memory allocated for HID parser...<br> TRACE: hid_close(): resetting HIDInterface...<br> NOTICE: hid_cleanup(): successfully deinitialised HID library.<br><br><br></td></tr></table><br>