Skip to content
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

fixes access to asyncio loop via loop property of SerialTransport #1804

Merged
merged 8 commits into from
Oct 8, 2023
8 changes: 4 additions & 4 deletions pymodbus/transport/transport_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, loop, protocol, *args, **kwargs):
"""Initialize."""
super().__init__()
self.async_loop = loop
self._protocol = protocol
self._protocol: asyncio.BaseProtocol = protocol
self.sync_serial = serial.serial_for_url(*args, **kwargs)
self._closing = False
self._write_buffer = []
Expand All @@ -37,7 +37,7 @@ def __init__(self, loop, protocol, *args, **kwargs):
@property
def loop(self):
"""Return asyncio event loop."""
return self._protocol.loop
return self.async_loop

def get_protocol(self) -> asyncio.BaseProtocol:
"""Return protocol"""
Expand Down Expand Up @@ -95,7 +95,7 @@ def _read_ready(self):
try:
data = self.sync_serial.read(1024)
except serial.SerialException as exc:
self._protocol.loop.call_soon(self._call_connection_lost, exc)
self.async_loop.call_soon(self._call_connection_lost, exc)
self.close()
else:
if data:
Expand Down Expand Up @@ -130,7 +130,7 @@ def _write_ready(self):
except (BlockingIOError, InterruptedError):
self._write_buffer.append(data)
except serial.SerialException as exc:
self._protocol.loop.call_soon(self._call_connection_lost, exc)
self.async_loop.call_soon(self._call_connection_lost, exc)
self.abort()
else:
if nlen == len(data):
Expand Down