summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2008-06-21 00:09:31 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2008-06-21 00:09:31 +0000
commit997b63ce4edd6242c1ed1819f7149c71a0290d31 (patch)
tree80c372c8730fe220fd2b05dd5d076683903d5f07
parent679bfa6d0a4ad51e1a310ab7ad7555522188ef2b (diff)
downloadpyserial-git-997b63ce4edd6242c1ed1819f7149c71a0290d31.tar.gz
[patch 1924805] add a setBreak function (proposed files attached)
-rw-r--r--pyserial/CHANGES.txt5
-rw-r--r--pyserial/serial/serialjava.py7
-rw-r--r--pyserial/serial/serialposix.py13
-rw-r--r--pyserial/serial/serialwin32.py10
4 files changed, 31 insertions, 4 deletions
diff --git a/pyserial/CHANGES.txt b/pyserial/CHANGES.txt
index 4070096..e85c42b 100644
--- a/pyserial/CHANGES.txt
+++ b/pyserial/CHANGES.txt
@@ -240,7 +240,7 @@ Version 2.3 19 Jun 2008
New Features:
- iterator interface. ``for line in Serial(...): ...`` is now possible
- Sugested by Bernhard Bender
+ Suggested by Bernhard Bender
- ``sendBreak()`` accepts a ``duration`` argument. Default duration increased.
@@ -277,7 +277,10 @@ Version 2.4
---------------------------
New Features:
- [Patch 1616790] pyserial: Add inter-character timeout feature
+- [patch 1924805] add a setBreak function (proposed files attached)
+
Bugfixes:
Bugfixes (posix):
- [Bug 1783159] Arbitrary baud rates (Linux/Posix)
+
Bugfixes (win32):
diff --git a/pyserial/serial/serialjava.py b/pyserial/serial/serialjava.py
index 9b56c95..f2e0c1b 100644
--- a/pyserial/serial/serialjava.py
+++ b/pyserial/serial/serialjava.py
@@ -153,10 +153,15 @@ class Serial(SerialBase):
self._outstream.flush()
def sendBreak(self, duration=0.25):
- """Send break condition."""
+ """Send break condition. Timed, returns to idle state after given duration."""
if not self.sPort: raise portNotOpenError
self.sPort.sendBreak(duration*1000.0)
+ def setBreak(self, level=1):
+ """Set break: Controls TXD. When active, to transmitting is possible."""
+ if self.fd is None: raise portNotOpenError
+ raise SerialException("The setBreak function is not implemented in java.")
+
def setRTS(self, level=1):
"""Set terminal status line: Request To Send"""
if not self.sPort: raise portNotOpenError
diff --git a/pyserial/serial/serialposix.py b/pyserial/serial/serialposix.py
index 6f57d73..f19920b 100644
--- a/pyserial/serial/serialposix.py
+++ b/pyserial/serial/serialposix.py
@@ -121,6 +121,9 @@ TIOCM_zero_str = struct.pack('I', 0)
TIOCM_RTS_str = struct.pack('I', TIOCM_RTS)
TIOCM_DTR_str = struct.pack('I', TIOCM_DTR)
+TIOCSBRK = hasattr(TERMIOS, 'TIOCSBRK') and TERMIOS.TIOCSBRK or 0x5427
+TIOCCBRK = hasattr(TERMIOS, 'TIOCCBRK') and TERMIOS.TIOCCBRK or 0x5428
+
ASYNC_SPD_MASK = 0x1030
ASYNC_SPD_CUST = 0x0030
@@ -398,11 +401,19 @@ class Serial(SerialBase):
termios.tcflush(self.fd, TERMIOS.TCOFLUSH)
def sendBreak(self, duration=0.25):
- """Send break condition."""
+ """Send break condition. Timed, returns to idle state after given duration."""
if self.fd is None:
raise portNotOpenError
termios.tcsendbreak(self.fd, int(duration/0.25))
+ def setBreak(self, level=1):
+ """Set break: Controls TXD. When active, to transmitting is possible."""
+ if self.fd is None: raise portNotOpenError
+ if level:
+ fcntl.ioctl(self.fd, TIOCSBRK)
+ else:
+ fcntl.ioctl(self.fd, TIOCCBRK)
+
def setRTS(self, level=1):
"""Set terminal status line: Request To Send"""
if self.fd is None: raise portNotOpenError
diff --git a/pyserial/serial/serialwin32.py b/pyserial/serial/serialwin32.py
index 3be67af..3601615 100644
--- a/pyserial/serial/serialwin32.py
+++ b/pyserial/serial/serialwin32.py
@@ -248,13 +248,21 @@ class Serial(SerialBase):
win32file.PurgeComm(self.hComPort, win32file.PURGE_TXCLEAR | win32file.PURGE_TXABORT)
def sendBreak(self, duration=0.25):
- """Send break condition."""
+ """Send break condition. Timed, returns to idle state after given duration."""
if not self.hComPort: raise portNotOpenError
import time
win32file.SetCommBreak(self.hComPort)
time.sleep(duration)
win32file.ClearCommBreak(self.hComPort)
+ def setBreak(self, level=1):
+ """Set break: Controls TXD. When active, to transmitting is possible."""
+ if not self.hComPort: raise portNotOpenError
+ if level:
+ win32file.SetCommBreak(self.hComPort)
+ else:
+ win32file.ClearCommBreak(self.hComPort)
+
def setRTS(self, level=1):
"""Set terminal status line: Request To Send"""
if not self.hComPort: raise portNotOpenError