[prev in list] [next in list] [prev in thread] [next in thread] 

List:       libusb-devel
Subject:    Re: [Libusb-devel] Controlling HID device
From:       Tim Roberts <timr () probo ! com>
Date:       2010-07-27 16:56:05
Message-ID: 4C4F0FA5.70802 () probo ! com
[Download RAW message or body]

 xementhia wrote:
>
> I got a HID device which I would like use and control from Linux side.
> However, controlling device over LibUSB is not easier than I think.

What made you think it would be easy?  It's a piece of hardware.  You
are writing a device driver.  That's never easy.

> This is lsbsub -vvv shows in the Terminal:
>
> Bus 002 Device 005: ID XXXX:00XX
> Device Descriptor:
>   bLength                18
>   bDescriptorType         1
>   bcdUSB               1.10
>   bDeviceClass            0 (Defined at Interface level)
>   bDeviceSubClass         0
>   bDeviceProtocol         0
>   bMaxPacketSize0         8
>   idVendor           0xXXXX
>   idProduct          0x00XX

Why did you feel it necessary to shroud this information?  What do you
think you are protecting?  I've never understood this.  If you include
the real vendor/product information, those of us you are good at Google
might actually find a piece of code that handle this device right out of
the box.Output is here:

> libusb_detach_kernel_driver() return error : -5
> libusb_get_configuration() returned config = 1
> libusb_bulk_transfer() return : -9, a 0
> libusb:error [submit_control_transfer] submiturb failed error -1 errno=2
> libusb_control_transfer() return error : -1
>
> Q1: What is still missing, should I try to make bulk request as ASYNC?
> By default, I'm not intresting data what is coming back... As they are
> always same but that may not avoided anyway.
> Q2: Is control transfer parameters correct? What 0x22 stands for?
> Q3. Can someone point direction where I could find some example.

I'm amazed that so many people try to dabble at a hardware level without
any attempt at all to learn how the hardware works.  Virtually all of
your questions are answered in the USB HID Specification, which can be
downloaded for free from the USB Implementor's Forum at www.usb.org.

Q1: The Windows code has submitted the interrupt pipe read
asynchronously.  It then sends a SET_REPORT request, which triggers the
device to send something back on the interrupt pipe.  Did you notice
that the requests completed out of order?  You don't necessarily need to
do that, but if you want to do things synchronously, you need to wait
until after the SET_REPORT command to read the interrupt pipe.

Q2: You already have comments in the code that supposedly describe what
the 0x22 stands for, but they don't match the number.  The comments say
it is a class-specific request going out to an interface, but that would
be 0x21.  0x22 is a class-specific request going out to an endpoint.  In
this case, the comments are correct, and the number is wrong.  The
bRequest value of 9 is a SET_REPORT request, and that is aimed at an
interface.  You should change the 0x22 to 0x21 (or, better yet, don't
use the hex at all, and just use the constants that you have in the
comments).

You might object that the Windows trace shows 0x22, but note that the
URB code is URB_FUNCTION_CLASS_INTERFACE.  With that set of URB codes,
Windows overwrites the bmRequestType byte in the request with the proper
one.  Notice that, when the request comes back, the first byte of the
request is, indeed, 0x21.

Q3: If all you are doing is simple exchanges, you might consider using
libhid, which manages HID devices at a higher level.  I've heard mixed
reviews of libhid on this mailing list, so you might decide to stay with
libusb, but it's worth investigating.

-- 
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.


------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
_______________________________________________
Libusb-devel mailing list
Libusb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic