Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Instruments Staying in Remote after Closing Connections #73

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading