[libhid-discuss] Paths to usage pages / python wrapper

Charles Lepple clepple at ghz.cc
Thu Nov 13 02:13:05 UTC 2008


On Nov 12, 2008, at 11:28 AM, Sarah Mount wrote:

> Hi all,
>
> I'm using the SWIG/Python wrapper to libhid and just having some
> trouble figuring out usage paths. The device I'm trying to communicate
> with has the following parse tree:

Please provide some details about the version of libhid, and where  
you got it (since it looks like it was installed as part of a Linux  
distribution).

[...]
> Presumably anything with type 0xb0 can be used to set a feature
> report? If I say something like:

Almost; usage paths that end in 0x00000000 are vestiges of a bug in  
hid_dump_tree for arrays.

>   path = (0xff000001, 0xff000002)
>   buffer = struct.pack('6b27x', 0x1, 0x1, 0x01, 0x01, 0x00, 0x02)
>   print 'Sending buffer of size %i to sensor: %s' % (len(buffer),  
> repr(buffer))
>   ret = hid_set_output_report(hid, path, buffer)
>   if ret != HID_RET_SUCCESS:
>     sys.stderr.write("hid_dump_tree failed with return code %d.\n"  
> % ret)
>   else: print 'Sent output report successfully!'

This looks like it should work.

> I get the following error:
>
> Traceback (most recent call last):
>   File "./toradex.py", line 94, in <module>
>     main()
>   File "./toradex.py", line 54, in main
>     ret = hid_set_output_report(hid, path, buffer)
>   File "/var/lib/python-support/python2.5/hid/__init__.py", line 206,
> in hid_set_output_report
>     return _hid.hid_set_output_report(*args)
> ValueError: Expecting a sequence of integers

Not sure, this probably would involve recompilation to figure out  
what is going wrong. Also, what version of swig is installed?

> Presumably because the path in question was a sequence of longs. I'm
> not sure whether the problem here is my understanding of the way paths
> work in HID or something else! I'd be very grateful if anyone can
> point me in the right direction. (output of lsusb listed below, in
> case it's helpful).


I couldn't get Python 2.5 to work with SWIG on OS X, so I started  
looking at alternatives.

Python 2.5 includes ctypes, which provides Python access to native  
libraries. You may be interested in this:

http://boxster.ghz.cc/projects/libhid/browser/trunk/swig/hid_ctypes.py

That should work with your existing libhid.so, with some minor path  
adjustments in the beginning.

-- 
Charles Lepple






More information about the libhid-discuss mailing list