diff options
Diffstat (limited to 'api_layers/protocols/mark10.py')
| -rw-r--r-- | api_layers/protocols/mark10.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/api_layers/protocols/mark10.py b/api_layers/protocols/mark10.py index b7dacb4..a209232 100644 --- a/api_layers/protocols/mark10.py +++ b/api_layers/protocols/mark10.py @@ -10,6 +10,11 @@ Commands (sent with CR terminator): Response format: "+0.1234 kgF" (sign, value, space, unit suffix) +Replies are read up to CR with Serial.read_until(b"\\r") rather than +readline(), since pyserial's readline() looks for LF by default and the +gauge only terminates with CR — readline() would otherwise block for the +full serial timeout on every poll. + Channels exposed: force — current force reading (in instrument's selected unit) unit_code — numeric index into UNITS list (lb=0, kgF=1, N=2, ozF=3) @@ -44,8 +49,10 @@ class Mark10Layer(BaseProtocol): def _poll(self) -> Dict[str, float]: try: with self._io_lock: + self._ser.reset_input_buffer() self._ser.write(b"?\r") - resp = self._ser.readline().decode(errors="replace").strip() + self._ser.flush() + resp = self._ser.read_until(b"\r").decode(errors="replace").strip() return self._parse(resp) except Exception: return {} |
