From fc86a327f95d4a70d652f88b9625a20b20680ce2 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Sat, 20 Jul 2024 12:43:06 +0200 Subject: [PATCH] Works ? --- pymodbus/transport/serialtransport.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/pymodbus/transport/serialtransport.py b/pymodbus/transport/serialtransport.py index 1c8634c2ee..111116b1bc 100644 --- a/pymodbus/transport/serialtransport.py +++ b/pymodbus/transport/serialtransport.py @@ -9,10 +9,11 @@ with contextlib.suppress(ImportError): import serial + class SerialTransport(asyncio.Transport): """An asyncio serial transport.""" - force_poll: bool + force_poll: bool = os.name == "nt" def __init__(self, loop, protocol, url, baudrate, bytesize, parity, stopbits, timeout) -> None: """Initialize.""" @@ -34,13 +35,7 @@ def setup(self) -> None: self.poll_task = asyncio.create_task(self.polling_task()) self.poll_task.set_name("SerialTransport poll") else: - try: - self.async_loop.add_reader(self.sync_serial.fileno(), self.intern_read_ready) - except Exception as exc: - text = f"JAN setup --> os.name({os.name}) and {exc} force({self.force_poll})" - raise Exception(text) # pylint: disable=raise-missing-from,broad-exception-raised - - + self.async_loop.add_reader(self.sync_serial.fileno(), self.intern_read_ready) self.async_loop.call_soon(self.intern_protocol.connection_made, self) def close(self, exc: Exception | None = None) -> None: @@ -64,11 +59,7 @@ def write(self, data) -> None: """Write some data to the transport.""" self.intern_write_buffer.append(data) if not self.force_poll: - try: - self.async_loop.add_writer(self.sync_serial.fileno(), self.intern_write_ready) - except Exception as exc: - text = f"JAN write --> os.name({os.name}) and {exc} force({self.force_poll})" - raise Exception(text) # pylint: disable=raise-missing-from,broad-exception-raised + self.async_loop.add_writer(self.sync_serial.fileno(), self.intern_write_ready) def flush(self) -> None: """Clear output buffer and stops any more data being written.""" @@ -182,6 +173,3 @@ async def create_serial_connection( timeout) loop.call_soon(transport.setup) return transport, protocol - - -SerialTransport.force_poll = os.name == "nt"