Skip to content

Commit

Permalink
fix: fixed timeout errors when calling serialport commands
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDygma committed Jul 7, 2023
1 parent 391cbf9 commit d8b760f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
8 changes: 5 additions & 3 deletions src/api/flash/defyFlasher/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ export class FlashDefyWireless {
*/
async saveBackupFile() {
const userDataPath = await ipcRenderer.invoke("get-userPath", "userData");
const route = path.join(userDataPath, this.backupFileName + ".json");
console.log("saving file to: " + route);
const route = path.join(userDataPath, `${this.backupFileName}.json`);
console.log(`saving file to: ${route}`);
fs.writeFile(route, JSON.stringify(this.backupFileData), err => {
if (err) throw err;
});
Expand Down Expand Up @@ -212,7 +212,9 @@ export class FlashDefyWireless {
this.backup = backup;
return new Promise(async (resolve, reject) => {
stateUpdate("reset", 10);
focus.command("upgrade.neuron");
focus.command("upgrade.neuron").catch(err => {
if (err) console.log("answer after shutdown not received");
});
console.log("waiting for bootloader");
await this.delay(1000);
stateUpdate("reset", 30);
Expand Down
47 changes: 25 additions & 22 deletions src/api/focus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,30 @@ class Focus {
}

async open(device, info, file) {
try {
if (file !== null) {
await this.fileOpen(info, file);
return true;
}

if (this._port !== undefined && this._port.isOpen === false) {
this.close();
}
if (file !== null) {
await this.fileOpen(info, file);
return true;
}

// console.log("Warning! device being opened");
// console.log("port status opened?", this._port ? this._port.isOpen : "unknown");
// console.log("received device", device);
// console.log("received info: ", info);
if (this._port !== undefined && this._port.isOpen === false) {
this.close();
}

// console.log("Warning! device being opened");
// console.log("port status opened?", this._port ? this._port.isOpen : "unknown");
// console.log("received device", device);
// console.log("received info: ", info);
try {
let path;
if (typeof device === "string") path = device;
if (typeof device === "object") path = device.settings.path;
if (path !== undefined) {
await SerialPort.list();
this._port = new SerialPort({ path, baudRate: 115200, autoOpen: true });
this._port = new SerialPort({ path, baudRate: 115200, autoOpen: false });
await this._port.open(err => {
if (err) console.error("error when opening port: ", err);
else console.log("connected");
});
} else {
throw Error("device not a string or object!");
}
Expand Down Expand Up @@ -142,18 +145,18 @@ class Focus {
// Ignore
}
}

// Setup error port alert
this._port.on("error", async function (err) {
console.error(`Error on SerialPort: ${err}`);
await this._port.close();
});
this.closed = false;
return this._port;
} catch (error) {
console.error("found this error while opening!", error);
// throw new Error("Unable to connect");
}

// Setup error port alert
this._port.on("error", async function (err) {
console.error(`Error on SerialPort: ${err}`);
await this._port.close();
});
this.closed = false;
return this._port;
}

clearContext() {
Expand Down

0 comments on commit d8b760f

Please # to comment.