[Twisted-Python] asyncronous access to serial ports under windows
Tom Brown
brown at esteem.com
Fri Oct 26 16:42:39 MDT 2007
Hi,
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)
install(a)
from twisted.internet import reactor
from twisted.internet.serialport import SerialPort
...
ports, badPorts = getGoodPorts()
if not ports:
exit(1)
data = ConfigData(join(sep, 'etc', 'qa.conf'))
dbInfo = copy(data['qadata'])
getLogin(dbInfo)
w = MainWindow(data, dbInfo, ports)
w.show()
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)
portObj.sendLine()
reactor.run()
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?
Thanks,
Tom
More information about the Twisted-Python
mailing list