Question regarding win32comport_demo.py

David Bolen db3l at fitlinxx.com
Sat Feb 2 01:19:34 CET 2002


"MDK" <mdk at mdk.com> writes:

> The reason behind this is I am trying to uderstand where I am getting the
> data from as the example uses a continusly looping thread to get the data
> which, in light of what you are saying, is not necessary.  Once the
> CreateFile() is done then I can just access the memory buffer.

Using ReadFile() is _how_ you access the memory buffer.  The buffer
Peter was referring to is inside the serial port driver under NT (or
possibly also the filesystem layer, but still within the OS domain).
You can't directly access it because it needs to be managed and
interlocked between retrieval and new insertions (during interrupt
processing).

The serial driver on the system is arbitrating between you and the
physical hardware.  On the receive path, this ensures that no data is
lost, as the driver buffers received information until your
application is ready to accept it (with ReadFile()).

To your original question about the "serial ports memory buffer", most
serial port hardware at best has an approximately 16 byte FIFO queue
of data it has received.  Data has to be drained from there rapidly or
you'll lose new incoming information, so access at that level is
handled by the hardware device driver during interrupt processing (the
serial port chip will interrupt when the FIFO is near full - or at
selectable fill levels).

You need far more buffering than that on most multitasking systems to
ensure data is held until an application gets around to looking at it,
thus the serial port driver has its own buffers, and there may even be
additional buffering being done at higher layers where the port is
behaving like a file handle.  The good news is that you don't really
need to worry about any of this - just open the port as a file, and
then use standard NT file I/O operations (ReadFile, WriteFile) to
perform the I/O.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list