plesty.lib.solver.scpi
SCPI command solver for Plesty device models.
Classes
Build SCPI command strings for parameter writes and queries, and dispatch |
Module Contents
- class plesty.lib.solver.scpi.SCPISolver(qfmt: str = '{cmd}?', wfmt: str = '{cmd} {value}', bfmt: str = '{cmd}? {bound}')
Bases:
plesty.lib.solver.CmdSolverBuild SCPI command strings for parameter writes and queries, and dispatch simple function operations described by a
FuncMeta.The existing parameter interface (
get_write_cmd,get_query_cmd,get_param_min_cmd,get_param_max_cmd) is unchanged. The newsolve_func()method handles operations whose entire protocol exchange is captured by a single SCPI command and a scalar response, as declared through the"command"field inschema_func.json.Operations that require multi-step exchanges or custom response parsing return
Nonefromsolve_func()and must be handled by the device’sOpSolver.Initialize the SCPISolver with optional command format strings.
- Parameters:
qfmt (str) – Format string for query commands, default
"{cmd}?".wfmt (str) – Format string for write commands, default
"{cmd} {value}".bfmt (str) – Format string for limit queries, default
"{cmd}? {bound}". SCPI asks for a limit by passingMIN/MAXas the query parameter (CORR:WAV? MIN), not by appending a node (CORR:WAV:MIN?) — an instrument does not recognise the latter, returns nothing, and the read times out. Override only for an instrument that genuinely implements a limit subnode.
- qfmt = '{cmd}?'
- wfmt = '{cmd} {value}'
- bfmt = '{cmd}? {bound}'
- get_write_cmd(cfg_param: plesty.lib.solver.ConfigParameter, value: Any) str | None
Build a SCPI write command for the given parameter value.
- Parameters:
cfg_param (plesty.lib.solver.ConfigParameter) – Parameter metadata containing a SCPI command base.
value (Any) – Value to serialize into command payload.
- Returns:
A formatted SCPI write command string, or
Nonewhen no command is defined oncfg_param.- Return type:
str | None
Notes
Supported value types are
str,int,float,bool,list, andtuple. Booleans are converted to1/0and sequences are comma-joined.
- get_query_cmd(cfg_param: plesty.lib.solver.ConfigParameter) str | None
Build a SCPI query command (
?suffix) for a parameter.- Parameters:
cfg_param (plesty.lib.solver.ConfigParameter) – Parameter metadata containing a SCPI command base.
- Returns:
Query command string like
<CMD>?, orNoneif undefined.- Return type:
str | None
- get_param_min_cmd(cfg_param: plesty.lib.solver.ConfigParameter) str | None
Build a SCPI command to query the parameter minimum value.
- Parameters:
cfg_param (plesty.lib.solver.ConfigParameter) – Parameter metadata containing a SCPI command base.
- Returns:
Query command string like
<CMD>? MIN, orNoneif undefined.- Return type:
str | None
- get_param_max_cmd(cfg_param: plesty.lib.solver.ConfigParameter) str | None
Build a SCPI command to query the parameter maximum value.
- Parameters:
cfg_param (plesty.lib.solver.ConfigParameter) – Parameter metadata containing a SCPI command base.
- Returns:
Query command string like
<CMD>? MAX, orNoneif undefined.- Return type:
str | None
- solve_func(op_name: str, send_fn: Callable[[str], Any], func_meta: FuncMeta | None) dict[str, Any] | None
Dispatch a function operation described by a
FuncMeta.Sends the mapped SCPI command via
send_fn, strips the raw string response, casts it tofunc_meta.output_dtype, and returns a single-key response dictionary. ReturnsNonewhenfunc_metaisNone, signalling that the caller must handle the operation through its own custom logic.- Parameters:
op_name (str) – PLESTY operation name (used only for error messages).
send_fn (Callable[[str], Any]) – Callable that accepts a raw SCPI command string and returns the device response (e.g.
tm.send_command).func_meta (FuncMeta | None) –
FuncMetainstance injected by theFunctionSystemvia the request dictionary, orNonefor custom operations.
- Returns:
{output_key: cast_value}whenfunc_metais present,Noneotherwise.- Raises:
ValueError – If the raw response cannot be cast to
func_meta.output_dtype.- Return type:
dict[str, Any] | None