Drive an analog output voltage into your DUT from a DAC net.
Handle
use lager::LagerBox;let lager = LagerBox::from_env()?;let dac = lager.dac("dac1");
Methods
Method
Description
name()
The net name this handle addresses
set()
Set the output voltage in volts
read()
Read back the current output voltage
Method Reference
name() -> &str
The net name this handle was created with.
set(volts: f64) -> Result<()>
Set the output voltage.
dac.set(1.8)?;
Parameters:
Parameter
Type
Description
volts
f64
Target output voltage in volts
read() -> Result<f64>
Read back the voltage that the DAC currently outputs.
let v = dac.read()?;
Returns:f64 — the output voltage in volts.
Not every DAC supports readback. On an MCC USB-202 this call fails with
Error::Box and the message USB-202 does not support DAC output readback.
A LabJack U3 has no readback either. The box returns the last value that it set,
and the call fails when the box has no value. Where you need a verified output,
measure it with an ADC net instead of trusting read() to exist.
Examples
Sweep a reference and check the DUT tracks it
let dac = lager.dac("dac1");let sense = lager.adc("adc1");for target in [0.0_f64, 0.5, 1.0, 1.5, 2.0] { dac.set(target)?; std::thread::sleep(std::time::Duration::from_millis(50)); let measured = sense.read()?; assert!((measured - target).abs() < 0.05, "set {target:.2} V, measured {measured:.4} V");}dac.set(0.0)?;
Supported Hardware
Instrument
Channels
Readback
LabJack T7
DAC0, DAC1
Supported
LabJack U3
DAC0, DAC1
Last value that the box set; output range 0.04 V to 4.95 V
MCC USB-202
DAC0, DAC1
Not supported
Notes
Leave the output where the next test expects it. A DAC holds its last value after
your test ends; setting it back to 0.0 in teardown is usually right. A LabJack U3
refuses 0.0, because its range is 0.04 V to 4.95 V. On a U3, use 0.04.
Output accuracy is the instrument’s, not the API’s. A LabJack T7 asked for 1.0 V
reads back around 0.99995 V, which is the DAC’s resolution rather than an error.