summaryrefslogtreecommitdiff
path: root/serial/serialjava.py
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2009-07-25 03:44:33 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2009-07-25 03:44:33 +0000
commit9b12562f15ac2cffc06fada3d19db679ae9bf259 (patch)
treeb9f35aeb97279b707c08080c3b94e6594d82440f /serial/serialjava.py
parentfdf8367b8d2d9ced7ccf0349afd476552f6e71ce (diff)
downloadpyserial-9b12562f15ac2cffc06fada3d19db679ae9bf259.tar.gz
- add more methods for file-like compatibility
- provide RawSerial when io library is present (not yet finished) -> changes internal class hierarchy -> renamed internal read/write -> _read/_write (FileLike resp. RawSerialBase provides read/write) -> add test_rawio.py - _write returns number of byte written - set minimal python version to 2.3 due to basestring - add "name" attribute - documentation updates (new io stuff and VERSION, device()) git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@249 f19166aa-fa4f-0410-85c2-fa1106f25c8a
Diffstat (limited to 'serial/serialjava.py')
-rw-r--r--serial/serialjava.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/serial/serialjava.py b/serial/serialjava.py
index 2dbaad6..d7e68c4 100644
--- a/serial/serialjava.py
+++ b/serial/serialjava.py
@@ -46,7 +46,8 @@ def device(portnumber):
ports.append(el)
return ports[portnumber].getName()
-class Serial(SerialBase):
+
+class JavaSerial(SerialBase):
"""Serial port class, implemented with Java Communications API and
thus usable with jython and the appropriate java extension."""
@@ -144,7 +145,7 @@ class Serial(SerialBase):
if not self.sPort: raise portNotOpenError
return self._instream.available()
- def read(self, size=1):
+ def _read(self, size=1):
"""Read size bytes from the serial port. If a timeout is set it may
return less characters as requested. With no timeout it will block
until the requested number of bytes is read."""
@@ -160,10 +161,11 @@ class Serial(SerialBase):
read = read + chr(x)
return read
- def write(self, data):
+ def _write(self, data):
"""Output the given string over the serial port."""
if not self.sPort: raise portNotOpenError
self._outstream.write(data)
+ return len(data)
def flushInput(self):
"""Clear input buffer, discarding all that is in the buffer."""
@@ -190,7 +192,7 @@ class Serial(SerialBase):
"""Set terminal status line: Request To Send"""
if not self.sPort: raise portNotOpenError
self.sPort.setRTS(level)
-
+
def setDTR(self, level=1):
"""Set terminal status line: Data Terminal Ready"""
if not self.sPort: raise portNotOpenError
@@ -217,6 +219,17 @@ class Serial(SerialBase):
self.sPort.isCD()
+# assemble Serial class with the platform specifc implementation and the base
+# for file-like behavior
+class Serial(JaveSerial, FileLike):
+ pass
+
+# for Python 2.6 and newer, that provide the new I/O library, implement a
+# RawSerial object that plays nice with it.
+if support_io_module:
+ class RawSerial(JavaSerial, RawSerialBase):
+ pass
+
if __name__ == '__main__':
s = Serial(0,