Skip to content

Commit

Permalink
TSP-839 Fix issue with visa connection model and serial number (#61)
Browse files Browse the repository at this point in the history
If the user doesn't provide a connection name, a new name is generated
within initialiseComponents() function using
the function "FriendlyNameMgr.generateUniqueName()". This flow is common
to both Lan and Visa connection.

---------

Co-authored-by: GT, Shreya <[email protected]>
  • Loading branch information
Shreya-GT and GT, Shreya authored Oct 16, 2024
1 parent f28ffd1 commit 5fc0e51
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
Security -- in case of vulnerabilities.
-->


## [0.18.2]

### Added
Expand All @@ -34,6 +33,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

- **tsp-toolkit-kic-cli**: Only call `readSTB` after a command or script is written to
the instrument
- When entering only visa instrument address, connection is saved with correct model and serial number (TSP-839)

### Removed

Expand Down
4 changes: 0 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ export function createTerminal(
} else {
Log.debug("Connection type was determined to be VISA", LOGLOC)
//VISA
//This only works if selected from Instrument discovery
if (name == "") {
name = FriendlyNameMgr.generateUniqueName(IoType.Visa, model_serial)
}
res = _activeConnectionManager?.createTerminal(
name,
IoType.Visa,
Expand Down
24 changes: 19 additions & 5 deletions src/resourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,28 @@ export class FriendlyNameMgr {
* @returns - unique friendly name for given instrument
*/
public static generateUniqueName(
io_type: IoType,
conn_type: string,
model_serial: string | undefined,
): string {
let unique_name = ""
let found = false
const io_type: IoType = FriendlyNameMgr.getIoType(conn_type)
const connections: Array<InstrInfo> =
vscode.workspace.getConfiguration("tsp").get("savedInstruments") ??
[]

if (connections.length > 0) {
connections.forEach((instr) => {
for (let i = 0; i < connections.length; i++) {
const instr = connections[i]
if (
io_type === instr.io_type &&
model_serial == instr.model + "#" + instr.serial_number
) {
unique_name = instr.friendly_name
found = true
return
break
}
})
}
}

if (!found) {
Expand All @@ -116,6 +118,18 @@ export class FriendlyNameMgr {
return unique_name
}

private static getIoType(conn_type: string) {
let io_type: IoType
if (conn_type === "usb") {
io_type = IoType.Usb
} else if (conn_type === "lan") {
io_type = IoType.Lan
} else {
io_type = IoType.Visa
}
return io_type
}

/**
* method checks and adds/updates new friendly name
*
Expand Down Expand Up @@ -338,7 +352,7 @@ export class KicCell extends EventEmitter {

if (name == "") {
verified_name = FriendlyNameMgr.generateUniqueName(
IoType.Lan,
connType,
_info.model + "#" + _info.serial_number,
)
name = verified_name
Expand Down

0 comments on commit 5fc0e51

Please sign in to comment.