Ticket #4525: 4525-1.diff
File 4525-1.diff, 5.4 KB (added by , 12 years ago) |
---|
-
twisted/internet/_posixserialport.py
3 3 4 4 """ 5 5 Serial Port Protocol 6 7 Requires: 8 pySerial - http://pyserial.sourceforge.net/ 6 9 """ 7 10 8 # dependent on pyserial ( http://pyserial.sf.net/ )9 11 # 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 12 from serial import PARITY_NONE, STOPBITS_ONE, EIGHTBITS 13 13 14 from serialport import BaseSerialPort15 16 14 # twisted imports 17 15 from twisted.internet import abstract, fdesc 16 from twisted.internet.serialport import BaseSerialPort 18 17 18 19 19 20 class SerialPort(BaseSerialPort, abstract.FileDescriptor): 20 21 """ 21 22 A select()able serial device, acting as a transport. … … 26 27 def __init__(self, protocol, deviceNameOrPortNumber, reactor, 27 28 baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE, 28 29 stopbits=STOPBITS_ONE, timeout=None, xonxoff=0, rtscts=0): 30 29 31 abstract.FileDescriptor.__init__(self, reactor) 30 32 BaseSerialPort.__init__( 31 self, deviceNameOrPortNumber,33 self, protocol, deviceNameOrPortNumber, reactor, 32 34 baudrate=baudrate, bytesize=bytesize, 33 35 parity=parity, stopbits=stopbits, 34 36 xonxoff=xonxoff, rtscts=rtscts) 35 self.reactor = reactor 36 self.flushInput() 37 self.flushOutput() 38 self.protocol = protocol 37 39 38 self.protocol.makeConnection(self) 40 39 self.startReading() 41 40 -
twisted/internet/_win32serialport.py
4 4 """ 5 5 Serial port support for Windows. 6 6 7 Requires PySerial and win32all, and needs to be used with win32event 8 reactor. 7 Requires: 8 pySerial - http://pyserial.sourceforge.net/ 9 pywin32 (previously win32all) - http://pywin32.sourceforge.net/ 10 11 Also, needs to be used with a reactor that implements 12 L{twisted.internet.interfaces.IReactorWin32Events} 13 e.g. L{twisted.internet.win32eventreactor} win32eventreactor. 9 14 """ 10 15 11 16 # system imports … … 14 19 15 20 # twisted imports 16 21 from twisted.internet import abstract 17 18 # sibling imports19 22 from twisted.internet.serialport import BaseSerialPort 20 23 21 24 25 22 26 class SerialPort(BaseSerialPort, abstract.FileDescriptor): 23 27 """ 24 28 A select()able serial device, acting as a transport. … … 29 33 def __init__(self, protocol, deviceNameOrPortNumber, reactor, 30 34 baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE, 31 35 stopbits=STOPBITS_ONE, xonxoff=0, rtscts=0): 36 37 abstract.FileDescriptor.__init__(self, reactor) 32 38 BaseSerialPort.__init__( 33 self, deviceNameOrPortNumber,39 self, protocol, deviceNameOrPortNumber, reactor, 34 40 baudrate=baudrate, bytesize=bytesize, 35 41 parity=parity, stopbits=stopbits, 36 42 xonxoff=xonxoff, rtscts=rtscts) 37 43 38 self.flushInput()39 self.flushOutput()40 self.reactor = reactor41 self.protocol = protocol42 44 self.outQueue = [] 43 45 self.closed = 0 44 46 self.closedNotifies = 0 45 47 self.writeInProgress = 0 46 48 47 self.protocol = protocol48 49 self._overlappedRead = win32file.OVERLAPPED() 49 50 self._overlappedRead.hEvent = win32event.CreateEvent(None, 1, 0, None) 50 51 self._overlappedWrite = win32file.OVERLAPPED() -
twisted/internet/serialport.py
28 28 def __init__( 29 29 self, protocol, deviceNameOrPortNumber, reactor, 30 30 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): 32 32 """ 33 33 Initialize this serial transport. 34 34 … … 70 70 @param rtscts: enable RTS/CTS flow control (0/1) 71 71 @type rtscts: C{int} 72 72 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 73 77 @raise ValueError: Will be raised when serial parameters are out of range, 74 78 e.g baudrate, bytesize, etc. 75 79 76 80 @raise SerialException: In case the device can not be found or can 77 81 not be configured. 78 82 """ 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 80 87 # and other initialization is done in the subclasses. 81 88 self._serial = serial.Serial( 82 89 deviceNameOrPortNumber, baudrate=baudrate, 83 90 bytesize=bytesize, parity=parity, 84 91 stopbits=stopbits, timeout=None, 85 92 xonxoff=xonxoff, rtscts=rtscts) 86 87 93 94 self.flushInput() 95 self.flushOutput() 96 88 97 def setBaudRate(self, baudrate): 89 98 if hasattr(self._serial, "setBaudrate"): 90 99 self._serial.setBaudrate(baudrate)