tags:

views:

288

answers:

2

I was interested in doing some cross platform work with a usb device in python, any tips or recommendations on modules that can do this type of thing?

I've looked around SF and googlecode without a lot of luck.

thanks!

ct

+3  A: 

PyUSB is what you are looking for. it is a wrapper around libusb which works on linux and was ported on Windows.

Adrien Plisson
is there something that doesn't require an external usb dep (like libusb)?
ct
i don't know of any. libusb (or any equivalent, like openusb) is a necessary evil since you need something like a device driver to write through the USB port, and you will not write such low-level stuffs in python.
Adrien Plisson
@Adrien, one could presumably write to the Windows APIs using ctypes, which is now standard in Python.
Peter Hansen
@Peter: of course... but since some part of the code might end up in the kernel, i am quite sure the python interpreter will not fit there. (however, i don't know if something like libusb lies entirely in user space or have any kernel code)
Adrien Plisson
I ran across this windows wrapper http://pypi.python.org/pypi/pywinusb/0.2.3
ct
I also noticed there's a linux variant: code.activestate.com/recipes/576834
ct
@Adrien, I'm not sure what you mean about "interpreter will not fit there". Are you suggesting it wouldn't be possible to write it with ctypes, or simply that it might be inadvisable?
Peter Hansen
@peter: i mean that i don't think it is a nice idea to execute a python program (with it's full-blown interpreter) in kernel space. some actions which are part of the initialization of the interpreter may be forbidden in kernel space. also, this might pose a security threat since any python module could then execute in the kernel...
Adrien Plisson
@Adrien, okay, understood. I would have thought that any such interface available through OS APIs that are reachable by ctypes would by definition execute in user space. I suppose I'm wrong about that for Linux, though probably not where Windows is concerned.
Peter Hansen
A: 

I ran across this a little while ago:

http://code.google.com/p/usb-devices/

has anyone played around with it?

ct
This might best be incorporated into your question (you can edit the question to include it, then delete this answer). In any case, I just peeked at the source to that project, and it's "not real". It has only a few snippets of code, and though it bills itself as "cross-platform", at least one module is tied to Windows (using the "wmi" package).
Peter Hansen
never used it, but from the link you gave it is very young, very empty, really lacking documentation, and, from the small code part i read, is heavily Win32 based and relies on PyGame...
Adrien Plisson
@Adrien gotcha thanks!
ct
@Peter thanks for checking into it!
ct