[Twisted-Python] About transport.

Francisco Herrero francisco.herrero at gmail.com
Thu Jun 14 15:51:34 EDT 2007


Hello community. At first excuse me for my poor english, I'm from Argentina.


I am building a abstraction layer for different protocols of communication
for microcontrolled components simulation on a PC. That is CAN, Mil-1553 and
RS422.
First I m building a model width serial port. The idea is to connect via tcp
to this channel. I choose as a model the class internet.serialport. This
works fine but I do not know how to redirect the protocol of serialport to
the protocol of TCP port:

-----------------------
from rs232 import RS232Connector
from twisted.internet import reactor, protocol
from twisted.application import service, internet

class RS232Channel(protocol.Protocol):
    def dataReceived(self, data):
        print "CHAN:" + data
        self.factory.port.transport.write(data)

class RS232Port(protocol.Protocol):
    def dataReceived(self, data):
        print "PORT:" + data
        self.factory.channel.protocol.transport.write(data)

class RS232Factory(protocol.Factory):
    protocol = RS232Port

    def __init__(self):
        conf = {}
        self.port = RS232Port()
        self.channel = RS232Connector(self.port, conf, reactor)

if __name__ == '__main__':
    factory = RS232Factory()
    reactor.listenTCP(5001, factory)
    reactor.run()
--------------
this works fine when data is received from the tcp port, but when come data
from the serial port the program can't find the factory for RS232Channel
protocol instance. That is logical. I try to switch the transport but I
can't go so far...
Anyone can tell me how to connect this 2 protocols

Thanks

Francisco

-- 
"El hombre se descubre cuando se mide con un obstáculo"
(Saint Exupéry)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20070614/b01589ae/attachment.htm 


More information about the Twisted-Python mailing list