summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2011-12-28 21:39:42 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2011-12-28 21:39:42 +0000
commit7bf24a25e8d754bcbd5f1946d5c4b36db7945ea6 (patch)
treec29261cf0a0118b9560f20eae6ef28ab729aad9c
parentc5fe0c0fc6d6e7f21e9bcf8aa3ea03f7938aaba1 (diff)
downloadpyserial-7bf24a25e8d754bcbd5f1946d5c4b36db7945ea6.tar.gz
implement outWaiting on Posix, doc updates
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@443 f19166aa-fa4f-0410-85c2-fa1106f25c8a
-rw-r--r--CHANGES.txt1
-rw-r--r--documentation/pyserial_api.rst18
-rw-r--r--serial/serialposix.py12
3 files changed, 26 insertions, 5 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 45638c8..cbce157 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -440,6 +440,7 @@ Version 2.7 2012-nn-nn
Bugfixes (posix):
- [Patch 3462364] Fix: NameError: global name 'base' is not defined
+- add platform specific method: outWaiting
Bugfixes (win32):
diff --git a/documentation/pyserial_api.rst b/documentation/pyserial_api.rst
index bafea46..f0a0cb1 100644
--- a/documentation/pyserial_api.rst
+++ b/documentation/pyserial_api.rst
@@ -73,10 +73,11 @@ Native ports
The parameter *baudrate* can be one of the standard values:
50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
9600, 19200, 38400, 57600, 115200.
- These are well supported on all platforms. Standard values above 115200
- such as: 230400, 460800, 500000, 576000, 921600, 1000000, 1152000,
- 1500000, 2000000, 2500000, 3000000, 3500000, 4000000 also work on many
- platforms.
+ These are well supported on all platforms.
+
+ Standard values above 115200, such as: 230400, 460800, 500000, 576000,
+ 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000,
+ 4000000 also work on many platforms and devices.
Non-standard values are also supported on some platforms (GNU/Linux, MAC
OSX >= Tiger, Windows). Though, even on these platforms some serial
@@ -360,6 +361,15 @@ Native ports
.. warning:: Programs using the following methods are not portable to other platforms!
+ .. method:: outWaiting()
+
+ :platform: Unix
+ :platform: Windows
+
+ Return the number of bytes in the output buffer.
+
+ .. versionchanged:: 2.7 (Posix support added)
+
.. method:: nonblocking()
:platform: Unix
diff --git a/serial/serialposix.py b/serial/serialposix.py
index f225c78..eccd782 100644
--- a/serial/serialposix.py
+++ b/serial/serialposix.py
@@ -247,7 +247,11 @@ TIOCM_CD = hasattr(TERMIOS, 'TIOCM_CD') and TERMIOS.TIOCM_CD or TIOCM_CAR
TIOCM_RI = hasattr(TERMIOS, 'TIOCM_RI') and TERMIOS.TIOCM_RI or TIOCM_RNG
#TIOCM_OUT1 = hasattr(TERMIOS, 'TIOCM_OUT1') and TERMIOS.TIOCM_OUT1 or 0x2000
#TIOCM_OUT2 = hasattr(TERMIOS, 'TIOCM_OUT2') and TERMIOS.TIOCM_OUT2 or 0x4000
-TIOCINQ = hasattr(TERMIOS, 'FIONREAD') and TERMIOS.FIONREAD or 0x541B
+if hasattr(TERMIOS, 'TIOCINQ'):
+ TIOCINQ = TERMIOS.TIOCINQ
+else:
+ TIOCINQ = hasattr(TERMIOS, 'FIONREAD') and TERMIOS.FIONREAD or 0x541B
+TIOCOUTQ = hasattr(TERMIOS, 'TIOCOUTQ') and TERMIOS.TIOCOUTQ or 0x5411
TIOCM_zero_str = struct.pack('I', 0)
TIOCM_RTS_str = struct.pack('I', TIOCM_RTS)
@@ -560,6 +564,12 @@ class PosixSerial(SerialBase):
# - - platform specific - - - -
+ def outWaiting(self):
+ """Return the number of characters currently in the output buffer."""
+ #~ s = fcntl.ioctl(self.fd, TERMIOS.FIONREAD, TIOCM_zero_str)
+ s = fcntl.ioctl(self.fd, TIOCOUTQ, TIOCM_zero_str)
+ return struct.unpack('I',s)[0]
+
def drainOutput(self):
"""internal - not portable!"""
if not self._isOpen: raise portNotOpenError