jmri_nce.transport.port
BytePort — the minimum surface an NCE transport needs to provide.
Unlike LocoNet's frame-oriented transport, NCE is plain byte-stream: write a request, read an exact number of reply bytes, read one ACK byte.
1"""``BytePort`` — the minimum surface an NCE transport needs to provide. 2 3Unlike LocoNet's frame-oriented transport, NCE is plain byte-stream: write 4a request, read an exact number of reply bytes, read one ACK byte. 5""" 6from __future__ import annotations 7 8from abc import ABC, abstractmethod 9 10 11class BytePort(ABC): 12 """Bidirectional byte-stream port for NCE.""" 13 14 @abstractmethod 15 async def write(self, data: bytes) -> None: ... 16 17 @abstractmethod 18 async def read_exact(self, n: int) -> bytes: ... 19 20 @abstractmethod 21 async def read_pending(self) -> bytes: 22 """Read any bytes already buffered, without waiting for more. 23 24 Used by the traffic controller to drain stale bytes between 25 commands. Returns ``b""`` if nothing is currently buffered. 26 """ 27 28 @abstractmethod 29 async def aclose(self) -> None: ... 30 31 @property 32 @abstractmethod 33 def is_open(self) -> bool: ...
class
BytePort(abc.ABC):
12class BytePort(ABC): 13 """Bidirectional byte-stream port for NCE.""" 14 15 @abstractmethod 16 async def write(self, data: bytes) -> None: ... 17 18 @abstractmethod 19 async def read_exact(self, n: int) -> bytes: ... 20 21 @abstractmethod 22 async def read_pending(self) -> bytes: 23 """Read any bytes already buffered, without waiting for more. 24 25 Used by the traffic controller to drain stale bytes between 26 commands. Returns ``b""`` if nothing is currently buffered. 27 """ 28 29 @abstractmethod 30 async def aclose(self) -> None: ... 31 32 @property 33 @abstractmethod 34 def is_open(self) -> bool: ...
Bidirectional byte-stream port for NCE.
@abstractmethod
async def
read_pending(self) -> bytes:
21 @abstractmethod 22 async def read_pending(self) -> bytes: 23 """Read any bytes already buffered, without waiting for more. 24 25 Used by the traffic controller to drain stale bytes between 26 commands. Returns ``b""`` if nothing is currently buffered. 27 """
Read any bytes already buffered, without waiting for more.
Used by the traffic controller to drain stale bytes between
commands. Returns b"" if nothing is currently buffered.