Change serial timeout per read

Hendrik van Rooyen mail at microcorp.co.za
Thu May 10 04:07:59 EDT 2007


 <r..n at syl..er-br...org> wrote:

> I'm writing a driver in Python for an old fashioned piece of serial
> equipment. Currently I'm using the USPP serial module. From what I can
> see all the serial modules seem to set the timeout when you open a
> serial port. This is not what I want to do. I need to change the
> timeout each time  I do a "read" on the serial port, depending on
> which part of the protocol I've got to. Sometimes a return character
> is expected within half a second, sometimes within 2 seconds, and
> sometimes within 20 seconds. How do I do this in USPP, or Pyserial, or
> anything else? Currently I'm working in Windows, but I'd prefer a
> platform independent solution if possible...

Yikes!

you will probably have to make the port non blocking, and roll your own
using different time.sleep(n) values between invocations to port.read(1) calls

Unless you can afford to close and open the port each time - but that way leads
to missed characters...

- Hendrik




More information about the Python-list mailing list