fix(tsp): check write_termination before loading large scripts#607
Open
AdarshJ173 wants to merge 1 commit into
Open
fix(tsp): check write_termination before loading large scripts#607AdarshJ173 wants to merge 1 commit into
AdarshJ173 wants to merge 1 commit into
Conversation
Closes tektronix#500 TSP instruments enforce a 1000-character maximum per write when `write_termination` is absent. `load_script()` previously issued the entire `loadscript ... endscript` block as a single write, silently truncating or erroring on scripts that exceed that limit. Changes in `tsp_control.py`: - Add `_TSP_WRITE_MAX_CHARS = 1000` module-level constant documenting the hardware limit. - In `load_script()`, after assembling the full command string: * If `len(cmd) <= 1000` — write as before (no behaviour change for small scripts). * If `len(cmd) > 1000` AND `write_termination` is falsy (empty string or None) — raise `ValueError` with a clear message explaining the limit and how to fix it. * If `len(cmd) > 1000` AND `write_termination` is set — split the load into three phases matching the TSP multi-write protocol: 1. `write("loadscript {name}")` — open the script context. 2. Iterate over `script_body` in ≤1000-char chunks, writing each. 3. `write("endscript")` — close the script context. - Update docstring to document the 1000-character limit and `write_termination` requirement for large scripts.
AdarshJ173
requested review from
amccann-Tek,
ldantek,
michaelwagoner,
nfelt14,
pradhansk,
tekperson and
v12ganesh
July 19, 2026 08:54
|
|
nfelt14
requested changes
Jul 23, 2026
| # write_termination character is configured. Scripts longer than this limit | ||
| # must be sent in multiple writes, which requires write_termination to be set | ||
| # so that the instrument can distinguish successive chunks. | ||
| _TSP_WRITE_MAX_CHARS: int = 1000 |
Collaborator
There was a problem hiding this comment.
This needs to be a class constant, so subclasses can overwrite it if necessary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #500
TSP instruments enforce a 1000-character maximum per VISA write when
write_terminationis not configured.load_script()previously assembled the entireloadscript … endscriptblock into a single write string with no length check, silently truncating or erroring on any script body that pushes the total over 1000 characters.Root Cause
The reporter's repro (
print("123456…"with 967+ chars) produces a 1000+ char write. Withoutwrite_termination, the instrument receives the truncated bytes and returns an unexpected error; the caller gets no indication of why.Fix
Three-path logic in
load_script(), replacing the single write:len(full_cmd) <= 1000len(full_cmd) > 1000ANDwrite_terminationfalsyValueErrorwith a clear message explaining the limit and how to fix itlen(full_cmd) > 1000ANDwrite_terminationsetloadscript {name}→ body in ≤1000-char chunks →endscriptMulti-write protocol (phase 3 path)
This matches the TSP multi-write protocol described in Keithley's TSP documentation.
Error message (path 2)
Impact
write_termination: was silent truncation / confusing instrument error → now immediateValueErrorwith actionable message.write_termination: was broken → now works correctly via chunked write.Changes
src/tm_devices/driver_mixins/device_control/tsp_control.py_TSP_WRITE_MAX_CHARS = 1000load_script()length check and three-path write logicRaisessection andNoteabout the 1000-char limitNo public API changes, no new dependencies, no schema migrations.