Skip to content
ytomaschPublic

About

A client for the FlashForge-style 3D printer protocol on port 8899 - including the undocumented framed upload format, and the single-session rule that permanently wedges the firmware until you physically power-cycle it. Ships a mock printer so you can test without gambling hardware.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gantry

A client for the network protocol FlashForge-style 3D printers speak on port 8899 — status, control, and file upload — written because the upload half is not documented anywhere and the control half will brick your printer if you get it wrong.

Tested against a bundled mock printer, so you can develop without a machine.

export GANTRY_HOST=192.0.2.10
gantry info
gantry status
gantry upload part.gx --start

The part that will cost you a printer

One connection. One command in flight. Always.

This firmware holds a single session. Open a second connection while one is live, or write several commands without waiting for each ok, and it wedges. From that moment it answers every request, on every new connection, with:

CMD M601 Received.
Control failed.
ok

and it stays that way. ~M602 does not clear it. ~M601 does not clear it. Rebooting your machine does not clear it. It is a firmware hang, and the only way out is physically power-cycling the printer. There is no remote recovery.

This is not a rare edge case. A first attempt that polled four commands in one write and opened two connections per poll hit it on the very first run.

That is why serialization is built into this library rather than written down as advice. Every operation — status polls, control commands, uploads — queues on one promise chain with a cooldown between connections:

const printer = new Printer('192.0.2.10');

// These do NOT race. They queue, in order, one connection at a time.
await Promise.all([
  printer.status(),
  printer.light(0, 0, 0),
  printer.upload('part.gx', buf),
  printer.status(),
]);

You cannot overlap two operations through this API. The one thing it cannot protect you from is running two clients against the same printer — a second process, or a browser tab left open on the vendor's own web UI. Don't.

There are two hangs, and only one of them is recoverable

What you did What happens Recovery
Overlapped connections, or pipelined commands Permanent Control failed. to everything Physical power cycle
Sent the file as a raw stream after M28 Firmware waits for a frame header that never comes Close the socket

The second is the one you hit while developing an uploader, and it is survivable. The first is the one that gets you off your chair.

The framed upload

After ~M28 the connection stops being ASCII and becomes a binary frame stream. This is the part that is not written down, and it was recovered by putting a transparent proxy between the vendor's slicer and a printer and reading the bytes — tools/ff-proxy.py is that proxy.

Every frame is exactly 4112 bytes:

 offset  size  field
 0       4     magic  5a 5a a5 a5
 4       4     frame counter, big-endian, from 0
 8       4     length, big-endian
 12      4     crc32, big-endian
 16      4096  payload

The trap: the payload is always 4096 bytes. The last chunk of a file almost never is, so it gets zero-padded up to 4096. But the length and crc fields are not padded — they describe the real bytes. On a final chunk of 1679 bytes, length is 1679 and the CRC covers those 1679 bytes, while the payload on the wire is still a full 4096.

So the frame is a fixed-size envelope carrying a variable-size payload, and the header deliberately disagrees with the payload size. Send a short final frame — the obvious reading — and the printer waits forever for the missing bytes.

Two consequences of ~M28 <size> <path> worth knowing:

  • The size must be exact. It is how the printer trims the final frame's padding back off.
  • It is also how the printer knows when to start listening for ASCII again. Understate it and your remaining frames get parsed as commands. Overstate it and it waits for frames that will never arrive.

Windowed flow control is not optional. Past roughly 389 frames the firmware's receive buffer is overrun and it silently drops frames. This client keeps at most 8 unacknowledged frames in flight, which is what the vendor's client does.

Full sequence:

~M601 S1                      take control
~M28 <rawSize> 0:/user/name   open for write — RAW size, not padded size
<frames>                      4112 bytes each, windowed
~M29                          close
~M23 0:/user/name             optional: start printing
~M602                         release control

Smaller things

  • Read-only queries do not need control. M105, M119, M27, M114 and M115 all answer without M601. Taking control for a temperature reading means holding a session you did not need.
  • Every reply ends with a line that is exactly ok. Wait for it. Do not wait for a byte count or a timeout.
  • Frame acks are anonymous. The printer sends ok per frame with nothing to match against, so counting them is the only backpressure signal you get.
  • .gx is a documented format and src/gx.js implements the published layout — it is here because you need it, not because it was discovered here. The one undocumented bit: the printer only truly requires a well-formed 80×60 BMP thumbnail and a correct g-code offset. Everything else in the header is cosmetic, and a wrong filament estimate prints fine.

The mock printer

mock/printer.js implements the protocol, including both hangs. It refuses to be polite about it: pipeline commands or open a second connection and it wedges, permanently, until you call powerCycle() — the same thing a real one makes you walk across the room to do.

node mock/printer.js 8899
GANTRY_HOST=127.0.0.1 gantry status

This is how you test an uploader without gambling a machine.

Verification

  • 22 tests pass against the mock (npm test), covering byte-identical round trips for files that are and are not multiples of 4096, one smaller than a single frame, and one large enough to exercise the window.
  • The suite is mutation-tested. Removing the final-frame padding on purpose fails 8 assertions — including, correctly, not the exact-multiple round trip, since that file has no partial frame to pad.
  • The protocol rules come from a byte-level capture of the vendor's slicer talking to a real Monoprice Voxel (a rebadged FlashForge Adventurer), and the logic here is extracted from a client that has driven real prints on that machine.
  • This extraction has not been re-run against hardware. It is verified against the mock. Given that the failure mode is a printer that needs unplugging, that felt like the right place to stop.

One thing is explicitly not tested: declaring 4096 as the final frame's length and CRCing the padded payload. That frame is internally consistent, so nothing at the frame level can catch it, and a printer that concatenates and trims would accept it. It may be survivable. This client sends the real remainder anyway, because that is what the vendor's client sends and there is no reason to deviate from the one the firmware was built against.

Compatibility

Written against a Monoprice Voxel, firmware 1.1.5. The same protocol is used across FlashForge's Adventurer line and its rebadges. If you run it against something else, the mock will not tell you whether your machine agrees — only a capture will.

License

MIT — see LICENSE. Copyright (c) 2026 Amur Labs LLC.

About

A client for the FlashForge-style 3D printer protocol on port 8899 - including the undocumented framed upload format, and the single-session rule that permanently wedges the firmware until you physically power-cycle it. Ships a mock printer so you can test without gambling hardware.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages