<div dir="ltr">Hi,<div>I try to use twisted for asynchronous&nbsp;serial port read().</div><div><br></div><div>Here is my simple twisted code:</div><div>==========================</div><div><div>from twisted.internet import reactor</div>
<div>from twisted.internet.serialport import SerialPort<br></div><div>from twisted.internet.protocol import Protocol</div><div><br></div><div>class Client(Protocol):</div><div>&nbsp;&nbsp; &nbsp;def connectionMade(self):<br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;print &#39;connected&#39;</div>
<div><br></div><div>&nbsp;&nbsp; &nbsp;def dataReceived(self, data):</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;print data</div><div>&nbsp;&nbsp; &nbsp;<br></div><div>SerialPort(Client(), &#39;COM4&#39;, reactor)</div><div>reactor.callLater(20, reactor.stop())</div><div>reactor.run()</div>
<div><br></div><div>==========================</div><div><br></div><div>It runs on my Mac with this line changed to SerialPort(Client, &#39;dev/tty.usbserial-A4001mLL&#39;, reactor) which is my Arduino board device.</div>
<div><br></div><div>But on Windows XP, it gave the error message:</div><div>&quot;AttributeError: &#39;module&#39; object has no attribute &#39;addEvent&#39; &quot;<br></div><div><br></div><div>I tried to used different reactor, such as selectreactor, win32eventreactor, but the error message became &quot;AssertionError: reactor already installed&quot;</div>
<div><br></div><div>Please help. Thanks</div><div><br></div><div><br></div></div></div>