From b8051b10413a50e6fd31c31c1073544f8e1753a7 Mon Sep 17 00:00:00 2001 From: Shreya-GT Date: Wed, 25 Sep 2024 18:22:34 +0530 Subject: [PATCH] TSP-809 Fix for showing correct model and serial number instead of undefined (#52) Co-authored-by: GT, Shreya --- CHANGELOG.md | 8 ++++- package-lock.json | 4 +-- package.json | 2 +- src/communicationmanager.ts | 20 ++++------- src/extension.ts | 68 ++++++++++++++----------------------- src/instruments.ts | 7 ---- src/resourceManager.ts | 25 +++++--------- 7 files changed, 52 insertions(+), 82 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 610c2f6..62b1a83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,11 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how Security -- in case of vulnerabilities. --> +## [0.18.1] + +### Fixed +- Showing correct model and serial number information instead of undefined (TSP-809) + ## [0.18.0] ### Fixed @@ -161,7 +166,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how - Feature to retrieve TSP-Link network details -[Unreleased]: https://github.com/tektronix/tsp-toolkit/compare/v0.18.0...HEAD +[Unreleased]: https://github.com/tektronix/tsp-toolkit/compare/v0.18.1...HEAD +[0.18.1]: https://github.com/tektronix/tsp-toolkit/releases/tag/v0.18.1 [0.18.0]: https://github.com/tektronix/tsp-toolkit/releases/tag/v0.18.0 [0.17.0]: https://github.com/tektronix/tsp-toolkit/releases/tag/v0.17.0 [0.16.4]: https://github.com/tektronix/tsp-toolkit/releases/tag/v0.16.4 diff --git a/package-lock.json b/package-lock.json index a874c57..2757cd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tsp-toolkit", - "version": "0.18.0", + "version": "0.18.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tsp-toolkit", - "version": "0.18.0", + "version": "0.18.1", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 36a404d..3b32354 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "publisher": "Tektronix", "displayName": "[Beta] Keithley TSP Toolkit", "description": "VSCode extension for Keithley Instruments' Test Script Processor", - "version": "0.18.0", + "version": "0.18.1", "icon": "./resources/TSP_Toolkit_128x128.png", "galleryBanner": { "color": "#EEEEEE", diff --git a/src/communicationmanager.ts b/src/communicationmanager.ts index c605f40..667ae3a 100644 --- a/src/communicationmanager.ts +++ b/src/communicationmanager.ts @@ -121,19 +121,13 @@ export class CommunicationManager { if (Ip == undefined) { return Promise.reject(new Error("IP is undefined")) - } - - const msn = await this._connHelper.getModelAndSerialNumber(Ip) - if (msn != undefined) { - void vscode.window.showInformationMessage( - Ip + - ": Found instrument model " + - msn.model + - " with S/N: " + - msn.sn, - ) - await createTerminal(Ip, msn.model, text) - return Promise.resolve(true) + } else { + if (createTerminal(Ip, undefined, text)) + return Promise.resolve(true) + else + return Promise.reject( + new Error("Unable to connect to instrument"), + ) } } } else if (kicTerminals.length === 1) { diff --git a/src/extension.ts b/src/extension.ts index b28b320..761bdb3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -38,17 +38,15 @@ let _connHelper: ConnectionHelper * @param command_text command text that needs to send to terminal * @returns None */ -export async function createTerminal( +export function createTerminal( connection_string: string, model_serial?: string, command_text?: string, -) { +): boolean { //'example@5e6:2461@2' OR 'example@127.0.0.1' let res: [string, string?] = ["", undefined] let ip = connection_string let name = "" - let msn - let model_serial_no = "" if (connection_string.split("@").length > 1) { name = connection_string.split("@")[0] ip = connection_string.split("@")[1] @@ -56,46 +54,25 @@ export async function createTerminal( if (_connHelper.IPTest(ip)) { //LAN - msn = await _connHelper.getModelAndSerialNumber(ip) //const to let - if (msn != undefined) { - model_serial_no = - (msn.model ?? "undefined") + "#" + (msn.sn ?? "undefined") //const to let - if (name == "") { - name = FriendlyNameMgr.generateUniqueName( - IoType.Lan, - model_serial_no, - ) - } - - void vscode.window.showInformationMessage( - connection_string + - ": Found instrument model " + - msn.model + - " with S/N: " + - msn.sn, - ) - res = _activeConnectionManager?.createTerminal( - name, - IoType.Lan, - `${connection_string}:${msn.port}`, - command_text, - ) - } - //TODO: Remove this else statement once lxi page is ready for versatest - else { - res = _activeConnectionManager?.createTerminal( - name, - IoType.Lan, - connection_string, - command_text, - ) - } + res = _activeConnectionManager?.createTerminal( + name, + IoType.Lan, + connection_string, + command_text, + ) //const instr_to_save: string = "Lan:" + model_serial_no const info = res[0].replace("\n", "") + if (info == "") { + void vscode.window.showErrorMessage( + "Unable to connect to instrument", + ) + return false + } name = res[1] == undefined ? name : res[1] + const port_number = "5025" - _instrExplorer.saveWhileConnect(ip, IoType.Lan, info, name, msn?.port) + _instrExplorer.saveWhileConnect(ip, IoType.Lan, info, name, port_number) } else { //VISA //This only works if selected from Instrument discovery @@ -110,10 +87,17 @@ export async function createTerminal( ) const info = res[0].replace("\n", "") + if (info == "") { + void vscode.window.showErrorMessage( + "Unable to connect to instrument", + ) + return false + } name = res[1] == undefined ? name : res[1] _instrExplorer.saveWhileConnect(ip, IoType.Visa, info, name, undefined) } + return true } // Called when the extension is activated. @@ -427,7 +411,7 @@ async function pickConnection(connection_info?: string): Promise { (option) => option.label === selectedItem.label, ) ) { - await createTerminal(selectedItem.label) + createTerminal(selectedItem.label) } else { const Ip = selectedItem.label if (Ip === undefined) { @@ -467,7 +451,7 @@ async function connect( } if (_activeConnectionManager?.connectionRE.test(Ip)) { - await createTerminal(Ip, model_serial) + createTerminal(Ip, model_serial) } else { void vscode.window.showErrorMessage("Bad connection string") } @@ -487,7 +471,7 @@ function connectCmd(def: object) { _instrExplorer.fetchConnectionArgs(def) if (_activeConnectionManager?.connectionRE.test(connection_str)) { - void createTerminal(connection_str, model_serial) + createTerminal(connection_str, model_serial) } else { void vscode.window.showErrorMessage("Unable to connect.") } diff --git a/src/instruments.ts b/src/instruments.ts index aab98d1..3706fa1 100644 --- a/src/instruments.ts +++ b/src/instruments.ts @@ -1426,13 +1426,6 @@ export class InstrumentsExplorer { friendly_name: string, port: string | undefined, ) { - if (info == "") { - void vscode.window.showErrorMessage( - "Unable to connect to instrument", - ) - return - } - const _info = JSON.parse(info) const __info = new InstrInfo() __info.io_type = ioType diff --git a/src/resourceManager.ts b/src/resourceManager.ts index a061cd2..d2279f6 100644 --- a/src/resourceManager.ts +++ b/src/resourceManager.ts @@ -319,11 +319,16 @@ export class KicCell extends EventEmitter { if (info == "") return [info] - if (name == "") { - const _info = JSON.parse(info) - //for instruments without lxi page, Ex: versatest, tspop etc, if user doesn't provide a connection name - //we generate a unique name based on *idn? info + const _info = JSON.parse(info) + void vscode.window.showInformationMessage( + unique_id + + ": Found instrument model " + + _info.model + + " with S/N: " + + _info.serial_number, + ) + if (name == "") { verified_name = FriendlyNameMgr.generateUniqueName( IoType.Lan, _info.model + "#" + _info.serial_number, @@ -454,18 +459,6 @@ export class ConnectionHelper { if (!this.IPTest(conn_str) && !this.VisaResourceStringTest(conn_str)) { return "Enter proper IPv4 address or VISA resource string" } - - void this.getModelAndSerialNumber(conn_str).then((msn) => { - if (msn != undefined) { - void vscode.window.showInformationMessage( - conn_str + - ": Found instrument model " + - msn.model + - " with S/N: " + - msn.sn, - ) - } - }) return null }