Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 0 additions & 139 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ categories = []
anyhow = "1.0.98"
rs-usbtmc = { git = "https://github.com/MatzeS/rs-usbtmc" }
thiserror = "^2.0.0"
tokio = { version = "^1.0.0", features = ["macros", "net", "io-util", "sync"] }

[dev-dependencies]

tokio = { version = "^1.0.0", features = ["rt"] }
serial_test = "3.2.0"
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ Rust library for controlling the *Siglent SPD3303X* programmable power supply.

## Usage
```
let mut power_supply = Spd3303x::connect_hostname("<IP goes here>").await?;
use spd3303x::{Driver, NetworkDriver, Spd3303x, UsbDriver},

// Via Network
let mut power_supply = NetworkDriver::connect_hostname("<IP goes here>")?;

// Via USB-TMC
let mut power_supply = UsbDriver::connect_device()?;

// Double check we talk to the correct device.
power_supply
.verify_serial_number("<your serial number>")
.await?;
?;

let (ch1, ch2, ch3) = power_supply.into_channels();

ch1.set_limit(LimitQuantity::Voltage, Reading::from(1.000)) .await?;
ch1.set_limit(LimitQuantity::Current, Reading::from(0.1)).await?;
ch1.set_output(State::On).await?;
ch1.set_limit(LimitQuantity::Voltage, Reading::from(1.000)) ?;
ch1.set_limit(LimitQuantity::Current, Reading::from(0.1))?;
ch1.set_output(State::On)?;
```

## Limitations

Only TCP/IP is supported.
The USB interface is not (yet) implemented.

## Notes

This library implements the complete command set based on the official datasheet. See [`src/commands.rs`](src/commands.rs).
Expand All @@ -35,6 +36,15 @@ The crate is currenlty on channel nightly for the 'pattern' feature.

In the current early version of the crate (0.x.x), there may be breaking API changes without a major version bump.

## Auto-Turn-Off Behavior

After certain channel configuration commands (e.g., voltage/current limit changes), the SPD3303X may automatically disable the channel output.
This is a built-in safety feature of the device and not a bug in this library.

This safety feature can be turned off using:

power_supply.disable_auto_off();

## Reliability

Integration tests may sporadically fail due to "Connection reset" errors.
Expand Down
27 changes: 11 additions & 16 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,32 @@ use spd3303x::{
spd3303x::{NetworkDriver, Spd3303x},
};

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
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 driver = NetworkDriver::connect_hostname(hostname.as_str()).await?;
let mut power_supply = Spd3303x { driver };
let driver = NetworkDriver::connect_hostname(hostname.as_str())?;
let mut power_supply = Spd3303x::new(driver);

// 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())
.await?;
power_supply.verify_serial_number(serial_number.as_str())?;

let (ch1, _ch2, ch3) = power_supply.into_channels();

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

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

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

ch1.set_output(State::On).await?;
ch1.set_output(State::Off).await?;
ch1.set_output(State::On)?;
ch1.set_output(State::Off)?;

Ok(())
}
Loading