[Twisted-Python] Wiring a new reactor/Client into Twisted

Eugene Coetzee projects at reedflute.com
Mon Jul 26 14:40:34 EDT 2004


I'm using Twisted in an industrial application to replace a 
multi-threaded C++ driver which I developed some time ago to drive an 
array of serial ports (COM port expander) simultaneously. This is quite 
a typical application found in industrial control, building 
security/access control systems,  etc.  where an extended multi-drop 
serial  protocol like RS485/422 is used together with a standard message 
format such as Modbus to do remote data aquisition and control of 
embedded devices.

These kind of systems make use of what is refered  to as a master/slave 
serial driver i.e. there is only one master (typically a PC)  and a 
slave device may only respond to polls from the master.

My aim is to create a new Twisted package - say twisted.industrial  - 
which I hope contribute to the  Twisted platform.  I want to achieve 
this by extending Twisted  without modifying any Twisted sources, 
reusing as much as possible of existing Twisted code and * doing things 
very much the "Twisted way" * :)

The main problem is that most of Twisted's base classes seems to  have 
TCP/UDP network connectivity in mind.

I have managed to subclass SelectReactor in order to create 
SerialSelectReactor, base.BaseConnector to create SerialConnector, 
SerialPort to create ExtendedSerialPort  and I have the following piece 
of code working. 

if __name__=='__main__':
        from serialreactor import serialreactor
        factory = ModbusFactory()
        print "start reactor"
        print "exit reactor"

This is good but I want to run more than one serialport (or serial 
protocol) simultaneously - i.e I need to drive up to 64 serial ports at 
the same time. I believe I need  to do something like:

if __name__=='__main__':
        from serialapplication import SerialClient,service
        factory = ModbusFactory()
        print "start client"
        print "exit client"

But I'm finding difficulty in grasping the code in application.internet 
(do not understand why it was done like that)  since I want to subclass 
_AbstractClient which is  seems to be  the product of some clever text 
manipulation and dynamic "class creation".

Any comments, suggestions, recommendations  and am I one the right track?



More information about the Twisted-Python mailing list