On Fri, 2007-10-26 at 15:42 -0700, Tom Brown wrote:
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?
Well, I found out that it has something to do with the qtreactor. If I use just a Win32Reactor, it will read/write the serial port just fine. I played around with writing to the serial port using scanner.transport.write('\n') and found that Win32Reactor.doWaitForMultipleEvents() is called when a Win32Reactor is used. It is not called when a QTReactor(Win32Reactor) is used. The question is why is this the case? Thanks, Tom