in src/serialmonitor/serialMonitor.ts [118:152]
public async selectSerialPort(vid: string, pid: string) {
const lists = await SerialPortCtrl.list();
if (!lists.length) {
vscode.window.showInformationMessage("No serial port is available.");
return;
}
if (vid && pid) {
const valueOfVid = parseInt(vid, 16);
const valueOfPid = parseInt(pid, 16);
const foundPort = lists.find((p) => {
// The pid and vid returned by SerialPortCtrl start with 0x prefix in Mac, but no 0x prefix in Win32.
// Should compare with decimal value to keep compatibility.
if (p.productId && p.vendorId) {
return parseInt(p.productId, 16) === valueOfPid && parseInt(p.vendorId, 16) === valueOfVid;
}
return false;
});
if (foundPort && !(this._serialPortCtrl && this._serialPortCtrl.isActive)) {
this.updatePortListStatus(foundPort.port);
}
} else {
const chosen = await vscode.window.showQuickPick(<vscode.QuickPickItem[]>lists.map((l: ISerialPortDetail): vscode.QuickPickItem => {
return {
description: l.desc,
label: l.port,
};
}).sort((a, b): number => {
return a.label === b.label ? 0 : (a.label > b.label ? 1 : -1);
}), { placeHolder: "Select a serial port" });
if (chosen && chosen.label) {
this.updatePortListStatus(chosen.label);
}
}
}