[Twisted-Python] serialport protocol as a service
Lucas Taylor
ltaylor.volks at gmail.com
Tue Dec 8 14:50:37 EST 2009
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
More information about the Twisted-Python
mailing list