fix: Release COM port after flashing and then Reconnect to get Serial Logs
This commit is contained in:
@@ -401,10 +401,13 @@ function StepFlash({ device, onFlashed }) {
|
|||||||
// Start reading raw UART output from the device after flash+reset
|
// Start reading raw UART output from the device after flash+reset
|
||||||
const startSerialMonitor = async (port) => {
|
const startSerialMonitor = async (port) => {
|
||||||
serialActiveRef.current = true;
|
serialActiveRef.current = true;
|
||||||
|
// Give the OS a moment to fully release the port from esptool before we re-open
|
||||||
|
await new Promise((r) => setTimeout(r, 500));
|
||||||
try {
|
try {
|
||||||
await port.open({ baudRate: 115200 });
|
await port.open({ baudRate: 115200 });
|
||||||
} catch (_) {
|
} catch (openErr) {
|
||||||
// Port may already be open if esptool left it that way — ignore
|
appendSerial(`[Error opening port: ${openErr.message}]`);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const decoder = new TextDecoderStream();
|
const decoder = new TextDecoderStream();
|
||||||
const readableStreamClosed = port.readable.pipeTo(decoder.writable);
|
const readableStreamClosed = port.readable.pipeTo(decoder.writable);
|
||||||
@@ -520,7 +523,13 @@ function StepFlash({ device, onFlashed }) {
|
|||||||
await loaderRef.current.after("hard_reset");
|
await loaderRef.current.after("hard_reset");
|
||||||
appendLog("Hard reset sent. Device is booting…");
|
appendLog("Hard reset sent. Device is booting…");
|
||||||
|
|
||||||
// 6. Update device status → flashed
|
// 6. Disconnect the esptool transport so it releases the port lock
|
||||||
|
try {
|
||||||
|
await loaderRef.current.transport.disconnect();
|
||||||
|
} catch (_) {}
|
||||||
|
appendLog("esptool disconnected. Opening serial monitor…");
|
||||||
|
|
||||||
|
// 7. Update device status → flashed
|
||||||
await api.request(`/manufacturing/devices/${device.serial_number}/status`, {
|
await api.request(`/manufacturing/devices/${device.serial_number}/status`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
body: JSON.stringify({ status: "flashed", note: "Flashed via browser provisioning wizard" }),
|
body: JSON.stringify({ status: "flashed", note: "Flashed via browser provisioning wizard" }),
|
||||||
@@ -529,7 +538,7 @@ function StepFlash({ device, onFlashed }) {
|
|||||||
setFlashing(false);
|
setFlashing(false);
|
||||||
setDone(true);
|
setDone(true);
|
||||||
|
|
||||||
// 7. Open serial monitor at 115200 to show live device output
|
// 8. Re-open the port at 115200 for live UART monitoring
|
||||||
appendSerial("── Serial monitor started (115200 baud) ──");
|
appendSerial("── Serial monitor started (115200 baud) ──");
|
||||||
startSerialMonitor(port);
|
startSerialMonitor(port);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user