Unexpected long pyserial read delay on Windows

John Nagle nagle at animats.com
Sun Feb 22 12:05:20 EST 2009


    I've been using PySerial on Windows (Win2000, amusingly) to drive
a Baudot teletype at 45.45 baud.  Input and output work, but there's
a delay of about 1 second (!) on the input side between receiving a
character and reporting it to the program.

    I'm using the latest "supports 1.5 stop bits" version of PySerial
(as noted previously, this is necessary for the old mechanical Teletypes),
and opening as follows:

	ser = serial.Serial(port, baudrate=baud,
			bytesize=serial.FIVEBITS,
			parity=serial.PARITY_NONE,
			stopbits=serial.STOPBITS_ONE5,
			timeout=None)

I've tried omitting the timeout parameter, "timeout=0", and "timeout=0.1",
none of which seem to change the behavior.  The code doing the
reading is simply

while True :
     s = ser.read()				# get some input
     for ch in s:
	ser.write(ch)				# write to tty

This correctly types back what's typed in, but with a delay of about 10
character times, over 1 second. (Remember, this is a VERY slow serial
device.) There's nothing else running; CPU load is under 1%.

I've tried "ser.read(1)"; makes no difference.

The delay is on the read side; if I put in a "print", the delay occurs
before the computer prints the received character.

Is this some Windows thing?  I've looked at serialwin32.py around line 88,
and don't see any nonzero timeout parameters being fed to Windows
when "timeout=None".  Checking the Microsoft documentation, at

http://msdn.microsoft.com/en-us/library/aa363190(VS.85).aspx

feeding all zeroes into the COMMTIMEOUT structure should result in no
additional delays.

				John Nagle

	



More information about the Python-list mailing list