<div class="gmail_quote">On Tue, Mar 30, 2010 at 9:01 AM, Marc <span dir="ltr"><<a href="mailto:marc@marcd.org">marc@marcd.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br>
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 <a href="http://dvlabs.tippingpoint.com" target="_blank">dvlabs.tippingpoint.com</a>, but am looking to see what else has been done in this area.<br>
<br></blockquote><div><br></div><div>I've used pyserial, I believe, to directly access the usb. Here's the important connection bits of my code:</div><div><br></div><div><div>import serial</div><div><br></div><div>
class pyDuin:</div><div> ser = serial.Serial()</div><div> def __init__(self, port="/dev/ttyUSB0", baud="115200", timeout=0):</div><div> self.ser.baudrate = baud</div><div> self.ser.port = port</div>
<div> self.ser.timeout = timeout</div><div><br></div><div> def ready(self):</div><div> self.ser.write("%c" % 41) </div><div><br></div><div> def open(self):</div><div> self.ser.open()</div>
<div> if not self.ser.isOpen():</div><div> print "Error, not able to open serial connection on %s" % \ </div><div> (self.ser.port, )</div><div><br></div></div><div>-------------</div>
<div><br></div><div>I was using it to connect to my arduino. If you'd like the rest of the source, let me know.</div><div><br></div><div>HTH,</div><div>Wayne</div></div>