|
From: Tim R. <ti...@pr...> - 2009-04-22 16:48:26
|
Al wrote:
> I`ve been trying to do an interrupt read from my usb device, so far I`ve
> had no success.
>
> Any help on what I might be doing wrong would be most appreciated.
>
This is a HID device. To save yourself a lot of grief, you should use
libhid to talk to it. libhid knows how to handle the interrupt
endpoints and provides a better level of abstraction for this class of
device.
> Here`s the code snippet.
>
> devh = libusb_open_device_with_vid_pid(ctx,vendor, product);
> ret = libusb_kernel_driver_active(devh, 0);
> if (ret == 1) {
> printf("interface 0 already claimed by driver \"%s\", attempting to
> detach it\n", buf);
> ret = libusb_detach_kernel_driver(devh, 0);
> printf("usb_detach_kernel_driver_np returned %d\n", ret);
> }
> ret = libusb_claim_interface(devh, 0);
> if (ret != 0) {
> printf("claim failed with error %d\n", ret);
> exit(1);
> }
>
>
> // send message to device, causes device to output configuration on
> endpoint 1
> memcpy(buf, "\x59\xdd\x00\x00", 0x0000004);
> ret = libusb_control_transfer(devh, LIBUSB_REQUEST_TYPE_CLASS +
> LIBUSB_RECIPIENT_INTERFACE, 0x0000009, 0x0000200, 0x0000000, buf,
> 0x0000004, 1000);
>
That's a SET_REPORT request for an output report (type 2), which means
it is an output request. In order to trigger a report to be read, you
would usually sent a GET_REPORT (bRequest = 1, not 9). Did you pull
this from a trace?
> // grab first 4 bytes of output
> int transferred;
> ret = libusb_interrupt_transfer(devh, LIBUSB_ENDPOINT_IN|0x1, buf,
> 0x0000004, &transferred,1000);
>
> it fails here with error -7
>
But did you get any data? What was in "transferred"?
--
Tim Roberts, ti...@pr...
Providenza & Boekelheide, Inc.
|