|
| 1 | +# Client Documentation |
| 2 | + |
| 3 | +This section documents the primary client classes used to interact with FlashForge printers. |
| 4 | + |
| 5 | +## FiveMClient |
| 6 | + |
| 7 | +The `FiveMClient` is the modern interface for Adventurer 5M, 5M Pro, and Adventurer 5X (AD5X) printers. It combines HTTP API calls with a TCP connection for comprehensive control. |
| 8 | + |
| 9 | +### Constructor |
| 10 | + |
| 11 | +```typescript |
| 12 | +constructor(ipAddress: string, serialNumber: string, checkCode: string) |
| 13 | +``` |
| 14 | + |
| 15 | +- **`ipAddress`** (`string`): The local IP address of the printer. |
| 16 | +- **`serialNumber`** (`string`): The printer's serial number (required for authentication). |
| 17 | +- **`checkCode`** (`string`): The check code for authentication. |
| 18 | + |
| 19 | +### Properties |
| 20 | + |
| 21 | +- **`control`** (`Control`): Interface for general printer controls (home, fans, LEDs, etc.). |
| 22 | +- **`jobControl`** (`JobControl`): Interface for managing print jobs (start, stop, pause, file upload). |
| 23 | +- **`info`** (`Info`): Interface for retrieving machine status and details. |
| 24 | +- **`files`** (`Files`): Interface for file management (list files, get thumbnails). |
| 25 | +- **`tempControl`** (`TempControl`): Interface for temperature management. |
| 26 | +- **`tcpClient`** (`FlashForgeClient`): The underlying TCP client instance. |
| 27 | +- **`printerName`** (`string`): The configured name of the printer. |
| 28 | +- **`isPro`** (`boolean`): True if the printer is a Pro model. |
| 29 | +- **`isAD5X`** (`boolean`): True if the printer is an AD5X model. |
| 30 | +- **`firmwareVersion`** (`string`): The full firmware version string. |
| 31 | +- **`ledControl`** (`boolean`): True if LED control is available/enabled. |
| 32 | +- **`filtrationControl`** (`boolean`): True if filtration control is available/enabled. |
| 33 | + |
| 34 | +### Key Methods |
| 35 | + |
| 36 | +#### `initialize()` |
| 37 | + |
| 38 | +```typescript |
| 39 | +public async initialize(): Promise<boolean> |
| 40 | +``` |
| 41 | + |
| 42 | +Initializes the client by verifying the connection to the printer. Returns `true` if successful. |
| 43 | + |
| 44 | +#### `initControl()` |
| 45 | + |
| 46 | +```typescript |
| 47 | +public async initControl(): Promise<boolean> |
| 48 | +``` |
| 49 | + |
| 50 | +Fully initializes control capabilities by authenticating via the product command and establishing the TCP connection. Must be called before performing control actions. |
| 51 | + |
| 52 | +#### `verifyConnection()` |
| 53 | + |
| 54 | +```typescript |
| 55 | +public async verifyConnection(): Promise<boolean> |
| 56 | +``` |
| 57 | + |
| 58 | +Checks connectivity by attempting to fetch printer details. Updates cached machine info. |
| 59 | + |
| 60 | +#### `dispose()` |
| 61 | + |
| 62 | +```typescript |
| 63 | +public async dispose(): Promise<void> |
| 64 | +``` |
| 65 | + |
| 66 | +Cleanly closes connections and stops background keep-alive processes. |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## FlashForgeClient |
| 71 | + |
| 72 | +The `FlashForgeClient` is a TCP-based client for legacy printers or low-level G-code operations. It extends `FlashForgeTcpClient`. |
| 73 | + |
| 74 | +### Constructor |
| 75 | + |
| 76 | +```typescript |
| 77 | +constructor(hostname: string) |
| 78 | +``` |
| 79 | + |
| 80 | +- **`hostname`** (`string`): The IP address or hostname of the printer. |
| 81 | + |
| 82 | +### Key Methods |
| 83 | + |
| 84 | +#### `initControl()` |
| 85 | + |
| 86 | +```typescript |
| 87 | +public async initControl(): Promise<boolean> |
| 88 | +``` |
| 89 | + |
| 90 | +Establishes the TCP connection, logs in, and starts the keep-alive loop. |
| 91 | + |
| 92 | +#### `getPrinterInfo()` |
| 93 | + |
| 94 | +```typescript |
| 95 | +public async getPrinterInfo(): Promise<PrinterInfo | null> |
| 96 | +``` |
| 97 | + |
| 98 | +Retrieves basic printer information (firmware, machine type, etc.). |
| 99 | + |
| 100 | +#### `getTempInfo()` |
| 101 | + |
| 102 | +```typescript |
| 103 | +public async getTempInfo(): Promise<TempInfo | null> |
| 104 | +``` |
| 105 | + |
| 106 | +Gets current extruder and bed temperatures. |
| 107 | + |
| 108 | +#### `move(x, y, z, feedrate)` |
| 109 | + |
| 110 | +```typescript |
| 111 | +public async move(x: number, y: number, z: number, feedrate: number): Promise<boolean> |
| 112 | +``` |
| 113 | + |
| 114 | +Moves the print head to the specified absolute coordinates. |
| 115 | + |
| 116 | +#### `setExtruderTemp(temp, waitFor)` |
| 117 | + |
| 118 | +```typescript |
| 119 | +public async setExtruderTemp(temp: number, waitFor: boolean = false): Promise<boolean> |
| 120 | +``` |
| 121 | + |
| 122 | +Sets the extruder target temperature. |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +## FlashForgePrinterDiscovery |
| 127 | + |
| 128 | +A utility class for finding printers on the local network. |
| 129 | + |
| 130 | +### Methods |
| 131 | + |
| 132 | +#### `discoverPrintersAsync()` |
| 133 | + |
| 134 | +```typescript |
| 135 | +public async discoverPrintersAsync(timeoutMs: number = 10000, idleTimeoutMs: number = 1500, maxRetries: number = 3): Promise<FlashForgePrinter[]> |
| 136 | +``` |
| 137 | + |
| 138 | +Broadcasts a discovery packet via UDP and listens for responses. |
| 139 | + |
| 140 | +- **`timeoutMs`**: Max time to wait for responses. |
| 141 | +- **`idleTimeoutMs`**: Time to wait after the last response before returning. |
| 142 | +- **`maxRetries`**: Number of broadcast attempts if no printers are found initially. |
| 143 | + |
| 144 | +**Returns:** An array of `FlashForgePrinter` objects containing IP, Serial, and Name. |
0 commit comments