using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace HTOLHAST { public class HMP4040 : SCPIInstrument { public HMP4040(string resourceString) : base(resourceString) { } public Sample MeasureCurrent(int channel) { string Channel = channel.ToString(); WriteCommand($"INST:NSEL {Channel}"); WriteCommand("MEAS:CURR?"); string response = ReadResponse(); Console.WriteLine($"[Hameg] Measured Current : {response}"); Sample sample = CreateSample(response, "A"); return sample; } public double ReadSetpoint(int channel) { double response = double.NaN; WriteCommand($"INST OUT{channel}"); WriteCommand($"VOLT? CH{channel}"); double.TryParse(ReadResponse(), out response); return response; } public Sample MeasureVolt(int channel) { string Channel = channel.ToString(); WriteCommand($"INST:NSEL {Channel}"); WriteCommand("MEAS:VOLT?"); string response = ReadResponse(); Console.WriteLine($"[Hameg] Measured Voltage : {response}"); Sample sample = CreateSample(response,"V"); return sample; } public string SetVoltage (double setpoint, int channel) { WriteCommand($"INST:NSEL {channel}"); WriteCommand($"VOLT {setpoint}"); WriteCommand($"VOLT?"); return ReadResponse(); } public string SetCurrent(double setpoint, int channel) { WriteCommand($"INST:NSEL {channel}"); WriteCommand($"CURR {setpoint}"); WriteCommand($"CURR?"); return ReadResponse(); } public void SetOutputChannel (int channel, bool enabled) { WriteCommand($"INST:NSEL {channel}"); if (enabled) { WriteCommand("OUTP ON"); } else { WriteCommand("OUTP OFF"); } } public void SetGeneralOutputState(bool enabled) { if (enabled) { WriteCommand("OUTP:GEN ON"); } else { WriteCommand("OUTP:GEN OFF"); } } public void PowerUpSequence(List powerUpSequence) { foreach (var sequence in powerUpSequence) { SetOutputChannel(sequence.Channel,true); Thread.Sleep(sequence.Delay); } } public void PowerDownSequence(List powerUpSequence) { foreach (var sequence in powerUpSequence) { SetOutputChannel(sequence.Channel, false); Thread.Sleep(sequence.Delay); } } public List GenerateSimulationPowerUpSequence() { List powerUpSequence = new List { new PowerUpSequence { Channel = 1, Delay = 1000}, new PowerUpSequence { Channel = 3, Delay = 1000}, new PowerUpSequence { Channel = 4, Delay = 1000}, new PowerUpSequence { Channel = 2, Delay = 1000}, }; return powerUpSequence; } public override Sample CreateSample(string response, string unit) { string Response = response; if (double.TryParse(Response, out double voltage)) { HMP4040Sample sample = new HMP4040Sample(DateTime.Now, voltage, unit); // Optionally, store or process the sample here Console.WriteLine($"[HMP4040] Sample Created, Value: {sample.Value} {sample.Unit}"); return sample; } throw new InvalidOperationException("Unsupported instrument type."); } } }