<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Feb 2, 2011, at 7:42 AM, Michael Thompson wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On 2 February 2011 10:11, Jason Heeris &lt;<a href="mailto:jason.heeris@gmail.com">jason.heeris@gmail.com</a>&gt; wrote:<br><blockquote type="cite">On 2 February 2011 17:53, Albert Brandl &lt;<a href="mailto:albert.brandl@weiermayer.com">albert.brandl@weiermayer.com</a>&gt; wrote:<br></blockquote><blockquote type="cite"><blockquote type="cite">"string" could be interpreted as "complete message". It might e.g. happen<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">that a message arrives in three chunks. Each time a chunk is read, the<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">dataReceived method is called. When it detects that the message is<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">complete, it calls stringReceived with the content of the message.<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Okay, but I don't see how to use that to solve my particular problem.<br></blockquote><blockquote type="cite">I'm not waiting passively to receive a complete string, I have to<br></blockquote><blockquote type="cite">react to whatever's sent back, character by character, either by<br></blockquote><blockquote type="cite">reporting completion, an error or sending more data. In effect, I<br></blockquote><blockquote type="cite">guess, each character is a "complete message" anyway. I don't think<br></blockquote><blockquote type="cite">the t.i.protocols offer much for that.<br></blockquote><br>Yep you have a pretty simple protocol there so even the basic examples<br>are probably more than you need.<br><br>Something like this might get you started.<br><br>class MyProtocol(Protocol):<br> &nbsp;&nbsp;&nbsp;def send(self, byte):<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.transport.write(byte)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.response = Deferred()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return self.response<br><br> &nbsp;&nbsp;&nbsp;def dataReceived(self, byte):<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.response.callback(byte)<br></div></blockquote></div><br><div>Not quite. &nbsp;You mean:</div><div><br></div><div>class MyProtocol(Protocol):</div><div>&nbsp;&nbsp;# ...</div><div>&nbsp;&nbsp;def dataReceived(self, data):</div><div>&nbsp;&nbsp; &nbsp;for octet in data:</div><div>&nbsp;&nbsp; &nbsp; &nbsp;self.process(octet)</div><div><br></div><div>If the device outputs multiple bytes it might show up to Twisted as strings of arbitrary length (this depends on timings of the serial port which are basically impossible to control), so if you want to process a byte at a time, you need to specifically iterate through the string that is passed, even if it's <i>usually</i>&nbsp;one byte long. &nbsp;(Some of the protocol examples showed multibyte sequences as messages. &nbsp;I don't understand the framing well enough to provide a better example though, sorry.)</div></body></html>