Re: python-list query re sockets, select or: twisted and other file-descriptors & twisted question

From: John Benson (jsbenson_at_bensonsystems.com)
Date: 11/30/03


Date: Sat, 29 Nov 2003 20:26:50 -0800
To: <python-list@python.org>

In response to the question about doing serial i/o and using a select
statement, I'd like to quote from
http://www.python.org/doc/current/lib/module-select.html

select(iwtd, owtd, ewtd[, timeout])

This is a straightforward interface to the Unix select() system call. The
first three arguments are lists of `waitable objects': either integers
representing file descriptors or objects with a parameterless method named
fileno() returning such an integer. The three lists of waitable objects are
for input, output and `exceptional conditions', respectively. Empty lists
are allowed, but acceptance of three empty lists is platform-dependent. (It
is known to work on Unix but not on Windows.) The optional timeout argument
specifies a time-out as a floating point number in seconds. When the timeout
argument is omitted the function blocks until at least one file descriptor
is ready. A time-out value of zero specifies a poll and never blocks.
The return value is a triple of lists of objects that are ready: subsets of
the first three arguments. When the time-out is reached without a file
descriptor becoming ready, three empty lists are returned.
Among the acceptable object types in the lists are Python file objects (e.g.
sys.stdin, or objects returned by open() or os.popen()), socket objects
returned by socket.socket(). You may also define a wrapper class yourself,
as long as it has an appropriate fileno() method (that really returns a file
descriptor, not just a random integer). Note: File objects on Windows are
not acceptable, but sockets are. On Windows, the underlying select()
function is provided by the WinSock library, and does not handle file
desciptors that don't originate from WinSock.

(end quote)

So, select might not yet work on Windows serial ports as well as sockets.
This is also a subject of interest to me, but all I can think of is handling
the sockets via select() and polling periodically for data on the serial
port using callLater() and some win32 calls. Maybe the win32 serial port
handling could even be wrapped in a 'waitable object' as described above for
use with the Python select() call.

I recall reading somewhere that the twisted framework has the ability to
handle serial communications in connection with Global Positioning System
device interaction, but don't have any information about it. I'm going to
post this to the twisted mailing list :

Question for twisted folks: How can I add serial Windows serial port
communications as a twisted protocol? Please cross-post back to the
python-list.



Relevant Pages

  • Re: Datatransfer via serial line
    ... The program maintains some lists according to what ... > comes in on the serial port. ... > remote device. ... Wrap a bit of protocol round the data. ...
    (comp.os.linux.development.system)
  • Re: UDP reading on multiple sockets
    ... you just pass it three lists of file-like ... together with an optional timeout. ... waiting to be read, writing to the ones waiting for something to be written, ... and perhaps reporting errors and closing the ones that report problems. ...
    (comp.lang.python)
  • Re: Understanding ipfw keep-state dynamic rules
    ... ipfw -d show lists: ... active but the timeout is kept under 5 seconds, ... ipfw has a default timeout of 300, and the it only uses the ... could in principle want to send more data on the connection ...
    (freebsd-net)
  • Re: GPRS card
    ... I tried some w/o a result. ... > card and it starts ringing. ... Have you tried with different serial port parameters like speed and parity? ... pcmcia-cs or kernel ARM/serial people and their mailing lists. ...
    (comp.os.linux.hardware)
  • Datatransfer via serial line
    ... The program maintains some lists according to what ... comes in on the serial port. ... remote device. ... Do I just rely on the transmission quality or, if not, how do I ensure ...
    (comp.os.linux.development.system)