diff --git a/libdp100/PowerSupply.cs b/libdp100/PowerSupply.cs
index c56e3e9..53dfc33 100644
--- a/libdp100/PowerSupply.cs
+++ b/libdp100/PowerSupply.cs
@@ -103,6 +103,11 @@ public class PowerSupply
///
private bool[] presetsValid = new bool[NumPresets];
+ ///
+ /// Indicates that the "Presets" object has been applied to the volatile preset's state.
+ ///
+ private bool[] presetsLoaded = new bool[NumPresets];
+
///
/// Indicates that the "SystemParams" object has been populated with valid data.
///
@@ -525,8 +530,14 @@ public PowerSupplyResult SetOutput(bool outputOn, ushort millivolts, ushort mill
Output.Setpoint.Voltage = millivolts;
Output.Setpoint.Current = milliamps;
+ if (Presets[Output.Preset] == null)
+ {
+ Presets[Output.Preset] = new PowerSupplySetpoint(Output.Preset);
+ }
+
// Output state affects the volatile state of a preset (group).
Presets[Output.Preset].Copy(Output.Setpoint);
+ presetsValid[Output.Preset] = true;
}
return result;
@@ -894,6 +905,14 @@ public PowerSupplyResult UsePreset(byte preset)
}
}
+ if (result == PowerSupplyResult.OK)
+ {
+ if (!presetsLoaded[preset])
+ {
+ result = SetOutput(Presets[preset]);
+ }
+ }
+
if (result == PowerSupplyResult.OK)
{
Output.Setpoint.Copy(Presets[preset]);
@@ -1042,18 +1061,6 @@ public PowerSupplyResult Reload()
{
return result;
}
-
- result = UsePreset(i);
- if (result != PowerSupplyResult.OK)
- {
- return result;
- }
-
- result = SetOutput(Presets[i]);
- if (result != PowerSupplyResult.OK)
- {
- return result;
- }
}
return result;