Skip to content

Commit

Permalink
fix serial errors
Browse files Browse the repository at this point in the history
  • Loading branch information
spiceywasabi committed Sep 25, 2024
1 parent 3b8eb0d commit 86224d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 8 additions & 7 deletions js/esptool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -295,6 +300,7 @@ async function connect(bypassRequest=false) {
}
if(attempts>=maxBreakRetries){
maxRetriesReached=true;
break;
}
throw err // boil anything else up
}
Expand All @@ -303,6 +309,7 @@ async function connect(bypassRequest=false) {
console.log("ABRT");
}
readLoop().catch((error) => {
console.log(error);
if(maxRetriesReached){
toggleUIConnected(false, error);
}
Expand Down

0 comments on commit 86224d9

Please sign in to comment.