<div dir="ltr">This works. Thanks a lot.<div><br><div>So sending and receiving works .. with low CPU usage.</div><div>I need to dig into twisted....</div><div><br></div><div>As a Python starter I want something like serial.send usabel in the main loop and serial.receive to work in the background and only trigger something once data has been received.</div>
<div>Obviously it is possible with python. Just have to find out how :-)</div></div><div><br></div><div>Thanks for the support so far.</div><div><br></div><div>Robert</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On 21 October 2013 22:21,  <span dir="ltr"><<a href="mailto:exarkun@twistedmatrix.com" target="_blank">exarkun@twistedmatrix.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 07:42 pm, <a href="mailto:ltaylor.volks@gmail.com" target="_blank">ltaylor.volks@gmail.com</a> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On Oct 21, 2013, at 6:57 AM, Robert Voigtländer wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks for the fast reply.<br>
I don't yet understand your answer. I may have to dig more into Python.<br>
<br>
On 21 October 2013 13:45, Itamar Turner-Trauring <<a href="mailto:itamar@itamarst.org" target="_blank">itamar@itamarst.org</a>> wrote:<br>
</blockquote>
<br>
<snip guidance to avoid threads><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
3. A reasonable place for the write() might be in your Protocol's connectionMade method.<br>
</blockquote>
<br>
The Protocol has access to a .transport attribute, which is the SerialPort() instance.<br>
<br>
Therefore, you can write to the serial port (the transport) from within your protocol:<br>
<br>
<br>
class Echo(LineReceiver):<br>
<br>
   def connectionMade(self):<br>
       self.transport.write('HELLO\n'<u></u>)<br>
<br>
   def lineReceived(self, line):<br>
       self.transport.write(line + '\n')<br>
</blockquote>
<br>
Additionally, since the serial transport tries hard to look just like a tcp transport or an ssl transport, the generic protocol code in LineReceiver.sendLine will work just fine with it.  So in addition to using the `lineReceived` callback to handle lines that arrive you can use `sendLine` to write lines out to the serial port:<br>

<br>
   class Echo(LineReceiver):<br>
       delimiter = b"\n"<br>
<br>
       def connectionMade(self):<br>
           self.sendLine(b"HELLO")<br>
<br>
       def lineReceived(self, line):<br>
           self.sendLine(line)<br>
<br>
This is part of the power of the transport/protocol separation: reusable protocol logic. :)<br>
<br>
Jean-Paul<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
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.<br>
<br>
<br>
Lucas<br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.<u></u>com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-<u></u>bin/mailman/listinfo/twisted-<u></u>python</a><br>
</blockquote></div><br></div>