This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
FlashForge Printer Emulator is a Python-based network protocol emulator for FlashForge 3D printers. It provides a complete implementation of the FlashForge printer discovery and command protocols, allowing developers to test client applications without physical hardware.
- PrinterEmulator (
emulator/printer.py): Core emulation logic handling printer state, temperature simulation, and file management - EmulatorServer (
emulator/server.py): Network layer handling UDP discovery (port 48899) and TCP commands (port 8899) - Command Processing (
emulator/commands.py): G-code command parser and dispatcher - Response Generation (
emulator/responses.py): Standard FlashForge protocol response formatting - GUI Interface (
ui/main_window.py): Main application window with tabbed interface
The GUI uses ttkbootstrap with a tabbed interface:
- MainTab: Basic controls and logging
- ConfigTab: Printer configuration and virtual file management
- PrinterStateTab: Temperature and print status controls
- NetworkTab: Network simulation settings (latency, failures)
- PrinterDetailsTab: Hardware specification settings
- FilesystemTab: Virtual file system management
- LogsTab: Application logging
python main.pypip install -r requirements.txtttkbootstrapfor modern GUI themingPillowfor thumbnail image processing
- UDP broadcast on port 48899
- Responds with printer name and serial in binary format
- Handles automatic printer detection by FlashForge clients
- TCP server on port 8899
- Command format:
~GCODE [parameters] - Response format:
CMD GCODE Received.\n[data]\nok
- Status: M115 (info), M105 (temps), M119 (endstops), M27 (print status), M114 (position)
- Control: M601/M602 (login/logout), M24/M25/M26 (print control), M104/M140 (temp setting)
- Files: M661 (list files), M662 (get thumbnail)
Configuration is centralized in config.py with defaults for:
- Network ports (DISCOVERY_PORT=48899, COMMAND_PORT=8899)
- Printer identification (name, serial, machine type, firmware version)
- Temperature defaults
- Virtual file list
- UI dimensions
The PrinterEmulator class maintains all printer state and provides methods for:
- Temperature simulation with realistic heating/cooling curves
- Print progress tracking
- Virtual file system management
- Server lifecycle management
UI components update printer state through the emulator instance, which propagates changes to the network server and updates the GUI in real-time.
The NetworkTab allows simulation of network conditions (latency, packet loss, connection failures) for testing client robustness.