Skip to content

Commit

Permalink
Fixes for Instruments Staying in Remote after Closing Connections (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
esarver authored Nov 15, 2024
1 parent ce12ceb commit e0cf4cf
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 48 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
clearing it so it can be printed when opening the terminal
- Added progress indication to connection notification

### Changed

- Discover will use LXI identification page to get instrument information instead of `*IDN?`

### Fixed

- Fixed Readme links and worked around markdown parser error
- Close and reset instrument connections when extension is deactivated


## [1.0.0]
Expand Down
68 changes: 34 additions & 34 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,9 @@
"xml-js": "1.6.11"
},
"optionalDependencies": {
"@tektronix/kic-cli-linux-x64": "0.19.0-0",
"@tektronix/kic-cli-win32-x64": "0.19.0-0",
"@tektronix/kic-cli-darwin-arm64": "0.19.0-0"
"@tektronix/kic-cli-linux-x64": "0.19.0-2",
"@tektronix/kic-cli-win32-x64": "0.19.0-2",
"@tektronix/kic-cli-darwin-arm64": "0.19.0-2"
},
"extensionDependencies": [
"sumneko.lua"
Expand Down
16 changes: 11 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,17 @@ export function activate(context: vscode.ExtensionContext) {

// Called when the extension is deactivated.
export function deactivate() {
Log.info("Deactivating TSP Toolkit", {
file: "extensions.ts",
func: "deactivate()",
})
/* empty */
const LOGLOC = { file: "extensions.ts", func: "deactivate()" }
Log.info("Deactivating TSP Toolkit", LOGLOC)
Log.trace("Closing all kic executables", LOGLOC)
_kicProcessMgr.dispose().then(
() => {
Log.info("Deactivation complete", LOGLOC)
},
() => {
Log.error("Deactivation had errors.")
},
)
}

//Request the instrument to be reset
Expand Down
53 changes: 47 additions & 6 deletions src/resourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ export class KicProcessMgr {
this._connHelper = connHelper
}

async dispose(): Promise<void> {
const disposer: Array<Promise<void>> = new Array<Promise<void>>()
for (const k of this.kicList) {
disposer.push(k.dispose())
}

await Promise.allSettled(disposer)
}

/**
* Used to establish a connection with an instrument
*
Expand Down Expand Up @@ -297,6 +306,43 @@ export class KicCell extends EventEmitter {
super()
}

async dispose(): Promise<void> {
const LOGLOC: SourceLocation = {
file: "resourceManager.ts",
func: "KicCell.dispose()",
}
const pid = await this._term?.processId
if (pid !== undefined) {
Log.debug(`Killing PID ${pid}`, LOGLOC)
process.kill(pid)
}
this._term?.dispose()
this.reset()
}

private reset() {
const LOGLOC: SourceLocation = {
file: "resourceManager.ts",
func: "KicCell.reset()",
}
if (this._connDetails) {
Log.debug(
`Resetting instrument at ${this._connDetails.ConnAddr}`,
LOGLOC,
)
child.spawnSync(EXECUTABLE, [
"--log-file",
join(
LOG_DIR,
`${new Date().toISOString().substring(0, 10)}-kic.log`,
),
"reset",
this._connDetails.ConnType,
this._connDetails.ConnAddr,
])
}
}

/**
* Used to create the components that establish communication with the instrument
* */
Expand Down Expand Up @@ -482,12 +528,7 @@ export class KicCell extends EventEmitter {
) {
setTimeout(() => {
Log.trace("Resetting closed instrument", LOGLOC)
child.spawnSync(EXECUTABLE, [
"-v",
"reset",
connType,
unique_id,
])
this.reset()
}, 500)
}
})
Expand Down

0 comments on commit e0cf4cf

Please sign in to comment.