Skip to content

Commit

Permalink
fixes access to asyncio loop via loop property of SerialTransport (#1804
Browse files Browse the repository at this point in the history
)
  • Loading branch information
MAKOMO authored Oct 8, 2023
1 parent a2a9e34 commit 7e3e9d9
Showing 1 changed file with 4 additions and 4 deletions.
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

0 comments on commit 7e3e9d9

Please sign in to comment.