Skip to content

feat(serial): make xTool lasers (D1) move by speaking their GRBL dialect - #4

Merged
SJLS27 merged 1 commit into
SJLS27:mainfrom
pkkid:feat/xtool-firmware
Nov 17, 2026
Merged

SJLS27 merged 1 commit into
SJLS27:mainfrom
pkkid:feat/xtool-firmware

Conversation

@pkkid

@pkkid pkkid commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

An xTool D1 connected fine but ignored every jog button, and typing $I in the console got no answer. LightBurn drives the same machine without trouble.

xTool's firmware answers to GRBL commands but differs in a few ways:

  • Input is strictly line based. GRBL's bare ? real-time poll gets buffered and corrupts the next command, so the D1 needs ?\n, which it answers with an extra ok.
  • $J= jogs are acknowledged but ignored, and motion only runs after M2.
  • Status reports have no state word: <MPos:x,y,z,a>.
  • It emits ok:IDLE / ok:512 chatter that isn't a line acknowledgement.

This adds src/serial/dialect.ts, which documents those differences and keeps them out of the GRBL path. On connect the machine sends $I and switches to the xTool command set only if the controller answers [XTool …]. If it answers [VER:…], or nothing arrives within 1.5 s (e.g. an Arduino resetting on open), it behaves exactly as before. A new Firmware device setting (Auto-detect / GRBL / xTool) lets users force either dialect; forced GRBL doesn't send $I at all.

xTool polling pauses while a job streams, because the extra ok per poll would be miscounted as a line acknowledgement. Jobs and frames already end with M2.

Testing

  • Unit tests for the dialect helpers and for the machine: auto-detection, fallback to GRBL on silence, forced settings, xTool status parsing and jog output.
  • npm run typecheck and npm run build pass. Same two pre-existing canvas test failures as main in my environment; e2e not run locally.
  • Manually on an xTool D1 (fw 40.30.002.01): identification, status and jog all work.

Not yet verified on hardware

Pause/Stop (!, ~, Ctrl+X) on the D1, job progress (the firmware may run a job only once M2 arrives, so progress could run ahead), and long jobs. Noted in TODO.md.

Independent of #3 (serial port chooser); whichever merges second has a one-line conflict in Machine.connectSerial.

1. The new Firmware setting: the default is Auto-detect; the other options are GRBL and xTool (D1 and similar).

image

2. Jogging a D1, before and after:

  • Before: the console fills with ok:512 / ok:IDLE, the $J jog is acknowledged and ignored, and MPos stays at 0.00.
  • After: the D1 is detected and the jog goes out as G91 / G1 / G90 / M2. The D1 replies [MSG:Pgm End] and MPos moves to 10.00.
image

Created with Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code

xTool's controllers answer GRBL commands but differ in ways that left
the D1 connected yet unable to move:

- input is line based, so the bare '?' poll corrupted the next command;
- '$J=' jogs are acknowledged but ignored, and motion only runs after an
  M2 program end (which is how LightBurn jogs it);
- status reports carry no state word and come with an extra 'ok';
- 'ok:IDLE' / 'ok:512' chatter is not an acknowledgement.

The dialect lives in serial/dialect.ts. On connect the machine sends $I
and switches to the xTool command set only when the controller answers
'[XTool ...]'; otherwise, or if nothing answers within 1.5 s, it behaves
as before. A new Firmware device setting (Auto-detect / GRBL / xTool)
lets users force either dialect; GRBL skips the $I entirely.

Verified on an xTool D1 (fw 40.30.002.01): connect, status and jog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SJLS27
SJLS27 merged commit b1eebc8 into SJLS27:main Nov 17, 2026
SJLS27 added a commit that referenced this pull request Nov 17, 2026
feat(serial): desktop port chooser and xTool firmware support (PRs #3 and #4)
@SJLS27

SJLS27 commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @pkkid, merged! 🎉 The xTool dialect detection ($I → [XTool …] with the 1.5 s fallback) and the Firmware setting went in clean apart from a one-line conflict with #3 in machine.ts.

Everything is on main via #7 (merge commit b1eebc8, your commit keeps its authorship).

I documented the limitation you noted in the PR body in TODO.md and in the changelog: the firmware commits motion on M2, so job progress can run ahead of the head, and Pause/Stop (!, ~, Ctrl+X) is unverified. If you can test that on your D1 it would be very welcome — there is an open item for it in TODO.md.

Thanks again, this is great work.

@pkkid

pkkid commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

I am able to connect fine now and move the laser. I have not tried burning anything yet and I don't think I'll be able to get to that until sometime next week. Thanks so much for getting the fix in!

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.

2 participants