FAQ
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

Search Discussions

  • Grant Edwards at Feb 22, 2009 at 4:57 pm

    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 and then interrupt the CPU to tell
    it there is receive data ready.

    The thought is that maybe there's more data coming -- we don't
    want to waste the CPU's time handling a single byte if there's
    more data coming in.

    At 45.45 baud, 40 bit-times is pretty close to 1 second.

    If you don't want to wait 40-bit times for the rx data timeout,
    then you need to disable the rx FIFO. I'm not sure how you do
    that in Windows. I don't remember seeing anything in pyserial
    to do it, but I avoid Windows as much as possible. You might
    want to go looking around in the device manager to see if
    there's a checkbox "disalbe FIFO" in the serial port driver
    config.

    If not, then Google can probably help.

    --
    Grant
  • John Nagle at Feb 22, 2009 at 6:38 pm

    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedFeb 22, '09 at 4:57p
activeFeb 22, '09 at 6:38p
posts3
users2
websitepython.org

2 users in discussion

John Nagle: 2 posts Grant Edwards: 1 post

People

Translate

site design / logo © 2022 Grokbase