473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

using a USB HID device

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
10 7137
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
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
>> 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
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
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
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
>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
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
Martin v. Löwis 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ruben Lysens | last post by:
Hi, Consider the example below. A Device controls a number of Ports. I'd like the Device to be in charge of creating/deleting Ports. I enforce this by making the Ports constructor and destructor...
22
by: Jan Richter | last post by:
Hi there, the Code below shows DJBs own implementation of strlen (str_len): unsigned int str_len(char *s) { register char *t; t = s; for (;;) { if (!*t) return t - s; ++t;
1
by: Ben Taylor | last post by:
Hi Does anybody have any code examples of using C# to draw to a window using device contexts, more specifically, erasing the entire window by painting a background color in the OnPaint / OnDraw...
8
by: Tony Liu | last post by:
I am having a "Null Device is Missing" compile error when compiling a c++ project. The documentation from MSDN said it could be caused by low system resource or the user account does not have...
0
by: stb | last post by:
I'm using Mobile Controls. I want to set up a device filter to trap HTML browsers, that bit is ok, it's what I want to do with them.... I want to be able to set a background image for all html...
1
by: solanki.chandrakant | last post by:
Hi All, i m working on Linux Fedora Core 4. i have to develop one program in that i have device id. Based on given device id i have to enable/disable particular device id. i have to work with...
3
by: =?Utf-8?B?UHJpeWE=?= | last post by:
Hi, Could someone tell me how to retrieve a drive's drive letter from user mode given its device name? Any information is greatly appreciated. Thanks, Priya
8
by: Konstantin Andreev | last post by:
Hello. I'm experiencing very disagreeable problem: DB2 refuses tablespace containers, which are DEVICE's bigger than 4G. So, If I below 4G limit: | # db2 create tablespace TS1 pagesize 4096...
0
by: Shival | last post by:
Hi, I have a Device that will be used by dentist to take their paitient teaath pics. this Device is having a click button from which the device takes pics. The Device is configured to my OS...
15
by: Konstantin Andreev | last post by:
I'm almost sure I've found bad bug, but for a while I can't neither confirm nor reject this. If anybody could make an independent test on it's own system, I'd appreciate it very much. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.