Q: serial port transmit pending count

Grant Edwards grante at visi.com
Wed Nov 27 14:42:02 EST 2002


In article <3de51ad1$1 at news.nz.asiaonline.net>, Colin Brown wrote:

> I was attempting to use file stats but figured that was
> probably not the right way to do it. Termios looked a little
> daunting. In my application I only need a rough count of the
> remaining characters in the queue so that I can keep it topped
> up during periodic checking.

The query tells you how many bytes are buffered, but it doesn't
tell you the size of the buffers. Figuring 4K as a minimum is
probably safe.

The way one usually does that is to configure it for
non-blocking writes, and then periodically just fill it up
using write() calls until write() returns with a count less
than the requested count.

Or you can select() on the file descriptor.  It will become
"writable" when the tx queue count drops below some hard-wired
value (256, IIRC).

Or, just fork off a thread for each port, and use blocking
writes.  I've gotten rather fond of that method lately.

-- 
Grant Edwards                   grante             Yow!  .. I must be a
                                  at               VETERINARIAN...
                               visi.com            



More information about the Python-list mailing list