From 1be79adfebb5d576b0da0fbbc04704ded9aa8606 Mon Sep 17 00:00:00 2001 From: Wesley Hofman Date: Wed, 17 Sep 2025 22:31:47 +0200 Subject: [PATCH] add color to textbox when connected/not connected --- HTOLHAST/Form1.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/HTOLHAST/Form1.cs b/HTOLHAST/Form1.cs index 324ba3b..197ae05 100644 --- a/HTOLHAST/Form1.cs +++ b/HTOLHAST/Form1.cs @@ -209,18 +209,18 @@ namespace HTOLHAST { // Mandatory instruments: - InitializePSU1(tbResourceStringPSU1.Text); - InitializeDAQ(tbResourceStringDAQ.Text); + Task.Run(() => InitializePSU1(tbResourceStringPSU1.Text)); + Task.Run(() => InitializeDAQ(tbResourceStringDAQ.Text)); // Optional Instruments check if to be used if (cbPSU2Enabled.Checked) { - InitializePSU2(tbResourceStringPSU2.Text); + Task.Run(() => InitializePSU2(tbResourceStringPSU2.Text)); } if (cbPAMEnabled.Checked) { - InitializePAM(tbResourceStringPAM.Text); + Task.Run(() => InitializePAM(tbResourceStringPAM.Text)); } } public void InitializePSU1(string resourceString) @@ -235,11 +235,12 @@ namespace HTOLHAST setting.Voltage = PSU1.ReadSetpoint(setting.Channel); } } + tbResourceStringPSU1.BackColor = Color.Green; dgvPowerSupplies.Refresh(); } catch (Exception) { - + tbResourceStringPSU1.BackColor = Color.Red; MessageBox.Show("Unable to Connect to HAMEG 1 PowerSupply"); throw; } @@ -250,9 +251,11 @@ namespace HTOLHAST try { PSU2 = new HMP4040(resourceString); + tbResourceStringPSU2.BackColor = Color.Green; } catch (Exception) { + tbResourceStringPSU2.BackColor = Color.Red; MessageBox.Show("Unable to Connect to HAMEG 2 PowerSupply"); throw; } @@ -270,9 +273,11 @@ namespace HTOLHAST // Measure DC current PAM.PerformZeroCheck(); + tbResourceStringPAM.BackColor = Color.Green; } catch (Exception) { + tbResourceStringPAM.BackColor = Color.Red; MessageBox.Show("Unable to Connect to PicoAmmeter"); throw; } @@ -283,10 +288,11 @@ namespace HTOLHAST try { DAQ = new Agilent34970a(resourceString); + tbResourceStringDAQ.BackColor = Color.Green; } catch (Exception e) { - + tbResourceStringDAQ.BackColor = Color.Red; MessageBox.Show("Unable to Connect to DAQ"); throw; }