simple-scpi 0.1.0

A lightweight SCPI command parser
Documentation
  • Coverage
  • 68.75%
    11 out of 16 items documented0 out of 7 items with examples
  • Size
  • Source code size: 31.56 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.42 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 16s Average build duration of successful builds.
  • all releases: 16s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • js216/simple-scpi
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • js216

simple-scpi

A lightweight SCPI (Standard Commands for Programmable Instruments) command parser for Rust.

Define your instrument's command set as a table of pattern strings and handler functions, and the library takes care of parsing input lines — including short/long keyword forms, numeric suffixes, optional nodes, and compound commands.

Usage

use simple_scpi::{CommandSet, Command, Handler, Param};

let set = CommandSet::from_table(&[
    ("*IDN?",                       handle_idn  as Handler),
    ("SOURce#:FREQuency num",       handle_freq as Handler),
    ("SOURce#:VOLTage[:LEVel] num", handle_volt as Handler),
    ("OUTPut#:STATe bool",          handle_outp as Handler),
]).unwrap();

for cmd in set.parse("SOUR2:FREQ 1e6;OUTP1:STAT ON").unwrap() {
    set.dispatch(&cmd);
}

Each handler receives a &Command with parsed params and numeric suffixes:

fn handle_freq(cmd: &Command) {
    let Param::Numeric(f) = cmd.params[0] else { return };
    println!("ch{} freq = {f}", cmd.suffixes[0]);
}

See examples/demo.rs for a complete working example.

Pattern syntax

Syntax Meaning
SYSTem Mixed-case keyword — uppercase is the required short form, full word is the long form. Matches SYST, SYSTE, SYSTEM (case-insensitive).
: Keyword hierarchy separator.
# Numeric suffix placeholder (defaults to 1 when omitted by the user).
[...] Optional keyword node, e.g. [:LEVel].
? Query suffix.
num Numeric parameter (integers, floats, scientific notation, #H/#Q/#B literals, optional unit suffix).
bool Boolean parameter (ON/OFF/1/0).
str String parameter (quoted or unquoted).

Multiple commands on one line are separated by ;.