diff --git a/TBF/Rig/RegisterReaders/GenesisRegReader/communication/OptoHeadTest.cs b/TBF/Rig/RegisterReaders/GenesisRegReader/communication/OptoHeadTest.cs index 794474dfa..7a10a767c 100644 --- a/TBF/Rig/RegisterReaders/GenesisRegReader/communication/OptoHeadTest.cs +++ b/TBF/Rig/RegisterReaders/GenesisRegReader/communication/OptoHeadTest.cs @@ -1,8 +1,10 @@ using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Common; using Config.Entities; +using CordonelPreadjustmentUi.Processes.Itinerary; using GenesisCordonelInterface.API; using log4net; using Results.Entities; @@ -13,6 +15,7 @@ using TBF.Rig.RegisterReaders.GenesisRegReader.implementations; using TBF.Rig.Sequences; using TBF.Rig.TestMethods.GenesisCommunication; using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.diagnosticLed; +using Xylem.Common.Ui.CordonelPreadjustmentUi; namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication @@ -2214,7 +2217,78 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication return value; } + + + public object PreAdjustmentInit(TestMethodCfg cfg, Test currentTest, CancellationToken token) + { + if (genesisHead != null && genesisHead.DebugLevel == DebugMode.Simulate) + { + log.Debug("Connect() - Simulated response"); + return ResultOk;//"Simulated Connect"; + } + + return Task.Run(() => PreAdjustmentInit_Async(genesisHead,cfg, currentTest, token)) + .GetAwaiter() + .GetResult(); + } - + private async Task PreAdjustmentInit_Async(GenesisSmartReader genesisSmartReader, TestMethodCfg cfg, + Test currentTest, CancellationToken token) + { + try + { + log.Debug("PreAdjustmentInit_Async called for iHead: " + genesisHead); + + if (genesisHead == null) + { + log.Error("PreAdjustmentInit_Async - GenesisHead is null"); + return string.Empty; + } + if (string.IsNullOrEmpty(genesisHead.CommInterface)) + { + log.Error("PreAdjustmentInit_Async - CommInterface is null"); + return string.Empty; + } + GciBridge gciBridge = genesisHead.CommInterfaceBridge; + if (gciBridge == null) + { + log.Error("PreAdjustmentInit_Async - CommInterfaceBridge is null"); + return string.Empty; + } + + // TODO MAREK add list of slots into list + List selectedSlots = null; + + // ProcessProgress pp = CreatePreparationProgress(); + // List mc = new List(); + // foreach (var slot in slots) + // { + // var ctl = new MeterStateControl(gciBridge.GetSlotAsync()); + // + // ctl.SetChecked(true); + // ctl.IsEnabled = true; + // + // mc.Add(ctl); + // } + + //TODO MAREK implement pp, mc !!! + PublicModels.PreAdjustmentInitializationResult preAdjustmentInitializationResult = gciBridge.Preadjustment_Initialization(null, null);//(pp, mc); + if (preAdjustmentInitializationResult == null || !preAdjustmentInitializationResult.Success) + { + log.Error( $"PreAdjustmentInit_Async( Slot: {genesisSmartReader.GetSlotNr}) - CalFactor2AsyncResult failed. Result: {preAdjustmentInitializationResult}"); + return $"Failed to Init Preadjustment"; + } + + var preAdjustmentInitAsync = preAdjustmentInitializationResult.Success ? ResultOk : ResultNok; + log.Debug( $"PreAdjustmentInit_Async( Slot: {genesisSmartReader.GetSlotNr}) Result: " + preAdjustmentInitAsync + " "); + + return preAdjustmentInitAsync; + } + catch (Exception ex) + { + log.Error($"CheckMeterPrepare_Async({genesisHead.GetSlotNr}) - Exception:", ex); + return ex.Message; + } + } } } \ No newline at end of file diff --git a/TBF/Rig/TestMethods/GenesisCommunication/iPerlCommunicationParams.cs b/TBF/Rig/TestMethods/GenesisCommunication/iPerlCommunicationParams.cs index 0ebaeea7d..cfd3eb910 100644 --- a/TBF/Rig/TestMethods/GenesisCommunication/iPerlCommunicationParams.cs +++ b/TBF/Rig/TestMethods/GenesisCommunication/iPerlCommunicationParams.cs @@ -66,6 +66,8 @@ namespace TBF.Rig.TestMethods.GenesisCommunication retVal.Add(iPerlCommunicationForm.CheckMeterPrepareStr); retVal.Add(iPerlCommunicationForm.HoldSlotStr); + retVal.Add(iPerlCommunicationForm.PrepareInitializeStr); + // retVal.Add(iPerlCommunicationForm.ReadConfigurationStr); // retVal.Add(iPerlCommunicationForm.ReadSerialNrStr); diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index 7e9d367b4..f5556a6c1 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -93,6 +93,10 @@ namespace TBF.Rig.TestMethods.iPerlCommunication public const string WriteSlotQ3CalibrationStr = "Write Q3 Calibration Slot"; public const string CheckMeterPrepareStr = "Check Meter Prepare Slot"; public const string HoldSlotStr = "Hold Slot"; + + public const string PrepareInitializeStr = "Initialise Prepare"; + + public const string ReadConfigurationStr = "Read configuration"; /// Example: "Read configuration" or "Read configuration if enabled" public const string SetTestModeStr = "Set Test mode"; /// Example: "Set Test mode" or "Set Test mode A0" (hexadecimal number is the required 'testModeConfig' @@ -810,6 +814,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication else if (currentActivity.ToLower().Equals(PrepareSlotQ3CalibrationStr.ToLower())) error = PrepareSlotQ3Calibration(threadID, ihead,wm, currentTest, tests , ref resultStr); else if (currentActivity.ToLower().Equals(WriteSlotQ3CalibrationStr.ToLower())) error = WriteSlotQ3Calibration(threadID, ihead, wm, currentTest, tests, ref resultStr); else if (currentActivity.ToLower().Equals(CheckMeterPrepareStr.ToLower())) error = CheckMeterPrepare(threadID, ihead, ref resultStr); + + //TODO MAREK dorobit dalsie moznosti podla vzoru + else if (currentActivity.ToLower().Contains(PrepareInitializeStr.ToLower())) error = PreAdjustmentInitialize(threadID, ihead, wm, currentTest, tests, ref resultStr); else if (currentActivity.ToLower().Contains(ReadSerialNrStr.ToLower())) error = ReadSerialNr(threadID, ihead, ref resultStr); else if (currentActivity.ToLower().Contains(SetTestModeStr.ToLower())) error = SetTestMode(threadID, ihead, ref resultStr); @@ -924,6 +931,28 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } } + private CommErr PreAdjustmentInitialize(int threadId, GenesisSmartReader iHead, WaterMeter wm, + Test currentTest, IList tests, ref string resultStr) + { + CommErr error = CommErr.FailedPrepare; + + log.DebugFormat("PreAdjustmentInitialize() threadId={0}, iHead: {1}, wm: {2}, currentTest: {3}, tests: {4}", threadId, iHead?.Name, wm?.Id, currentTest?.Name, tests?.Count); + + var cancellationToken = new CancellationToken(); + var gciFullLoginResult = iHead.OptoHeadTest.PreAdjustmentInit(cfg,currentTest, cancellationToken); + if (!string.IsNullOrEmpty(resultStr) && resultStr.Equals(TBF.Rig.RegisterReaders.GenesisRegReader.communication.OptoHeadTest.ResultOk)) + { + log.Debug("PreAdjustmentInitialize successful"); + resultStr = string.Format($"Meter Preadjust Prepare: OK"); + error = CommErr.None; + } + else + { + resultStr = "Meter Preadjust: Failed"; + } + return error; + } + private CommErr CheckMeterPrepare(int threadId, GenesisSmartReader iHead, ref string resultStr) { CommErr error = CommErr.FailedWriteRegister;