From 86224d93e2a3ea57d60eeb41570c32cd9a36d461 Mon Sep 17 00:00:00 2001 From: spiceywasabi Date: Tue, 24 Sep 2024 23:20:58 -0700 Subject: [PATCH] fix serial errors --- js/esptool.js | 15 ++++++++------- js/script.js | 9 ++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/js/esptool.js b/js/esptool.js index 64a7687..a49af8d 100755 --- a/js/esptool.js +++ b/js/esptool.js @@ -386,13 +386,13 @@ class EspLoader { if (!bypassRequest) { port = await navigator.serial.requestPort({ filters: filters }); } - if (port) { + /*if (port) { try { await disconnect(); } catch(e) { - console.log("caught error in disconnect") + console.log("caught error in disconnect:" + e) } - } + }*/ if (this.getChromeVersion() < 86) { await port.open({ baudrate: ESP_ROM_BAUD }); @@ -410,14 +410,15 @@ class EspLoader { } this.logMsg("Trying to reset...") - await this.preferredReset(true,ms); + await this.hardReset(true); + //await this.preferredReset(true,ms); outputStream = port.writable; inputStream = port.readable; } connected() { - if (port) { + if (port&&port.connected) { return true; } return false; @@ -935,13 +936,13 @@ class EspLoader { dataTerminalReady: false, requestToSend: true, }); - await new Promise((resolve) => setTimeout(resolve, 100)); + await new Promise((resolve) => setTimeout(resolve, 1000)); await port.setSignals({ dataTerminalReady: r, requestToSend: false, break: false, }); - await new Promise((resolve) => setTimeout(resolve, 500)); + await new Promise((resolve) => setTimeout(resolve, 2000)); } async preferredReset(r = false,ms=2000) { diff --git a/js/script.js b/js/script.js index 51c62c8..1df0624 100644 --- a/js/script.js +++ b/js/script.js @@ -14,7 +14,7 @@ const eraseFillByte = 0x00; const maxLogLength = 100; var maxRetriesReached = false; -const maxBreakRetries = 4; +var maxBreakRetries = 1; const log = document.getElementById("log"); const stepBox = document.getElementById("steps-container"); @@ -161,10 +161,15 @@ document.addEventListener("DOMContentLoaded", () => { if(e.name === "NotFoundError"){ logMsg("User did not select a serial device!") toggleUIHardware(false,"No device selected by user."); + } else if (e.name === "NetworkError"){ // e.name === "InvalidStateError"){ + console.log(e); + logMsg("Serial port is unavailable to be opened.") + toggleUIHardware(false,"Serial device unavailable and likely being used by another process."); } else { console.log(e); disconnect(); } + throw e; logMsg(e.message); // TODO: REST @@ -295,6 +300,7 @@ async function connect(bypassRequest=false) { } if(attempts>=maxBreakRetries){ maxRetriesReached=true; + break; } throw err // boil anything else up } @@ -303,6 +309,7 @@ async function connect(bypassRequest=false) { console.log("ABRT"); } readLoop().catch((error) => { + console.log(error); if(maxRetriesReached){ toggleUIConnected(false, error); }