From ee4965f4d4d1fc5d40be24b99341620e32386d40 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Mon, 27 Jul 2026 17:34:30 -0600 Subject: Enhance protocol layers: implement I/O locking for thread safety in serial communication --- api_layers/protocols/mark10.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'api_layers/protocols/mark10.py') diff --git a/api_layers/protocols/mark10.py b/api_layers/protocols/mark10.py index 4a97892..b7dacb4 100644 --- a/api_layers/protocols/mark10.py +++ b/api_layers/protocols/mark10.py @@ -43,8 +43,9 @@ class Mark10Layer(BaseProtocol): def _poll(self) -> Dict[str, float]: try: - self._ser.write(b"?\r") - resp = self._ser.readline().decode(errors="replace").strip() + with self._io_lock: + self._ser.write(b"?\r") + resp = self._ser.readline().decode(errors="replace").strip() return self._parse(resp) except Exception: return {} @@ -83,7 +84,8 @@ class Mark10Layer(BaseProtocol): if not self._ser: return False try: - self._ser.write(cmd) + with self._io_lock: + self._ser.write(cmd) return True except Exception: return False @@ -92,8 +94,10 @@ class Mark10Layer(BaseProtocol): def zero(self) -> None: if self._ser: - self._ser.write(b"Z\r") + with self._io_lock: + self._ser.write(b"Z\r") def cycle_units(self) -> None: if self._ser: - self._ser.write(b"U\r") + with self._io_lock: + self._ser.write(b"U\r") -- cgit v1.2.3