Ticket #4525: 4525-1.diff

File 4525-1.diff, 5.4 KB (added by Lucas Taylor, 12 years ago)

Minor modifications

  • twisted/internet/_posixserialport.py

     
    33
    44"""
    55Serial Port Protocol
     6
     7Requires:
     8pySerial - http://pyserial.sourceforge.net/
    69"""
    710
    8 # dependent on pyserial ( http://pyserial.sf.net/ )
    911# only tested w/ 1.18 (5 Dec 2002)
    10 from serial import PARITY_NONE
    11 from serial import STOPBITS_ONE
    12 from serial import EIGHTBITS
     12from serial import PARITY_NONE, STOPBITS_ONE, EIGHTBITS
    1313
    14 from serialport import BaseSerialPort
    15 
    1614# twisted imports
    1715from twisted.internet import abstract, fdesc
     16from twisted.internet.serialport import BaseSerialPort
    1817
     18
     19
    1920class SerialPort(BaseSerialPort, abstract.FileDescriptor):
    2021    """
    2122    A select()able serial device, acting as a transport.
     
    2627    def __init__(self, protocol, deviceNameOrPortNumber, reactor,
    2728        baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE,
    2829        stopbits=STOPBITS_ONE, timeout=None, xonxoff=0, rtscts=0):
     30       
    2931        abstract.FileDescriptor.__init__(self, reactor)
    3032        BaseSerialPort.__init__(
    31                 self, deviceNameOrPortNumber,
     33                self, protocol, deviceNameOrPortNumber, reactor,
    3234                baudrate=baudrate, bytesize=bytesize,
    3335                parity=parity, stopbits=stopbits,
    3436                xonxoff=xonxoff, rtscts=rtscts)
    35         self.reactor = reactor
    36         self.flushInput()
    37         self.flushOutput()
    38         self.protocol = protocol
     37       
    3938        self.protocol.makeConnection(self)
    4039        self.startReading()
    4140
  • twisted/internet/_win32serialport.py

     
    44"""
    55Serial port support for Windows.
    66
    7 Requires PySerial and win32all, and needs to be used with win32event
    8 reactor.
     7Requires:
     8pySerial - http://pyserial.sourceforge.net/
     9pywin32 (previously win32all) - http://pywin32.sourceforge.net/
     10
     11Also, needs to be used with a reactor that implements
     12L{twisted.internet.interfaces.IReactorWin32Events}
     13e.g. L{twisted.internet.win32eventreactor} win32eventreactor.
    914"""
    1015
    1116# system imports
     
    1419
    1520# twisted imports
    1621from twisted.internet import abstract
    17 
    18 # sibling imports
    1922from twisted.internet.serialport import BaseSerialPort
    2023
    2124
     25
    2226class SerialPort(BaseSerialPort, abstract.FileDescriptor):
    2327    """
    2428    A select()able serial device, acting as a transport.
     
    2933    def __init__(self, protocol, deviceNameOrPortNumber, reactor,
    3034        baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE,
    3135        stopbits=STOPBITS_ONE, xonxoff=0, rtscts=0):
     36
     37        abstract.FileDescriptor.__init__(self, reactor)
    3238        BaseSerialPort.__init__(
    33             self, deviceNameOrPortNumber,
     39            self, protocol, deviceNameOrPortNumber, reactor,
    3440            baudrate=baudrate, bytesize=bytesize,
    3541            parity=parity, stopbits=stopbits,
    3642            xonxoff=xonxoff, rtscts=rtscts)
    3743
    38         self.flushInput()
    39         self.flushOutput()
    40         self.reactor = reactor
    41         self.protocol = protocol
    4244        self.outQueue = []
    4345        self.closed = 0
    4446        self.closedNotifies = 0
    4547        self.writeInProgress = 0
    4648
    47         self.protocol = protocol
    4849        self._overlappedRead = win32file.OVERLAPPED()
    4950        self._overlappedRead.hEvent = win32event.CreateEvent(None, 1, 0, None)
    5051        self._overlappedWrite = win32file.OVERLAPPED()
  • twisted/internet/serialport.py

     
    2828    def __init__(
    2929        self, protocol, deviceNameOrPortNumber, reactor,
    3030        baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE,
    31         stopbits=STOPBITS_ONE, timeout=0, xonxoff=0, rtscts=0):
     31        stopbits=STOPBITS_ONE, timeout=None, xonxoff=0, rtscts=0):
    3232        """
    3333        Initialize this serial transport.
    3434
     
    7070        @param rtscts: enable RTS/CTS flow control (0/1)
    7171        @type rtscts: C{int}
    7272       
     73        @raise ValueError: on Windows, if the reactor does not support
     74                           L{twisted.internet.interfaces.IReactorWin32Events}
     75                           e.g. L{twisted.internet.win32eventreactor}
     76       
    7377        @raise ValueError: Will be raised when serial parameters are out of range,
    7478            e.g baudrate, bytesize, etc.
    75 
     79       
    7680        @raise SerialException: In case the device can not be found or can
    7781            not be configured.
    7882        """
    79         # Only initialize the underlying Serial instance.  Error checking
     83        self.protocol = protocol
     84        self.reactor = reactor
     85
     86        # Initialize the underlying Serial instance.  Error checking
    8087        # and other initialization is done in the subclasses.
    8188        self._serial = serial.Serial(
    8289            deviceNameOrPortNumber, baudrate=baudrate,
    8390            bytesize=bytesize, parity=parity,
    8491            stopbits=stopbits, timeout=None,
    8592            xonxoff=xonxoff, rtscts=rtscts)
    86 
    87 
     93       
     94        self.flushInput()
     95        self.flushOutput()
     96       
    8897    def setBaudRate(self, baudrate):
    8998        if hasattr(self._serial, "setBaudrate"):
    9099            self._serial.setBaudrate(baudrate)