added .csv export

This commit is contained in:
2025-09-18 23:44:17 +02:00
parent 94a7c0e3fa
commit 326e0d2d12
2 changed files with 249 additions and 205 deletions

View File

@@ -10,6 +10,7 @@ using System.Windows.Forms;
using System.Threading;
using System.Text.RegularExpressions;
using Maser.Palantir.Model;
using System.IO;
namespace HTOLHAST
{
@@ -70,9 +71,6 @@ namespace HTOLHAST
List<HeaderSetting> headerSettings = new List<HeaderSetting>();
DataTable dataTablePowersupplySettings = new DataTable();
List<PowerSupplySetting> powerSupplySettings = new List<PowerSupplySetting>();
@@ -103,11 +101,22 @@ namespace HTOLHAST
//InitializeDataTablePowerSupplySettings();
//InitializeDgvPowerSupplySettings();
//KeithleyValidationOfMethods();
InitializeButtons();
InitDgvPowersupply();
InitDgvHeaderSetting();
InitDgvMeasurements();
InitSwitchMatrix();
InitializePowerupSequence();
}
#region INITIALIZATION
private void InitializeButtons()
{
btnClear.Enabled = false;
btnMeasure.Enabled = false;
btnNextPosition.Enabled = false;
btnSendPsuSettings.Enabled = false;
}
private void InitDgvMeasurements()
{
@@ -302,6 +311,9 @@ namespace HTOLHAST
}
}
#endregion
#region INSTRUMENTVALIDATION
public void HamegValidationOfMethods()
{
string resourceString = "ASRL4::INSTR"; // Replace with your instrument's resource string
@@ -370,6 +382,8 @@ namespace HTOLHAST
{
InitializeInstruments();
}
#endregion
private void btnSelectProject_Click(object sender, EventArgs e)
{
// Create new Form and show in showdialog window.
@@ -596,6 +610,25 @@ namespace HTOLHAST
PSU1.SetCurrent(powerSupplySetting.CurrentLimit, powerSupplySetting.Channel);
}
}
private void WriteBindingListToCsv(BindingList<Measurement> list, string filePath)
{
StringBuilder csvContent = new StringBuilder();
// Add header
csvContent.AppendLine("Timestamp,Position,Device,Description,Value,Unit");
// Add data
foreach (var measurement in list)
{
csvContent.AppendLine($"{measurement.Timestamp:yyyy-MM-dd},{measurement.Position},{measurement.Device},{measurement.Description},{measurement.Value},{measurement.Unit}");
}
// Write to file
File.WriteAllText(filePath, csvContent.ToString());
MessageBox.Show("Data exported successfully!", "Export", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void btnNextPosition_Click(object sender, EventArgs e)
{
CurrentPosition += PositionIncrement;
@@ -605,5 +638,18 @@ namespace HTOLHAST
{
measurements.Clear(); // Clear the list
}
private void btnExport_Click(object sender, EventArgs e)
{
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
saveFileDialog.Title = "Save a CSV File";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
WriteBindingListToCsv(measurements, saveFileDialog.FileName);
}
}
}
}
}