using a USB HID device

W

Wouter van Ooijen

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
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Wouter said:
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
 
S

Samuel Schulenburg

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
 
W

Wouter van Ooijen

I want to use Python to interface with an USB HID device (not a
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
 
R

Roger Binns

Samuel said:
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
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Jeff said:
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
 
W

Wouter van Ooijen

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
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Wouter said:
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
 
R

Roger Binns

Martin said:
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
 
S

Samuel Schulenburg

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top