plesty.lib.solver.scpi

SCPI command solver for Plesty device models.

Classes

SCPISolver

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.CmdSolver

Build 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 new solve_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 in schema_func.json.

Operations that require multi-step exchanges or custom response parsing return None from solve_func() and must be handled by the device’s OpSolver.

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 passing MIN/MAX as 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:
Returns:

A formatted SCPI write command string, or None when no command is defined on cfg_param.

Return type:

str | None

Notes

Supported value types are str, int, float, bool, list, and tuple. Booleans are converted to 1/0 and 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>?, or None if 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, or None if 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, or None if 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 to func_meta.output_dtype, and returns a single-key response dictionary. Returns None when func_meta is None, 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) – FuncMeta instance injected by the FunctionSystem via the request dictionary, or None for custom operations.

Returns:

{output_key: cast_value} when func_meta is present, None otherwise.

Raises:

ValueError – If the raw response cannot be cast to func_meta.output_dtype.

Return type:

dict[str, Any] | None