Again problem with libhid
Hi,
I have a problem with libhid, I asked it in a thread but I did not receive any solution, so I'm writing about my problem again,
The problem is basically with opening a hid device,when I run the program, once it runs truly, but the next time the program can not open the device, it means once open successfully and the next time it fails, again the next time success and the time after that fail , ...
My code is as below code:
>>>
int main(void)
{
HIDInterface* hid;
hid_return ret;
HIDInterfaceMatcher matcher = { 0x0925,0x1234, NULL, NULL, 0 };
/* see include/debug.h for possible values */
hid_set_debug(HID_DEBUG_ALL);
hid_set_debug_stream(stderr);
/* passed directly to libusb */
hid_set_usb_debug(0);
ret = hid_init();
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_init failed with return code %d\n", ret);
return 1;
}
hid = hid_new_HIDInterface();
if (hid == 0) {
fprintf(stderr, "hid_new_HIDInterface() failed, out of memory?\n");
return 1;
}
ret = hid_force_open(hid, 0, &matcher, 2,0);
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_force_open failed with return code %d\n", ret);
return 1;
}
else{
printf("Open Device successfully\n");
}
ret = hid_close(hid);
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_close failed with return code %d\n", ret);
return 1;
}
hid_delete_HIDInterface(&hid);
ret = hid_cleanup();
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_cleanup failed with return code %d\n", ret);
return 1;
}
return 0;
}
<<<
Please help me whit it.
Thanx
|