[Twisted-Python] Guidance needed on serial device interaction
Michael Thompson
michaelnt at gmail.com
Wed Feb 2 08:42:22 MST 2011
On 2 February 2011 10:11, Jason Heeris <jason.heeris at gmail.com> wrote:
> On 2 February 2011 17:53, Albert Brandl <albert.brandl at weiermayer.com> wrote:
>> "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.
>
> Okay, but I don't see how to use that to solve my particular problem.
> I'm not waiting passively to receive a complete string, I have to
> react to whatever's sent back, character by character, either by
> reporting completion, an error or sending more data. In effect, I
> guess, each character is a "complete message" anyway. I don't think
> the t.i.protocols offer much for that.
Yep you have a pretty simple protocol there so even the basic examples
are probably more than you need.
Something like this might get you started.
class MyProtocol(Protocol):
def send(self, byte):
self.transport.write(byte)
self.response = Deferred()
return self.response
def dataReceived(self, byte):
self.response.callback(byte)
More information about the Twisted-Python
mailing list