Discussion:
[pyusb-users] Python and USB HID Device
Xiaofan Chen
2011-04-27 02:48:39 UTC
Permalink
Just a summary for the situation.

Firstly you may want to see if you really want to use
a generic HID device, in most cases, you can use
a custom device and then use libusb0.sys or winusb.sys
as the driver under Windows and then use pyusb with it.

Using a custom device will also make it possible to use
pyusb under Mac OS X. Recent Mac OS X makes it
very difficult (or impossible) to detach the kernel HID driver.
In that case, it is not possible to use libusb (0.1 or 1.0)
and thus pyusb with the device.

So if you really want to use pyusb and care about
cross-platfrom, then you should forget about generic
HID device and use a custom device instead.

If you really need to use HID device, there are a few
options.

1) If you only cares about Linux, then you can use
pyusb with no issues. libusb under Linux can detach
the kernel HID driver.

2) If you only care about Windows, you may want
to look at pywinusb.
http://code.google.com/p/pywinusb/

3) If you really want to use pyusb under Windows with the
HID device, you can use libusb-win32 filter driver for
that particular HID device. Please use the latest
libusb-win32 for this purpose. And take note this is
not a recommended solution.

4) If you want to have cross-platform support for the
HID device, then you need to look at HIDAPI and
use the python binding for it. Take note the python
binding for HIDAPI is not mature yet.
http://libusb.6.n5.nabble.com/Opinion-HID-and-Windows-back-end-td3716872.html
http://comments.gmane.org/gmane.comp.python.pyusb.user/749

5) Another option under Windows is to use the HID branch
of the libusb-pbatard git repo or older version of libusb-pbatard
(up to pbr332). This is not recommended as the official stand
of libusb-1.0 admin is not to support HID native backend under
Windows.
--
Xiaofan
Prashant Patel
2011-04-27 04:19:37 UTC
Permalink
Hi Xiaofan,

This is very very helpful. Finally I have found the LibUSB example for
Renesas Rx62N. So now I don't mind using custom driver. I don't see any
reason to stick with HID.
One thing, I will need, is to include this drivers in my installation
utility NSIS. Is there any help on this, anywhere?

You said, I need to use libusb0.sys or winusb.sys. I have already
install libusb0.sys using inf-wizard.exe. Is there any advantage of
using winusb.sys?

Thank you very much. Now I understand the point.

Regards,
Prashant
Post by Xiaofan Chen
Just a summary for the situation.
Firstly you may want to see if you really want to use
a generic HID device, in most cases, you can use
a custom device and then use libusb0.sys or winusb.sys
as the driver under Windows and then use pyusb with it.
Using a custom device will also make it possible to use
pyusb under Mac OS X. Recent Mac OS X makes it
very difficult (or impossible) to detach the kernel HID driver.
In that case, it is not possible to use libusb (0.1 or 1.0)
and thus pyusb with the device.
So if you really want to use pyusb and care about
cross-platfrom, then you should forget about generic
HID device and use a custom device instead.
If you really need to use HID device, there are a few
options.
1) If you only cares about Linux, then you can use
pyusb with no issues. libusb under Linux can detach
the kernel HID driver.
2) If you only care about Windows, you may want
to look at pywinusb.
http://code.google.com/p/pywinusb/
3) If you really want to use pyusb under Windows with the
HID device, you can use libusb-win32 filter driver for
that particular HID device. Please use the latest
libusb-win32 for this purpose. And take note this is
not a recommended solution.
4) If you want to have cross-platform support for the
HID device, then you need to look at HIDAPI and
use the python binding for it. Take note the python
binding for HIDAPI is not mature yet.
http://libusb.6.n5.nabble.com/Opinion-HID-and-Windows-back-end-td3716872.html
http://comments.gmane.org/gmane.comp.python.pyusb.user/749
5) Another option under Windows is to use the HID branch
of the libusb-pbatard git repo or older version of libusb-pbatard
(up to pbr332). This is not recommended as the official stand
of libusb-1.0 admin is not to support HID native backend under
Windows.
Xiaofan Chen
2011-04-27 05:24:08 UTC
Permalink
Post by Prashant Patel
Hi Xiaofan,
This is very very helpful. Finally I have found the LibUSB example for
Renesas Rx62N. So now I don't mind using custom driver. I don't see any
reason to stick with HID.
One thing, I will need, is to include this drivers in my installation
utility NSIS. Is there any help on this, anywhere?
Yes there is an example in libusb-win32 which does this. Please
take a look at this. It is also included in the source package download.
http://libusb-win32.svn.sourceforge.net/viewvc/libusb-win32/trunk/libusb/examples/driver_installer_template.iss?revision=395&view=markup
Post by Prashant Patel
You said, I need to use libusb0.sys or winusb.sys. I have already
install libusb0.sys using inf-wizard.exe. Is there any advantage of
using winusb.sys?
No, libusb0.sys is obvously better than winusb.sys. :-)

I am biased as I am the admin of libusb-win32 project.
WinUSB is not bad either but libusb0.sys has features
which WinUSB does not support.

1) libusb0.sys supports isoc transfer, WinUSB does not
support isoc transfer
2) libusb0.sys supports Win2k, Windows XP64 and Windows
2003, winusb.sys does not support these OS.
3) libusb0.sys supports USB device reset whereas
WinUSB does not support this feature

That being said, if you want to use libusb-1.0 Windows
backend right now, you have to use WinUSB since the
current Windows backend only supports WinUSB.
We are working on a libusb0.sys and libusbk.sys
backend so in the future you can use libusbk.sys
or libusb0.sys with libusb-1.0 Windows backend.

libusbk.sys is the next-gen libusb0.sys. It is still
under active development.
http://code.google.com/p/usb-travis/
Post by Prashant Patel
Thank you very much. Now I understand the point.
--
Xiaofan
Loading...