[Twisted-Python] Guidance needed on serial device interaction

Jason Heeris jason.heeris at gmail.com
Wed Feb 2 03:58:30 EST 2011


On 2 February 2011 15:58, Michael Thompson <michaelnt at gmail.com> wrote:
> The job of the protocol class is to assemble the bytes that you
> receive into packets or messages. Ideally the protocol will have
> characters that frame a message, and it sounds like you might have
> this if > or ! is always sent at the end of every reply.

Apologies, but I just went over the code for the device controller and
I described the protocol a little incorrectly. But anyway... It
depends on what you mean by reply. For example a programming session
might go:

Dev: ">"
PC: "P"
Dev: "."
PC: ":"
Dev: "."
PC: "02000004"
Dev: "."
PC: "1D00"
Dev: "."
PC: "DD"
Dev: "."
<skip to last transmission for last record>
PC: "FF"
Dev: ".0>" (this is the confirmation ".", the status code of the
programming, and the "ready" character)

It's not like the PC sends all the data at once, and the device
processes it all and sends a reply framed by ">". If something goes
wrong in the device, it might be:

Dev: ">"
PC: "P"
Dev: "1>"

...or if the sent data is invalid...

Dev: ">"
PC: "P"
Dev: "."
PC: ":"
Dev "."
PC: "09"
Dev: "3>"

> 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?

> There are some protocol that might be suitable in twisted/protocols/basic.py

No, that all seems to be unrelated to what I need.

>> I'd also like to structure things so that successive calls to the
>> DeviceProtocol object queue up, something like:
>
> You can use a DeferredSemaphore for this.

That looks interesting, thanks :)

— Jason



More information about the Twisted-Python mailing list