Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

lazy check for serial port opening #532

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const messages = {
INVALID_ARDUINO_PATH: "Cannot find the Arduino installation path. You can specify the path in the user settings.",
FAILED_SEND_SERIALPORT: "Failed to send message to serial port.",
SERIAL_PORT_NOT_STARTED: "Serial Monitor has not been started.",
SEND_BEFORE_OPEN_SERIALPORT: "Please open a serial port first.",
SEND_BEFORE_OPEN_SERIALPORT: "Please open Serial Monitor first.",
};

export const statusBarPriority = {
Expand Down
21 changes: 8 additions & 13 deletions src/serialmonitor/serialportctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,8 @@ export class SerialPortCtrl {
this._currentSerialPort = new SerialPortCtrl.serialport(this._currentPort, { baudRate: this._currentBaudRate });
this._outputChannel.show();
this._currentSerialPort.on("open", () => {
this._currentSerialPort.write("TestingOpen", "Both NL & CR", (err) => {
// TODO: Fix this on the serial port lib: https://github.com/EmergingTechnologyAdvisors/node-serialport/issues/795
if (err && !(err.message.indexOf("Writing to COM port (GetOverlappedResult): Unknown error code 121") >= 0)) {
this._outputChannel.appendLine(`[Error] Failed to open the serial port - ${this._currentPort}`);
reject(err);
} else {
this._outputChannel.appendLine(`[Info] Opened the serial port - ${this._currentPort}`);
resolve();
}
});
this._outputChannel.appendLine(`[Info] Opened the serial port - ${this._currentPort}`);
return resolve();
});

this._currentSerialPort.on("data", (_event) => {
Expand All @@ -109,10 +101,13 @@ export class SerialPortCtrl {
}

this._currentSerialPort.write(text, SerialPortEnding[this._ending], (error) => {
if (!error) {
resolve();
} else {
// Make it lazy check for serial port opening
// https://github.com/Microsoft/vscode-arduino/issues/530
if (error && !(error.message.indexOf("Writing to COM port (GetOverlappedResult): Unknown error code 121") >= 0)) {
this._outputChannel.appendLine(`[Error] Failed to open the serial port - ${this._currentPort}`);
return reject(error);
} else {
return resolve();
}
});
});
Expand Down