[Tutor] USB Access

Wayne Werner waynejwerner at gmail.com
Tue Mar 30 16:33:30 CEST 2010


On Tue, Mar 30, 2010 at 9:01 AM, Marc <marc at marcd.org> wrote:

> Hi,
> I was wondering if anyone could point me to Python modules or example code
> for accessing USB connected devices.  I would like to get as close to the
> hardware as possible with Python.  I would like to be able to monitor as
> well as control USB connected devices.  I've looked at the missile launcher
> code by Pedram Amini at dvlabs.tippingpoint.com, but am looking to see
> what else has been done in this area.
>
>
I've used pyserial, I believe, to directly access the usb. Here's the
important connection bits of my code:

import serial

class pyDuin:
    ser = serial.Serial()
    def __init__(self, port="/dev/ttyUSB0", baud="115200", timeout=0):
        self.ser.baudrate = baud
        self.ser.port = port
        self.ser.timeout = timeout

    def ready(self):
        self.ser.write("%c" % 41)

    def open(self):
        self.ser.open()
        if not self.ser.isOpen():
            print "Error, not able to open serial connection on %s" % \
                    (self.ser.port, )

-------------

I was using it to connect to my arduino. If you'd like the rest of the
source, let me know.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100330/a5e15c56/attachment.html>


More information about the Tutor mailing list