[Twisted-Python] Serial port communication

Daniel Marfil dmarfil at citic.es
Tue Mar 25 07:45:25 EDT 2008


Hi, I'm trying to send some commands to a modem connected to the serial 
port, in a sequential way.
I can send the first command to the modem but I must wait for the whole 
response before sending the next command. I haven't got much experience 
with Twisted so I'm not sure about the best protocol I can use for this.
At this moment I'm trying with SerialPort (from 
twisted.internet.serialport) as my factory, and LineReceiver (from 
twisted.protocols.basic) as its protocol.
I can write to the serial port with the SerialPort's method 
writeSomeData and it works fine, but the modem returns the response byte 
to byte, so the dataReceived method (in the LineReceiver protocol) is 
launched with every byte received, so I have to store the bytes in a 
string so I can find the end of the response and then I can see the 
whole response.
So I can get the whole response from the modem, but in that moment I 
don't know how to tell the factory that it can send another 
writeSomeData (remember that it must be done in a sequential way).
So the question is: how can I tell the factory that it can run another 
writeSomeData once I got the right response from the modem?

I know that the main problem is my inexperience with Twisted, so I'm 
sure there's a better way to implement this. Maybe a more appropiate 
protocol?

Any clue will be very welcome ;-)

Thanks in advance,

Daniel Marfil




More information about the Twisted-Python mailing list