Skip to content

Made write truly asynchronous, bypasses bug in pyserial which made it… #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions serial_asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,11 @@ def write(self, data):
return

if self.get_write_buffer_size() == 0:
# Attempt to send it right away first
try:
n = self._serial.write(data)
except (BlockingIOError, InterruptedError):
n = 0
except serial.SerialException as exc:
self._fatal_error(exc, 'Fatal write error on serial transport')
return
if n == len(data):
return # Whole request satisfied
assert 0 <= n < len(data)
data = data[n:]
self._write_buffer.append(data)
self._ensure_writer()
else:
self._write_buffer.append(data)

self._write_buffer.append(data)
self._maybe_pause_protocol()

def can_write_eof(self):
Expand Down Expand Up @@ -188,6 +178,13 @@ def abort(self):
"""
self._abort(None)

def flush(self):
""" clears output buffer and stops any more data being written
"""
self._remove_writer()
self._write_buffer.clear()
self._maybe_resume_protocol()

def _maybe_pause_protocol(self):
"""To be called whenever the write-buffer size increases.

Expand Down