diff --git a/pymodbus/transport/transport_serial.py b/pymodbus/transport/transport_serial.py index 1a13fb17c..f5b28d5e3 100644 --- a/pymodbus/transport/transport_serial.py +++ b/pymodbus/transport/transport_serial.py @@ -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 = [] @@ -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""" @@ -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: @@ -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):