[libhid-discuss] hid_set_feature_report()

Felipe Augusto de Souza fel.asouza at gmail.com
Tue Jan 15 15:34:22 UTC 2008


Hi all,

I'm using libHid to do usb communication with Python to run in Linux and
Windows. The project has still a C++ code that communicates with the device
using HID.dll in Windows.

The complete code is in the final of this message:

For receive message:
in C++:
 if (!(HidD_GetFeature)(g_hDevice, buf_ent, sizeof(buf_ent))) //Receive
message
g_hDevice is the deviceHandle, buf_ent is a pointer to the buffer

this I translated to Python as:
int, buffer = hid_get_feature_report(hid,path,64)

this good works..

but for send message
in C++:
  if(!(HidD_SetFeature)(g_hDevice, &OUTPUT_BUFFER, sizeof(OUTPUT_BUFFER))
g_hDevice is the deviceHandle, OUTPUT_BUFFER is a pointer and the size of
the message.
in OUTPUT_BUFFER the first byte is the ReportID and always sets to zero (0).

and I tried to write this:
hid_set_feature_report(hid,path,'\0x2A\0x0C\0x00\0x00\0x43\0x05\0x0A\0x14\0x13\0x29\0x26\0x30\0xD7')
or hid_set_output_report.
"failed to send report to USB device 003/007[0]:error sending control
message: Connection timed out." But tells that the ReportID is 0x00.

the path I tried all that appears in debug mode, but You can view the
following complete code:
=======================================================================================
import sys
import time
from hid import *


def main():
  hid_set_debug(HID_DEBUG_ALL)
  hid_set_debug_stream(sys.stderr)
  #hid_set_usb_debug(0)

  ret = hid_init()
  if ret != HID_RET_SUCCESS:
    sys.stderr.write("hid_init failed with return code %d.\n" % ret)

  hid = hid_new_HIDInterface()
  matcher = HIDInterfaceMatcher()
  matcher.vendor_id = 0x483
  matcher.product_id = 0x0001

  ret = hid_force_open(hid, 0, matcher, 3
                       )
  if ret != HID_RET_SUCCESS:
    sys.stderr.write("hid_force_open failed with return code %d.\n" % ret)

  ret = hid_write_identification(sys.stdout, hid);
  if ret != HID_RET_SUCCESS:
    sys.stderr.write("hid_write_identification failed with return code
%d.\n" % ret)

  ret = hid_dump_tree(sys.stdout, hid);
  if ret != HID_RET_SUCCESS:
    sys.stderr.write("hid_dump_tree failed with return code %d.\n" % ret)
    ret = hid_close(hid)
  if ret != HID_RET_SUCCESS:
    sys.stderr.write("hid_close failed with return code %d.\n" % ret)

  path = [0xffa000a5,0xffa000a9]

  int, buffer = hid_get_feature_report(hid,path,64)
  print buffer

  time.sleep(2)

hid_set_feature_report(hid,path,'\0x2A\0x0C\0x00\0x00\0x43\0x05\0x0A\0x14\0x13\0x29\0x26\0x30\0xD7')
  hid_cleanup()
  hid_close(hid)

if __name__ == '__main__':
  main()
============================================================================================
I have tried all paths that appears in the output. The output of this code
is:

==========================================================================================
NOTICE: hid_init(): libhid 0.2.15+20060325.0.0 is being initialized.
  TRACE: hid_init(): initialising USB subsystem...
  TRACE: hid_init(): scanning for USB busses...
  TRACE: hid_init(): scanning for USB devices...
 NOTICE: hid_init(): successfully initialised HID library.
  TRACE: hid_new_HIDInterface(): creating a new HIDInterface instance...
  TRACE: hid_force_open(): forcefully opening a device interface according
to matching criteria...
  TRACE: hid_get_usb_handle(): acquiring handle for a USB device...
  TRACE: hid_find_usb_device(): enumerating USB busses...
  TRACE: hid_find_usb_device(): enumerating USB devices on bus 005...
  TRACE: hid_find_usb_device(): inspecting USB device 005/001[0]...
  TRACE: hid_compare_usb_device(): comparing match specifications to USB
device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): no match on vendor ID.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): vendor 0x0000 of USB device 005/001[0] does
not match 0x0483.
  TRACE: hid_find_usb_device(): enumerating USB devices on bus 001...
  TRACE: hid_find_usb_device(): inspecting USB device 001/001[0]...
  TRACE: hid_compare_usb_device(): comparing match specifications to USB
device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): no match on vendor ID.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): vendor 0x0000 of USB device 001/001[0] does
not match 0x0483.
  TRACE: hid_find_usb_device(): enumerating USB devices on bus 004...
  TRACE: hid_find_usb_device(): inspecting USB device 004/001[0]...
  TRACE: hid_compare_usb_device(): comparing match specifications to USB
device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): no match on vendor ID.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): vendor 0x0000 of USB device 004/001[0] does
not match 0x0483.
  TRACE: hid_find_usb_device(): enumerating USB devices on bus 002...
  TRACE: hid_find_usb_device(): inspecting USB device 002/003[0]...
  TRACE: hid_compare_usb_device(): comparing match specifications to USB
device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): no match on vendor ID.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): vendor 0x0458 of USB device 002/003[0] does
not match 0x0483.
  TRACE: hid_find_usb_device(): inspecting USB device 002/001[0]...
  TRACE: hid_compare_usb_device(): comparing match specifications to USB
device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): no match on vendor ID.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): vendor 0x0000 of USB device 002/001[0] does
not match 0x0483.
  TRACE: hid_find_usb_device(): enumerating USB devices on bus 003...
  TRACE: hid_find_usb_device(): inspecting USB device 003/007[0]...
  TRACE: hid_compare_usb_device(): comparing match specifications to USB
device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): match on vendor ID: 0x0483.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): match on product ID: 0x0001.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): found a matching USB device 003/007[0].
  TRACE: hid_force_open(): claiming USB device 003/007[0].
 NOTICE: hid_force_open(): successfully claimed USB device 003/007[0].
  TRACE: hid_init_parser(): initialising the HID parser for USB Device
003/007[0]...
  TRACE: hid_init_parser(): allocating space for HIDData structure...
  TRACE: hid_init_parser(): successfully allocated memory for HIDData
strcture.
  TRACE: hid_init_parser(): allocating space for HIDParser structure...
  TRACE: hid_init_parser(): successfully allocated memory for HIDParser
strcture.
 NOTICE: hid_init_parser(): successfully initialised the HID parser for USB
Device 003/007[0].
  TRACE: hid_prepare_hid_descriptor(): initialising the HID descriptor for
USB device 003/007[0]...
  TRACE: hid_prepare_hid_descriptor(): retrieving HID descriptor for USB
device 003/007[0]...
 NOTICE: hid_prepare_hid_descriptor(): successfully initialised HID
descriptor for USB device 003/007[0] (46 bytes).
  TRACE: hid_prepare_report_descriptor(): initialising the report descriptor
for USB device 003/007[0]...
  TRACE: hid_prepare_report_descriptor(): retrieving report descriptor for
USB device 003/007[0]...
 NOTICE: hid_prepare_report_descriptor(): successfully initialised report
descriptor for USB device 003/007[0].
  TRACE: hid_prepare_parser(): setting up the HID parser for USB device
003/007[0]...
  TRACE: hid_reset_parser(): resetting the HID parser for USB device
003/007[0]...
  TRACE: hid_prepare_parser(): dumping the raw report descriptor
  TRACE: hid_prepare_parser(): 0x000: 0x06 0xa0 0xff 0x09 0xa5 0xa1 0x01
0x09
  TRACE: hid_prepare_parser(): 0x008: 0xa6 0x09 0xa5 0x15 0x80 0x25 0x7f
0x75
  TRACE: hid_prepare_parser(): 0x010: 0x08 0x95 0x40 0xb1 0x02 0x09 0xa7
0x15
  TRACE: hid_prepare_parser(): 0x018: 0x80 0x25 0x7f 0x75 0x08 0x95 0x08
0x81
  TRACE: hid_prepare_parser(): 0x020: 0x02 0x09 0xa9 0x15 0x80 0x25 0x7f
0x75
  TRACE: hid_prepare_parser(): 0x028: 0x08 0x95 0x40 0x91 0x02 0xc0
  TRACE: hid_prepare_parser(): parsing the HID tree of USB device
003/007[0]...
 NOTICE: hid_prepare_parser(): successfully set up the HID parser for USB
device 003/007[0].
 NOTICE: hid_force_open(): successfully opened USB device 003/007[0].
device identification of HIDInterface 003/007[0]:
  dev_handle:    0x00812c00
  device:        0x0081dda0
  location:      003/007
  manufacturer:  ST Microelectronics

parse tree of HIDInterface 003/007[0]:
  TRACE: hid_reset_parser(): resetting the HID parser for USB device
003/007[0]...
  TRACE: hid_dump_tree(): iterating the parse tree for USB device
003/007[0]...
  path: 0xffa000a5.0xffa000a6; type: 0xb0
  path: 0xffa000a5.0xffa000a5; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0x00000000; type: 0xb0
  path: 0xffa000a5.0xffa000a7; type: 0x80
  path: 0xffa000a5.0x00000000; type: 0x80
  path: 0xffa000a5.0x00000000; type: 0x80
  path: 0xffa000a5.0x00000000; type: 0x80
  path: 0xffa000a5.0x00000000; type: 0x80
  path: 0xffa000a5.0x00000000; type: 0x80
  path: 0xffa000a5.0x00000000; type: 0x80
  path: 0xffa000a5.0x00000000; type: 0x80
  path: 0xffa000a5.0xffa000a9; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  path: 0xffa000a5.0x00000000; type: 0x90
  TRACE: hid_reset_parser(): resetting the HID parser for USB device
003/007[0]...
  TRACE: hid_get_feature_report(): looking up report ID...
  TRACE: hid_prepare_parse_path(): preparing search path of depth 2 for
parse tree of USB device 003/007[0]...
  TRACE: hid_prepare_parse_path(): search path prepared for parse tree of
USB device 003/007[0].
 NOTICE: hid_find_object(): found requested item.
  TRACE: hid_get_feature_report(): retrieving report ID 0x00 (length: 64)
from USB device 003/007[0]...
 NOTICE: hid_get_feature_report(): successfully retrieved report from USB
device 003/007[0].
TRACE: hid_set_feature_report(): looking up report ID...
  TRACE: hid_prepare_parse_path(): preparing search path of depth 2 for
parse tree of USB device 003/007[0]...
  TRACE: hid_prepare_parse_path(): search path prepared for parse tree of
USB device 003/007[0].
 NOTICE: hid_find_object(): found requested item.
  TRACE: hid_set_feature_report(): sending report ID 0x00 (length: 52) to
USB device 003/007[0]...
WARNING: hid_set_feature_report(): failed to send report to USB device
003/007[0]:error sending control message: Connection timed out.
 NOTICE: hid_cleanup(): successfully deinitialised HID library.
  TRACE: hid_close(): closing USB device 003/007[0]...
  TRACE: hid_close(): closing handle of USB device 003/007[0]...
 NOTICE: hid_close(): successfully closed USB device 003/007[0].
  TRACE: hid_reset_parser(): resetting the HID parser for USB device
003/007[0]...
  TRACE: hid_close(): freeing memory allocated for HID parser...
  TRACE: hid_close(): resetting HIDInterface...
=====================================================================================

if anybody can tell what's wrong in this code..

Thanks,


Felipe Augusto


More information about the libhid-discuss mailing list