Skip to content

Commit 391ee9c

Browse files
committed
Fixed bug in receiving data.
1 parent 3fccab8 commit 391ee9c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tinylink/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
__version__ = "1.1"
66

7+
__all__ = ["Frame", "DamagedFrame", "ResetFrame", "TinyLink"]
8+
79
# This can be anything, and is used to synchronize a frame
810
PREAMBLE = 0xAA55AA55
911

@@ -153,8 +155,8 @@ def write(self, data, flags=FLAG_NONE):
153155

154156
def read(self, limit=1):
155157
"""
156-
Read at `limit' bytes from the handle and process this byte. Returns a
157-
list of received frames, if any. A reset frame is indicated by a
158+
Read up to `limit' bytes from the handle and process this byte. Returns
159+
a list of received frames, if any. A reset frame is indicated by a
158160
`ResetFrame' instance.
159161
"""
160162

@@ -163,7 +165,13 @@ def read(self, limit=1):
163165

164166
# Bytes are added one at a time
165167
while limit:
166-
self.stream[self.index] = self.handle.read(1)
168+
char = self.handle.read(1)
169+
170+
if not char:
171+
return []
172+
173+
# Append to stream
174+
self.stream[self.index] = char
167175
self.index += 1
168176

169177
# Decide what to do

0 commit comments

Comments
 (0)