summaryrefslogtreecommitdiff
path: root/api_layers/protocols/mark10.py
diff options
context:
space:
mode:
authorChristian Kolset <ckolset@colostate.edu>2026-07-27 17:34:30 -0600
committerChristian Kolset <ckolset@colostate.edu>2026-07-27 17:34:30 -0600
commitee4965f4d4d1fc5d40be24b99341620e32386d40 (patch)
tree0dbafaa8aee899895b974ade9c9a2c7b66918701 /api_layers/protocols/mark10.py
parentc3f07a7ffa320aecb3fca5dd40e7644424bddfb5 (diff)
Enhance protocol layers: implement I/O locking for thread safety in serial communication
Diffstat (limited to 'api_layers/protocols/mark10.py')
-rw-r--r--api_layers/protocols/mark10.py14
1 files changed, 9 insertions, 5 deletions
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")