Skip to content

Match Sutter MP-285 13-byte position reply (no prefix echo) - #81

Merged
dccote merged 1 commit into
masterfrom
sutter-no-prefix-echo
May 18, 2026
Merged

dccote merged 1 commit into
masterfrom
sutter-no-prefix-echo

Conversation

@dccote

@dccote dccote commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Updates the `SutterDevice` `GET_POSITION` command to expect a 13-byte reply (``: 3 int32 positions + b'\r' terminator) instead of the previous 14-byte assumption (``: prefix echo + 3 int32 + terminator).

Verified live against a Sutter ROE-200 (serial `SIDCACD9`) — the device replies with 13 bytes, no echoed command prefix.

Background

The Sutter MP-285 protocol has two response modes for `GET_POSITION`:

  • Echo on: 14-byte reply with the command character `C` echoed as the first byte
  • Echo off: 13-byte reply with no prefix

The library previously assumed echo-on. Hardware testing in this session showed the same physical device returning 14 bytes early on, then 13 bytes after a power cycle — confirming the mode is not stable across firmware resets.

Changes

  • `hardwarelibrary/motion/sutterdevice.py`: `GET_POSITION` command
    • `replyDataLength`: 14 → 13
    • `unpackingMask`: `<xlllx` → `<lllx`
    • `responseFormat` (mock side): `<clllc` → `<lllc`
    • `responseFields` (mock side): drops `'header'`
    • `DebugSerialPort.process_command` for `GET_POSITION`: drops `'header': b'c'` from the returned dict
  • `hardwarelibrary/tests/testSutterSerialPort.py::testMoveGet`:
    • `readData` length: 14 → 13
    • `unpack` format: `<xlllx` → `<lllx`

Total: 6 insertions, 7 deletions across 2 files.

Caveat — this is a unilateral mode switch

If a future MP-285 boots into echo-on mode (the previous library assumption), `GET_POSITION` will fail with a 14-byte read that includes the echoed prefix as a corrupting offset.

The robust long-term fix is one of:

  • Detect/toggle the echo mode at `doInitializeDevice` time (need to identify the right Sutter command — not currently documented in this repo)
  • Make `GET_POSITION` tolerate both 13- and 14-byte replies (peek for `\r` or try both formats)

This PR opts for the simpler one-mode fix because (a) the device is clearly in 13-byte mode for the current lab unit, and (b) implementing dual-mode handling is a more invasive change to the `DataCommand` machinery.

Test plan

  • Mock-side `TestSutterDebugSerialPort` tests still pass (7/7) — dual-role mock kept in sync
  • Real-hardware `TestSutterDevice` tests pass against the live ROE-200 with stage actually moving (timing confirms: `testDeviceMoveBy` 1.33s, `testDeviceMove` 0.91s, `testDeviceHome` 0.89s)
  • `testSutterSerialPort.py` full suite: 14 passed, 10 skipped (pyserial-based tests skip because pyserial doesn't enumerate the Sutter on macOS via libusb — pre-existing environmental skip)
  • Verify against an MP-285 in echo-on mode before this is trusted as a universal fix

Related

Surfaced while bringing up live Sutter hardware to validate PR #73's table-driven debug port pattern. The dual-role consistency between the device reply parser and the mock's response builder caught the mock test failure when only the receive side was updated — exactly the safety net the pattern is supposed to provide.

🤖 Generated with Claude Code

The library expected a 14-byte reply for GET_POSITION:
<xlllx> = pad + 3 int32 + terminator, where the leading pad is
the echoed command prefix 'C'. Testing against live hardware
(serial SIDCACD9, after a power cycle) showed the device replies
with only 13 bytes: 3 int32 + b'\r' -- no prefix echo.

The protocol has two reply modes (echo on / off). The mode appears
to depend on firmware state and is reset by a power cycle. The
prior 14-byte assumption worked for the previous device state
earlier in the session; this commit accepts the no-echo mode.

Changes:
- SutterDevice.commands['GET_POSITION']:
    replyDataLength: 14 -> 13
    unpackingMask:   '<xlllx' -> '<lllx'
    responseFormat:  '<clllc' -> '<lllc'      (mock side)
    responseFields:  drops 'header'           (mock side)
- DebugSerialPort.process_command for 'GET_POSITION':
    drops the {'header': b'c', ...} entry in the returned dict.
- testSutterSerialPort.py::testMoveGet:
    readData length: 14 -> 13
    unpack format: '<xlllx' -> '<lllx'

Caveat: if a future MP-285 boots into echo-on mode, this commit
will break GET_POSITION for it. The robust long-term fix is
either to detect/toggle the mode at init or to accept both reply
lengths. Filed as a follow-up to be addressed before this is
trusted across all MP-285 firmwares.

Verified against live hardware: 7/7 SutterDevice tests pass with
real stage motion (1.33s testDeviceMoveBy, 0.91s testDeviceMove,
0.89s testDeviceHome) and 7/7 DebugSerialPort tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dccote
dccote merged commit 40bd94c into master May 18, 2026
@dccote
dccote deleted the sutter-no-prefix-echo branch May 18, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant