Skip to content

Commit

Permalink
TSP-809 Fix for showing correct model and serial number instead of un…
Browse files Browse the repository at this point in the history
…defined (#52)

Co-authored-by: GT, Shreya <[email protected]>
  • Loading branch information
Shreya-GT and GT, Shreya authored Sep 25, 2024
1 parent 32e05df commit b8051b1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 82 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -161,7 +166,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
- Feature to retrieve TSP-Link network details

<!-- Version Comparison Links -->
[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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 7 additions & 13 deletions src/communicationmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
68 changes: 26 additions & 42 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,64 +38,41 @@ 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 '[email protected]'
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]
}

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
Expand All @@ -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.
Expand Down Expand Up @@ -427,7 +411,7 @@ async function pickConnection(connection_info?: string): Promise<void> {
(option) => option.label === selectedItem.label,
)
) {
await createTerminal(selectedItem.label)
createTerminal(selectedItem.label)
} else {
const Ip = selectedItem.label
if (Ip === undefined) {
Expand Down Expand Up @@ -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")
}
Expand All @@ -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.")
}
Expand Down
7 changes: 0 additions & 7 deletions src/instruments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <IIDNInfo>JSON.parse(info)
const __info = new InstrInfo()
__info.io_type = ioType
Expand Down
25 changes: 9 additions & 16 deletions src/resourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,16 @@ export class KicCell extends EventEmitter {

if (info == "") return [info]

if (name == "") {
const _info = <IIDNInfo>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 = <IIDNInfo>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,
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit b8051b1

Please sign in to comment.