Is python suitable for embedded programming?

Peter Hansen peter at engcorp.com
Mon Jun 10 12:52:00 EDT 2002


Dennis Nash wrote:
> 
> I am considering using Python to control embedded hardware, and would
> like to know whether other people have done this, what their experiences
> were, and whether they recommend it.

We've been doing similar things for the last two and half years with
a great deal of success.  We use serial ports, CAN interfaces (connected
via USB), and GPIB interfaces to control various RF equipment and
embedded systems.

> The system in question is in three parts: Industrial hardware talks to a
> control system (a Linux or Windows2000 box). The control system outputs
> the data from the hardware onto a web server. A 3rd computer contains a
> web browser which will interact with the web server, allowing an operator
> to view what's happening with the hardware and change parameters.
> 
> I am thinking of using Python for the middle part, i.e. the control
> system which polls the hardware continually to get its state, and updates
> the web pages accordingly.
> 
> Some specific questions:
> 
> * how good is serial port access in Python?

It was poor when we started, but we hacked together our own wrapper
on win32comm (at the time), then win32file in the more recent Windows
extensions to Python.  There are now at least two, maybe three released
serial port packages for Python, running on Linux and Windows.  (When
we get a chance, we're going to either integrate their best bits into
ours and release it, or vice versa.)  A quick google search would turn
up the various options.

> * the program will be running forever, in a big loop. Is it liable to
> gradually use all the memory up and then fall over?

No, never in my experience.  We have applications running for months.
Python is an excellent choice for long-running applications.

> * output to web pages: how good is Python Server Pages? is this the best
> way to do it?

"Best" is entirely dependent on your own needs of course, not all of
which you've presented. :)  You might, for example, output the data
as simple XML and just dump it into folders somewhere with a web 
server in front serving them up.  No need for any Python (or code)
at that point, if you're willing to write a little XSLT.

You could also use something like Zope and make the data available
through that.  Anything in between these two would work okay too,
depending on what you really care about.

-Peter



More information about the Python-list mailing list