diff --git a/src/common/constants.ts b/src/common/constants.ts index 4a1f70d2..0f2d48ef 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -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 = { diff --git a/src/serialmonitor/serialportctrl.ts b/src/serialmonitor/serialportctrl.ts index 5a252093..f22e6b93 100644 --- a/src/serialmonitor/serialportctrl.ts +++ b/src/serialmonitor/serialportctrl.ts @@ -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) => { @@ -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(); } }); });