Discussion:
[libhid-discuss] libhid + swig -> c#
Rudolf Muehlbauer
2011-04-08 17:25:35 UTC
Permalink
Hello,

I am wondering what the current status of libhid is. Is it still
maintained, used? The last svn commit was back in 2008.

I am interested to use it in a project written with Mono/C#. Is it much
of a hassle to generate the C# bindings?

Is there a more vivid alternative to libhid?

Any hints appreciated.
--
Rudolf Muehlbauer <rudolf.muehlbauer at gmail.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20110408/f1dc67e2/attachment.pgp>
Charles Lepple
2011-04-09 22:56:33 UTC
Permalink
Post by Rudolf Muehlbauer
Hello,
I am wondering what the current status of libhid is. Is it still
maintained, used? The last svn commit was back in 2008.
I have been recommending that people consider HIDAPI instead. It seems
to be much better at the cross-platform goal than libhid, since libusb
isn't always the best solution. (On the other hand, I haven't tried
HIDAPI myself. Maybe someone else on the list has.)
Post by Rudolf Muehlbauer
I am interested to use it in a project written with Mono/C#. Is it much
of a hassle to generate the C# bindings?
It would certainly be a to me, since I don't know C#. If you have used
SWIG before, I imagine it would not be that difficult. I suspect the
biggest hurdle would be wrapping libusb for use in C#.

Actually, if you don't need the hidparser library (i.e. you know the
report structures), there is not much to libhid. Look at the source
for the functions which you would use - they are mostly error-checking.
Xiaofan Chen
2011-04-09 23:54:20 UTC
Permalink
Post by Rudolf Muehlbauer
I am wondering what the current status of libhid is. Is it still
maintained, used? The last svn commit was back in 2008.
I have been recommending that people consider HIDAPI instead. It seems to be
much better at the cross-platform goal than libhid, since libusb isn't
always the best solution. (On the other hand, I haven't tried HIDAPI myself.
Maybe someone else on the list has.)
I tried HIDAPI a bit and it is quite good. On the other hand, it does
not have enough bindings and the packaging of it is not that great.
It has great potentials though.
http://www.signal11.us/oss/hidapi/
Post by Rudolf Muehlbauer
I am interested to use it in a project written with Mono/C#. Is it much
of a hassle to generate the C# bindings?
It would certainly be a to me, since I don't know C#. If you have used SWIG
before, I imagine it would not be that difficult. I suspect the biggest
hurdle would be wrapping libusb for use in C#.
Travis Robinson (current developers of libusb-win32) is also the developer
of libusbdotnet, a great C# bindings for libusb. It works under Linux
and Mac OS X with Mono, but only with libusb-1.0. For Windows, it
works with libusb-1.0, WinUSB and libusb-win32.
http://libusbdotnet.sourceforge.net/V2/Index.html
Actually, if you don't need the hidparser library (i.e. you know the report
structures), there is not much to libhid. Look at the source for the
functions which you would use - they are mostly error-checking.
--
Xiaofan
Rudolf Muehlbauer
2011-04-10 12:33:17 UTC
Permalink
Thanks for the wonderful replies,

I was already aware of the LibUsbDotNet und HIDAPI. My guess was that
libhid would not be worth the effort - since with such a library my
deployment would get more difficult. When I only use the LibUsbDotNet
and write my HID-related code myself, I would not need an additional
Library, libusb is available in most distributions I think.

I will try to write the HID code in C# with LibUsbDotNet like in this
example: http://www.lvr.com/code/generic_hid.c$

Anyhow, thank you for your valuable input.
Post by Xiaofan Chen
Post by Rudolf Muehlbauer
I am wondering what the current status of libhid is. Is it still
maintained, used? The last svn commit was back in 2008.
I have been recommending that people consider HIDAPI instead. It seems to be
much better at the cross-platform goal than libhid, since libusb isn't
always the best solution. (On the other hand, I haven't tried HIDAPI myself.
Maybe someone else on the list has.)
I tried HIDAPI a bit and it is quite good. On the other hand, it does
not have enough bindings and the packaging of it is not that great.
It has great potentials though.
http://www.signal11.us/oss/hidapi/
Post by Rudolf Muehlbauer
I am interested to use it in a project written with Mono/C#. Is it much
of a hassle to generate the C# bindings?
It would certainly be a to me, since I don't know C#. If you have used SWIG
before, I imagine it would not be that difficult. I suspect the biggest
hurdle would be wrapping libusb for use in C#.
Travis Robinson (current developers of libusb-win32) is also the developer
of libusbdotnet, a great C# bindings for libusb. It works under Linux
and Mac OS X with Mono, but only with libusb-1.0. For Windows, it
works with libusb-1.0, WinUSB and libusb-win32.
http://libusbdotnet.sourceforge.net/V2/Index.html
Actually, if you don't need the hidparser library (i.e. you know the report
structures), there is not much to libhid. Look at the source for the
functions which you would use - they are mostly error-checking.
--
Rudolf Muehlbauer <rudolf.muehlbauer at gmail.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20110410/b38d6cbf/attachment.pgp>
Xiaofan Chen
2011-04-10 12:39:31 UTC
Permalink
On Sun, Apr 10, 2011 at 8:33 PM, Rudolf Muehlbauer
Post by Rudolf Muehlbauer
Thanks for the wonderful replies,
I was already aware of the LibUsbDotNet und HIDAPI. My guess was that
libhid would not be worth the effort - since with such a library my
deployment would get more difficult. When I only use the LibUsbDotNet
and write my HID-related code myself, I would not need an additional
Library, libusb is available in most distributions I think.
I will try to write the HID code in C# with LibUsbDotNet like in this
example: http://www.lvr.com/code/generic_hid.c
That code was adapted from my original code. :-)
"This firmware is adapted from code provided by Xiaofan."

The main issue if you want to use libusb-1.0 with HID device
is when you want to have cross-platform capability. There is
no HID backend for Mac OS X and it is not easy now to
detach the kernel driver. And the Windows HID backend
is removed thanks to Peter Stuge's vehement objection to the
idea.

So you may want to look HIDAPI instead...
--
Xiaofan
Rudolf Muehlbauer
2011-04-11 21:17:10 UTC
Permalink
Well, i decided to use HIDAPI. It works great! Also the .NET P/Invoke
bindings were ok to implement, there are still some problems, but I can
open devices, read data from my mouse, for example. Receiving strings is
still somewhat strange, only the first character is received. But this
is just a thing that needs some work, I hope.

Though I would require some more functionality. The API I port from uses
HidD_GetCaps, HidD_GetPreparsedData,
{Input,Output,Feature}ReportByteLength, ... and now I have to find some
way to emulate that.

thanks for the helpful input;
Post by Xiaofan Chen
On Sun, Apr 10, 2011 at 8:33 PM, Rudolf Muehlbauer
Post by Rudolf Muehlbauer
Thanks for the wonderful replies,
I was already aware of the LibUsbDotNet und HIDAPI. My guess was that
libhid would not be worth the effort - since with such a library my
deployment would get more difficult. When I only use the LibUsbDotNet
and write my HID-related code myself, I would not need an additional
Library, libusb is available in most distributions I think.
I will try to write the HID code in C# with LibUsbDotNet like in this
example: http://www.lvr.com/code/generic_hid.c
That code was adapted from my original code. :-)
"This firmware is adapted from code provided by Xiaofan."
The main issue if you want to use libusb-1.0 with HID device
is when you want to have cross-platform capability. There is
no HID backend for Mac OS X and it is not easy now to
detach the kernel driver. And the Windows HID backend
is removed thanks to Peter Stuge's vehement objection to the
idea.
So you may want to look HIDAPI instead...
--
Rudolf Muehlbauer <rudolf.muehlbauer at gmail.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20110411/3400564a/attachment.pgp>
Peter Stuge
2011-04-11 21:30:30 UTC
Permalink
Receiving strings is still somewhat strange, only the first
character is received.
If your device is not actually a human interface device and you have
some control over the firmware I very strongly recommend not using
the HID device class. If no class fits then vendor specific is an
excellent choice; it allows you complete freedom in how communication
works, and it can take advantage of the packet based nature of USB
communication. Reading a string could be as simple as giving a string
number and receiving the string bytes.


//Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20110411/d73e08ca/attachment.pgp>
Peter Stuge
2011-04-10 14:46:56 UTC
Permalink
Post by Rudolf Muehlbauer
I will try to write the HID code in C# with LibUsbDotNet
I'd strongly recommend using HIDAPI instead.
Post by Rudolf Muehlbauer
The main issue if you want to use libusb-1.0 with HID device
is when you want to have cross-platform capability.
Indeed. There must always be a helpful kernel driver for libusb, and
as Xiaofan points out it's no longer possible to "blacklist" a HID
class device so that the Mac OS X HID kernel driver (which by
definition can not support libusb) will not grab it, making libusb
access impossible.

Windows and Linux both permit replacing the HID class kernel driver
with something that supports libusb from within the application, but
there is no portable API (libusb can do it on Linux, libwdi can do it
on Windows) but Mac is unfortunately no longer possible.
Post by Rudolf Muehlbauer
There is no HID backend for Mac OS X and it is not easy now to
detach the kernel driver. And the Windows HID backend
is removed thanks to Peter Stuge's vehement objection to the
idea.
Yes. libusb isn't the right tool for talking to the kernel HID
driver.
Post by Rudolf Muehlbauer
So you may want to look HIDAPI instead...
Agree. You will avoid all system-specific issues by using HIDAPI,
since it is intended exactly for communicating with HID class devices
through the various API offered by different kernel HID class drivers.

If you go with libusb you'll have to do some kernel driver management,
which doesn't currently have a great portable solution, and for
Mac OS X has no solution at all when it comes to HID class.


//Peter
Loading...