Skip to content

Commit

Permalink
Works ?
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Jul 20, 2024
1 parent 802cb2b commit fc86a32
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions pymodbus/transport/serialtransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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:
Expand All @@ -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."""
Expand Down Expand Up @@ -182,6 +173,3 @@ async def create_serial_connection(
timeout)
loop.call_soon(transport.setup)
return transport, protocol


SerialTransport.force_poll = os.name == "nt"

0 comments on commit fc86a32

Please sign in to comment.