[Twisted-Python] serialport protocol as a service

Aníbal Pacheco apacheco.uy at gmail.com
Tue Dec 8 20:36:59 EST 2009

On 12/08/2009 05:50 PM, Lucas Taylor wrote:
> On 12/8/09 5:24 AM, Aníbal Pacheco wrote:
>> Hello list,
>> Is there any way to get a service like the twisted.internet.TCPServer
>> but for serialport?
>> I read the serialport code but couldn't figure out how to build such an
>> analogy with the tcp server.
>> The goal I wanna reach is to attach this "serial port service" to my
>> service.MultiService object which already works great with a TCPServer
>> and two TimerService
> You should be able to implement your own Service class and create your
> SerialPort instances in the startService method. e.g. (untested):
> from twisted.application import service
> from twisted.internet import reactor
> from twisted.internet.serialport import SerialPort
> from twisted.protocols.basic import LineReceiver
> class SerialService(service.Service):
>      def startService(self):
>          self.serial = SerialPort(LineReceiver, '/dev/tty/serialport',
> reactor)
> multiService = service.MultiService()
> serialService = SerialService()
> serialService.setServiceParent(multiService)
> # Add some other services...
> application = service.Application("Serial MultiService Example")
> multiService.setServiceParent(application)
> http://twistedmatrix.com/documents/9.0.0/api/twisted.application.service.Service.html

Many thanks!

I could solve the problem after asking for help, I've "attached" my 
serial protocol to the reactor,  I was confused because before that in 
my program there was no need for importing the reactor. Anyway, I will 
consider your code because it seems to fit better in my service than my 

More information about the Twisted-Python mailing list