diff options
-rw-r--r-- | pyserial/CHANGES.txt | 5 | ||||
-rw-r--r-- | pyserial/serial/serialutil.py | 28 | ||||
-rw-r--r-- | pyserial/serial/serialwin32.py | 8 |
3 files changed, 34 insertions, 7 deletions
diff --git a/pyserial/CHANGES.txt b/pyserial/CHANGES.txt index 7f93e64..1eacd11 100644 --- a/pyserial/CHANGES.txt +++ b/pyserial/CHANGES.txt @@ -156,3 +156,8 @@ Version 2.2 XXXX Bugfixes (win32): - keep RTS/CTS state on port setting changes [Patch 983106] + New Features: + - dsrdtr setting to enable/disable DSR/DTR flow control independently + from the rtscts setting. (Currenly Win32 only, ignored on other + platforms) + diff --git a/pyserial/serial/serialutil.py b/pyserial/serial/serialutil.py index 053aca7..e608264 100644 --- a/pyserial/serial/serialutil.py +++ b/pyserial/serial/serialutil.py @@ -122,6 +122,7 @@ class SerialBase(FileLike): xonxoff=0, #enable software flow control rtscts=0, #enable RTS/CTS flow control writeTimeout=None, #set a timeout for writes + dsrdtr=None, #None: use rtscts setting, dsrdtr override if true or false ): """Initialize comm port object. If a port is given, then the port will be opened immediately. Otherwise a Serial port object in closed state @@ -137,6 +138,7 @@ class SerialBase(FileLike): self._writeTimeout = None #correct value is assigned below trough properties self._xonxoff = None #correct value is assigned below trough properties self._rtscts = None #correct value is assigned below trough properties + self._dsrdtr = None #correct value is assigned below trough properties #assign values using get/set methods using the properties feature self.port = port @@ -148,6 +150,7 @@ class SerialBase(FileLike): self.writeTimeout = writeTimeout self.xonxoff = xonxoff self.rtscts = rtscts + self.dsrdtr = dsrdtr if port is not None: self.open() @@ -308,21 +311,37 @@ class SerialBase(FileLike): xonxoff = property(getXonXoff, setXonXoff, doc="Xon/Xoff setting") def setRtsCts(self, rtscts): - """Change RtsCts setting.""" + """Change RtsCts flow control setting.""" self._rtscts = rtscts if self._isOpen: self._reconfigurePort() def getRtsCts(self): - """Get the current RtsCts setting.""" + """Get the current RtsCts flow control setting.""" return self._rtscts - rtscts = property(getRtsCts, setRtsCts, doc="RTS/CTS setting") + rtscts = property(getRtsCts, setRtsCts, doc="RTS/CTS flow control setting") + def setDsrDtr(self, dsrdtr=None): + """Change DsrDtr flow control setting.""" + if dsrdtr is None: + #if not set, keep backwards compatibility and follow rtscts setting + self._dsrdtr = self._rtscts + else: + #if defined independently, follow its value + self._dsrdtr = dsrdtr + if self._isOpen: self._reconfigurePort() + + def getDsrDtr(self): + """Get the current DsrDtr flow control setting.""" + return self._dsrdtr + + dsrdtr = property(getDsrDtr, setDsrDtr, "DSR/DTR flow control setting") + # - - - - - - - - - - - - - - - - - - - - - - - - def __repr__(self): """String representation of the current port settings and its state.""" - return "%s<id=0x%x, open=%s>(port=%r, baudrate=%r, bytesize=%r, parity=%r, stopbits=%r, timeout=%r, xonxoff=%r, rtscts=%r)" % ( + return "%s<id=0x%x, open=%s>(port=%r, baudrate=%r, bytesize=%r, parity=%r, stopbits=%r, timeout=%r, xonxoff=%r, rtscts=%r, dsrdtr=%r)" % ( self.__class__.__name__, id(self), self._isOpen, @@ -334,6 +353,7 @@ class SerialBase(FileLike): self.timeout, self.xonxoff, self.rtscts, + self.dsrdtr, ) if __name__ == '__main__': diff --git a/pyserial/serial/serialwin32.py b/pyserial/serial/serialwin32.py index af94bd8..cda6205 100644 --- a/pyserial/serial/serialwin32.py +++ b/pyserial/serial/serialwin32.py @@ -11,7 +11,7 @@ import win32event # We use events and the WaitFor[Single|Multiple]Objects functi import win32con # constants. from serialutil import * -VERSION = "$Revision: 1.30 $".split()[1] #extract CVS version +VERSION = "$Revision: 1.31 $".split()[1] #extract CVS version #from winbase.h. these should realy be in win32con MS_CTS_ON = 16 @@ -142,12 +142,14 @@ class Serial(SerialBase): # Char. w/ Parity-Err are replaced with 0xff (if fErrorChar is set to TRUE) if self._rtscts: comDCB.fRtsControl = win32file.RTS_CONTROL_HANDSHAKE - comDCB.fDtrControl = win32file.DTR_CONTROL_HANDSHAKE else: comDCB.fRtsControl = self._rtsState + if self._dsrdtr: + comDCB.fDtrControl = win32file.DTR_CONTROL_HANDSHAKE + else: comDCB.fDtrControl = self._dtrState comDCB.fOutxCtsFlow = self._rtscts - comDCB.fOutxDsrFlow = self._rtscts + comDCB.fOutxDsrFlow = self._dsrdtr comDCB.fOutX = self._xonxoff comDCB.fInX = self._xonxoff comDCB.fNull = 0 |