[libhid-discuss] help with usage path

Washington Trindade washingtonuesc at gmail.com
Wed Jun 27 12:18:37 UTC 2007


I'm new using libhid, then I take the test_libhid.c e suit them to my
problem. All I have to do is to write the buffer "T\r\n" to the device.

When I execute the program it says the output report was successfully sent,
but the device don't show any reaction. There is some way of be sure the
report was really sent?

Below is the code I'm using and the output of the command lsusb -d
0x0483:0x0035 -vvv.I'm not sure if the usage path is correctly.

Thank you all!

#include <hid.h>
#include <stdio.h>
#include <string.h>

bool match_serial_number(struct usb_dev_handle* usbdev, void* custom,
unsigned int len)
{
  bool ret;
  char* buffer = (char*)malloc(len);
  usb_get_string_simple(usbdev, usb_device(usbdev)->descriptor.iSerialNumber
,
      buffer, len);
  ret = strncmp(buffer, (char*)custom, len) == 0;
  free(buffer);
  return ret;
}

int main(void)
{
  HIDInterface* hid;
  hid_return ret;

  HIDInterfaceMatcher matcher = { 0x0483, 0x0035, NULL, NULL, 0 };

  hid_set_debug(HID_DEBUG_ALL);
  hid_set_debug_stream(stderr);
  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, 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;
  }

    unsigned char const PATHLEN = 2;
    //int const PATH_IN[2] = { 0xff80000, 0xff800001 };
    int const PATH_OUT[2] = { 0xff800000, 0xff800002};

    unsigned char const SEND_PACKET_LEN = 3;

    char const PACKET[3] = "T\r\n";

    ret = hid_set_output_report(hid, PATH_OUT, PATHLEN, PACKET,
SEND_PACKET_LEN);
    if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_set_output_report failed with return code %d\n",
ret);
    }


    char packet[8];
      ret = hid_get_input_report(hid, PATH_OUT, PATHLEN, packet, 8);
      if (ret != HID_RET_SUCCESS) {
        fprintf(stderr, "hid_get_input_report failed with return code %d\n",
ret);
      }

  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;
}



lsusb -d 0x0483:0x0035

Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x0483 ......
  idProduct          0x0035
  bcdDevice            2.00
  iManufacturer           3 ...
  iProduct                1 ......
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           41
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               20mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Devices
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode           33 US
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      29
          Report Descriptor: (length is 29)
            Item(Global): Usage Page, data= [ 0x80 0xff ] 65408
                            (null)
            Item(Local ): Usage, data= [ 0x00 ] 0
                            (null)
            Item(Main  ): Collection, data= [ 0x01 ] 1
                            Application
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0x08 ] 8
            Item(Global): Logical Minimum, data= [ 0x00 ] 0
            Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
            Item(Local ): Usage, data= [ 0x01 ] 1
                            (null)
            Item(Main  ): Feature, data= [ 0x82 ] 130
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Volatile
Bitfield
            Item(Local ): Usage, data= [ 0x01 ] 1
                            (null)
            Item(Main  ): Input, data= [ 0x82 ] 130
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Volatile
Bitfield
            Item(Local ): Usage, data= [ 0x02 ] 2
                            (null)
            Item(Main  ): Output, data= [ 0x82 ] 130
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Volatile
Bitfield
            Item(Main  ): End Collection, data=none
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              10
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              10
Device Status:     0x0000
  (Bus Powered)

Output of the test_libhid program:

parse tree of HIDInterface 005/002[0]:
  path: 0xff800000.0xff800001; type: 0xb0
  path: 0xff800000.0x00000000; type: 0xb0
  path: 0xff800000.0x00000000; type: 0xb0
  path: 0xff800000.0x00000000; type: 0xb0
  path: 0xff800000.0x00000000; type: 0xb0
  path: 0xff800000.0x00000000; type: 0xb0
  path: 0xff800000.0x00000000; type: 0xb0
  path: 0xff800000.0x00000000; type: 0xb0
  path: 0xff800000.0xff800001; type: 0x80
  path: 0xff800000.0x00000000; type: 0x80
  path: 0xff800000.0x00000000; type: 0x80
  path: 0xff800000.0x00000000; type: 0x80
  path: 0xff800000.0x00000000; type: 0x80
  path: 0xff800000.0x00000000; type: 0x80
  path: 0xff800000.0x00000000; type: 0x80
  path: 0xff800000.0x00000000; type: 0x80
  path: 0xff800000.0xff800002; type: 0x90
  path: 0xff800000.0x00000000; type: 0x90
  path: 0xff800000.0x00000000; type: 0x90
  path: 0xff800000.0x00000000; type: 0x90
  path: 0xff800000.0x00000000; type: 0x90
  path: 0xff800000.0x00000000; type: 0x90
  path: 0xff800000.0x00000000; type: 0x90
  path: 0xff800000.0x00000000; type: 0x90
-- 
The best index to a person's character is a) how he treats people who can't
do him any good and b) how he treats people who can't fight back


More information about the libhid-discuss mailing list