From 77c131f414f276e4fbb03771fa5f7c9e57d69328 Mon Sep 17 00:00:00 2001 From: Michal Buzik Date: Thu, 4 Jun 2026 11:00:20 +0200 Subject: [PATCH] Increment assembly version to `3.9.3129.0`, streamline context menu options in `iPerlCommunicationForm`, consolidate unused menu items, improve `PBC_Read_Build_Async` with retry logic for slot and PCB ID operations, and optimize GenesisSmartReader communication and debugging. --- TBF/Properties/AssemblyInfo.cs | 4 +- .../communication/OptoHeadTest.cs | 82 +++---------- .../iPerlCommunicationParams.cs | 110 +++++++++--------- .../iPerlCommunicationForm.cs | 57 +++------ 4 files changed, 83 insertions(+), 170 deletions(-) diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index e47e6dc29..9e7fa1b5f 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("3.9.3128.0")] -[assembly: AssemblyFileVersion("3.9.3128.0")] +[assembly: AssemblyVersion("3.9.3129.0")] +[assembly: AssemblyFileVersion("3.9.3129.0")] diff --git a/TBF/Rig/RegisterReaders/GenesisRegReader/communication/OptoHeadTest.cs b/TBF/Rig/RegisterReaders/GenesisRegReader/communication/OptoHeadTest.cs index 16fb7f668..794474dfa 100644 --- a/TBF/Rig/RegisterReaders/GenesisRegReader/communication/OptoHeadTest.cs +++ b/TBF/Rig/RegisterReaders/GenesisRegReader/communication/OptoHeadTest.cs @@ -434,6 +434,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication .GetResult(); } + public string ConnectSlot() { if (genesisHead != null && genesisHead.DebugLevel == DebugMode.Simulate) @@ -491,7 +492,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication private async Task PBC_Read_Build_Async( GenesisSmartReader genesisSmartReader) { log.Debug($"PBC_Read_Build_Async called for iHead: {genesisSmartReader}"); - var slotInfo = await genesisSmartReader.CommInterfaceBridge.GetSlotAsync(genesisSmartReader.GetSlotNr); + var slotInfo = await genesisSmartReader.CommInterfaceBridge.GetSlotWithRetryAsync(genesisSmartReader.GetSlotNr); if (slotInfo == null) { log.Debug($"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) - SlotInfo is null."); @@ -504,10 +505,10 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication return PcbReadResult.Fail("SlotInfo failed."); } - if (!string.IsNullOrEmpty(slotInfo.PcbId)) + if (!string.IsNullOrEmpty(slotInfo?.Result?.PcbId)) { log.Debug($"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) - Slot already has PcbId."); - return PcbReadResult.Ok(slotInfo.PcbId); + return PcbReadResult.Ok(slotInfo.Result.PcbId); } log.Debug($"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) - Connecting..."); @@ -516,70 +517,16 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication // PCB READ LOOP try { - + string validPcbId = null; + int maxAttempts = 5; - string validPcbId = null; - int maxAttempts = 5; - DateTime startTime = DateTime.UtcNow; - TimeSpan maxDuration = TimeSpan.FromSeconds(30); + var pcbTask = genesisSmartReader.CommInterfaceBridge.GetPcbIdWithRetryAsync(genesisSmartReader.GetSlotNr); - //LOOP - for (int attempt = 1; attempt <= maxAttempts; attempt++) + if (pcbTask?.Result?.Success == true) { - if (DateTime.UtcNow - startTime > maxDuration) - { - log.Debug($"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) - PCB max duration exceeded"); - break; - } - - log.Debug($"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) - PCB attempt {attempt}/{maxAttempts}"); - var pcbTask = genesisSmartReader.CommInterfaceBridge.GetPcbIdAsync(genesisSmartReader.GetSlotNr); - var timeoutTaskPcb = Task.Delay(TimeSpan.FromSeconds(5)); - var completedTaskPcb = await Task.WhenAny(pcbTask, timeoutTaskPcb); - - if (completedTaskPcb != pcbTask) - { - log.Debug($"PBC_Read_Build_Async() PCB attempt {attempt} - Timeout"); - continue; - } - - var resultPCB = await pcbTask; - - // VALIDATION BLOCK - { - if (resultPCB == null) - { - log.Debug($"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) PCB attempt {attempt} - result is null"); - continue; - } - - if (!resultPCB.Success) - { - log.Debug($"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) PCB attempt {attempt} - Success=false"); - continue; - } - - string pcbId = resultPCB.PcbId; - - if (string.IsNullOrWhiteSpace(pcbId)) - { - log.Debug($"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) PCB attempt {attempt} - PCB empty"); - continue; - } - - pcbId = pcbId.Trim(); - - if (pcbId.Length != 9) - { - log.Debug( $"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) PCB attempt {attempt} - Invalid PCB length: '{pcbId}', len={pcbId.Length}"); - continue; - } - - validPcbId = pcbId; - log.Debug($"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) PCB valid: {validPcbId}"); - break; - } + validPcbId = pcbTask.Result.Result.PcbId; } + if (string.IsNullOrEmpty(validPcbId)) { @@ -590,7 +537,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication { genesisSmartReader.ConfigStruct.PCBNumberString = validPcbId; } - //genesisSmartReader.SerialNr = validPcbId; + genesisSmartReader.SerialNr = validPcbId; log.Debug( $"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) " + $"ValidPcbId:({validPcbId})"); return PcbReadResult.Ok(validPcbId); } @@ -599,9 +546,6 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication log.Error($"PBC_Read_Build_Async({genesisSmartReader.GetSlotNr}) - Exception:", e); return PcbReadResult.Fail(e.Message); } - /// /////////////////////////////////////////////////////////////////////////////////////////////////////////// - //var result = await genesisSmartReader.CommInterfaceBridge.GetPcbIdAsync(genesisSmartReader.GetSlotNr, token); - } @@ -1360,7 +1304,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication if (genesisHead != null && genesisHead.DebugLevel == DebugMode.Simulate) { log.Debug("Connect() - Simulated response"); - return "Simulated Connect"; + return "Simulated SetTestModeSlot"; } return Task.Run(() => SetTestModeSlot_Async(genesisHead)) .GetAwaiter() @@ -1408,7 +1352,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication if (genesisHead != null && genesisHead.DebugLevel == DebugMode.Simulate) { log.Debug("Connect() - Simulated response"); - return "Simulated Connect"; + return "Simulated SetActiveModeSlot"; } return Task.Run(() => SetActiveModeSlot_Async(genesisHead)) .GetAwaiter() diff --git a/TBF/Rig/TestMethods/GenesisCommunication/iPerlCommunicationParams.cs b/TBF/Rig/TestMethods/GenesisCommunication/iPerlCommunicationParams.cs index bf36352c2..0ebaeea7d 100644 --- a/TBF/Rig/TestMethods/GenesisCommunication/iPerlCommunicationParams.cs +++ b/TBF/Rig/TestMethods/GenesisCommunication/iPerlCommunicationParams.cs @@ -67,61 +67,61 @@ namespace TBF.Rig.TestMethods.GenesisCommunication retVal.Add(iPerlCommunicationForm.HoldSlotStr); - retVal.Add(iPerlCommunicationForm.ReadConfigurationStr); - retVal.Add(iPerlCommunicationForm.ReadSerialNrStr); - retVal.Add(string.Format("{0} A0", iPerlCommunicationForm.SetTestModeStr)); - retVal.Add(string.Format("{0} A4", iPerlCommunicationForm.SetTestModeStr)); - retVal.Add(iPerlCommunicationForm.ReadCalibrationStr); - retVal.Add(iPerlCommunicationForm.ReadCalibrationV4Str); - retVal.Add(iPerlCommunicationForm.NormalizeCalibrationFactorStr); - retVal.Add(iPerlCommunicationForm.NormalizeCalibrationV4FactorsStr); - retVal.Add(iPerlCommunicationForm.GetDefaultQ2CorrectionsStr); - retVal.Add(iPerlCommunicationForm.ReadQ2CorrectionStr); - retVal.Add(iPerlCommunicationForm.ResetQ2CorrectionStr); - retVal.Add(iPerlCommunicationForm.WriteDefaultQ2CorrectionsStr); - retVal.Add(iPerlCommunicationForm.InitOrReadQ2CorrectionsStr); - retVal.Add(iPerlCommunicationForm.WriteCalibrationFactorStr); - retVal.Add(iPerlCommunicationForm.WriteCalibrationV4FactorsStr); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionStr); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionAltStr); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionGreeceStr); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionRLStr); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionLRStr); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionIncl05Str); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionAltIncl05Str); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionPlusIncl05Str); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionPlusAltIncl05Str); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionGreeceIncl05Str); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionRLIncl05Str); - retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionLRIncl05Str); - retVal.Add(iPerlCommunicationSeq.Q2correctedFromCmd + "Qx"); - retVal.Add(iPerlCommunicationSeq.StrictQ2ErrorCheckStr + "Qx"); - retVal.Add(iPerlCommunicationSeq.Q2correctionCheckCmd); - retVal.Add(iPerlCommunicationSeq.IperlCheckCmd); - retVal.Add(iPerlCommunicationForm.UpdateBothQ2FactorsTestRLOnlyStr); - retVal.Add(iPerlCommunicationForm.UpdateBothQ2FactorsTestLROnlyStr); - retVal.Add(iPerlCommunicationForm.UpdateQ2CorrectionsStr); - retVal.Add(iPerlCommunicationForm.ConditnlUpdateQ2CorrectionsStr); - retVal.Add(iPerlCommunicationForm.ConditnlUpdateQ2CorrRLStr); - retVal.Add(iPerlCommunicationForm.ConditnlUpdateQ2CorrLRStr); - retVal.Add("Q2 corrected from Q2adj"); - retVal.Add("Q2 correction check Q2bc Q2ac"); - retVal.Add(iPerlCommunicationForm.SetActiveModeStr); - retVal.Add(iPerlCommunicationForm.SetIdleModeStr); - retVal.Add("---"); - retVal.Add(iPerlCommunicationForm.Reset2HzCorrectionStr); - retVal.Add(iPerlCommunicationForm.Write2HzCorrectionStr); - retVal.Add(iPerlCommunicationForm.DewaReworkRLStr); - retVal.Add(iPerlCommunicationForm.DewaReworkLRStr); - retVal.Add(iPerlCommunicationForm.StartTestingSealedMetersStr); - retVal.Add(iPerlCommunicationForm.EndTestingSealedMetersStr); - retVal.Add(string.Format("{0} if enabled", iPerlCommunicationForm.ReadConfigurationStr)); - retVal.Add(string.Format("{0} 80", iPerlCommunicationForm.SetTestModeStr)); - retVal.Add("iPerl_check prevWorkStep direction q2factors"); - for (ConditionID id = ConditionID.A; id < ConditionID.Count; id++) - { - retVal.Add(string.Format(SequenceConditionOp.ConditionNameFmt, id)); - } + // retVal.Add(iPerlCommunicationForm.ReadConfigurationStr); + // retVal.Add(iPerlCommunicationForm.ReadSerialNrStr); + // retVal.Add(string.Format("{0} A0", iPerlCommunicationForm.SetTestModeStr)); + // retVal.Add(string.Format("{0} A4", iPerlCommunicationForm.SetTestModeStr)); + // retVal.Add(iPerlCommunicationForm.ReadCalibrationStr); + // retVal.Add(iPerlCommunicationForm.ReadCalibrationV4Str); + // retVal.Add(iPerlCommunicationForm.NormalizeCalibrationFactorStr); + // retVal.Add(iPerlCommunicationForm.NormalizeCalibrationV4FactorsStr); + // retVal.Add(iPerlCommunicationForm.GetDefaultQ2CorrectionsStr); + // retVal.Add(iPerlCommunicationForm.ReadQ2CorrectionStr); + // retVal.Add(iPerlCommunicationForm.ResetQ2CorrectionStr); + // retVal.Add(iPerlCommunicationForm.WriteDefaultQ2CorrectionsStr); + // retVal.Add(iPerlCommunicationForm.InitOrReadQ2CorrectionsStr); + // retVal.Add(iPerlCommunicationForm.WriteCalibrationFactorStr); + // retVal.Add(iPerlCommunicationForm.WriteCalibrationV4FactorsStr); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionStr); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionAltStr); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionGreeceStr); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionRLStr); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionLRStr); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionIncl05Str); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionAltIncl05Str); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionPlusIncl05Str); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionPlusAltIncl05Str); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionGreeceIncl05Str); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionRLIncl05Str); + // retVal.Add(iPerlCommunicationForm.WriteQ2CorrectionLRIncl05Str); + // retVal.Add(iPerlCommunicationSeq.Q2correctedFromCmd + "Qx"); + // retVal.Add(iPerlCommunicationSeq.StrictQ2ErrorCheckStr + "Qx"); + // retVal.Add(iPerlCommunicationSeq.Q2correctionCheckCmd); + // retVal.Add(iPerlCommunicationSeq.IperlCheckCmd); + // retVal.Add(iPerlCommunicationForm.UpdateBothQ2FactorsTestRLOnlyStr); + // retVal.Add(iPerlCommunicationForm.UpdateBothQ2FactorsTestLROnlyStr); + // retVal.Add(iPerlCommunicationForm.UpdateQ2CorrectionsStr); + // retVal.Add(iPerlCommunicationForm.ConditnlUpdateQ2CorrectionsStr); + // retVal.Add(iPerlCommunicationForm.ConditnlUpdateQ2CorrRLStr); + // retVal.Add(iPerlCommunicationForm.ConditnlUpdateQ2CorrLRStr); + // retVal.Add("Q2 corrected from Q2adj"); + // retVal.Add("Q2 correction check Q2bc Q2ac"); + // retVal.Add(iPerlCommunicationForm.SetActiveModeStr); + // retVal.Add(iPerlCommunicationForm.SetIdleModeStr); + // retVal.Add("---"); + // retVal.Add(iPerlCommunicationForm.Reset2HzCorrectionStr); + // retVal.Add(iPerlCommunicationForm.Write2HzCorrectionStr); + // retVal.Add(iPerlCommunicationForm.DewaReworkRLStr); + // retVal.Add(iPerlCommunicationForm.DewaReworkLRStr); + // retVal.Add(iPerlCommunicationForm.StartTestingSealedMetersStr); + // retVal.Add(iPerlCommunicationForm.EndTestingSealedMetersStr); + // retVal.Add(string.Format("{0} if enabled", iPerlCommunicationForm.ReadConfigurationStr)); + // retVal.Add(string.Format("{0} 80", iPerlCommunicationForm.SetTestModeStr)); + // retVal.Add("iPerl_check prevWorkStep direction q2factors"); + // for (ConditionID id = ConditionID.A; id < ConditionID.Count; id++) + // { + // retVal.Add(string.Format(SequenceConditionOp.ConditionNameFmt, id)); + // } return retVal; } diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index 059591c7f..7e9d367b4 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -271,26 +271,15 @@ namespace TBF.Rig.TestMethods.iPerlCommunication ContextMenu cm = new ContextMenu(); ////////////////////////////////////////////////////////////////////// cm.MenuItems.Add(NewMenuItem("Initialise Slot" , "Initialize")); - cm.MenuItems.Add(NewMenuItem("Update Slot" , "Update")); - cm.MenuItems.Add(NewMenuItem("Connect Slot" , "Connect")); + // cm.MenuItems.Add(NewMenuItem("Update Slot" , "Update")); + // cm.MenuItems.Add(NewMenuItem("Connect Slot" , "Connect")); + cm.MenuItems.Add(NewMenuItem("Login (Combined)" , "Login (Combined)")); cm.MenuItems.Add(NewMenuItem("PCB Slot" , "PCBSlot")); - cm.MenuItems.Add(NewMenuItem("Set Password" , "SetPassword")); - cm.MenuItems.Add(NewMenuItem("Login" , "Login")); + // cm.MenuItems.Add(NewMenuItem("Set Password" , "SetPassword")); + // cm.MenuItems.Add(NewMenuItem("Login" , "Login")); cm.MenuItems.Add(NewMenuItem("Switch to Test Mode" , "SetTestMode")); cm.MenuItems.Add(NewMenuItem("Switch to Active Mode" , "SetActiveMode")); ///////////////////////////////////////////////////////////////////// - cm.MenuItems.Add(NewMenuItem("Read PCB Number" , "ReadPCB")); - cm.MenuItems.Add(NewMenuItem("Enter Test Mode" , "StartTestMode")); - cm.MenuItems.Add(NewMenuItem("Turn Off Test Mode (Enter Active Mode)", "TurnOffTestMode")); - cm.MenuItems.Add(NewMenuItem("Set Production Mode (Radio not start with flow)" , "SetProductionMode")); - cm.MenuItems.Add(NewMenuItem("Turn Off Radio" , "TurnOffRadio")); - cm.MenuItems.Add(NewMenuItem($"Set RFID mode ({Strings.Program_restart_is_required_to_apply_some_settings})" , "SetRFID")); - cm.MenuItems.Add(NewMenuItem($"Set NFC mode ({Strings.Program_restart_is_required_to_apply_some_settings})" , "SetNFC")); - /*if (Users.CurrentUser.AuthorizedAs == AuthorizedAs.PowerUser) - { - //cm.MenuItems.Add(NewMenuItem("Test WriteRequestPort (u8_Customer_Text)", "WriteRequestPort_u8_Customer_Text")); - cm.MenuItems.Add(NewMenuItem("Open sealing", "OpenSealing")); - }*/ this.ContextMenu = cm; #endif } @@ -1891,56 +1880,36 @@ namespace TBF.Rig.TestMethods.iPerlCommunication case "Initialize": txt = iHead.OptoHeadTest.InitialiseSlot(); break; + //now unused case "Update": txt = iHead.OptoHeadTest.UpdateSlot(); break; case "Connect": txt = iHead.OptoHeadTest.ConnectSlot(); break; + //~now unused case "PCBSlot": PcbReadResult pcbReadSlot = iHead.OptoHeadTest.PCB_ReadSlot(); txt = pcbReadSlot.Success ? pcbReadSlot.PcbId : "PCB read failed"; break; + //now unused case "SetPassword": txt = iHead.OptoHeadTest.SetPasswordSlot(); break; case "Login": txt = iHead.OptoHeadTest.LoginSlot(); break; + //~ now unused + case "Login (Combined)": + var result = iHead.OptoHeadTest.GroupedLoginSlot(); + txt = result?.LoginResult?.Success ?? false ? ("Login successful; PCB: " + result?.PcbResult?.Result?.PcbId): "Login failed"; + break; case "SetTestMode": txt = iHead.OptoHeadTest.SetTestModeSlot(); break; case "SetActiveMode": txt = iHead.OptoHeadTest.SetActiveModeSlot(); break; - //////////////////////////////////////////////////////// - case "ReadPCB": - txt = iHead.OptoHeadTest.ReadRequest_PCB(); - break; - case "WriteRequestPort_u8_Customer_Text": - txt = "Not Supported NOW!";//OpticalHeadTest.WriteRequestPort_u8_Customer_Text(iHead); - break; - case "OpenSealing": - txt = "Not Supported NOW!";//OpticalHeadTest.OpenSealing(iHead); - break; - case "StartTestMode": - txt = iHead.OptoHeadTest.SetTestMode(ref success); - break; - case "TurnOffTestMode": - txt = iHead.OptoHeadTest.SetActiveMode(ref success); - break; - case "TurnOffRadio": - txt = iHead.OptoHeadTest.TurnOffRadio(ref success); - break; - case "SetProductionMode": - txt = "Not Supported NOW!";//OpticalHeadTest.SetProductionMode(iHead); - break; - case "SetRFID": - txt = "Not Supported NOW!";//OpticalHeadTest.SetRfidMode(iHead); - break; - case "SetNFC": - txt = "Not Supported NOW!";//OpticalHeadTest.SetNfcMode(iHead); - break; } return txt; }