Python for PLC-type control systems

Warren Postma embed at
Mon Mar 6 16:15:27 CET 2000

I noticed from the thread on Python for Lisp Programmers
[], from discussions on Smalltalk
newsgroups and mailing lists, and on previous discussions comparing Python
and Perl that everybody's beating up on Python's performance.
Okay, so not everyone's a speed-daemon, but I'm wondering if Python 1.6 is
driven by core VM performance gain?   Well, I have an application for Python
that just might strain at it's limits.  That's good though. Perhaps I can
get to a point where I can help with Python's performance.

Basically, I am interested in doing a Ladder Logic (PLC) engine on Python.
If you've seen Modicon or Allen Bradley PLCs you know the idea.

Basically this involves:

- A local and remote IO device driver architecture, and possibly in the
future a Python-based high level way of writing serial and network protocols
(aka "device drivers") for communicating to industrial equipment.

- Read large numbers of Analog and Discrete IO [this is an embedded system,
so for Local IO, this basically means inportb()/outportb() type IO register
writes]. I have C code already written for most of this stuff.

- I will implement a number of complex tuneable or self-tuning analog PID
loop control functions, using C extension modules. [This is a lower
priority, but it's Part of a Complete Breakfast.]

- High performance exception-driven Digital Logic.  Generally PLCs have scan
times in the 1 ms to 20 ms range, ranging from 50 to over 1000 digital
inputs, some of which are local and some of which are slower remote IO.
Each input generates 'exception' events whenever it changes state. These
exceptions drive up to hundreds of boolean-logic networks [known as Ladder
Logic Rungs in PLC land] which in turn control relay outputs, or internal
memory flags or drive "function blocks" which are composed of procedural
(Python) code and extension modules.  [This part is in early development.]

- A python module to create, edit, and debug the visual "ladder logic"
representation of these ladder logic rungs. [not sure what GUI to use, but
wxPython looks good. We're a ways away from doing this part.]

- Testability is a key attribute. In the same time as building a control
program, a test harness will be created, to simulate the system.  Simulation
is a key part of the testing approach.

Neato Pytyhon Stuff I'm looking into includes Christian Tismer's stackless
python and the 'stackless/microthreads' merge.  I am not entirely sure if
I'll need Microthreads, but I might, especially if the aforementioned
"function blocks" which are Python objects, need to execute concurrently
with fine-grained thread scheduling.

Anybody else out there doing anything similar?


More information about the Python-list mailing list