From b34b920759ae819aed645b329381ad0554d52dd4 Mon Sep 17 00:00:00 2001 From: jack Date: Mon, 15 Jun 2026 11:37:51 -0700 Subject: [PATCH] refactor: standardize timing with monotonic clocks, remove redundant stream parsing --- .../backend/controllers/session_controller.py | 6 ++---- src/pygui/serialcomm/stream_reader.py | 16 +--------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/pygui/backend/controllers/session_controller.py b/src/pygui/backend/controllers/session_controller.py index 549a2c4..8f190ca 100644 --- a/src/pygui/backend/controllers/session_controller.py +++ b/src/pygui/backend/controllers/session_controller.py @@ -1,6 +1,7 @@ """QML-facing controller for the live/review wafer dashboard.""" from __future__ import annotations import logging +import time from typing import Any, Optional from PySide6.QtCore import QObject, Property, QTimer, Qt, Signal, Slot @@ -325,10 +326,7 @@ class SessionController(QObject): result = -result values.append(result) - # Create a mock timestamp or use elapsed time since start. - # We don't have a time value from the binary stream header right now. - t = seq * 0.05 # approx 20Hz if seq increments 1 per frame - return Frame(seq=seq, time=t, values=values) + return Frame(seq=seq, time=time.monotonic(), values=values) # Clear out any old data from the prev sessions self._model.reset() diff --git a/src/pygui/serialcomm/stream_reader.py b/src/pygui/serialcomm/stream_reader.py index 4bdb884..e908cbf 100644 --- a/src/pygui/serialcomm/stream_reader.py +++ b/src/pygui/serialcomm/stream_reader.py @@ -32,18 +32,6 @@ class StreamReader: self._thread = threading.Thread(target=self._run, daemon = True) self._thread.start() - def _read_exact(self, count: int) -> bytes | None: - """Read exactly `count` bytes. Returns None if timed out/stopped.""" - buf = bytearray() - while len(buf) < count and not self._stop.is_set(): - b = self._transport.read(1) - if not b: - continue - buf.extend(b) - if self._stop.is_set(): - return None - return bytes(buf) - def _run(self) -> None: try: # Check the first few bytes to determine if the wafer is streaming binary, ASCII hex dump, or text lines. @@ -198,13 +186,11 @@ class StreamReader: values.append(0.0) try: - frame = Frame(seq=seq, time=seq * 0.1, values=values) + frame = Frame(seq=seq, time=time.monotonic(), values=values) self._on_frame(frame) seq += 1 except Exception as exc: log.error("Error emitting ASCII frame: %s", exc) - - time.sleep(0.05) def _run_text_lines(self, initial_bytes: bytes) -> None: log.info("StreamReader: starting line-by-line ASCII text parsing")