[Twisted-Python] Re: python-list query re sockets, select or: twisted and other file-descriptors & twisted question
![](https://secure.gravatar.com/avatar/f0679e5e26b35bb36f920755b05e1643.jpg?s=120&d=mm&r=g)
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.
![](https://secure.gravatar.com/avatar/88040ce438148017cf0692406e5d28c7.jpg?s=120&d=mm&r=g)
On Sat, Nov 29, 2003 at 08:26:50PM -0800, John Benson wrote:
So, select might not yet work on Windows serial ports as well as sockets.
That's correct. Windows select is from the Winsock library, and only works with sockets.
Thankfully, pySerial has already taken care of the details of cross-platform serial-port access (apparently, I've never used it): http://pyserial.sourceforge.net/
Twisted uses pySerial, so the platform you're running Twisted on shouldn't matter. There are some examples in the doc/examples directory of Twisted that use the serial port: mouse.py -- example using MouseMan protocol with the SerialPort transport gpsfix.py -- example using the SerialPort transport and the NMEA 0183 and Rockwell Zodiac GPS protocols to display fix data as it is received from the device. -Andrew.
![](https://secure.gravatar.com/avatar/88040ce438148017cf0692406e5d28c7.jpg?s=120&d=mm&r=g)
On Sat, Nov 29, 2003 at 08:26:50PM -0800, John Benson wrote:
So, select might not yet work on Windows serial ports as well as sockets.
That's correct. Windows select is from the Winsock library, and only works with sockets.
Thankfully, pySerial has already taken care of the details of cross-platform serial-port access (apparently, I've never used it): http://pyserial.sourceforge.net/
Twisted uses pySerial, so the platform you're running Twisted on shouldn't matter. There are some examples in the doc/examples directory of Twisted that use the serial port: mouse.py -- example using MouseMan protocol with the SerialPort transport gpsfix.py -- example using the SerialPort transport and the NMEA 0183 and Rockwell Zodiac GPS protocols to display fix data as it is received from the device. -Andrew.
participants (2)
-
Andrew Bennetts
-
John Benson