spd3303x 0.2.1

Library for controlling the *Siglent SPD3303X* programmable power supply.
Documentation
use anyhow::anyhow;
use spd3303x::{
    Result,
    commands::{LimitQuantity, Quantity, Reading, State},
    spd3303x::Spd3303x,
};

fn main() -> Result<()> {
    let hostname = std::env::var("TEST_SPD3303X")
        .map_err(|e| anyhow!("Environment variable TEST_SPD3303X not set! `{e}`"))?;
    let serial_number = std::env::var("TEST_SPD3303X_SERIAL")
        .map_err(|e| anyhow!("Environment variable TEST_SPD3303X_SERIAL not set! `{e}`"))?;

    let mut power_supply = Spd3303x::connect_hostname(hostname.as_str())?;

    // Serial number verification is recommended, to ensure
    // you are not accidentally connecting to the wrong device.
    power_supply.verify_serial_number(serial_number.as_str())?;

    // Auto turn off ensures the channel is turned off, when the channel is dropped.
    let (ch1, _ch2, ch3) = power_supply.into_auto_turn_off_channels();

    ch1.set_limit(LimitQuantity::Voltage, Reading::from(1.000))?;
    ch1.set_limit(LimitQuantity::Current, Reading::from(0.1))?;

    let voltage = ch1.measure(Quantity::Voltage)?;
    println!("V {voltage}");

    ch3.set_output(State::On)?;
    ch3.set_output(State::Off)?;

    ch1.set_output(State::On)?;
    // Due to auto turnoff, ch1 will be turned off before exiting.

    Ok(())
}