By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,547 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,547 IT Pros & Developers. It's quick & easy.

using a USB HID device

P: n/a
I want to use Python to interface with an USB HID device (not a
keyboard or mouse, just something that uses the HID driver to avoid
the need for a specific driver). Is this possible in pure Python on
Windows, or even better, in a portable way?

Wouter van Ooijen

-- ------------------------------------
http://www.voti.nl
PICmicro chips, programmers, consulting
Jul 18 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Wouter van Ooijen (www.voti.nl) wrote:
I want to use Python to interface with an USB HID device (not a
keyboard or mouse, just something that uses the HID driver to avoid
the need for a specific driver). Is this possible in pure Python on
Windows, or even better, in a portable way?


What is the Win32 API for such devices? If it is plain
CreateFile/ReadFile/WriteFile/DeviceIoControl, you should be
able to do it in pure Python, using the PythonWin extensions.

Likewise, on Unix, you can use device nodes, and the fcntl module.

I don't think there is a platform-independent Python module for
such devices, yet, but you could write your own abstraction layer
using those building blocks.

HTH,
Martin

Jul 18 '05 #2

P: n/a
wo****@voti.nl (Wouter van Ooijen (www.voti.nl)) wrote in message news:<40*****************@news.xs4all.nl>...
I want to use Python to interface with an USB HID device (not a
keyboard or mouse, just something that uses the HID driver to avoid
the need for a specific driver). Is this possible in pure Python on
Windows, or even better, in a portable way?

Wouter van Ooijen

-- ------------------------------------
http://www.voti.nl
PICmicro chips, programmers, consulting


I have developed routines for Windows that address mass storage
devices using the Windows SCSIPASSTHROUGH layer. I found that USB
devices do not use this layer, and as a result I am also investigating
using python to access USB devices. So far it looks like a seperate
driver along with a interfaceing DLL will needed.

Sam Schulenburg
Jul 18 '05 #3

P: n/a
>> I want to use Python to interface with an USB HID device (not a
keyboard or mouse, just something that uses the HID driver to avoid
the need for a specific driver). Is this possible in pure Python on
Windows, or even better, in a portable way?


What is the Win32 API for such devices?


To be honest, I don't have the faintest idea. I hoped there would be
some abstraction layer (freferrably a portable one) like for serial
ports.
Wouter van Ooijen

-- ------------------------------------
http://www.voti.nl
PICmicro chips, programmers, consulting
Jul 18 '05 #4

P: n/a
libusb is portable to Linux, BSD including OS X, and Windows.
I don't know of a Python wrapper, however, and my experience using
libusb on windows is limited.

http://libusb.sf.net
http://libusb-win32.sf.net/

For my own application, I wrote my device's API in C and wrapped it
using Pyrex.

Jeff

Jul 18 '05 #5

P: n/a
Samuel Schulenburg wrote:
wo****@voti.nl (Wouter van Ooijen (www.voti.nl)) wrote in message news:<40*****************@news.xs4all.nl>...
I want to use Python to interface with an USB HID device (not a


I found that USB
devices do not use this layer, and as a result I am also investigating
using python to access USB devices. So far it looks like a seperate
driver along with a interfaceing DLL will needed.


Here is one I made earlier:

http://cvs.sf.net/viewcvs.py/bitpim/bitpim/native/usb/

It is a Python wrapper (using SWIG) around libusb (including libusb-win32).
My BitPim project currently ships using it on Windows, Linux and Mac.

Roger
Jul 18 '05 #6

P: n/a
Jeff Epler wrote:
libusb is portable to Linux, BSD including OS X, and Windows.
I don't know of a Python wrapper, however, and my experience using
libusb on windows is limited.

http://libusb.sf.net
http://libusb-win32.sf.net/


It looks like libusb, on Windows, installs its own kernel driver,
which generates devices named \\.\libusb*. So this is not exactly
a pure-python solution :-)

OTOH, it may well be that USB devices, on Windows, cannot be
accessed purely from user mode, and that you always need some
sort of kernel driver.

Regards,
Martin

Jul 18 '05 #7

P: n/a
>OTOH, it may well be that USB devices, on Windows, cannot be
accessed purely from user mode, and that you always need some
sort of kernel driver.


But I can live with something that appears to be pure python, like one
which only requires a win-specific addition. after all win32all is
windows-specific too, but I regard it as part of the windows-python
installation. One more dll is no problem, as long as I don't have to
write (and maintain!) it :)

Wouter van Ooijen

-- ------------------------------------
http://www.voti.nl
PICmicro chips, programmers, consulting
Jul 18 '05 #8

P: n/a
Wouter van Ooijen (www.voti.nl) wrote:

But I can live with something that appears to be pure python, like one
which only requires a win-specific addition. after all win32all is
windows-specific too, but I regard it as part of the windows-python
installation. One more dll is no problem, as long as I don't have to
write (and maintain!) it :)


So libusb-win32 might be the solution for you (with other libusb
incarnations for other systems).

Notice, however, that your users need administrator privileges to
install a kernel mode driver.

Regards,
Martin

Jul 18 '05 #9

P: n/a
Martin v. Lwis wrote:
Notice, however, that your users need administrator privileges to
install a kernel mode driver.


Yup. However you can access a device if there is a device driver
attached as well, as long as it is not open. For example if you
have a USB to serial device, you can open it under libusb-win32
providing no other user space code has it open as a com port device.

Unfortunately with both Linux and Mac, libusb can only open devices
for which there is no driver currently attached (irrespective of
whether there is a user space program with the device open).

Windows also requires that a driver be present. There is a do
nothing driver included with libusb-win32 that can be used.

Roger
Jul 18 '05 #10

P: n/a
wo****@voti.nl (Wouter van Ooijen (www.voti.nl)) wrote in message news:<40*****************@news.xs4all.nl>...
I want to use Python to interface with an USB HID device (not a
keyboard or mouse, just something that uses the HID driver to avoid
the need for a specific driver). Is this possible in pure Python on
Windows, or even better, in a portable way?

Wouter van Ooijen

-- ------------------------------------
http://www.voti.nl
PICmicro chips, programmers, consulting


I have been trying different approches to accessing mass storage
flash memory cards via the SCSIPASSTHROUGH layer under windows. I was
able to issue the reduced instruction scsi command set with a windows
DeviceIoControl() call. The main problem is finding information on how
Microsoft merged the usb mass storage interface to the scsi routines.

Sam Schulenburg
Jul 18 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.