[Twisted-Python] asyncronous access to serial ports under windows

Tom Brown brown at esteem.com
Fri Oct 26 18:42:39 EDT 2007


I've been able to create an application in Linux that reads/writes
multiple serial ports asyncronously. The setup code that does this looks
like this:

from twisted.internet.qtreactor import install
a = QApplication(argv)
from twisted.internet import reactor
from twisted.internet.serialport import SerialPort
  ports, badPorts = getGoodPorts()
  if not ports:
  data = ConfigData(join(sep, 'etc', 'qa.conf'))
  dbInfo = copy(data['qadata'])
  w = MainWindow(data, dbInfo, ports)
  reactor.addSystemEventTrigger('after', 'shutdown', a.quit)
  a.connect(a, SIGNAL('lastWindowClosed()'), reactor.stop)
  for portObj in w.portObjs:
    SerialPort(portObj.scanner, portObj.port, reactor, baudrate=38400)

Where the portObj.scanner is an instance of a descendent of Protocol.
Like I said, the above code works under Linux. Then I tried porting this
to Windows. The first problem I came across is that the qtreactor.py
would not work. I had to subclass QTReactor from Win32Reactor. It runs
without errors. However, I am not reading anything off of the serial
port. I can see the lights blink on the port when the portObj.sendLine()
is called, so I believe I am writing to it ok and data is coming back.
The data is just not read by the application. I think it must have
something to do with the SerialPort instance not getting an even that
data is ready. I suspect this is a Windows issue in that Windows is not
signaling an event when data is ready to read on the serial port.

Does anybody have any experience with this? Is there a work around? Am I
doing something wrong?


More information about the Twisted-Python mailing list