feat(serialcomm): implement stream auto-detection, fallback baudrate, and virtual port discovery

- Add automatic format detection (binary, ASCII hex dump, or text line) in StreamReader based on stream preambles.
- Implement fallback to 115200 baudrate when 888888 ioctl fails (critical for macOS PTYs).
- Parse binary streams (X family) with little-endian sequence/length headers and Modbus CRC-16 checks.
- Discover and prioritize virtual serial ports (from running socat instances) in enumerate_ports using lsof.
- Update FakeTransport to mock read() and readline() calls for unit test compatibility.
This commit is contained in:
jack
2026-06-15 11:11:00 -07:00
parent f89a735d51
commit 5b186df888
4 changed files with 297 additions and 33 deletions
+22 -3
View File
@@ -3,11 +3,30 @@ from pygui.backend.models.frame import Frame
from pygui.serialcomm.stream_reader import StreamReader
class FakeTransport:
"""Yield canned line then blocks (returns b'')."""
def __init__(self, lines): self._lines = list(lines); self.closed = False
"""Yield canned data then blocks (returns b'')."""
def __init__(self, lines):
self._data = b"".join(lines)
self._pos = 0
self.closed = False
def read(self, n=1):
time.sleep(0.001)
if self._pos >= len(self._data):
return b""
res = self._data[self._pos:self._pos+n]
self._pos += n
return res
def readline(self):
time.sleep(0.001)
return self._lines.pop(0) if self._lines else b""
if self._pos >= len(self._data):
return b""
idx = self._data.find(b"\n", self._pos)
if idx == -1:
res = self._data[self._pos:]
self._pos = len(self._data)
return res
res = self._data[self._pos:idx+1]
self._pos = idx + 1
return res
def close(self): self.closed = True
def parse_line(raw: str, seq: int) -> Frame: