-
Notifications
You must be signed in to change notification settings - Fork 1k
SerialServer added handle_local_echo equivalent to SerialClient #1184
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,7 @@ def __init__(self, owner): | |
| self.running = False | ||
| self.receive_queue = asyncio.Queue() | ||
| self.handler_task = None # coroutine to be run on asyncio loop | ||
| self._sent = b'' # for handle_local_echo | ||
|
|
||
| def _log_exception(self): | ||
| """Show log exception.""" | ||
|
|
@@ -450,6 +451,17 @@ def connection_lost(self, call_exc): | |
|
|
||
| def data_received(self, data): | ||
| """Receive data.""" | ||
| if (hasattr(self.server, "handle_local_echo") | ||
| and self.server.handle_local_echo is True | ||
| and self._sent): | ||
| if self._sent in data: | ||
| data, self._sent = data.replace(self._sent, b'', 1), b'' | ||
| elif self._sent.startswith(data): | ||
| self._sent, data = self._sent.replace(data, b'', 1), b'' | ||
| else: | ||
| self._sent = b'' | ||
| if not data: | ||
| return | ||
| self.receive_queue.put_nowait(data) | ||
|
|
||
| async def _recv_(self): | ||
|
|
@@ -458,6 +470,9 @@ async def _recv_(self): | |
| def _send_(self, data): | ||
| if self.transport is not None: | ||
| self.transport.write(data) | ||
| if (hasattr(self.server, "handle_local_echo") | ||
| and self.server.handle_local_echo is True): | ||
| self._sent = data | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- # | ||
|
|
@@ -784,6 +799,7 @@ def __init__( | |
| :param parity: Which kind of parity to use | ||
| :param baudrate: The baud rate to use for the serial device | ||
| :param timeout: The timeout to use for the serial device | ||
| :param handle_local_echo: (optional) Discard local echo from dongle. | ||
| :param ignore_missing_slaves: True to not send errors on a request | ||
| to a missing slave | ||
| :param broadcast_enable: True to treat unit_id 0 as broadcast address, | ||
|
|
@@ -800,6 +816,7 @@ def __init__( | |
| self.timeout = kwargs.get("timeout", Defaults.Timeout) | ||
| self.device = kwargs.get("port", 0) | ||
| self.stopbits = kwargs.get("stopbits", Defaults.Stopbits) | ||
| self.handle_local_echo = kwargs.get("handle_local_echo", Defaults.HandleLocalEcho) # handle_local_echo: bool = None ; handle_local_echo: bool = Defaults.HandleLocalEcho, | ||
| self.ignore_missing_slaves = kwargs.get( | ||
| "ignore_missing_slaves", Defaults.IgnoreMissingSlaves | ||
| ) | ||
|
|
@@ -849,6 +866,7 @@ async def _connect(self): | |
| parity=self.parity, | ||
| stopbits=self.stopbits, | ||
| timeout=self.timeout, | ||
| # handle_local_echo=self.handle_local_echo, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should this mean ? |
||
| ) | ||
| except serial.serialutil.SerialException as exc: | ||
| txt = f"Failed to open serial port: {self.device}" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the comment it is confusing.