Every field is Option because the box returns a full-shaped record even when an
individual read fails, and because not every supply reports every quantity.
pub struct SupplyState { pub netname: Option<String>, pub channel: Option<i64>, pub error: Option<String>, // set when the whole gather failed pub voltage: Option<f64>, // measured, V pub current: Option<f64>, // measured, A pub power: Option<f64>, // measured, W pub enabled: Option<bool>, pub mode: Option<String>, // "CV" or "CC" pub voltage_set: Option<f64>, // setpoint, V pub current_set: Option<f64>, // setpoint, A pub voltage_max: Option<f64>, // instrument hardware limit, V pub current_max: Option<f64>, // instrument hardware limit, A pub ocp_limit: Option<f64>, pub ocp_tripped: Option<bool>, pub ovp_limit: Option<f64>, pub ovp_tripped: Option<bool>,}
The box refuses a value above the instrument’s hardware limit before it reaches the
instrument, as Error::Box with a message naming the limit. The message reads
Voltage 999.0V exceeds hardware limit 60.0V.
use lager::LagerBox;let lager = LagerBox::from_env()?;let supply = lager.supply("supply1");supply.set_voltage(3.3)?;supply.set_current(0.5)?;supply.enable()?;std::thread::sleep(std::time::Duration::from_millis(200));let s = supply.state()?;assert_eq!(s.enabled, Some(true));let v = s.voltage.expect("output is on, so a measurement exists");assert!((v - 3.3).abs() < 0.05, "rail at {v:.4} V");supply.disable()?;
supply.set_voltage(3.3)?;supply.set_ocp(0.25)?; // trip rather than let it draw moresupply.enable()?;std::thread::sleep(std::time::Duration::from_secs(5));let s = supply.state()?;assert_eq!(s.ocp_tripped, Some(false), "DUT tripped the 250 mA budget");supply.disable()?;
A measurement can be None while the output is off. A Keithley 2281S reports
voltage, current and power as None with the output disabled, and real
numbers once enabled. A Rigol DP821 reports zeros in both states. This is why the
fields are Option — treat None as “not measured”, not as zero.
state() returning Ok does not mean the instrument answered. When the box
cannot reach the hardware service, you get a fully-shaped SupplyState with every
measurement None and error set to a string explaining why. Check error before
trusting a field.
Safety limits cap setpoints, not trips. With a max_voltage ceiling configured
on the net, set_voltage() above it is refused, but set_ovp() above it is
accepted and applied. See Client and Box.
Supply and battery nets can point at the same physical instrument. The box
serializes them under one per-instrument lock, so they cannot interleave, but they
do share the instrument’s mode.