Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Serial Monitor Fix (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
vandyliu authored Mar 28, 2020
1 parent 3a3ae68 commit 4a638e5
Show file tree
Hide file tree
Showing 73 changed files with 3,205 additions and 6,381 deletions.
1 change: 1 addition & 0 deletions locales/en/out/constants.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"dialogResponses.agreeAndRun": "Agree and Run",
"dialogResponses.acceptPrivacy": "Got it",
"dialogResponses.cancel": "Cancel",
"dialogResponses.select": "Select",
"dialogResponses.dontShowAgain": "Don't Show Again",
"dialogResponses.exampleCode": "Example Code on GitHub",
"dialogResponses.help": "I need help",
Expand Down
4,455 changes: 3,184 additions & 1,271 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"instrumentationKey": "__AIKEY__",
"icon": "assets/icon.png",
"engines": {
"vscode": "^1.34.0"
"vscode": "^1.43.0"
},
"categories": [
"Other"
Expand Down Expand Up @@ -353,6 +353,7 @@
"socket.io": "^2.2.0",
"svg-inline-react": "^3.1.0",
"ts-jest": "^25.0.0",
"usb-native": "^5.0.1",
"util": "^0.12.1",
"vscode-extension-telemetry": "^0.1.1",
"vscode-nls": "^4.1.0"
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ export namespace DialogResponses {
export const CANCEL: MessageItem = {
title: localize("dialogResponses.cancel", "Cancel"),
};
export const SELECT: MessageItem = {
title: localize("dialogResponses.select", "Select"),
};
export const HELP: MessageItem = {
title: localize("dialogResponses.help", "I need help"),
};
Expand Down
12 changes: 6 additions & 6 deletions src/serialMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { logToOutputChannel } from "./extension_utils/utils";
import { SerialPortControl } from "./serialPortControl";

export interface ISerialPortDetail {
comName: string;
path: string;
manufacturer: string;
vendorId: string;
productId: string;
Expand Down Expand Up @@ -127,7 +127,7 @@ export class SerialMonitor implements vscode.Disposable {
foundPort &&
!(this._serialPortControl && this._serialPortControl.isActive)
) {
this.updatePortListStatus(foundPort.comName);
this.updatePortListStatus(foundPort.path);
}
} else {
const chosen = await vscode.window.showQuickPick(
Expand All @@ -136,7 +136,7 @@ export class SerialMonitor implements vscode.Disposable {
(port: ISerialPortDetail): vscode.QuickPickItem => {
return {
description: port.manufacturer,
label: port.comName,
label: port.path,
};
}
)
Expand All @@ -160,10 +160,10 @@ export class SerialMonitor implements vscode.Disposable {
if (!this._currentPort) {
const ans = await vscode.window.showInformationMessage(
CONSTANTS.WARNING.NO_SERIAL_PORT_SELECTED,
DialogResponses.YES,
DialogResponses.NO
DialogResponses.SELECT,
DialogResponses.CANCEL
);
if (ans === DialogResponses.YES) {
if (ans === DialogResponses.SELECT) {
await this.selectSerialPort(null, null);
}
if (!this._currentPort) {
Expand Down
22 changes: 8 additions & 14 deletions src/serialPortControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CONSTANTS } from "./constants";
import { logToOutputChannel } from "./extension_utils/utils";

interface ISerialPortDetail {
comName: string;
path: string;
manufacturer: string;
vendorId: string;
productId: string;
Expand All @@ -18,21 +18,16 @@ interface ISerialPortDetail {
export class SerialPortControl {
public static get serialport(): any {
if (!SerialPortControl._serialport) {
SerialPortControl._serialport = require("../vendor/node-usb-native").SerialPort;
SerialPortControl._serialport = require("usb-native").SerialPort;
}
return SerialPortControl._serialport;
}

public static list(): Promise<ISerialPortDetail[]> {
return new Promise((resolve, reject) => {
SerialPortControl.serialport.list(
(error: any, ports: ISerialPortDetail[]) => {
if (error) {
reject(error);
} else {
resolve(ports);
}
}
SerialPortControl.serialport.list().then(
ports => resolve(ports),
err => reject(err)
);
});
}
Expand All @@ -53,7 +48,7 @@ export class SerialPortControl {
}

public get isActive(): boolean {
return this._currentSerialPort && this._currentSerialPort.isOpen();
return this._currentSerialPort && this._currentSerialPort.isOpen;
}

public get currentPort(): string {
Expand All @@ -66,7 +61,7 @@ export class SerialPortControl {
CONSTANTS.INFO.OPENING_SERIAL_PORT(this._currentPort)
);
return new Promise((resolve, reject) => {
if (this._currentSerialPort && this._currentSerialPort.isOpen()) {
if (this._currentSerialPort && this._currentSerialPort.isOpen) {
this._currentSerialPort.close((err: any) => {
if (err) {
return reject(err);
Expand All @@ -89,8 +84,7 @@ export class SerialPortControl {
this._outputChannel.show();
this._currentSerialPort.on("open", () => {
this._currentSerialPort.write(
CONSTANTS.MISC.SERIAL_MONITOR_TEST_IF_OPEN,
"Both NL & CR",
CONSTANTS.MISC.SERIAL_MONITOR_TEST_IF_OPEN + os.EOL,
(err: any) => {
if (
err &&
Expand Down
2 changes: 1 addition & 1 deletion src/usbDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class UsbDetector {
if (os.platform() === "linux" || !enableUSBDetection) {
return;
}
this._usbDetector = require("../vendor/node-usb-native").detector;
this._usbDetector = require("usb-native").detector;

if (!this._usbDetector) {
return;
Expand Down
26 changes: 0 additions & 26 deletions vendor/node-usb-native/.eslintrc

This file was deleted.

14 changes: 0 additions & 14 deletions vendor/node-usb-native/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions vendor/node-usb-native/.npmignore

This file was deleted.

4 changes: 0 additions & 4 deletions vendor/node-usb-native/README.md

This file was deleted.

64 changes: 0 additions & 64 deletions vendor/node-usb-native/binding.gyp

This file was deleted.

44 changes: 0 additions & 44 deletions vendor/node-usb-native/lib/bindings.js

This file was deleted.

Loading

0 comments on commit 4a638e5

Please sign in to comment.