Unexpected long pyserial read delay on Windows

Discussion in 'Python' started by John Nagle, Feb 22, 2009.

  1. John Nagle

    John Nagle Guest

    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
    John Nagle, Feb 22, 2009
    #1
    1. Advertising

  2. John Nagle

    John Nagle Guest

    Grant Edwards wrote:
    > On 2009-02-22, John Nagle <> wrote:
    >
    >> 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.

    >
    > The UART you're using almost certainly has a receive FIFO.
    > Normally, the UART doesn't interrupt the CPU to tell it there's
    > receeve data ready until the FIFO is almost full (eg 12 bytes
    > present in a 16 byte FIFO).
    >
    > If the UART has an empty receive FIFO, and it receives a single
    > character that character goes into the receive FIFO. If data
    > stops coming in before the rx FIFO threshold is reached, the
    > UART will wait 40 bit-times...


    Ah, 40 bit times. That's the default. And that's the problem.
    I thought the accumulation timer was a fixed timer of a few milliseconds.

    There is a "disable FIFO" checkbox in Windows 2000. It's hard to
    find.

    - Log off as user.
    - Log on as "administrator"
    - Open Control Panel -> System
    - Go to "Devices" tab and select "Device manager".
    - Open "Ports" in the tree and click on desired COM1 port.
    - Click "Advanced" button.
    - Set "Receive buffer size" slider to 1.
    - Click "Disable FIFO" checkbox.
    - Close all the dialogs.
    - Reboot. (Yes, it doesn't take effect until the next reboot.)

    That fixed the problem. Thanks.

    John Nagle
    John Nagle, Feb 22, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    645
    Eric Sosman
    Jul 8, 2003
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,161
    Peter Shaggy Haywood
    Sep 20, 2005
  3. Mathieu Dutour

    long long and long

    Mathieu Dutour, Jul 17, 2007, in forum: C Programming
    Replies:
    4
    Views:
    447
    santosh
    Jul 24, 2007
  4. Bart C

    Use of Long and Long Long

    Bart C, Jan 9, 2008, in forum: C Programming
    Replies:
    27
    Views:
    767
    Peter Nilsson
    Jan 15, 2008
  5. Steven Woody

    pyserial: Unexpected Local Echo

    Steven Woody, Jan 11, 2010, in forum: Python
    Replies:
    5
    Views:
    1,523
    Steve Holden
    Jan 18, 2010
Loading...

Share This Page