[libhid-discuss] Still can't interrupt_read() properly
amruth
amruth_pv at yahoo.com
Fri Sep 5 15:19:49 UTC 2008
Hi
Maria
The issue may be that interrupt is not getting clear The USB state is not getting cleared. Please try using usb_clear_halt and it should work.
Thanks
Amruth p.v
--- On Fri, 9/5/08, Marian Aldenhövel <marian.aldenhoevel at mba-software.de> wrote:
> From: Marian Aldenhövel <marian.aldenhoevel at mba-software.de>
> Subject: Re: [libhid-discuss] Still can't interrupt_read() properly
> To: "libhid-discuss List" <libhid-discuss at lists.alioth.debian.org>
> Date: Friday, September 5, 2008, 8:18 AM
> Hi,
>
> I have reproduced the problem in a simple testcase based on
> libhid_test.c to
> make sure that it was not something unrelated in the rest
> of my read program.
>
> The attached simple program sends the same command three
> times. The device
> acts on it three times, but the results do not come back
> the second and third
> time. The second and third attempts fail with different
> results.
>
> Ciao, MM
> --
> Marian Aldenhövel, Rosenhain 23, 53123 Bonn
> http://www.marian-aldenhoevel.de
> "I ran some quick calculations on it. He's about
> 80% on the right
> track. That leaves him only 20% dead when he
> crashes." Bob C
> #include <hid.h>
> #include <stdio.h>
> #include <string.h>
> #include <unistd.h> /* for getopt() */
>
> int main()
> {
> HIDInterface* hid;
> int iface_num = 0;
> hid_return ret;
>
> unsigned short vendor_id = 0x0590;
> unsigned short product_id = 0x0034;
>
> HIDInterfaceMatcher matcher = { vendor_id, product_id,
> 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(1);
>
> 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, iface_num, &matcher, 3);
> if (ret != HID_RET_SUCCESS) {
> fprintf(stderr, "hid_force_open failed with return
> code %d\n", ret);
> return 1;
> }
>
> ret = hid_write_identification(stdout, hid);
> if (ret != HID_RET_SUCCESS) {
> fprintf(stderr, "hid_write_identification failed
> with return code %d\n", ret);
> return 1;
> }
>
> ret = hid_dump_tree(stdout, hid);
> if (ret != HID_RET_SUCCESS) {
> fprintf(stderr, "hid_dump_tree failed with return
> code %d\n", ret);
> return 1;
> }
>
> int sendloop;
> for (sendloop = 0 ; sendloop < 3 ; sendloop++) {
> unsigned char const SEND_PACKET_LEN = 11;
> char const PACKET[11] = { 0x02, 0x00, 0x03, 0x43, 0x30,
> 0x30, 0x00, 0x00, 0x00, 0x00, 0x00 };
>
> const int PATHLEN=3;
> const int PATH_IN[3] = { 0xff000001, 0xff000021,
> 0xff000121 };
>
> ret = hid_set_output_report(hid, PATH_IN, PATHLEN,
> PACKET, SEND_PACKET_LEN);
> if (ret != HID_RET_SUCCESS) {
> fprintf(stderr, "hid_set_output_report failed with
> return code %d\n", ret);
> }
>
> const int size = 11;
> char buffer[11];
> ret = hid_interrupt_read(hid,0x81,buffer,size,1000);
> if (ret != HID_RET_SUCCESS) {
> fprintf(stderr, "hid_get_input_report failed with
> return code %d\n", ret);
> }
>
> fprintf(stderr, "reply is
> [%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d]\n",
>
> buffer[0],buffer[1],buffer[2],buffer[3],buffer[4],buffer[5],
>
> buffer[6],buffer[7],buffer[8],buffer[9],buffer[10]);
>
> }
>
> 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;
> }
> _______________________________________________
> libhid-discuss mailing list
> libhid-discuss at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
More information about the libhid-discuss
mailing list