PreAdjustment preparation

This commit is contained in:
Michal Buzik 2026-06-09 16:23:00 +02:00
parent d73eac8332
commit 19ff06b01e
3 changed files with 106 additions and 1 deletions

View File

@ -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
@ -2216,5 +2219,76 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
}
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<string> 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<GenesisCordonelInterface.API.PublicModels.MeterBatchDebugStatus> selectedSlots = null;
// ProcessProgress pp = CreatePreparationProgress();
// List<MeterStateControl> mc = new List<MeterStateControl>();
// 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;
}
}
}
}

View File

@ -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);

View File

@ -94,6 +94,10 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
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'
public const string SetActiveModeStr = "Set Active mode";
@ -811,6 +815,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
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);
else if (currentActivity.ToLower().Equals(SetActiveModeStr.ToLower())) error = SetActiveMode(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<Test> 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;