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
commitfb2306ba81e6b3aaf336b117b331c04c0cbb6775 (patch)
tree2be4167d69000f3111e9d5172bd5688dc5e0a1b7
parent330185edc7ca8d6f9d1d4be8c602ea273da27f87 (diff)
downloadpyserial-git-fb2306ba81e6b3aaf336b117b331c04c0cbb6775.tar.gz
fix for patial reads with loop://, ensure bytes type is used
-rw-r--r--pyserial/serial/urlhandler/protocol_loop.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/pyserial/serial/urlhandler/protocol_loop.py b/pyserial/serial/urlhandler/protocol_loop.py
index beb3938..d97c44c 100644
--- a/pyserial/serial/urlhandler/protocol_loop.py
+++ b/pyserial/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)