[Twisted-Python] Guidance needed on serial device interaction

Albert Brandl albert.brandl at weiermayer.com
Wed Feb 2 02:53:09 MST 2011


Hi!

On Wed, Feb 02, 2011 at 04:58:30PM +0800, Jason Heeris wrote:
> > The protocol dataReceived method will be called as  data arrives at
> > the serial port once enough data has arrived to complete a message
> > this method calls stringReceived with the complete message.
> 
> I don't know what this is for though... what's the point of
> stringReceived? What uses that?

"string" could be interpreted as "complete message". It might e.g. happen 
that a message arrives in three chunks. Each time a chunk is read, the 
dataReceived method is called. When it detects that the message is 
complete, it calls stringReceived with the content of the message.

Beware that the third chunk might also contain a part of the next 
message. This should of course _not_ be forwarded to stringReceived,
but buffered until the next message is complete.

It helped me a lot to read the source code in basic.py, which can be 
found in the directory twisted/protocols, or online here:

http://twistedmatrix.com/trac/browser/tags/releases/twisted-10.2.0/twisted/protocols/basic.py

It has lots of documentation and is very readable IMHO.

Regards, Albert
-- 
Albert Brandl
Weiermayer Solutions GmbH      | Abteistraße 12, A-4813 Altmünster
phone: +43 (0) 720 70 30 14    | fax: +43 (0) 7612 20 3 56
web: http://www.weiermayer.com




More information about the Twisted-Python mailing list