[portland] Python Frontend to Microcontoller demo

Jeff Rush jeff at taupro.com
Tue Jul 17 06:11:15 CEST 2007


Ron Jackson wrote:
> 
> Thanks for taking a look at my demo of a Python program communicating with a 
> USB-enabled microcontroller! I've attached the code I used.

Cool!

> I'd appreciate feedback on this code from more experienced Python programmers, 
> particularly to use the favored Python programming style.

You have a tiny bug in the fallback code where a COM number is not entered. 
You need to change serial.Serial(i) to serial.Serial('COM' + i), as you did in 
the try clause agove that.

             for i in range(256):
                 try:
                     s = serial.Serial(i)
                     print s.portstr,
                     s.close()
                 except serial.SerialException:
                     pass

Overall the code looks fine, very Pythonic in style so far.  Although I'm not 
in Portland, I look forward to seeing where you go with this.

Looking over your website, FascinatingElectronics.com, I see you do really 
neat controllers.  For more complex serial protocols, you might want to look 
into the Twisted Framework for Python (http://twistedmatrix.com/).  It 
provides some nice asynchronous event processing facilities, where you can 
easily design your own serial protocol and interact with it cleanly.  It takes 
some work to understand the async way of programming but once you do, it is 
very powerful.

-Jeff


More information about the Portland mailing list