[Twisted-Python] serial communication - getting started

Lucas Taylor ltaylor.volks at gmail.com
Mon Oct 21 13:42:27 MDT 2013


On Oct 21, 2013, at 6:57 AM, Robert Voigtländer wrote:

> Thanks for the fast reply.
> I don't yet understand your answer. I may have to dig more into Python.
> 
> On 21 October 2013 13:45, Itamar Turner-Trauring <itamar at itamarst.org> wrote:

<snip guidance to avoid threads>

> 
> 3. A reasonable place for the write() might be in your Protocol's connectionMade method.
> 
> 



The Protocol has access to a .transport attribute, which is the SerialPort() instance. 

Therefore, you can write to the serial port (the transport) from within your protocol:


class Echo(LineReceiver):

    def connectionMade(self):
        self.transport.write('HELLO\n')

    def lineReceived(self, line):
        self.transport.write(line + '\n')


The connectionMade method will be called once the transport (the SerialPort instance) is ready (the serial port is open), making it an appropriate place to kick off an init sequence or similar.


Lucas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20131021/645a739d/attachment.html>


More information about the Twisted-Python mailing list