Ticket #3802 (reopened defect )

Opened 10 months ago

Last modified 3 weeks ago

win32 SerialPort requires a reactor that provides "addEvent" method, but doesn't have a good error message if it gets a different one

Reported by: tiendalinux Assigned to: glyph
Type: defect Priority: low
Milestone: Component: core
Keywords: serialport win32 easy documentation Cc:
Branch: Author:
Launchpad Bug:

Description (last modified by glyph)

SerialPort? raises the following exception on Windows if it is used with the default reactor:

  File "twisted\internet\_win32serialport.py", line 56, in __init__
    self.reactor.addEvent(self._overlappedRead.hEvent, self, 'serialReadEvent')
AttributeError: 'SelectReactor' object has no attribute 'addEvent'

It should say something more helpful when given a SelectReactor, explaining that win32eventreactor is required for serial port support on Windows.

Attachments

Change History

  2009-04-26 21:53:33+00:00 changed by itamar

  • status changed from new to closed
  • resolution set to invalid

On windows you need to use the win32eventreactor, e.g.:

from twisted.internet import win32eventreactor
win32eventreactor.install()

before you do any other imports, and all the rest of the code can be the same.

  2009-04-26 21:54:05+00:00 changed by itamar

In particular, you need to use this reactor for *serial* support, not for normal usage.

  2009-04-27 03:12:56+00:00 changed by glyph

  • status changed from closed to reopened
  • description deleted
  • summary changed from SerialPort Outdated to win32 SerialPort requires a reactor that provides "addEvent" method, but doesn't have a good error message if it gets a different one
  • priority changed from normal to low
  • milestone deleted
  • keywords changed from Serial Win32 to serial win32
  • resolution deleted

There's a valid problem here, that's both a documentation and specification problem: twisted.internet.serialport's documentation is unclear as to what is required of the reactor parameter to SerialPort, and it differs between platforms. addEvent is not specified on any reactor interface.

To close this ticket I would say that we need an addEvent method that provides an error message that explains what itamar just did in response to this ticket. There may also be a need for a separate ticket for an interface that explains the semantics of addEvent; ideally this could be added to e.g. the IOCP reactor as well.

  2009-04-27 03:13:25+00:00 changed by glyph

  • keywords changed from serial win32 to serial win32 easy

Since this is a documentation issue, it should be pretty easy to resolve.

  2009-04-27 13:15:38+00:00 changed by tiendalinux

  • status changed from reopened to closed
  • type changed from defect to enhancement
  • resolution set to fixed

Sorry, i initially didn't understand how to use the Win32Reactor, i finally was able to use it, this is a code example, that reads from the serial port and print everything on the screen:

#!/usr/bin/python2.4

from twisted.internet.win32eventreactor import Win32Reactor from twisted.internet import protocol from twisted.internet.serialport import SerialPort?

class MyProtocol( protocol.Protocol ) :

def dataReceived(self, data):

print data

def connectionLost(self, reason='connectionDone'):

print reason

if name == "main":

port = 0 protocol = MyProtocol() reactor = Win32Reactor() myserial = SerialPort? (protocol, port, reactor) print "Server running, press ctrl-C to stop." reactor.run()

  2009-04-27 13:16:38+00:00 changed by exarkun

  • keywords changed from serial win32 easy to serial win32 easy documentation
  • status changed from closed to reopened
  • resolution deleted
  • type changed from enhancement to defect

We should still improve our documentation.

  2010-01-21 16:58:19+00:00 changed by exarkun

  • keywords changed from serial win32 easy documentation to serialport win32 easy documentation
Note: See TracTickets for help on using tickets.