bambu-printer-mcp 1.1.38 → 1.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTORS.md +1 -0
- package/dist/index.js +5 -2
- package/dist/printers/bambu.js +25 -7
- package/dist/safety/printer-state.d.ts +10 -0
- package/dist/safety/printer-state.js +17 -2
- package/package.json +1 -1
- package/src/index.ts +5 -2
- package/src/printers/bambu.ts +25 -7
- package/src/safety/printer-state.ts +18 -2
package/CONTRIBUTORS.md
CHANGED
|
@@ -6,6 +6,7 @@ Thank you to everyone who builds, tests, reports problems, and shares real print
|
|
|
6
6
|
|
|
7
7
|
| Contributor | Contribution |
|
|
8
8
|
| --- | --- |
|
|
9
|
+
| [JackCA](https://github.com/JackCA) | Reports an X2D retaining `FAILED` with no active print/HMS error after cancellation, supplies read-only printer evidence for `fail_reason: 0300400C`, and contributes narrow canceled-task recovery, job-bound physical confirmation, a recheck of the job and error codes after connecting and before clearing hardware errors on any model, and regression coverage in [#76](https://github.com/DMontgomery40/bambu-printer-mcp/pull/76). Physical print delivery after the fix remains unverified. |
|
|
9
10
|
| [ZombieLurker](https://github.com/ZombieLurker) | Reports and diagnoses the unused-nozzle preheat rejection for OrcaSlicer 2.4.2 single-filament H2D jobs in [#73](https://github.com/DMontgomery40/bambu-printer-mcp/issues/73), supplies the exact startup commands and environment, and verifies a local inspection fix. H2D Pro coverage is independently supported by its official profile; no physical printing is claimed by this release. |
|
|
10
11
|
| [MorganFreeeman](https://github.com/MorganFreeeman) | Reports in [#67](https://github.com/DMontgomery40/bambu-printer-mcp/issues/67) that every H2D print stopped on stock HS01 nozzles. Supplies idle and mid-print firmware 01.04.00.00 nozzle reports showing a permanent `stat: 1` with `sn: "N/A"`, proposes keeping the check narrow to nozzles without an identity chip, and points out the misleading declined-confirmation advice and the missing settings-table entries. Maintainer validation uses their reports in regressions; no H2D hardware was available. |
|
|
11
12
|
| [Aaron Roberts (aaroberts)](https://github.com/aaroberts) | Diagnoses FULU's Linux host exit 101 and its working-directory library loading in [#68](https://github.com/DMontgomery40/bambu-printer-mcp/issues/68), reports both upstream as [FULU #50](https://github.com/FULU-Foundation/OrcaSlicer-bambulab/issues/50) and [#51](https://github.com/FULU-Foundation/OrcaSlicer-bambulab/issues/51), and shares a working configuration: the `cat` wrapper, absolute plug-in paths, the FULU GUI's session file for cloud login, and the required 02.05.02.5x plug-in. Reports cloud printing on two P1S printers with 1.1.33. The server now sets the library paths and explains exit 101. The host fixes themselves remain with FULU. |
|
package/dist/index.js
CHANGED
|
@@ -103,11 +103,11 @@ function assertUniformCliNozzles(args) {
|
|
|
103
103
|
throw new Error("Mixed nozzle diameters require a pre-sliced 3MF with complete per-nozzle metadata. Export it from the slicer GUI before printing.");
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
const VALID_BAMBU_MODELS = ["p1s", "p1p", "p2s", "x1c", "x1e", "a1", "a1mini", "h2d", "h2s", "h2c", "x2d"];
|
|
106
|
+
const VALID_BAMBU_MODELS = ["p1s", "p1p", "p2s", "x1c", "x1e", "a1", "a1mini", "h2d", "h2dpro", "h2s", "h2c", "x2d"];
|
|
107
107
|
// X2D uses the same project_file/ams_mapping2 family of LAN print fields as
|
|
108
108
|
// the dual-nozzle H2 path. Keep it in this gate so pre-sliced multi-filament
|
|
109
109
|
// jobs take the correct branch instead of the legacy 5-slot mapping.
|
|
110
|
-
const H2_BAMBU_MODELS = new Set(["h2d", "h2s", "h2c", "x2d"]);
|
|
110
|
+
const H2_BAMBU_MODELS = new Set(["h2d", "h2dpro", "h2s", "h2c", "x2d"]);
|
|
111
111
|
const VALID_BED_TYPES = ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"];
|
|
112
112
|
const VALID_NOZZLE_TYPES = ["stainless_steel", "hardened_steel", "tungsten_carbide", "brass"];
|
|
113
113
|
/** The installed hotend material. Bambu machine presets assume the stock nozzle; the print gate compares this with the printer. */
|
|
@@ -146,6 +146,7 @@ const BAMBU_MODEL_PRESETS = {
|
|
|
146
146
|
a1: (n) => `Bambu Lab A1 ${n} nozzle`,
|
|
147
147
|
a1mini: (n) => `Bambu Lab A1 mini ${n} nozzle`,
|
|
148
148
|
h2d: (n) => `Bambu Lab H2D ${n} nozzle`,
|
|
149
|
+
h2dpro: (n) => `Bambu Lab H2D Pro ${n} nozzle`,
|
|
149
150
|
h2s: (n) => `Bambu Lab H2S ${n} nozzle`,
|
|
150
151
|
h2c: (n) => `Bambu Lab H2C ${n} nozzle`,
|
|
151
152
|
x2d: (n) => `Bambu Lab X2D ${n} nozzle`,
|
|
@@ -159,6 +160,7 @@ const FILAMENT_MODEL_CODES = {
|
|
|
159
160
|
a1: "A1",
|
|
160
161
|
a1mini: "A1M",
|
|
161
162
|
h2d: "H2D",
|
|
163
|
+
h2dpro: "H2DP",
|
|
162
164
|
h2s: "H2S",
|
|
163
165
|
h2c: "H2C",
|
|
164
166
|
x2d: "X2D",
|
|
@@ -991,6 +993,7 @@ class BambuPrinterMCPServer {
|
|
|
991
993
|
{ const: "a1", title: "A1" },
|
|
992
994
|
{ const: "a1mini", title: "A1 Mini" },
|
|
993
995
|
{ const: "h2d", title: "H2D" },
|
|
996
|
+
{ const: "h2dpro", title: "H2D Pro" },
|
|
994
997
|
{ const: "h2s", title: "H2S" },
|
|
995
998
|
{ const: "h2c", title: "H2C" },
|
|
996
999
|
{ const: "x2d", title: "X2D" },
|
package/dist/printers/bambu.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { readFreshPrinterStatus } from "../safety/printer-state.js";
|
|
2
|
+
import { isCancelledX2DJob, readFreshPrinterStatus } from "../safety/printer-state.js";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import { readFileSync, existsSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
@@ -438,7 +438,10 @@ export class BambuImplementation {
|
|
|
438
438
|
}
|
|
439
439
|
}
|
|
440
440
|
finishedJobIdentity(status) {
|
|
441
|
-
|
|
441
|
+
const raw = status.raw;
|
|
442
|
+
return raw.gcode_state === "FINISH" || isCancelledX2DJob(raw, String(status.model ?? ""))
|
|
443
|
+
? JSON.stringify([raw.gcode_state, raw.gcode_file, raw.subtask_name, raw.task_id, raw.subtask_id, raw.job_id])
|
|
444
|
+
: undefined;
|
|
442
445
|
}
|
|
443
446
|
/**
|
|
444
447
|
* The human print confirmation. Its result goes to assertBedClearance at
|
|
@@ -453,7 +456,9 @@ export class BambuImplementation {
|
|
|
453
456
|
await this.confirmHardwareAction(`Start a checked print on ${inspection.model.toUpperCase()} (${serial})? Nozzles: ${inspection.nozzleDiameters.join(", ")} mm. ` +
|
|
454
457
|
`Materials: ${inspection.materials.join(", ")}. Peak targets: nozzle ${inspection.maxNozzleTemperature}°C, bed ${inspection.maxBedTemperature}°C, chamber ${inspection.maxChamberTemperature}°C. ` +
|
|
455
458
|
`File SHA-256: ${inspection.sha256}. Confirm the physical spool labels and that the build plate is clear.` +
|
|
456
|
-
(finishedJob !== undefined ?
|
|
459
|
+
(finishedJob !== undefined ? (status.raw.gcode_state === "FAILED"
|
|
460
|
+
? " The previous X2D task was canceled (0300400C): remove every detached part, support and strand from the plate and nozzle before confirming. FAILED is the previous job's terminal state; no error-reset command is sent."
|
|
461
|
+
: " The printer reports FINISH: remove the previous part and debris before confirming.") : "") +
|
|
457
462
|
(cleared ? ` Previously cleared hardware codes: ${cleared.map(describeHmsKey).join(", ")}. Confirm their physical causes have been resolved.` : "") +
|
|
458
463
|
(notices.length ? ` The printer also reports ${notices.join(", ")}, which Bambu lists for this model without text and never shows as a fault; ` +
|
|
459
464
|
`${notices.length === 1 ? "it does" : "they do"} not block printing.` : "") +
|
|
@@ -979,11 +984,22 @@ export class BambuImplementation {
|
|
|
979
984
|
const hidden = new Set(hiddenHmsKeys(status.raw, serial, String(status.model ?? "")));
|
|
980
985
|
return [`print_error:${status.raw.print_error}`, ...status.raw.hms.map(reportedHmsKey).filter((key) => !hidden.has(key))].sort();
|
|
981
986
|
};
|
|
982
|
-
const
|
|
983
|
-
|
|
987
|
+
const initialStatus = await this.getSafetyStatus(host, serial, token);
|
|
988
|
+
const codes = codesFor(initialStatus);
|
|
989
|
+
// Bind the physical inspection to the job observed before asking the
|
|
990
|
+
// person. Identical error codes alone cannot identify a different job.
|
|
991
|
+
const jobIdentity = (raw) => JSON.stringify([
|
|
992
|
+
raw.gcode_file, raw.subtask_name, raw.task_id, raw.subtask_id, raw.job_id,
|
|
993
|
+
]);
|
|
994
|
+
const confirmedJob = jobIdentity(initialStatus.raw);
|
|
995
|
+
const jobName = initialStatus.raw.subtask_name || initialStatus.raw.gcode_file;
|
|
996
|
+
await this.confirmHardwareAction(`Clear reported hardware errors on ${serial}: ${codes.map(describeHmsKey).join(", ")}?${jobName ? ` Current job: ${String(jobName)}.` : ""} Inspect the printer and resolve the physical cause first. Confirm only after removing obstructions and correcting the fault.`, true);
|
|
984
997
|
const beforeDispatch = async () => {
|
|
985
998
|
assertActive();
|
|
986
|
-
const
|
|
999
|
+
const currentStatus = await this.getSafetyStatus(host, serial, token);
|
|
1000
|
+
if (jobIdentity(currentStatus.raw) !== confirmedJob)
|
|
1001
|
+
throw new Error("Printer job changed before clearing hardware errors. Inspect the current job and confirm again; nothing further sent.");
|
|
1002
|
+
const current = codesFor(currentStatus);
|
|
987
1003
|
if (JSON.stringify(current) !== JSON.stringify(codes))
|
|
988
1004
|
throw new Error("Hardware errors changed before clearing. Inspect the new report before retrying.");
|
|
989
1005
|
assertActive();
|
|
@@ -993,8 +1009,10 @@ export class BambuImplementation {
|
|
|
993
1009
|
assertActive();
|
|
994
1010
|
if (dispatch)
|
|
995
1011
|
await dispatch(assertActive, beforeDispatch);
|
|
996
|
-
else
|
|
1012
|
+
else {
|
|
1013
|
+
await beforeDispatch();
|
|
997
1014
|
await printer.publish({ print: { command: "clean_print_error", sequence_id: "0" } });
|
|
1015
|
+
}
|
|
998
1016
|
this.clearedErrors.set(serial, codes);
|
|
999
1017
|
await sleep(COMMAND_SETTLE_MS);
|
|
1000
1018
|
return { status: "success", message: "Confirmed HMS clear command sent. The next print requires acknowledgment of these cleared codes.", cleared_codes: codes };
|
|
@@ -39,6 +39,16 @@ export interface ValidatedPrinterState {
|
|
|
39
39
|
reportedNozzles: ReportedNozzle[];
|
|
40
40
|
filaments: ReportedFilament[];
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* X2D retains FAILED after a canceled job even with no active print error.
|
|
44
|
+
* Bambu Studio classifies FAILED as a finished job; its v02.08.02.61
|
|
45
|
+
* hms_en_20P table (926a7192574bcb9b3a732e1ec59a46d79cb45466)
|
|
46
|
+
* calls 0300400C "The task was canceled."
|
|
47
|
+
* Only this observed terminal condition qualifies, never an arbitrary failure.
|
|
48
|
+
* Callers still validate HMS, identity, hardware and material configuration,
|
|
49
|
+
* and print dispatch must obtain job-bound physical bed-clearance confirmation.
|
|
50
|
+
*/
|
|
51
|
+
export declare function isCancelledX2DJob(raw: Record<string, any>, model: string): boolean;
|
|
42
52
|
/** Nozzles whose reported diameter and type are configured settings rather than chip readings. */
|
|
43
53
|
export declare function unchippedNozzles(raw: unknown): number[];
|
|
44
54
|
/** The one key format for a reported entry, shared by the gate and clear_hms_errors. */
|
|
@@ -116,6 +116,20 @@ function finiteNumber(value) {
|
|
|
116
116
|
const number = Number(value);
|
|
117
117
|
return Number.isFinite(number) ? number : undefined;
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* X2D retains FAILED after a canceled job even with no active print error.
|
|
121
|
+
* Bambu Studio classifies FAILED as a finished job; its v02.08.02.61
|
|
122
|
+
* hms_en_20P table (926a7192574bcb9b3a732e1ec59a46d79cb45466)
|
|
123
|
+
* calls 0300400C "The task was canceled."
|
|
124
|
+
* Only this observed terminal condition qualifies, never an arbitrary failure.
|
|
125
|
+
* Callers still validate HMS, identity, hardware and material configuration,
|
|
126
|
+
* and print dispatch must obtain job-bound physical bed-clearance confirmation.
|
|
127
|
+
*/
|
|
128
|
+
export function isCancelledX2DJob(raw, model) {
|
|
129
|
+
return normalizeModel(model) === "x2d" && raw.gcode_state === "FAILED" &&
|
|
130
|
+
finiteNumber(raw.print_error) === 0 && finiteNumber(raw.fail_reason) === 0x0300400c &&
|
|
131
|
+
[raw.gcode_file, raw.subtask_name].some(value => typeof value === "string" && value.trim().length > 0);
|
|
132
|
+
}
|
|
119
133
|
const token = (value) => typeof value === "string" ? value.trim().toLowerCase().replace(/[\s_-]/g, "") : "";
|
|
120
134
|
function nozzleTypeAndFlow(value) {
|
|
121
135
|
const text = String(value ?? "");
|
|
@@ -296,9 +310,10 @@ function logHiddenNotices(raw, serial, model) {
|
|
|
296
310
|
}
|
|
297
311
|
function validateErrors(raw, requireIdle, serial, model) {
|
|
298
312
|
const state = typeof raw.gcode_state === "string" ? raw.gcode_state.toUpperCase() : "UNKNOWN";
|
|
299
|
-
|
|
313
|
+
const cancelled = isCancelledX2DJob(raw, model);
|
|
314
|
+
if (requireIdle && !["IDLE", "FINISH"].includes(state) && !cancelled)
|
|
300
315
|
throw new Error(`Printer state ${state} is not safely idle.`);
|
|
301
|
-
if (!requireIdle && !["IDLE", "FINISH", "RUNNING", "PAUSE"].includes(state))
|
|
316
|
+
if (!requireIdle && !["IDLE", "FINISH", "RUNNING", "PAUSE"].includes(state) && !cancelled)
|
|
302
317
|
throw new Error(`Printer state ${state} is unknown or failed.`);
|
|
303
318
|
if (finiteNumber(raw.print_error) !== 0)
|
|
304
319
|
throw new Error("Printer reports a print error or did not report its error state.");
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -138,12 +138,12 @@ function assertUniformCliNozzles(args: Record<string, any>): void {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
const VALID_BAMBU_MODELS = ["p1s", "p1p", "p2s", "x1c", "x1e", "a1", "a1mini", "h2d", "h2s", "h2c", "x2d"] as const;
|
|
141
|
+
const VALID_BAMBU_MODELS = ["p1s", "p1p", "p2s", "x1c", "x1e", "a1", "a1mini", "h2d", "h2dpro", "h2s", "h2c", "x2d"] as const;
|
|
142
142
|
type BambuModel = typeof VALID_BAMBU_MODELS[number];
|
|
143
143
|
// X2D uses the same project_file/ams_mapping2 family of LAN print fields as
|
|
144
144
|
// the dual-nozzle H2 path. Keep it in this gate so pre-sliced multi-filament
|
|
145
145
|
// jobs take the correct branch instead of the legacy 5-slot mapping.
|
|
146
|
-
const H2_BAMBU_MODELS = new Set<string>(["h2d", "h2s", "h2c", "x2d"]);
|
|
146
|
+
const H2_BAMBU_MODELS = new Set<string>(["h2d", "h2dpro", "h2s", "h2c", "x2d"]);
|
|
147
147
|
|
|
148
148
|
const VALID_BED_TYPES = ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"] as const;
|
|
149
149
|
const VALID_NOZZLE_TYPES = ["stainless_steel", "hardened_steel", "tungsten_carbide", "brass"] as const;
|
|
@@ -185,6 +185,7 @@ const BAMBU_MODEL_PRESETS: Record<string, (nozzle: string) => string> = {
|
|
|
185
185
|
a1: (n) => `Bambu Lab A1 ${n} nozzle`,
|
|
186
186
|
a1mini: (n) => `Bambu Lab A1 mini ${n} nozzle`,
|
|
187
187
|
h2d: (n) => `Bambu Lab H2D ${n} nozzle`,
|
|
188
|
+
h2dpro: (n) => `Bambu Lab H2D Pro ${n} nozzle`,
|
|
188
189
|
h2s: (n) => `Bambu Lab H2S ${n} nozzle`,
|
|
189
190
|
h2c: (n) => `Bambu Lab H2C ${n} nozzle`,
|
|
190
191
|
x2d: (n) => `Bambu Lab X2D ${n} nozzle`,
|
|
@@ -199,6 +200,7 @@ const FILAMENT_MODEL_CODES: Record<string, string> = {
|
|
|
199
200
|
a1: "A1",
|
|
200
201
|
a1mini: "A1M",
|
|
201
202
|
h2d: "H2D",
|
|
203
|
+
h2dpro: "H2DP",
|
|
202
204
|
h2s: "H2S",
|
|
203
205
|
h2c: "H2C",
|
|
204
206
|
x2d: "X2D",
|
|
@@ -1294,6 +1296,7 @@ class BambuPrinterMCPServer {
|
|
|
1294
1296
|
{ const: "a1", title: "A1" },
|
|
1295
1297
|
{ const: "a1mini", title: "A1 Mini" },
|
|
1296
1298
|
{ const: "h2d", title: "H2D" },
|
|
1299
|
+
{ const: "h2dpro", title: "H2D Pro" },
|
|
1297
1300
|
{ const: "h2s", title: "H2S" },
|
|
1298
1301
|
{ const: "h2c", title: "H2C" },
|
|
1299
1302
|
{ const: "x2d", title: "X2D" },
|
package/src/printers/bambu.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { readFreshPrinterStatus } from "../safety/printer-state.js";
|
|
2
|
+
import { isCancelledX2DJob, readFreshPrinterStatus } from "../safety/printer-state.js";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import { readFileSync, existsSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
@@ -527,7 +527,10 @@ export class BambuImplementation {
|
|
|
527
527
|
}
|
|
528
528
|
|
|
529
529
|
private finishedJobIdentity(status: any): string | undefined {
|
|
530
|
-
|
|
530
|
+
const raw = status.raw;
|
|
531
|
+
return raw.gcode_state === "FINISH" || isCancelledX2DJob(raw, String(status.model ?? ""))
|
|
532
|
+
? JSON.stringify([raw.gcode_state, raw.gcode_file, raw.subtask_name, raw.task_id, raw.subtask_id, raw.job_id])
|
|
533
|
+
: undefined;
|
|
531
534
|
}
|
|
532
535
|
|
|
533
536
|
/**
|
|
@@ -544,7 +547,9 @@ export class BambuImplementation {
|
|
|
544
547
|
`Start a checked print on ${inspection.model.toUpperCase()} (${serial})? Nozzles: ${inspection.nozzleDiameters.join(", ")} mm. ` +
|
|
545
548
|
`Materials: ${inspection.materials.join(", ")}. Peak targets: nozzle ${inspection.maxNozzleTemperature}°C, bed ${inspection.maxBedTemperature}°C, chamber ${inspection.maxChamberTemperature}°C. ` +
|
|
546
549
|
`File SHA-256: ${inspection.sha256}. Confirm the physical spool labels and that the build plate is clear.` +
|
|
547
|
-
(finishedJob !== undefined ?
|
|
550
|
+
(finishedJob !== undefined ? (status.raw.gcode_state === "FAILED"
|
|
551
|
+
? " The previous X2D task was canceled (0300400C): remove every detached part, support and strand from the plate and nozzle before confirming. FAILED is the previous job's terminal state; no error-reset command is sent."
|
|
552
|
+
: " The printer reports FINISH: remove the previous part and debris before confirming.") : "") +
|
|
548
553
|
(cleared ? ` Previously cleared hardware codes: ${cleared.map(describeHmsKey).join(", ")}. Confirm their physical causes have been resolved.` : "") +
|
|
549
554
|
(notices.length ? ` The printer also reports ${notices.join(", ")}, which Bambu lists for this model without text and never shows as a fault; ` +
|
|
550
555
|
`${notices.length === 1 ? "it does" : "they do"} not block printing.` : "") +
|
|
@@ -1101,11 +1106,21 @@ export class BambuImplementation {
|
|
|
1101
1106
|
const hidden = new Set(hiddenHmsKeys(status.raw, serial, String(status.model ?? "")));
|
|
1102
1107
|
return [`print_error:${status.raw.print_error}`, ...status.raw.hms.map(reportedHmsKey).filter((key: string) => !hidden.has(key))].sort();
|
|
1103
1108
|
};
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1109
|
+
const initialStatus = await this.getSafetyStatus(host, serial, token);
|
|
1110
|
+
const codes = codesFor(initialStatus);
|
|
1111
|
+
// Bind the physical inspection to the job observed before asking the
|
|
1112
|
+
// person. Identical error codes alone cannot identify a different job.
|
|
1113
|
+
const jobIdentity = (raw: Record<string, any>) => JSON.stringify([
|
|
1114
|
+
raw.gcode_file, raw.subtask_name, raw.task_id, raw.subtask_id, raw.job_id,
|
|
1115
|
+
]);
|
|
1116
|
+
const confirmedJob = jobIdentity(initialStatus.raw);
|
|
1117
|
+
const jobName = initialStatus.raw.subtask_name || initialStatus.raw.gcode_file;
|
|
1118
|
+
await this.confirmHardwareAction(`Clear reported hardware errors on ${serial}: ${codes.map(describeHmsKey).join(", ")}?${jobName ? ` Current job: ${String(jobName)}.` : ""} Inspect the printer and resolve the physical cause first. Confirm only after removing obstructions and correcting the fault.`, true);
|
|
1106
1119
|
const beforeDispatch = async () => {
|
|
1107
1120
|
assertActive();
|
|
1108
|
-
const
|
|
1121
|
+
const currentStatus = await this.getSafetyStatus(host, serial, token);
|
|
1122
|
+
if (jobIdentity(currentStatus.raw) !== confirmedJob) throw new Error("Printer job changed before clearing hardware errors. Inspect the current job and confirm again; nothing further sent.");
|
|
1123
|
+
const current = codesFor(currentStatus);
|
|
1109
1124
|
if (JSON.stringify(current) !== JSON.stringify(codes)) throw new Error("Hardware errors changed before clearing. Inspect the new report before retrying.");
|
|
1110
1125
|
assertActive();
|
|
1111
1126
|
};
|
|
@@ -1113,7 +1128,10 @@ export class BambuImplementation {
|
|
|
1113
1128
|
const printer = dispatch ? undefined : await this.getPrinter(host, serial, token);
|
|
1114
1129
|
assertActive();
|
|
1115
1130
|
if (dispatch) await dispatch(assertActive, beforeDispatch);
|
|
1116
|
-
else
|
|
1131
|
+
else {
|
|
1132
|
+
await beforeDispatch();
|
|
1133
|
+
await printer!.publish({ print: { command: "clean_print_error", sequence_id: "0" } });
|
|
1134
|
+
}
|
|
1117
1135
|
this.clearedErrors.set(serial, codes);
|
|
1118
1136
|
await sleep(COMMAND_SETTLE_MS);
|
|
1119
1137
|
return { status: "success", message: "Confirmed HMS clear command sent. The next print requires acknowledgment of these cleared codes.", cleared_codes: codes };
|
|
@@ -126,6 +126,21 @@ function finiteNumber(value: unknown): number | undefined {
|
|
|
126
126
|
const number = Number(value);
|
|
127
127
|
return Number.isFinite(number) ? number : undefined;
|
|
128
128
|
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* X2D retains FAILED after a canceled job even with no active print error.
|
|
132
|
+
* Bambu Studio classifies FAILED as a finished job; its v02.08.02.61
|
|
133
|
+
* hms_en_20P table (926a7192574bcb9b3a732e1ec59a46d79cb45466)
|
|
134
|
+
* calls 0300400C "The task was canceled."
|
|
135
|
+
* Only this observed terminal condition qualifies, never an arbitrary failure.
|
|
136
|
+
* Callers still validate HMS, identity, hardware and material configuration,
|
|
137
|
+
* and print dispatch must obtain job-bound physical bed-clearance confirmation.
|
|
138
|
+
*/
|
|
139
|
+
export function isCancelledX2DJob(raw: Record<string, any>, model: string): boolean {
|
|
140
|
+
return normalizeModel(model) === "x2d" && raw.gcode_state === "FAILED" &&
|
|
141
|
+
finiteNumber(raw.print_error) === 0 && finiteNumber(raw.fail_reason) === 0x0300400c &&
|
|
142
|
+
[raw.gcode_file, raw.subtask_name].some(value => typeof value === "string" && value.trim().length > 0);
|
|
143
|
+
}
|
|
129
144
|
const token = (value: unknown) => typeof value === "string" ? value.trim().toLowerCase().replace(/[\s_-]/g, "") : "";
|
|
130
145
|
function nozzleTypeAndFlow(value: unknown): {type?: string; flow?: string} {
|
|
131
146
|
const text = String(value ?? "");
|
|
@@ -304,8 +319,9 @@ function logHiddenNotices(raw: Record<string, any>, serial: string, model: strin
|
|
|
304
319
|
|
|
305
320
|
function validateErrors(raw: Record<string,any>, requireIdle: boolean, serial: string, model: string) {
|
|
306
321
|
const state = typeof raw.gcode_state === "string" ? raw.gcode_state.toUpperCase() : "UNKNOWN";
|
|
307
|
-
|
|
308
|
-
if (
|
|
322
|
+
const cancelled = isCancelledX2DJob(raw, model);
|
|
323
|
+
if (requireIdle && !["IDLE","FINISH"].includes(state) && !cancelled) throw new Error(`Printer state ${state} is not safely idle.`);
|
|
324
|
+
if (!requireIdle && !["IDLE","FINISH","RUNNING","PAUSE"].includes(state) && !cancelled) throw new Error(`Printer state ${state} is unknown or failed.`);
|
|
309
325
|
if (finiteNumber(raw.print_error) !== 0) throw new Error("Printer reports a print error or did not report its error state.");
|
|
310
326
|
if (!Array.isArray(raw.hms)) throw new Error("Printer HMS error state is missing or malformed.");
|
|
311
327
|
for (const reported of raw.hms) {
|