Various updates

This commit is contained in:
Wesley Hofman
2025-09-15 20:24:09 +02:00
parent 9292dcfad5
commit 14e8e2f267
18 changed files with 1241 additions and 483 deletions

View File

@@ -8,25 +8,203 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Text.RegularExpressions;
using Maser.Palantir.Model;
namespace HTOLHAST
{
public partial class Form1 : Form
{
public int PositionIncrement
{
get
{
int result;
if (int.TryParse(tbPositionIncrement.Text, out result))
{
return result;
}
else
{
// Handle the case where the conversion fails
throw new FormatException("Invalid input for PAMMaxCurrent.");
}
}
set
{
tbPositionIncrement.Text = value.ToString();
}
}
public int CurrentPosition
{
get
{
int result;
if (int.TryParse(tbCurrentPosition.Text, out result))
{
return result;
}
else
{
// Handle the case where the conversion fails
throw new FormatException("Invalid input for PAMMaxCurrent.");
}
}
set
{
tbCurrentPosition.Text = value.ToString();
}
}
HMP4040 PSU1;
HMP4040 PSU2;
Keithley6485 PAM;
Agilent34970a DAQ;
Project Project;
List<SwitchMatrix> switchMatrix;
List<PowerUpSequence> powerUpSequences;
List<PowerUpSequence> powerDownSequences;
List<Measurement> measurements;
List<HeaderSetting> headerSettings = new List<HeaderSetting>();
DataTable dataTablePowersupplySettings = new DataTable();
List<PowerSupplySetting> powerSupplySettings = new List<PowerSupplySetting>();
List<int> voltageChannels = new List<int>() { 201, 202, 203, 204, 205, 206, 207, 208, 209, 210,
214, 215, 216, 217, 218, 219 };
public double PAMMaxCurrent
{
get
{
double result;
if (double.TryParse(tbPamMaxCurrent.Text, out result))
{
return result;
}
else
{
// Handle the case where the conversion fails
throw new FormatException("Invalid input for PAMMaxCurrent.");
}
}
}
public Form1()
{
InitializeComponent();
InitializeEvents();
//InitializeDataTablePowerSupplySettings();
//InitializeDgvPowerSupplySettings();
//KeithleyValidationOfMethods();
InitDgvPowersupply();
InitDgvHeaderSetting();
InitDgvMeasurements();
InitSwitchMatrix();
InitializePowerupSequence();
}
private void InitDgvMeasurements()
{
measurements = new List<Measurement>();
dgvMeasurements.DataSource = measurements;
}
private void InitBeginPositionOfSwitches()
{
foreach (var sw in switchMatrix)
{
DAQ.CloseChannel(sw.SW1);
DAQ.OpenChannel(sw.SW2);
DAQ.CloseChannel(sw.SW3);
}
}
private void InitSwitchMatrix()
{
switchMatrix = new List<SwitchMatrix>()
{
//00926 20 Channel Actuator / GP Switch Module SLOT1
new SwitchMatrix { Channel = 1, SW1 = 102, SW2 = 103, SW3 = 104 },
new SwitchMatrix { Channel = 2, SW1 = 105, SW2 = 106, SW3 = 107 },
new SwitchMatrix { Channel = 3, SW1 = 108, SW2 = 109, SW3 = 110 },
new SwitchMatrix { Channel = 4, SW1 = 111, SW2 = 112, SW3 = 113 },
new SwitchMatrix { Channel = 5, SW1 = 114, SW2 = 115, SW3 = 116 },
new SwitchMatrix { Channel = 6, SW1 = 117, SW2 = 118, SW3 = 119 }
};
}
public void InitDgvHeaderSetting()
{
for (int headerpin = 1; headerpin <= 10; headerpin++)
{
HeaderSetting headerSetting = new HeaderSetting() { HeaderPin = headerpin.ToString(), Channel = voltageChannels[headerpin -1], Description = "-", Setpoint = 0.0, Tolerance = 0.0 };
headerSettings.Add(headerSetting);
}
dgvHeaderSettings.DataSource = headerSettings;
dgvHeaderSettings.Update();
}
public void InitDgvPowersupply ()
{
for (int channel = 1; channel <= 6; channel++)
{
PowerSupplySetting powerSupplySetting = new PowerSupplySetting() { Channel = channel, Description = "-", Voltage = 0.0, Tolerance = 1, CurrentLimit = 0.1, Enabled = false };
powerSupplySettings.Add(powerSupplySetting);
}
dgvPowerSupplies.DataSource = powerSupplySettings;
dgvPowerSupplies.Update();
}
public void InitializeDataTablePowerSupplySettings()
{
dataTablePowersupplySettings.Columns.Add("Channel", typeof(int));
dataTablePowersupplySettings.Columns.Add("Description", typeof(string));
dataTablePowersupplySettings.Columns.Add("Voltage", typeof(double));
dataTablePowersupplySettings.Columns.Add("Tolerance", typeof(double));
dataTablePowersupplySettings.Columns.Add("CurrentLimit", typeof(double));
dataTablePowersupplySettings.Columns.Add("Enabled", typeof(bool));
}
public void InitializeDgvPowerSupplySettings()
{
dgvPowerSupplies.DataSource = dataTablePowersupplySettings;
for (int channel = 1; channel <= 6; channel++)
{
PowerSupplySetting powerSupplySetting = new PowerSupplySetting() { Channel = channel, Description = "-", Voltage = 0.0, Tolerance = 1, CurrentLimit = 0.1, Enabled = false };
dataTablePowersupplySettings.Rows.Add(powerSupplySetting.Channel, powerSupplySetting.Description, powerSupplySetting.Voltage,
powerSupplySetting.Tolerance, powerSupplySetting.CurrentLimit, powerSupplySetting.Enabled);
}
dgvPowerSupplies.Update();
}
private void InitializeEvents ()
{
cbCH1.CheckedChanged += OnPowerSupplyCheckboxClicked;
cbCH2.CheckedChanged += OnPowerSupplyCheckboxClicked;
cbCH3.CheckedChanged += OnPowerSupplyCheckboxClicked;
cbCH4.CheckedChanged += OnPowerSupplyCheckboxClicked;
cbCH5.CheckedChanged += OnPowerSupplyCheckboxClicked;
cbCH6.CheckedChanged += OnPowerSupplyCheckboxClicked;
cbCH7.Enabled = false;
cbCH8.Enabled = false;
}
private void InitializePowerupSequence()
{
powerUpSequences = new List<PowerUpSequence>()
{ new PowerUpSequence { Channel = 1, Delay = 100},
new PowerUpSequence { Channel = 2, Delay = 100},
new PowerUpSequence { Channel = 3, Delay = 100},
new PowerUpSequence { Channel = 4, Delay = 100}
};
}
private void InitializePowerDownSequence()
{
powerDownSequences = new List<PowerUpSequence>()
{ new PowerUpSequence { Channel = 1, Delay = 1},
new PowerUpSequence { Channel = 2, Delay = 1},
new PowerUpSequence { Channel = 3, Delay = 1},
new PowerUpSequence { Channel = 4, Delay = 1}
};
}
public void InitializeInstruments()
{
@@ -35,7 +213,7 @@ namespace HTOLHAST
InitializeDAQ(tbResourceStringDAQ.Text);
// Optional Instruments check if to be used
if (cbPSU1Enabled.Checked)
if (cbPSU2Enabled.Checked)
{
InitializePSU2(tbResourceStringPSU2.Text);
}
@@ -50,10 +228,19 @@ namespace HTOLHAST
try
{
PSU1 = new HMP4040(resourceString);
foreach (var setting in powerSupplySettings)
{
if (setting.Channel <=4)
{
setting.Voltage = PSU1.ReadSetpoint(setting.Channel);
}
}
dgvPowerSupplies.Refresh();
}
catch (Exception)
{
MessageBox.Show("Unable to Connect to HAMEG 1 PowerSupply");
throw;
}
@@ -66,7 +253,7 @@ namespace HTOLHAST
}
catch (Exception)
{
MessageBox.Show("Unable to Connect to HAMEG 2 PowerSupply");
throw;
}
@@ -76,10 +263,17 @@ namespace HTOLHAST
try
{
PAM = new Keithley6485(resourceString);
// Query the instrument ID
PAM.Reset();
string idnResponse = PAM.GetID();
Console.WriteLine($"Instrument ID: {idnResponse}");
// Measure DC current
PAM.PerformZeroCheck();
}
catch (Exception)
{
MessageBox.Show("Unable to Connect to PicoAmmeter");
throw;
}
@@ -90,24 +284,24 @@ namespace HTOLHAST
{
DAQ = new Agilent34970a(resourceString);
}
catch (Exception)
catch (Exception e)
{
MessageBox.Show("Unable to Connect to DAQ");
throw;
}
}
public void HamegValidationOfMethods()
{
string resourceString = "ASRL4::INSTR"; // Replace with your instrument's resource string
HMP4040 hameg = new HMP4040(resourceString);
hameg.GetID();
string voltageResponse = hameg.MeasureVolt(1);
Console.WriteLine($"Measured Voltage: {voltageResponse} V");
HMP4040Sample voltageResponse = (HMP4040Sample)hameg.MeasureVolt(1);
Console.WriteLine($"Measured Voltage: {voltageResponse.Value} V");
string currentResponse = hameg.MeasureCurrent(1);
Console.WriteLine($"Measured Current: {currentResponse} A");
HMP4040Sample currentResponse = (HMP4040Sample)hameg.MeasureCurrent(1);
Console.WriteLine($"Measured Current: {currentResponse.Value} A");
string voltageSetpoint = hameg.SetVoltage(1.1, 1);
@@ -132,17 +326,282 @@ namespace HTOLHAST
// Measure DC current
keithley.PerformZeroCheck();
string currentResponse = keithley.MeasureDCCurrent();
Console.WriteLine($"Measured Current: {currentResponse}");
Keithley6485Sample currentResponse = (Keithley6485Sample) keithley.MeasureDCCurrent();
Console.WriteLine($"Measured Current: {currentResponse.Value}");
// Close the instrument connection
keithley.Close();
}
public void AgilentValidationOfMethods()
{
// Example usage
string resourceString = "ASRL9::INSTR"; // Replace with your instrument's resource string
Agilent34970a agilent = new Agilent34970a(resourceString);
// Query the instrument ID
agilent.Reset();
string idnResponse = agilent.GetID();
Console.WriteLine($"Instrument ID: {idnResponse}");
//Measure DC Voltage
foreach (var channel in voltageChannels)
{
agilent.ConfigVoltageChannel(channel);
Agilent34970aSample sample =(Agilent34970aSample) agilent.MeasureVolt(channel);
Console.WriteLine($"Measured voltage CH{channel} : {sample.Value}");
}
// Close the instrument connection
agilent.Close();
}
private void btnInitializeInstruments_Click(object sender, EventArgs e)
{
InitializeInstruments();
}
private void btnSelectProject_Click(object sender, EventArgs e)
{
// Create new Form and show in showdialog window.
FormSelectProject formSelectProject = new FormSelectProject();
if (formSelectProject.ShowDialog() == DialogResult.OK)
{
// Get Project information from formSelectProject Form.
Project = formSelectProject.Project;
// Update Project information
UpdateProjectInfoTextboxes(Project);
}
}
private void UpdateProjectInfoTextboxes(Project project)
{
// Fill in project information textboxes.
tbProject.Text = $"Project: P{project.MIDSProject} Sub: {project.MIDSSubProject} Step: {project.MIDSStep}";
tbProjectDescription.Text = project.MIDSProjectDescription;
tbSubProjectDescription.Text = project.MIDSSubProjectDescription;
tbStepDescription.Text = project.MIDSStepDescription;
}
public void OnPowerSupplyCheckboxClicked (object sender, EventArgs e)
{
CheckBox SelectedChannel = (CheckBox)sender;
Console.WriteLine(SelectedChannel.Name);
int.TryParse(SelectedChannel.Name[4].ToString(), out int channel);
//DataRow row = dataTablePowersupplySettings.Rows[channel-1];
//row["Enabled"] = SelectedChannel.Checked;
foreach (var setting in powerSupplySettings)
{
if (setting.Channel == channel)
{
setting.Enabled = SelectedChannel.Checked;
dgvPowerSupplies.Refresh();
}
}
}
private void btnMeasure_Click(object sender, EventArgs e)
{
InitBeginPositionOfSwitches();
PowerUpPSU(powerUpSequences);
MeasurePSUVoltage();
MeasureHeaderVoltage();
MeasureCurrent();
PowerDownPSU(powerUpSequences);
UpdateMeasureDGV();
// Timestamp, Position, Device, Measurement, Voltage, Current
// 2025-01-09, 1, HAMEG1, CH1, 1.0, 0.1
// 2025-01-09, 1, HAMEG2, CH5, 1.0, 0.1
// 2025-01-09, 1, KEITHLEY, CH1, -, 1.0
// 2025-01-09, 1, AGILENT, HEADER1, 1.0, -
}
private void UpdateMeasureDGV()
{
dgvMeasurements.DataSource = null;
dgvMeasurements.DataSource = measurements;
dgvMeasurements.Refresh();
}
private void PowerUpPSU(List<PowerUpSequence> powerUpsequences)
{
PSU1.PowerUpSequence(powerUpsequences);
PSU1.SetGeneralOutputState(true);
}
private void PowerDownPSU(List<PowerUpSequence> powerUpsequences)
{
PSU1.PowerDownSequence(powerUpsequences);
PSU1.SetGeneralOutputState(false);
}
private void MeasureHeaderVoltage()
{
//02700 20 Channel Multiplexer Module (BLR) SLOT2
foreach (var header in headerSettings)
{
DAQ.ConfigVoltageChannel(header.Channel);
Agilent34970aSample sample =(Agilent34970aSample)DAQ.MeasureVolt(header.Channel);
this.measurements.Add(new Measurement
{
Description = $"Headerpin : {header.HeaderPin}",
Device = "Agilent34970A",
Position = CurrentPosition,
Timestamp = sample.TimeStamp,
Value = sample.Value,
Unit = sample.Unit
});
Console.WriteLine($"Measured voltage CH{header.Channel} : {sample.Value}");
}
}
private void MeasurePSUVoltage()
{
var powerSupplies = GetEnabledPowerSupplies();
foreach (var powersupply in powerSupplies)
{
if (powersupply.Channel <= 4)
{
HMP4040Sample sample = (HMP4040Sample)PSU1.MeasureVolt(powersupply.Channel);
this.measurements.Add(new Measurement
{
Description = $"PSU1_CH{powersupply.Channel}",
Device = "HAMEG4040",
Position = CurrentPosition,
Timestamp = sample.TimeStamp,
Value = sample.Value,
Unit = sample.Unit
});
sample = (HMP4040Sample)PSU1.MeasureCurrent(powersupply.Channel);
this.measurements.Add(new Measurement
{
Description = $"PSU1_CH{powersupply.Channel}",
Device = "HAMEG4040",
Position = CurrentPosition,
Timestamp = sample.TimeStamp,
Value = sample.Value,
Unit = sample.Unit
});
}
else
{
HMP4040Sample sample = (HMP4040Sample)PSU2.MeasureVolt(powersupply.Channel);
this.measurements.Add(new Measurement
{
Description = $"PSU2_CH{powersupply.Channel}",
Device = "HAMEG4040",
Position = CurrentPosition,
Timestamp = sample.TimeStamp,
Value = sample.Value,
Unit = sample.Unit
});
sample = (HMP4040Sample)PSU2.MeasureCurrent(powersupply.Channel);
this.measurements.Add(new Measurement
{
Description = $"PSU1_CH{powersupply.Channel}",
Device = "HAMEG4040",
Position = CurrentPosition,
Timestamp = sample.TimeStamp,
Value = sample.Value,
Unit = sample.Unit
});
}
}
}
private void MeasureCurrent()
{
var enabledPowersupplies = GetEnabledPowerSupplies();
foreach (var powersupply in enabledPowersupplies)
{
if (powersupply.Channel <= 4)
{
HMP4040Sample current = (HMP4040Sample) PSU1.MeasureCurrent(powersupply.Channel);
if (PAM == null) { return; }
if (current.Value < PAMMaxCurrent )
{
DAQ.CloseChannel(101); // Switch relay for PAM measurement
SetSwitchesBeforeCurrentMeasurement(powersupply.Channel);
Keithley6485Sample sample = (Keithley6485Sample) PAM.MeasureDCCurrent();
this.measurements.Add(new Measurement
{
Description = $"PSU1_CH{powersupply.Channel}",
Device = "Keithley6485",
Position = CurrentPosition,
Timestamp = sample.TimeStamp,
Value = sample.Value,
Unit = sample.Unit
});
SetSwitchesAfterCurrentMeasurement(powersupply.Channel);
}
}
else
{
DAQ.CloseChannel(101); // Switch relay for PAM measurement
HMP4040Sample current = (HMP4040Sample)PSU2.MeasureCurrent(powersupply.Channel);
if (PAM == null) { return; }
if (current.Value < PAMMaxCurrent)
{
SetSwitchesBeforeCurrentMeasurement(powersupply.Channel);
PAM.MeasureDCCurrent();
Keithley6485Sample sample = (Keithley6485Sample)PAM.MeasureDCCurrent();
this.measurements.Add(new Measurement
{
Description = $"PSU2_CH{powersupply.Channel}",
Device = "Keithley6485",
Position = CurrentPosition,
Timestamp = sample.TimeStamp,
Value = sample.Value,
Unit = sample.Unit
});
SetSwitchesAfterCurrentMeasurement(powersupply.Channel);
}
}
}
}
private void SetSwitchesBeforeCurrentMeasurement(int channel)
{
SwitchMatrix switches = switchMatrix.Where(x => x.Channel == channel).First();
DAQ.CloseChannel(switches.SW1);
DAQ.CloseChannel(switches.SW2);
DAQ.CloseChannel(switches.SW3);
DAQ.OpenChannel(switches.SW1);
}
private void SetSwitchesAfterCurrentMeasurement(int channel)
{
SwitchMatrix switches = switchMatrix.Where(x => x.Channel == channel).First();
DAQ.CloseChannel(switches.SW1);
DAQ.OpenChannel(switches.SW2);
DAQ.OpenChannel(switches.SW3);
}
private List<PowerSupplySetting> GetEnabledPowerSupplies()
{
var enabledPowerSupplies = powerSupplySettings.Where(x => x.Enabled == true).ToList();
return enabledPowerSupplies;
}
private void btnSendPsuSettings_Click(object sender, EventArgs e)
{
foreach (PowerSupplySetting powerSupplySetting in powerSupplySettings)
{
PSU1.SetVoltage(powerSupplySetting.Voltage, powerSupplySetting.Channel);
PSU1.SetCurrent(powerSupplySetting.CurrentLimit, powerSupplySetting.Channel);
}
}
private void btnNextPosition_Click(object sender, EventArgs e)
{
CurrentPosition += PositionIncrement;
}
private void btnClear_Click(object sender, EventArgs e)
{
measurements.Clear(); // Clear the list
dgvMeasurements.DataSource = null; // Clear the data source
dgvMeasurements.DataSource = measurements;
}
}
}