summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2011-08-18 22:46:57 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2011-08-18 22:46:57 +0000
commit15a4af935efd0fde13bb2cbac8a5dce4d391ae8b (patch)
tree0b82bda33fd38c57c7a54d7f55ecee9ddbbb5a2d
parent3bf988e877a2393ea22fa1e5213eaa3085160e92 (diff)
downloadpyserial-15a4af935efd0fde13bb2cbac8a5dce4d391ae8b.tar.gz
fix for patial reads with loop://, ensure bytes type is used
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@411 f19166aa-fa4f-0410-85c2-fa1106f25c8a
-rw-r--r--serial/urlhandler/protocol_loop.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/serial/urlhandler/protocol_loop.py b/serial/urlhandler/protocol_loop.py
index beb3938..d97c44c 100644
--- a/serial/urlhandler/protocol_loop.py
+++ b/serial/urlhandler/protocol_loop.py
@@ -124,7 +124,7 @@ class LoopbackSerial(SerialBase):
else:
timeout = None
data = bytearray()
- while len(data) < size:
+ while size > 0:
self.buffer_lock.acquire()
try:
block = to_bytes(self.loop_buffer[:size])
@@ -132,6 +132,7 @@ class LoopbackSerial(SerialBase):
finally:
self.buffer_lock.release()
data += block
+ size -= len(block)
# check for timeout now, after data has been read.
# useful for timeout = 0 (non blocking) read
if timeout and time.time() > timeout:
@@ -143,6 +144,8 @@ class LoopbackSerial(SerialBase):
connection is blocked. May raise SerialException if the connection is
closed."""
if not self._isOpen: raise portNotOpenError
+ # ensure we're working with bytes
+ data = bytes(data)
# calculate aprox time that would be used to send the data
time_used_to_send = 10.0*len(data) / self._baudrate
# when a write timeout is configured check if we would be successful
@@ -152,7 +155,7 @@ class LoopbackSerial(SerialBase):
raise writeTimeoutError
self.buffer_lock.acquire()
try:
- self.loop_buffer += bytes(data)
+ self.loop_buffer += data
finally:
self.buffer_lock.release()
return len(data)