Fix exception when disconnecting

This commit is contained in:
GHOSCHT 2021-08-27 21:19:11 +02:00
parent a60acb1381
commit 6c720bd8aa
2 changed files with 6 additions and 4 deletions

View file

@ -32,7 +32,7 @@ class PortController {
this.parser = this.port.pipe(new parsers.Readline({ delimiter: "\r\n" }));
}
open(callback: (error:Error | null | undefined)=>void, onCloseCallback:(error:Error)=>void) {
open(callback: (error:Error | null | undefined)=>void, onCloseCallback:(error:Error | null | undefined)=>void) {
if (this.isOpen) {
throw new Error("Port already open");
}

View file

@ -25,10 +25,12 @@ const connect = (): ThunkResult<void> => async (dispatch, getState) => {
dispatch(connectionFailure(error));
}
}, (error) => {
if (error !== null && error !== undefined) {
if (error.message === "Reading from COM port (ReadIOCompletion): Access denied") {
dispatch(connectionFailure(new Error("Device disconnected")));
dispatch(connectionFailure(new Error(`Device ${state.serialConnection.port} disconnected`)));
dispatch(connectionEnd());
}
}
});
};