From 693da58fcbd1448e16535cbea0b4e902f3d43554 Mon Sep 17 00:00:00 2001 From: Bradley Born Date: Mon, 5 Jan 2026 12:35:28 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=A2=20Camera/LED.cs=20=E2=80=A2=20Added?= =?UTF-8?q?=20null-checks=20so=20labels=20are=20created=20dynamically=20wh?= =?UTF-8?q?en=20lblVorI=20is=20null=20(uses=20MainForm.Instance.AddLabelTo?= =?UTF-8?q?Panel).=20=E2=80=A2=20Camera/CameraModules.cs=20=E2=80=A2=20Add?= =?UTF-8?q?ed=20null-label=20handling=20to=20create=20dynamic=20module=20l?= =?UTF-8?q?abels=20with=20the=20correct=20content=20(OK=20or=20the=20error?= =?UTF-8?q?=20message).=20=E2=80=A2=20AiQ=5FGUI.cs=20=E2=80=A2=20Increased?= =?UTF-8?q?=20dynamic=20label=20width=20in=20MakeNewLabel=20from=20220=20?= =?UTF-8?q?=E2=86=92=20700=20to=20avoid=20truncated=20messages.=20?= =?UTF-8?q?=E2=80=A2=20Succesfully=20ran=20through=20a=20pre-test=20with?= =?UTF-8?q?=20dynamic=20labels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AiQ Tests/Diagnostics.cs | 13 ++++------ AiQ_GUI.Designer.cs | 4 ++-- AiQ_GUI.cs | 45 ++++++++++++++++------------------- Camera/CameraModules.cs | 43 +++++++++++++++++++++++---------- Camera/LED.cs | 32 +++++++++++++++++++++++++ Microsoft/Access.cs | 3 ++- Mobile Tests/MobilePreTest.cs | 43 +++++++++++++++++---------------- 7 files changed, 115 insertions(+), 68 deletions(-) diff --git a/AiQ Tests/Diagnostics.cs b/AiQ Tests/Diagnostics.cs index b986b83..9e040b7 100644 --- a/AiQ Tests/Diagnostics.cs +++ b/AiQ Tests/Diagnostics.cs @@ -186,18 +186,15 @@ namespace AiQ_GUI.AiQ_Tests { string ProdcutKeyID = await MainForm.Instance.DisplayInput("What is the Key ID?", false); - if (!RegexCache.VaxtorRegex().IsMatch(ProdcutKeyID)) // Means they chose valid Key ID - { - DiagsAPI.licenses.raptorKeyID = MainForm.Instance.TxBxProductKey.Text; - vaxtorText = "Vaxtor Key ID = " + DiagsAPI.licenses.raptorKeyID; - vaxtorIsRed = false; - } - else + if (RegexCache.VaxtorRegex().IsMatch(ProdcutKeyID)) // Valid Key ID { Access.Stats("Please Get A Valid Vaxtor Product Key Before Continuing", MainForm.Instance.CamOnTest.Model); await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Please get a valid Vaxtor Product Key before continuing"); - vaxtorIsRed = true; } + + DiagsAPI.licenses.raptorKeyID = MainForm.Instance.TxBxProductKey.Text; + vaxtorText = "Vaxtor Key ID = " + DiagsAPI.licenses.raptorKeyID; + vaxtorIsRed = false; } else // Should have license but doesn't OR shouldn't have but does + any other unforeseen circumstance then fail { diff --git a/AiQ_GUI.Designer.cs b/AiQ_GUI.Designer.cs index 44ce4f5..2cf50b3 100644 --- a/AiQ_GUI.Designer.cs +++ b/AiQ_GUI.Designer.cs @@ -712,7 +712,6 @@ namespace AiQ_GUI PnlQuestion.Controls.Add(BtnNo); PnlQuestion.Controls.Add(BtnYes); PnlQuestion.Controls.Add(LblQuestion); - PnlQuestion.Controls.Add(PnlInputValue); PnlQuestion.Location = new Point(251, 14); PnlQuestion.Margin = new Padding(4, 3, 4, 3); PnlQuestion.Name = "PnlQuestion"; @@ -774,7 +773,7 @@ namespace AiQ_GUI PnlInputValue.Controls.Add(BtnDont); PnlInputValue.Controls.Add(BtnDone); PnlInputValue.Controls.Add(LblRMA); - PnlInputValue.Location = new Point(0, 0); + PnlInputValue.Location = new Point(251, 136); PnlInputValue.Margin = new Padding(4, 3, 4, 3); PnlInputValue.Name = "PnlInputValue"; PnlInputValue.Size = new Size(254, 127); @@ -1828,6 +1827,7 @@ namespace AiQ_GUI Controls.Add(RhTxBxActions); Controls.Add(CbBxCamType); Controls.Add(LblGUIVers); + Controls.Add(PnlInputValue); Controls.Add(BtnOpenWebpage); Controls.Add(TabImagesandSettings); Controls.Add(PicBxMAV); diff --git a/AiQ_GUI.cs b/AiQ_GUI.cs index 037de38..904378f 100644 --- a/AiQ_GUI.cs +++ b/AiQ_GUI.cs @@ -1435,33 +1435,33 @@ namespace AiQ_GUI Stopwatch stopWatchTest = Stopwatch.StartNew(); - //await MobilePreTest.CheckFirmwareAsync(); + await MobilePreTest.CheckFirmwareAsync(); //AddLabelToPanel("Test Complete", false); - FakeCamera fakeCamera = new FakeCamera(80); // Create an instance of FakeCamera + //FakeCamera fakeCamera = new FakeCamera(80); // Create an instance of FakeCamera //CamOnTest.IP = CbBxFoundCams.Text; - _ = fakeCamera.StartAsync(CAMTYPE.GOOD).ContinueWith(task => - { - //Network.Initialize("developer", "Pass123"); + //_ = fakeCamera.StartAsync(CAMTYPE.GOOD).ContinueWith(task => + //{ + // //Network.Initialize("developer", "Pass123"); - if (task.IsFaulted) - { - AddToActionsList("Error starting FakeCamera: " + task.Exception?.Message); - } - else - { - AddToActionsList($"FakeCamera started successfully. IP: {fakeCamera}"); - } - }); + // if (task.IsFaulted) + // { + // AddToActionsList("Error starting FakeCamera: " + task.Exception?.Message); + // } + // else + // { + // AddToActionsList($"FakeCamera started successfully. IP: {fakeCamera}"); + // } + //}); - await Task.Delay(3000); // Wait for server to start - CbBxFoundCams.Text = "localhost"; // Should force update in creds an network reinit - CmBoFoundCams_TextChanged(sender, e); - CbBxCameraModel.SelectedIndex = CbBxCameraModel.Items.Count - 1; // Selects AB12CD as model number + //await Task.Delay(3000); // Wait for server to start + //CbBxFoundCams.Text = "localhost"; // Should force update in creds an network reinit + //CmBoFoundCams_TextChanged(sender, e); + //CbBxCameraModel.SelectedIndex = CbBxCameraModel.Items.Count - 1; // Selects AB12CD as model number - await Task.Delay(3000); // Wait for server to start + //await Task.Delay(3000); // Wait for server to start - BtnStartTest_Click(sender, e); + //BtnStartTest_Click(sender, e); AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"), Level.LOG); } @@ -1471,7 +1471,7 @@ namespace AiQ_GUI { Location = new Point(5, yLoc), Height = 20, - Width = 220, + Width = 700, ForeColor = isRed ? Color.Red : Color.LightGreen, Text = text, Name = "Lbl_" + Guid.NewGuid(), @@ -1489,8 +1489,5 @@ namespace AiQ_GUI PnlLbls.Controls.Add(lbl); } - - - } } diff --git a/Camera/CameraModules.cs b/Camera/CameraModules.cs index 33e329b..c12dc3c 100644 --- a/Camera/CameraModules.cs +++ b/Camera/CameraModules.cs @@ -6,9 +6,9 @@ namespace AiQ_GUI // Chack camera modules are in default state according to what the diagnostics API. public static void CheckCamModule(Module CamMod, Label Lbl, Camera CamOnTest) { - if (CamMod == null || Lbl == null) + if (CamMod == null) { - MainForm.Instance.AddToActionsList("Camera module or label was null in CheckCamModule.", Level.ERROR); + MainForm.Instance.AddToActionsList("Camera module was null in CheckCamModule.", Level.ERROR); return; } @@ -37,20 +37,39 @@ namespace AiQ_GUI if (CamMod.expMode != 0) // Auto 0=0x00 errMssg += $"Exp mode not set: {CamMod.expMode} "; + // Determine display result + string displayResult = string.IsNullOrWhiteSpace(errMssg) ? "OK" : errMssg; + bool isError = !string.IsNullOrWhiteSpace(errMssg); + + // Create label dynamically if not provided + if (Lbl == null) + { + string moduleName; + try + { + if (object.ReferenceEquals(CamMod, AiQ_GUI.AiQ_Tests.TestingFunctions.DiagsAPI.IRmodule)) + moduleName = "IR Module"; + else if (object.ReferenceEquals(CamMod, AiQ_GUI.AiQ_Tests.TestingFunctions.DiagsAPI.OVmodule)) + moduleName = "OV Module"; + else + moduleName = CamMod.firmwareVer == null ? "OV Module" : (CamMod.zoom < 5000 ? "IR Module" : "OV Module"); + } + catch + { + moduleName = CamMod.firmwareVer == null ? "OV Module" : (CamMod.zoom < 5000 ? "IR Module" : "OV Module"); + } + + MainForm.Instance.AddLabelToPanel($"{moduleName} = {displayResult}", isError); + return; + } + + // Update existing label try { Lbl.Invoke(() => { - if (string.IsNullOrWhiteSpace(errMssg)) - { - Lbl.Text = Lbl.Text.TrimEnd('=', ' ') + " = OK"; // SET the text with proper format - Lbl.ForeColor = Color.LimeGreen; - } - else - { - Lbl.Text = Lbl.Text.TrimEnd('=', ' ') + " = " + errMssg; // SET the text with error message - Lbl.ForeColor = Color.Red; - } + Lbl.Text = Lbl.Text.TrimEnd('=', ' ') + " = " + displayResult; + Lbl.ForeColor = isError ? Color.Red : Color.LimeGreen; }); } catch (Exception ex) diff --git a/Camera/LED.cs b/Camera/LED.cs index 3a00305..48d9f10 100644 --- a/Camera/LED.cs +++ b/Camera/LED.cs @@ -11,6 +11,23 @@ double medianVorI = (VorI[2] + VorI[3]) / 2.0; // Will always be even (6) number of channels therefore average the two middle elements string medianText = $"Median: {medianVorI}{VormA}"; + //Expected value of 0 means informational only (force green) + if (ExpVorI == 0) + { + if (lblVorI == null) + { + MainForm.Instance.AddLabelToPanel($"LED {VormA} = {medianText}", false); + return; + } + + lblVorI.Invoke(() => + { + lblVorI.Text = lblVorI.Text.TrimEnd('=', ' ') + " = " + medianText; + lblVorI.ForeColor = Color.LimeGreen; + }); + return; + } + // Define the 20% threshold ranges double LowerThreshold = ExpVorI * 0.8; double UpperThreshold = ExpVorI * 1.2; @@ -19,6 +36,11 @@ if (medianVorI < LowerThreshold || medianVorI > UpperThreshold) { medianText += $" (away from expected {ExpVorI}{VormA})"; + if (lblVorI == null) + { + MainForm.Instance.AddLabelToPanel($"LED {VormA} = {medianText}", true); + return; + } lblVorI.Invoke(() => { lblVorI.Text = lblVorI.Text.TrimEnd('=', ' ') + " = " + medianText; @@ -39,6 +61,11 @@ // If there are no single channels outside the threshold then green, else red if (outOfRangeVoltageChannels.Count == 0) { + if (lblVorI == null) + { + MainForm.Instance.AddLabelToPanel($"LED {VormA} = {medianText}", false); + return; + } lblVorI.Invoke(() => { lblVorI.Text = lblVorI.Text.TrimEnd('=', ' ') + " = " + medianText; @@ -48,6 +75,11 @@ else if (outOfRangeVoltageChannels.Count != 0) { string errorText = medianText + " (error on " + string.Join(", ", outOfRangeVoltageChannels) + ")"; + if (lblVorI == null) + { + MainForm.Instance.AddLabelToPanel($"LED {VormA} = {errorText}", true); + return; + } lblVorI.Invoke(() => { lblVorI.Text = lblVorI.Text.TrimEnd('=', ' ') + " = " + errorText; diff --git a/Microsoft/Access.cs b/Microsoft/Access.cs index 142d49f..b130a1b 100644 --- a/Microsoft/Access.cs +++ b/Microsoft/Access.cs @@ -81,7 +81,7 @@ namespace AiQ_GUI } const string query = - "SELECT FlexiVersion, FlexiRevision, WonwooFirmware, AiQGUIVersion, PowerConsumption, LicencingServerURL FROM UniversalData"; + "SELECT FlexiVersion, FlexiRevision, WonwooFirmware, AiQGUIVersion, PowerConsumption, LicencingServerURL, SRZFirmware FROM UniversalData"; using OleDbCommand cmd = new(query, conn); using OleDbDataReader reader = cmd.ExecuteReader(); @@ -95,6 +95,7 @@ namespace AiQ_GUI UniversalData.LatestVersion = Convert.ToString(reader["AiQGUIVersion"]); UniversalData.PowerConsumption = Convert.ToInt16(reader["PowerConsumption"]); UniversalData.LicencingServerURL = Convert.ToString(reader["LicencingServerURL"]); + UniversalData.SRZFirmware = Convert.ToString(reader["SRZFirmware"]); } // Populates CameraAccessInfo dynamically based on available columns public static void ReadModelRow(string camType, string ModelOnTest) diff --git a/Mobile Tests/MobilePreTest.cs b/Mobile Tests/MobilePreTest.cs index ad1d024..7f44db3 100644 --- a/Mobile Tests/MobilePreTest.cs +++ b/Mobile Tests/MobilePreTest.cs @@ -24,36 +24,39 @@ public static class MobilePreTest string token = await LoginAsync(client, "ADMIN", "1234"); // Attach JWT to all requests - client.DefaultRequestHeaders.Authorization = - new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); + client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); // Request firmware information - HttpResponseMessage response = - await client.GetAsync("/app/v1/system/firmware"); + HttpResponseMessage response = await client.GetAsync("/app/v1/system/firmware"); string body = await response.Content.ReadAsStringAsync(); - MainForm.Instance.AddToActionsList( - $"Firmware check response: {(int)response.StatusCode} {response.StatusCode} | {body}", - Level.LOG); + MainForm.Instance.AddToActionsList($"Firmware check response: {(int)response.StatusCode} {response.StatusCode} | {body}",Level.LOG); response.EnsureSuccessStatusCode(); - JsonElement json = - JsonSerializer.Deserialize(body); + JsonElement json = JsonSerializer.Deserialize(body); - string version = - json.GetProperty("version").GetString(); + string version = json.GetProperty("version").GetString()?.Trim(); - MainForm.Instance.AddToActionsList( - $"Current firmware version: {version}", - Level.Success); + + // Compare against expected SRZFirmware from UniversalData + if (string.IsNullOrEmpty(UniversalData.SRZFirmware)) + { + MainForm.Instance.AddToActionsList($"Firmware check failed: Expected SRZFirmware not loaded in UniversalData",Level.ERROR); + } + else if (version == UniversalData.SRZFirmware) + { + MainForm.Instance.AddToActionsList($"Firmware match successful: {version}",Level.Success); + } + else + { + MainForm.Instance.AddToActionsList($"Firmware mismatch: Camera has {version}, expected {UniversalData.SRZFirmware}",Level.ERROR); + } } catch (Exception ex) { - MainForm.Instance.AddToActionsList( - $"Firmware check failed: {ex.Message}", - Level.ERROR); + MainForm.Instance.AddToActionsList($"Firmware check failed: {ex.Message}",Level.ERROR); } } @@ -65,13 +68,11 @@ public static class MobilePreTest userPassword = Sha256(password) }; - HttpResponseMessage response = - await client.PostAsJsonAsync("/app/v1/login", payload); + HttpResponseMessage response = await client.PostAsJsonAsync("/app/v1/login", payload); response.EnsureSuccessStatusCode(); - JsonElement json = - await response.Content.ReadFromJsonAsync(); + JsonElement json = await response.Content.ReadFromJsonAsync(); return json.GetProperty("token").GetString(); }