Increment assembly version to 3.9.3121.1, add FailedPrepare error constant and handling in iPerlCommunicationForm, enhance PrepareSlotQ3Calibration and WriteSlotQ3Calibration with exception handling and logging, introduce IsCalibFactorValid property and mappings for calibration logic, and extend debug logging across Genesis operations.

This commit is contained in:
Michal Buzik 2026-05-27 14:00:40 +02:00
parent e88e441875
commit 3cd488fc76
73 changed files with 680 additions and 257 deletions

View File

@ -307,38 +307,45 @@ namespace Results
{
bool hasCalibrationFactors = false;
foreach (var tstRslt in batch.TestRslts)
try
{
if (tstRslt.CalibFactorResultsToSave != null &&
tstRslt.CalibFactorResultsToSave.Count > 0)
{
hasCalibrationFactors = true;
break;
}
}
if (hasCalibrationFactors)
{
TestRsltCalibFactorHelper.CreateTableIfNotExists(session);
foreach (var tstRslt in batch.TestRslts)
{
if (tstRslt.CalibFactorResultsToSave == null ||
tstRslt.CalibFactorResultsToSave.Count == 0)
if (tstRslt.CalibFactorResultsToSave != null &&
tstRslt.CalibFactorResultsToSave.Count > 0)
{
continue;
}
TestRsltCalibFactorHelper.DeleteByTestRsltIdNoTransaction(session, tstRslt.Id);
foreach (var calib in tstRslt.CalibFactorResultsToSave)
{
calib.TestRslt = tstRslt;
calib.ErrorStr = TestRsltCalibFactorHelper.Truncate(calib.ErrorStr, 240);
session.SaveOrUpdate(calib);
hasCalibrationFactors = true;
break;
}
}
if (hasCalibrationFactors)
{
TestRsltCalibFactorHelper.CreateTableIfNotExists(session);
foreach (var tstRslt in batch.TestRslts)
{
if (tstRslt.CalibFactorResultsToSave == null ||
tstRslt.CalibFactorResultsToSave.Count == 0)
{
continue;
}
TestRsltCalibFactorHelper.DeleteByTestRsltIdNoTransaction(session, tstRslt.Id);
foreach (var calib in tstRslt.CalibFactorResultsToSave)
{
calib.TestRslt = tstRslt;
calib.ErrorStr = TestRsltCalibFactorHelper.Truncate(calib.ErrorStr, 240);
session.SaveOrUpdate(calib);
}
}
}
}catch(Exception exc)
{
log.ErrorFormat("DB - Cannot save calibration factors: {0}", exc.Message);
}
}

View File

@ -8,6 +8,8 @@ namespace Results.Entities
public virtual int CalibFactorIndex { get; set; } // 1, 2, 3
public virtual bool IsCalibFactorValid { get; set; }
public virtual int BaseCalibFactor { get; set; }
public virtual int CalculatedCalibFactor { get; set; }
@ -29,6 +31,7 @@ namespace Results.Entities
{
Stored = false;
ErrorStr = string.Empty;
IsCalibFactorValid = false;
}
}
}

View File

@ -66,8 +66,7 @@ namespace Results.Entities.helpers
{
alter.Transaction = transaction;
alter.CommandText =
"ALTER TABLE `" + tableName + "` ADD COLUMN `" + columnName + "` " + columnDefinition;
alter.CommandText = "ALTER TABLE `" + tableName + "` ADD COLUMN `" + columnName + "` " + columnDefinition;
alter.ExecuteNonQuery();
}

View File

@ -1,10 +1,14 @@
using System.Collections.Generic;
using log4net;
using NHibernate;
namespace Results.Entities.helpers
{
public static class TestRsltCalibFactorHelper
{
private static readonly ILog log = LogManager.GetLogger(typeof(TestRsltCalibFactorHelper));
public static bool TableExists(ISession session)
{
try
@ -24,6 +28,7 @@ namespace Results.Entities.helpers
ISession session,
int testRsltId)
{
log.DebugFormat("Deleting TestRsltCalibFactor records for TestRsltId: {0}", testRsltId);
session.CreateSQLQuery(@" DELETE FROM TestRsltCalibFactor WHERE TestRsltId = :testRsltId")
.SetParameter("testRsltId", testRsltId)
.ExecuteUpdate();
@ -65,6 +70,7 @@ CREATE TABLE IF NOT EXISTS TestRsltCalibFactor (
CalibFactorIndex INT NOT NULL,
BaseCalibFactor INT NOT NULL,
CalculatedCalibFactor INT NOT NULL,
IsCalibFactorValid BIT NOT NULL,
Stored BIT NOT NULL,
ErrorStr VARCHAR(240) NULL,
TimeStart DOUBLE NOT NULL,
@ -90,6 +96,7 @@ CREATE TABLE IF NOT EXISTS TestRsltCalibFactor (
CalibFactorIndex INTEGER NOT NULL,
BaseCalibFactor INTEGER NOT NULL,
CalculatedCalibFactor INTEGER NOT NULL,
IsCalibFactorValid INTEGER NOT NULL,
Stored INTEGER NOT NULL,
ErrorStr VARCHAR(240) NULL,
TimeStart DOUBLE NOT NULL,
@ -103,6 +110,7 @@ CREATE TABLE IF NOT EXISTS TestRsltCalibFactor (
);";
}
log.InfoFormat("Creating TestRsltCalibFactor table: {0}", sql);
session.CreateSQLQuery(sql).ExecuteUpdate();
}
}

View File

@ -49,7 +49,7 @@ namespace Results.Mappings
#endif
References(x => x.WaterMeter);
References(x => x.TestRslt);
Map(x => x.Q3Channel).Not.Nullable() .Default("0");
Map(x => x.Q3Channel);
}
}
}

View File

@ -14,6 +14,7 @@ namespace Results.Mappings
.Not.Nullable();
Map(x => x.CalibFactorIndex).Not.Nullable();
Map(x => x.IsCalibFactorValid).Not.Nullable();
Map(x => x.BaseCalibFactor).Not.Nullable();
Map(x => x.CalculatedCalibFactor).Not.Nullable();

View File

@ -58,7 +58,7 @@ namespace Results.Mappings
#if ORACLE_DB
Map(x => x.WMTypeId);
#endif
Map(x => x.Q3Channel) .Not.Nullable() .Default("0");
Map(x => x.Q3Channel);
}
}

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("3.9.3110.1")]
[assembly: AssemblyFileVersion("3.9.3110.1")]
[assembly: AssemblyVersion("3.9.3121.1")]
[assembly: AssemblyFileVersion("3.9.3121.1")]

View File

@ -380,6 +380,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
if (pcbResult.IsValidPcb)
{
log.Debug($"Setting PCB: {pcbResult.PcbId} for Head: {genesisHead.Name}");
genesisHead.SerialNr = pcbResult.PcbId;
if (genesisHead.ConfigStruct != null)
{
@ -474,6 +475,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
if (pbcReadBuildAsync.Success && !string.IsNullOrEmpty(pbcReadBuildAsync.PcbId))
{
log.Debug($"Setting PCB: {pbcReadBuildAsync.PcbId} for Head: {genesisHead.Name}");
genesisHead.SerialNr = pbcReadBuildAsync.PcbId;
}
@ -1330,6 +1332,16 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
BridgeComponents.GciBridge.Interfaces.PublicModels.GciFullLoginResult connectFullPassLoginWithRetryAsync = await genesisSmartReader.CommInterfaceBridge.ConnectFullPassLoginWithRetryAsync(genesisSmartReader.GetSlotNr, token);
log.Debug($"GroupedLoginSlot_Async( Slot: {genesisSmartReader.GetSlotNr}) - Result: " + connectFullPassLoginWithRetryAsync);
if (connectFullPassLoginWithRetryAsync?.PcbResult?.Success == true)
{
log.Debug($"Setting PCB: {connectFullPassLoginWithRetryAsync?.PcbResult?.Result?.PcbId} for Head: {genesisSmartReader.Name}");
genesisSmartReader.SerialNr = connectFullPassLoginWithRetryAsync?.PcbResult?.Result?.PcbId;
if (genesisSmartReader.ConfigStruct != null)
{
genesisSmartReader.ConfigStruct.PCBNumberString = genesisSmartReader.SerialNr;
}
}
return connectFullPassLoginWithRetryAsync;
}
catch (Exception ex)
@ -1447,30 +1459,78 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
}
}
public string WriteQ3Calibration()
public string WriteQ3Calibration(TestMethodCfg cfg, Test test, WaterMeter wm)
{
if (genesisHead != null && genesisHead.DebugLevel == DebugMode.Simulate)
{
log.Debug("Connect() - Simulated response");
return ResultOk; //"Simulated Connect";
}
return Task.Run(() => WriteQ3Calibration_Async(genesisHead))
if (cfg == null)
{
log.Error("WriteQ3Calibration() - Missing TestMethodCfg");
return "Missing TestMethodCfg";
}
if (test == null)
{
log.Error("WriteQ3Calibration() - Missing Test");
return "Missing Test";
}
return Task.Run(() => WriteQ3Calibration_Async(genesisHead, cfg, test, wm))
.GetAwaiter()
.GetResult();
}
private async Task<string> WriteQ3Calibration_Async(GenesisSmartReader genesisSmartReader)
private async Task<string> WriteQ3Calibration_Async(GenesisSmartReader genesisSmartReader,
TestMethodCfg cfg,
Test test, WaterMeter wm)
{
try
{
log.Debug("WriteQ3Calibration_Async called for iHead: " + genesisHead);
log.Debug("WriteQ3Calibration_Async called for iHead: " + genesisHead?.Name + " , cfg: " + cfg?.Name + " , test: " + test?.Name);
if (genesisHead == null) return string.Empty;
if (string.IsNullOrEmpty(genesisHead.CommInterface)) return string.Empty;
if (genesisHead == null)
{
log.Error("WriteQ3Calibration_Async() - Missing GenesisSmartReader");
return string.Empty;
}
if (string.IsNullOrEmpty(genesisHead.CommInterface))
{
log.Error("WriteQ3Calibration_Async() - Missing CommInterface");
return string.Empty;
}
GciBridge gciBridge = genesisHead.CommInterfaceBridge;
if (gciBridge == null) return string.Empty;
if (gciBridge == null)
{
log.Error("WriteQ3Calibration_Async() - Missing GciBridge");
return string.Empty;
}
Results.Entities.TestRslt tstRslt = ProcessData.BatchRslts.GetTestRslt(test.Name, test.Part);
log.Debug($"WriteQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Test: {test.Name} - Part: {test.Part} - IsTestRslt: {(tstRslt==null?true:false)}");
try
{
if (tstRslt.CalibFactorResultsToSave.Count == 0)
{
for (int i = 0; i < genesisSmartReader.ChannelsCount; i++)
{
tstRslt.CalibFactorResultsToSave.Add(new TestRsltCalibFactor()
{
Stored = false,
CalibFactorIndex = i
}
);
}
}
}catch(Exception ex)
{
log.Error($"WriteQ3Calibration_Async() - DB Exception: {ex.Message}");
}
CancellationToken token = default;
@ -1481,6 +1541,8 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
return "CalculateQ3Calibration Initialised Data not valid";
}
StoreCalibrationValuesResults(tstRslt, genesisSmartReader);
if (!genesisSmartReader.Q3CalibValid)
{
log.Error("WriteQ3Calibration_Async() - Q3Channel not valid");
@ -1490,36 +1552,112 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
//Get Activity Status
LedState ledMode = LedState.inactive; // swich on LED
byte valueLed = (ledMode == LedState.active) ? (byte)6 : (byte)0;
UInt16 calibFactor1 = Convert.ToUInt16(genesisSmartReader.Q3Calib_Ch1Value);
UInt16 calibFactor2 = Convert.ToUInt16(genesisSmartReader.Q3Calib_Ch2Value);
UInt16 calibFactor3 = Convert.ToUInt16(genesisSmartReader.Q3Calib_Ch3Value);
UInt16 valueSampleRate = 2;
UInt16 ResetAccumulatorsValue = 0;
UInt16 ForwardArrowValue = 0;
UInt16 StoreCalibrationValue = 1;
log.Debug( $"WriteQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Start - Set Led Mode: {valueLed}");
log.Debug( $"WriteQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Start");
log.Debug( $"WriteQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Start - Set CalFactor1: {calibFactor1}");
var CalFactor1AsyncResult = await gciBridge.WriteRegisterWithRetryAsync(genesisSmartReader.GetSlotNr, RadioService.CalFactor1, calibFactor1, false, false, token);
if (CalFactor1AsyncResult == null || !CalFactor1AsyncResult.Success)
{
log.Error( $"WriteQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - CalFactor1AsyncResult failed. Result: {CalFactor1AsyncResult}");
return "Failed to set CalFactor1";
}
wm.OrigCalibFactor = calibFactor1;
if (genesisSmartReader.Q3CalibDiffPercentageValue.Length == 3)
wm.Q2ErrWOCorrection = genesisSmartReader.Q3CalibDiffPercentageValue[0];
//CH3 to DB
try
{
if (tstRslt != null &&
tstRslt?.CalibFactorResultsToSave?.Count == 3 &&
tstRslt?.CalibFactorResultsToSave?[0] != null)
{
tstRslt.CalibFactorResultsToSave[0].CalculatedCalibFactor = Convert.ToInt32(calibFactor1);
tstRslt.CalibFactorResultsToSave[0].Stored = true;
tstRslt.CalibFactorResultsToSave[0].IsCalibFactorValid = true;
tstRslt.CalibFactorResultsToSave[0].Error = genesisSmartReader.Q3CalibDiffPercentageValue[0];
}
log.Debug( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB Stored tstRslt:{tstRslt.Name()} - CalFactor3: {calibFactor1}");
}
catch (Exception ex)
{
log.Error($"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB CH1 Exception:", ex);
}
log.Debug( $"WriteQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Start - Set CalFactor2: {calibFactor2}");
var CalFactor2AsyncResult = await gciBridge.WriteRegisterWithRetryAsync(genesisSmartReader.GetSlotNr, RadioService.CalFactor2, calibFactor2, false, false, token);
if (CalFactor2AsyncResult == null || !CalFactor2AsyncResult.Success)
{
log.Error( $"WriteQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - CalFactor2AsyncResult failed. Result: {CalFactor2AsyncResult}");
return "Failed to set CalFactor2";
}
wm.CalibFactorLNA = calibFactor2;
if (genesisSmartReader.Q3CalibDiffPercentageValue.Length == 3)
wm.OrigCalibFactorLNA = genesisSmartReader.Q3CalibDiffPercentageValue[1];
//CH3 to DB
try
{
if (tstRslt != null &&
tstRslt?.CalibFactorResultsToSave?.Count == 3 &&
tstRslt?.CalibFactorResultsToSave?[1] != null)
{
tstRslt.CalibFactorResultsToSave[1].CalculatedCalibFactor = Convert.ToInt32(calibFactor2);
tstRslt.CalibFactorResultsToSave[1].Stored = true;
tstRslt.CalibFactorResultsToSave[1].IsCalibFactorValid = true;
tstRslt.CalibFactorResultsToSave[1].Error = genesisSmartReader.Q3CalibDiffPercentageValue[1];
}
log.Debug( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB Stored tstRslt:{tstRslt.Name()} - CalFactor3: {calibFactor2}");
}
catch (Exception ex)
{
log.Error($"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB CH2 Exception:", ex);
}
log.Debug( $"WriteQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Start - Set CalFactor3: {calibFactor3}");
var CalFactor3AsyncResult = await gciBridge.WriteRegisterWithRetryAsync(genesisSmartReader.GetSlotNr, RadioService.CalFactor3, calibFactor3, false, false, token);
if (CalFactor3AsyncResult == null || !CalFactor3AsyncResult.Success)
{
log.Error( $"WriteQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - CalFactor3AsyncResult failed. Result: {CalFactor3AsyncResult}");
return "Failed to set CalFactor3";
}
wm.CalibFactor = calibFactor3;
if (genesisSmartReader.Q3CalibDiffPercentageValue.Length == 3)
wm.Diff2Hz8Hz = genesisSmartReader.Q3CalibDiffPercentageValue[2];
//CH3 to DB
try
{
if (tstRslt != null &&
tstRslt?.CalibFactorResultsToSave?.Count == 3 &&
tstRslt?.CalibFactorResultsToSave?[2] != null)
{
tstRslt.CalibFactorResultsToSave[2].CalculatedCalibFactor = Convert.ToInt32(calibFactor3);
tstRslt.CalibFactorResultsToSave[2].Stored = true;
tstRslt.CalibFactorResultsToSave[2].IsCalibFactorValid = true;
tstRslt.CalibFactorResultsToSave[2].Error = genesisSmartReader.Q3CalibDiffPercentageValue[2];
}
log.Debug( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB Stored tstRslt:{tstRslt.Name()} - CalFactor3: {calibFactor3}");
}
catch (Exception ex)
{
log.Error($"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB CH3 Exception:", ex);
}
log.Info( $"WriteQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Set DONE CalFactor1: {calibFactor1}, CalFactor2: {calibFactor2}, CalFactor2: {calibFactor3}");
@ -1569,46 +1707,133 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
}
}
public string PrepareQ3Calibration(TestMethodCfg cfg, Test test)
private void StoreCalibrationValuesResults(TestRslt tstRslt, GenesisSmartReader genesisSmartReader)
{
try
{
if (tstRslt == null || tstRslt.CalibFactorResultsToSave == null)
{
log.Error("StoreCalibrationValuesResults() - Missing TestRslt OR CalibFactorResultsToSave");
return;
}
for (int i = 0; i < tstRslt.CalibFactorResultsToSave.Count; i++)
{
ushort calibFactor = 0;
switch (i)
{
case 0:
calibFactor = Convert.ToUInt16(genesisSmartReader.Q3Calib_Ch1Value);
break;
case 1:
calibFactor = Convert.ToUInt16(genesisSmartReader.Q3Calib_Ch2Value);
break;
case 2:
calibFactor = Convert.ToUInt16(genesisSmartReader.Q3Calib_Ch3Value);
break;
}
tstRslt.CalibFactorResultsToSave[i].CalculatedCalibFactor = calibFactor;
tstRslt.CalibFactorResultsToSave[i].IsCalibFactorValid = genesisSmartReader.Q3CalibValid;
tstRslt.CalibFactorResultsToSave[i].Error = genesisSmartReader.Q3CalibDiffPercentageValue[i];
log.Debug($"StoreCalibrationValuesResults() - CalibFactor: {i} - CalibFactor: {calibFactor} - Q3CalibValid: {genesisSmartReader.Q3CalibValid} - Q3CalibDiffPercentageValue: {genesisSmartReader.Q3CalibDiffPercentageValue[i]}");
}
}
catch (Exception ex)
{
log.Error("StoreCalibrationValuesResults() - Exception:", ex);
}
}
public string PrepareQ3Calibration(TestMethodCfg cfg, Test test, WaterMeter wm)
{
log.Debug("PrepareQ3Calibration() - Start, Head: " + genesisHead?.Name);
if (genesisHead != null && genesisHead.DebugLevel == DebugMode.Simulate)
{
log.Debug("Connect() - Simulated response");
log.Debug("PrepareQ3Calibration() - Simulated response");
return ResultOk;//"Simulated Connect";
}
return Task.Run(() => PrepareQ3Calibration_Async(genesisHead, cfg, test))
if (cfg == null)
{
log.Error($"PrepareQ3Calibration({genesisHead?.Name}) - Missing TestMethodCfg");
return "PrepareQ3Calibration - Missing TestMethodCfg";
}
if (test == null)
{
log.Error($"PrepareQ3Calibration({genesisHead?.Name}) - Missing Test");
return "PrepareQ3Calibration - Missing Test";
}
return Task.Run(() => PrepareQ3Calibration_Async(genesisHead, cfg, test, wm))
.GetAwaiter()
.GetResult();
}
private async Task<string> PrepareQ3Calibration_Async(
GenesisSmartReader genesisSmartReader,
private async Task<string> PrepareQ3Calibration_Async(GenesisSmartReader genesisSmartReader,
TestMethodCfg cfg,
Test test)
Test test, WaterMeter wm)
{
try
{
log.Debug("PrepareQ3Calibration_Async called for iHead: " + genesisHead);
log.Debug("PrepareQ3Calibration_Async called for iHead: " + genesisHead?.Name + ", cfg: " + cfg?.Name + ", test: " + test?.Name);
if (genesisHead == null) return string.Empty;
if (string.IsNullOrEmpty(genesisHead.CommInterface)) return string.Empty;
GciBridge gciBridge = genesisHead.CommInterfaceBridge;
if (gciBridge == null) return string.Empty;
if (test == null) return "Valid Test Missing!";
Results.Entities.TestRslt tstRslt = ProcessData.BatchRslts.GetTestRslt(test.Name, test.Part);
log.Debug($"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Test: {test.Name} - Part: {test.Part} - IsTestRslt: {(tstRslt==null?true:false)}");
if (tstRslt.CalibFactorResultsToSave.Count == 0)
if (genesisHead == null)
{
for (int i = 0; i < genesisSmartReader.ChannelsCount; i++)
{
tstRslt.CalibFactorResultsToSave.Add(new TestRsltCalibFactor());
}
log.Error("PrepareQ3Calibration_Async() - Missing GenesisSmartReader");
return string.Empty;
}
if (string.IsNullOrEmpty(genesisHead.CommInterface))
{
log.Error("PrepareQ3Calibration_Async() - Missing CommInterface");
return string.Empty;
}
GciBridge gciBridge = genesisHead.CommInterfaceBridge;
if (gciBridge == null)
{
log.Error("PrepareQ3Calibration_Async() - Missing GciBridge");
return string.Empty;
}
Results.Entities.TestRslt tstRslt = null;
try
{
if (test == null)
{
log.Error($"PrepareQ3Calibration_Async({genesisHead?.Name}) - Missing Test");
return "Valid Test Missing!";
}
tstRslt = ProcessData.BatchRslts.GetTestRslt(test.Name, test.Part);
log.Debug($"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Test: {test.Name} - Part: {test.Part} - IsTestRslt: {(tstRslt==null?true:false)}");
if (tstRslt?.CalibFactorResultsToSave?.Count > 0)
{
tstRslt?.CalibFactorResultsToSave.Clear();
}
if (tstRslt?.CalibFactorResultsToSave?.Count == 0)
{
for (int i = 0; i < genesisSmartReader.ChannelsCount; i++)
{
tstRslt.CalibFactorResultsToSave.Add(new TestRsltCalibFactor()
{
Stored = false,
CalibFactorIndex = i
}
);
}
}
}
catch (Exception ex)
{
log.Error($"PrepareQ3Calibration_Async({genesisSmartReader.GetSlotNr}) - DB TestRslt Exception:", ex);
return ex.Message;
}
CancellationToken token = default;
//Get Activity Status
@ -1618,34 +1843,95 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
UInt16 valueSampleRate = 10;
//TODO BUMI - implement variable values for Q3Channel - be shure is implemented in Head
string prepareMeterSizeAndCalibration = await PrepareMeterSizeAndCalibration(genesisSmartReader, cfg, gciBridge, token);
string prepareMeterSizeAndCalibration = await PrepareMeterSizeAndCalibration(genesisSmartReader, cfg, gciBridge, tstRslt, token);
if (prepareMeterSizeAndCalibration != ResultOk)
{
log.Error($"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - prepareMeterSizeAndCalibration failed. Result: {prepareMeterSizeAndCalibration}");
return prepareMeterSizeAndCalibration;
}
log.Debug( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Start - Set Led Mode: {valueLed}");
var CalFactor1AsyncResult = await gciBridge.WriteRegisterWithRetryAsync(genesisSmartReader.GetSlotNr, RadioService.CalFactor1, genesisSmartReader.Q3CalibValue[0], false, false, token);
ushort calibrationFactor1 = Convert.ToUInt16(genesisSmartReader?.Q3CalibValue[0]);
log.Debug( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Start - Set CalFactor1: {calibrationFactor1}");
var CalFactor1AsyncResult = await gciBridge.WriteRegisterWithRetryAsync(genesisSmartReader.GetSlotNr, RadioService.CalFactor1, calibrationFactor1, false, false, token);
if (CalFactor1AsyncResult == null || !CalFactor1AsyncResult.Success)
{
log.Error( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - CalFactor1AsyncResult failed. Result: {CalFactor1AsyncResult}");
return "Failed to disable Led Mode";
}
var CalFactor2AsyncResult = await gciBridge.WriteRegisterWithRetryAsync(genesisSmartReader.GetSlotNr, RadioService.CalFactor2, genesisSmartReader.Q3CalibValue[1], false, false, token);
//CH1 to DB
try
{
if (tstRslt != null &&
tstRslt?.CalibFactorResultsToSave?.Count == 3 &&
tstRslt?.CalibFactorResultsToSave?[0] != null)
{
tstRslt.CalibFactorResultsToSave[0].BaseCalibFactor = Convert.ToInt32(calibrationFactor1);
tstRslt.CalibFactorResultsToSave[0].Stored = false;
}
//wm.OrigCalibFactor = calibrationFactor1; // now dosabled
log.Debug( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB Stored tstRslt:{tstRslt.Name()} - CalFactor1: {calibrationFactor1}");
}
catch (Exception ex)
{
log.Error($"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB CH1 Exception:", ex);
}
ushort calibrationFactor2 = Convert.ToUInt16(genesisSmartReader?.Q3CalibValue[1]);
log.Debug( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Start - Set CalFactor2: {calibrationFactor2}");
var CalFactor2AsyncResult = await gciBridge.WriteRegisterWithRetryAsync(genesisSmartReader.GetSlotNr, RadioService.CalFactor2, calibrationFactor2, false, false, token);
if (CalFactor2AsyncResult == null || !CalFactor2AsyncResult.Success)
{
log.Error( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - CalFactor2AsyncResult failed. Result: {CalFactor2AsyncResult}");
return "Failed to disable Led Mode";
}
//CH2 to DB
try
{
if (tstRslt != null &&
tstRslt?.CalibFactorResultsToSave?.Count == 3 &&
tstRslt?.CalibFactorResultsToSave?[1] != null)
{
tstRslt.CalibFactorResultsToSave[1].BaseCalibFactor = Convert.ToInt32(calibrationFactor2);
tstRslt.CalibFactorResultsToSave[1].Stored = false;
}
//wm.CalibFactorLNA = calibrationFactor2; // now dosabled
log.Debug( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB Stored tstRslt:{tstRslt.Name()} - CalFactor2: {calibrationFactor2}");
}
catch (Exception ex)
{
log.Error($"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB CH2 Exception:", ex);
}
var CalFactor3AsyncResult = await gciBridge.WriteRegisterWithRetryAsync(genesisSmartReader.GetSlotNr, RadioService.CalFactor3, genesisSmartReader.Q3CalibValue[2], false, false, token);
ushort calibrationFactor3 = Convert.ToUInt16(genesisSmartReader?.Q3CalibValue[2]);
log.Debug( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - Start - Set CalFactor1: {calibrationFactor3}");
var CalFactor3AsyncResult = await gciBridge.WriteRegisterWithRetryAsync(genesisSmartReader.GetSlotNr, RadioService.CalFactor3, calibrationFactor3, false, false, token);
if (CalFactor3AsyncResult == null || !CalFactor3AsyncResult.Success)
{
log.Error( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - CalFactor3AsyncResult failed. Result: {CalFactor3AsyncResult}");
return "Failed to disable Led Mode";
}
//CH3 to DB
try
{
if (tstRslt != null &&
tstRslt?.CalibFactorResultsToSave?.Count == 3 &&
tstRslt?.CalibFactorResultsToSave?[2] != null)
{
tstRslt.CalibFactorResultsToSave[2].BaseCalibFactor = Convert.ToInt32(calibrationFactor3);
tstRslt.CalibFactorResultsToSave[2].Stored = false;
}
//wm.CalibFactor = calibrationFactor3; // now dosabled
log.Debug( $"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB Stored tstRslt:{tstRslt.Name()} - CalFactor3: {calibrationFactor3}");
}
catch (Exception ex)
{
log.Error($"PrepareQ3Calibration_Async( Slot: {genesisSmartReader.GetSlotNr}) - DB CH3 Exception:", ex);
}
var SampleRateAsyncResult = await gciBridge.WriteRegisterWithRetryAsync(genesisSmartReader.GetSlotNr, RadioService.SampleRate, valueSampleRate, false, false, token);
if (SampleRateAsyncResult == null || !SampleRateAsyncResult.Success)
@ -1673,66 +1959,82 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.communication
}
private static async Task<string> PrepareMeterSizeAndCalibration(GenesisSmartReader genesisSmartReader, TestMethodCfg cfg,
GciBridge gciBridge, CancellationToken token)
GciBridge gciBridge, Results.Entities.TestRslt tstRslt, CancellationToken token)
{
UInt16 valueCalibrate = 15625; //Predefined Calibration Value
log.Debug( $"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader?.GetSlotNr}) - Start - predefined {valueCalibrate}");
try
{
if (cfg != null)
{
var MeterSizeAsyncResult = await gciBridge.ReadRegisterWithRetryAsync(genesisSmartReader.GetSlotNr,
RadioService.MeterSize, token);
if (MeterSizeAsyncResult == null || !MeterSizeAsyncResult.Success)
{
log.Error($"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - Error reading MeterSize register. Result: {MeterSizeAsyncResult}");
return "Error reading MeterSize register";
}
string rawHex = MeterSizeAsyncResult.Result?.RawHex;
if (string.IsNullOrWhiteSpace(rawHex))
{
log.Error(
$"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - MeterSize RawHex is empty");
return "MeterSize RawHex is empty";
}
uint meterSizeRaw = ParseRawHexToUInt32(rawHex);
// If register returns 4 bytes like "00 00 00 02", this gives 2.
// If it returns "02", this also gives 2.
if (meterSizeRaw > ushort.MaxValue)
{
log.Error(
$"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - MeterSize too large. RawHex='{rawHex}', Value={meterSizeRaw}");
return "MeterSize value too large";
}
ushort int16MeterSize = (ushort)meterSizeRaw;
double[] dSize = cfg.GetQ3CalibrationBySizeDoubles(int16MeterSize);
if (dSize == null || dSize.Length != 3)
{
log.Info(
$"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - Problem with Q3Channel calculation. Size: {int16MeterSize}");
return ResultNok;
}
genesisSmartReader
.SetQ3Calibration(dSize); // new double[]{valueCalibrate,valueCalibrate,valueCalibrate}
log.Info(
$"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - Based MeterSize: {int16MeterSize} Set Q3Channel: CH1({dSize[0]}), CH2({dSize[1]}), CH3({dSize[2]})");
}
else
// if (cfg != null)
// {
// var MeterSizeAsyncResult = await gciBridge.ReadRegisterWithRetryAsync(genesisSmartReader.GetSlotNr,
// RadioService.MeterSize, token);
//
// if (MeterSizeAsyncResult == null || !MeterSizeAsyncResult.Success)
// {
// log.Error($"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - Error reading MeterSize register. Result: {MeterSizeAsyncResult}");
// return "Error reading MeterSize register";
// }
//
// string rawHex = MeterSizeAsyncResult.Result?.RawHex;
// if (string.IsNullOrWhiteSpace(rawHex))
// {
// log.Error(
// $"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - MeterSize RawHex is empty");
// return "MeterSize RawHex is empty";
// }
//
// uint meterSizeRaw = ParseRawHexToUInt32(rawHex);
//
// // If register returns 4 bytes like "00 00 00 02", this gives 2.
// // If it returns "02", this also gives 2.
// if (meterSizeRaw > ushort.MaxValue)
// {
// log.Error(
// $"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - MeterSize too large. RawHex='{rawHex}', Value={meterSizeRaw}");
// return "MeterSize value too large";
// }
//
// ushort int16MeterSize = (ushort)meterSizeRaw;
//
// double[] dSize = cfg.GetQ3CalibrationBySizeDoubles(int16MeterSize);
// if (dSize == null || dSize.Length != 3)
// {
// log.Info(
// $"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - Problem with Q3Channel calculation. Size: {int16MeterSize}");
// return ResultNok;
// }
//
// genesisSmartReader .SetQ3Calibration(dSize); // new double[]{valueCalibrate,valueCalibrate,valueCalibrate}
// for (int i = 0; i < genesisSmartReader.ChannelsCount; i++)
// {
// tstRslt.CalibFactorResultsToSave[i].BaseCalibFactor = Convert.ToInt32(dSize[i]);
// }
//
// log.Info(
// $"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - Based MeterSize: {int16MeterSize} Set Q3Channel: CH1({dSize[0]}), CH2({dSize[1]}), CH3({dSize[2]})");
// }
// else
{
genesisSmartReader.SetQ3Calibration(new double[]
{ valueCalibrate, valueCalibrate, valueCalibrate });
for (int i = 0; i < genesisSmartReader.ChannelsCount; i++)
{
if(tstRslt != null && tstRslt?.CalibFactorResultsToSave[i] != null)
tstRslt.CalibFactorResultsToSave[i].BaseCalibFactor = Convert.ToInt32(valueCalibrate);
}
log.Info( $"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - Hard Set Q3Channel: CH1({valueCalibrate}), CH2({valueCalibrate}), CH3({valueCalibrate})");
}
}catch(Exception ex)
{
log.Error($"PrepareMeterSizeAndCalibration( Slot: {genesisSmartReader.GetSlotNr}) - Error during Q3Channel calculation: {ex.Message}");
genesisSmartReader.SetQ3Calibration(new double[]
{ valueCalibrate, valueCalibrate, valueCalibrate });
for (int i = 0; i < genesisSmartReader.ChannelsCount; i++)
{
tstRslt.CalibFactorResultsToSave[i].BaseCalibFactor = Convert.ToInt32(valueCalibrate);
}
return ResultNok;
}

View File

@ -1340,16 +1340,6 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
void DataStreamPostProcessing()
{
PrepareCalculatedChannelData();
try
{
log.DebugFormat("DataStreamPostProcessing() - harcoded call GetQ3Calibration(200.0, 120.0, 17969.0);");
SetQ3Calibration(new double[]{17969.0,17969.0,17969.0 });
CalculateQ3Calibration(200.0, 120.0);
}
catch (Exception ex)
{
log.Error($"DataStreamPostProcessing -- Q3 CALIBRATION -- failed: {ex}");
}
}
/// <summary>
@ -1883,7 +1873,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
_readLoopTask = Task.Run(() =>
{
log.Debug($"OPTHO {OptoComPortNr} background read loop started.");
logStream.Debug($"OPTHO {OptoComPortNr} background read loop started.");
while (!token.IsCancellationRequested)
{
@ -1939,12 +1929,12 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
catch (Exception ex)
{
log.Error($"OPTHO {OptoComPortNr} background read error: {ex.Message}");
logStream.Error($"OPTHO {OptoComPortNr} background read error: {ex.Message}");
Thread.Sleep(100);
}
}
log.Debug($"OPTHO {OptoComPortNr} background read loop stopped.");
logStream.Debug($"OPTHO {OptoComPortNr} background read loop stopped.");
}, token);
}
@ -2025,7 +2015,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
{
try
{
log.Debug($"OPTHO {OptoComPortNr} processing loop started.");
logStream.Debug($"OPTHO {OptoComPortNr} processing loop started.");
while (!token.IsCancellationRequested)
{
@ -2055,14 +2045,14 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
if (blockCompleted)
{
log.Debug("Processing loop completed flow block detected.");
logStream.Debug("Processing loop completed flow block detected.");
if (resetSerialBuffersOnCompletedFlowBlock)
ResetDataBuffer();
}
}
catch (Exception ex)
{
log.Error($"Processing loop failed: {ex}");
logStream.Error($"Processing loop failed: {ex}");
}
continue;
@ -2076,16 +2066,16 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
catch (Exception ex)
{
log.Error($"OPTHO {OptoComPortNr} processing loop error: {ex}");
logStream.Error($"OPTHO {OptoComPortNr} processing loop error: {ex}");
Thread.Sleep(50);
}
}
log.Debug($"OPTHO {OptoComPortNr} processing loop stopped.");
logStream.Debug($"OPTHO {OptoComPortNr} processing loop stopped.");
}
catch (Exception ex)
{
log.Error($"StartProcessingLoop fatal error: {ex}");
logStream.Error($"StartProcessingLoop fatal error: {ex}");
}
}, token);
}
@ -2114,13 +2104,13 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
// 🔴 STEP 1: Check if we should start processing
if (startDataProcessing && optoState == DataStreamState.ProcessAndSave)
{
log.DebugFormat("Read Opto Data Line timestamp:{0} to process from queue: {1}",timestamp.ToString("HH:mm:ss.fff") , line);
logStream.DebugFormat("Read Opto Data Line timestamp:{0} to process from queue: {1}",timestamp.ToString("HH:mm:ss.fff") , line);
bool blockCompleted;
ProcessOptoLine(line, optoState, out blockCompleted);
if (blockCompleted)
{
log.Debug("ReadOptoData() completed flow block detected.");
logStream.Debug("ReadOptoData() completed flow block detected.");
if (resetSerialBuffersOnCompletedFlowBlock) // DO NOT call ResetDataBuffer() here
ResetDataBuffer();
}
@ -2128,7 +2118,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
catch (Exception ex)
{
log.Error($"OPTHO {OptoComPortNr} processing queued line failed: {ex.Message}");
logStream.Error($"OPTHO {OptoComPortNr} processing queued line failed: {ex.Message}");
}
}
}
@ -2144,7 +2134,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
var encoding = optoSerialPort?.Encoding ?? Encoding.ASCII;
byte[] bytes = encoding.GetBytes(line);
log.Debug("ComPort: " + OptoComPortNr + " OPTHO RX ← " + HexFormatter.ToSerialHex(bytes));
logStream.Debug("ComPort: " + OptoComPortNr + " OPTHO RX ← " + HexFormatter.ToSerialHex(bytes));
var streamingDecode = new StreamingDecoder(true);
streamingDecode.DecodeMsg(line);
@ -2154,14 +2144,14 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
if (streamingDecode.DataFlowTest != null && streamingDecode.DataFlowTest.IsValid)
{
blockCompleted = HandleFlowMarker();
log.Debug("ComPort: " + OptoComPortNr + " Decoded Flow data: " + streamingDecode.DataFlowTest +
" OPTHO RX ← " + HexFormatter.ToSerialHex(bytes));
logStream.Debug("ComPort: " + OptoComPortNr + " Decoded Flow data: " + streamingDecode.DataFlowTest +
" OPTHO RX ← " + HexFormatter.ToSerialHex(bytes));
}
if (calibData != null && calibData.IsValid)
{
log.Debug("ComPort: " + OptoComPortNr + " Decoded Calib: " + calibData + " OPTHO RX ← " +
HexFormatter.ToSerialHex(bytes));
logStream.Debug("ComPort: " + OptoComPortNr + " Decoded Calib: " + calibData + " OPTHO RX ← " +
HexFormatter.ToSerialHex(bytes));
MarkCalibrationChannelSeen(calibData.Channel);
}
@ -2181,7 +2171,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
if (optoData[bufferIx] == null)
{
log.ErrorFormat("{0}: optoData[{1}] was null, recreating.", Name, bufferIx);
logStream.ErrorFormat("{0}: optoData[{1}] was null, recreating.", Name, bufferIx);
optoData[bufferIx] = new OptoTelegramRaw();
}
@ -2194,7 +2184,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
int iChanel = calibData.Channel - 1;
if (iChanel >= 0 && iChanel < iChanelsCount)
{
log.Debug(
logStream.Debug(
$"Before UpdateFromSmart ch={iChanel + 1}: " +
$"volumeRawExtLast={volumeRawExtLast[iChanel]}, " +
$"timestampExtLast={timestampExtLast[iChanel]}, " +
@ -2262,7 +2252,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
var encoding = optoSerialPort?.Encoding ?? Encoding.ASCII;
byte[] bytes = encoding.GetBytes(line);
received = HexFormatter.ToSerialHex(bytes);
log.Debug("RX ← " + received);
logStream.Debug("RX ← " + received);
try
{
@ -2271,19 +2261,19 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
CalibrationRecord data = _streamingDecode.DataCalib;
if (data != null && data.IsValid)
{
log.Info($"OPTHO {OptoComPortNr} DataCalib Parsed opto data: " + data + " RX ← " +
received);
logStream.Info($"OPTHO {OptoComPortNr} DataCalib Parsed opto data: " + data + " RX ← " +
received);
MarkCalibrationChannelSeen(data.Channel);
}
FlowTestRecord dataFlow = _streamingDecode.DataFlowTest;
if (dataFlow != null && dataFlow.IsValid)
{
log.Info($"OPTHO {OptoComPortNr} FLOW Parsed opto data: " + dataFlow + " RX ← " + received);
logStream.Info($"OPTHO {OptoComPortNr} FLOW Parsed opto data: " + dataFlow + " RX ← " + received);
if (HandleFlowMarker())
{
log.Debug("ReadOptoData() completed flow block detected.");
logStream.Debug("ReadOptoData() completed flow block detected.");
if (resetSerialBuffersOnCompletedFlowBlock)
ResetDataBuffer(); // no ResetDataBuffer() here
}
@ -2292,7 +2282,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
catch (Exception ex)
{
log.Error($"OPTHO {OptoComPortNr} Read error: {ex.Message}");
logStream.Error($"OPTHO {OptoComPortNr} Read error: {ex.Message}");
}
// string line = optoSerialPort.ReadExisting();
@ -2337,11 +2327,11 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
catch (TimeoutException)
{
log.Debug($"ReadOptoData() OPTHO {OptoComPortNr} timeout - continuing.");
logStream.Debug($"ReadOptoData() OPTHO {OptoComPortNr} timeout - continuing.");
}
catch (Exception ex)
{
log.Error($"ReadOptoData() OPTHO {OptoComPortNr} Read error: {ex.Message}");
logStream.Error($"ReadOptoData() OPTHO {OptoComPortNr} Read error: {ex.Message}");
}
}
@ -2357,11 +2347,11 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
{
optoSerialPort.DiscardInBuffer();
optoSerialPort.DiscardOutBuffer();
log.Debug("-- Reaset Data Buffer --");
logStream.Debug("-- Reaset Data Buffer --");
return;
}
}
log.Debug("-- Reaset Data Buffer - no serial port --");
logStream.Debug("-- Reaset Data Buffer - no serial port --");
}
void ISmartReader.SetNfcInterface()
@ -2387,17 +2377,17 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
byte[] bytes = optoSerialPort.Encoding.GetBytes(line);
string received = HexFormatter.ToSerialHex(bytes);
log.Debug("RX ← " + received);
logStream.Debug("RX ← " + received);
return line;
}
}
catch (TimeoutException)
{
log.Debug($"ReadOptoData() OPTHO {OptoComPortNr} ReadLine timeout (3s) - continuing.");
logStream.Debug($"ReadOptoData() OPTHO {OptoComPortNr} ReadLine timeout (3s) - continuing.");
}
catch (Exception ex)
{
log.Error($"ReadOptoData() OPTHO {OptoComPortNr} Read error: {ex.Message}");
logStream.Error($"ReadOptoData() OPTHO {OptoComPortNr} Read error: {ex.Message}");
}
return string.Empty;
@ -2408,7 +2398,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
if (completedTask == readTask)
return await readTask;
log.Debug("ReadOptoData timeout after " + timeoutMs + " ms");
logStream.Debug("ReadOptoData timeout after " + timeoutMs + " ms");
return string.Empty;
}
@ -2957,7 +2947,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
if (data == null || !data.IsValid)
continue;
log.Info($"OPTHO {OptoComPortNr} Parsed optho data:" + data);
logStream.Info($"OPTHO {OptoComPortNr} Parsed optho data:" + data);
int dch = data.Channel - 1;
if (dch >= 0 && dch < iChanelsCount)
@ -2970,7 +2960,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
catch (Exception ex)
{
log.Warn($"Parsing DiagnosticLedState4Data: {ex.Message}");
logStream.Warn($"Parsing DiagnosticLedState4Data: {ex.Message}");
}
}
}
@ -2981,7 +2971,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
log.Debug($"Try get End Volume! COM: {this.OptoComPortNr}, Volume: {volumeLtr}");
logStream.Debug($"Try get End Volume! COM: {this.OptoComPortNr}, Volume: {volumeLtr}");
if (optoSerialPort != null && optoSerialPort.IsOpen) CloseOptoSerialPort();
if (!Double.IsNaN(volumeLtr[channel0]))
@ -2992,12 +2982,12 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
//Solve roll over
if (endWMState < beginWMState)
{
log.Debug($"Solve roll over! endWMState: {endWMState} < beginWMState: {beginWMState}");
logStream.Debug($"Solve roll over! endWMState: {endWMState} < beginWMState: {beginWMState}");
const double VOL_RANGE_LITERS = 16777216.0 * 0.00025; // 4,194.304 l
endWMState += VOL_RANGE_LITERS;
volumeLtr[channel0] = endWMState;
ReadPulses();
log.Debug(
logStream.Debug(
$"Solve roll over! Upgraded endWMState: {endWMState}, beginWMState: {beginWMState}");
}
}
@ -3006,7 +2996,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
//}
log.Warn("Default NaN value returned! Data Opto stream reading failed!");
logStream.Warn("Default NaN value returned! Data Opto stream reading failed!");
return Double.NaN;
}).ConfigureAwait(false);
}
@ -3016,14 +3006,14 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
{
if (ConfigStruct == null)
{
log.Debug("ConfigStruct is null - created new in ReadSerialNr()");
logStream.Debug("ConfigStruct is null - created new in ReadSerialNr()");
ConfigStruct = new ConfigStruct();
}
return await Task.Run(() =>
{
log.Debug($"Try get Start Volume! COM: {this.OptoComPortNr}");
logStream.Debug($"Try get Start Volume! COM: {this.OptoComPortNr}");
Start();
@ -3044,7 +3034,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
StreamingDecoder _streamingDecode = new StreamingDecoder(true);
_streamingDecode.DecodeMsg(readOptoDataWithTimeout);
CalibrationRecord data = _streamingDecode.DataCalib;
log.Info($"OPTHO {OptoComPortNr} Parsed optho data:" + data);
logStream.Info($"OPTHO {OptoComPortNr} Parsed optho data:" + data);
if (data == null || !data.IsValid)
continue;
@ -3060,7 +3050,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
catch (Exception ex)
{
log.Warn($"Parsing DiagnosticLedState4Data: {ex.Message}");
logStream.Warn($"Parsing DiagnosticLedState4Data: {ex.Message}");
}
}
}
@ -3070,7 +3060,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
}
log.Debug($"Try get Start Volume! COM: {this.OptoComPortNr}, Volume: {volumeLtr0}");
logStream.Debug($"Try get Start Volume! COM: {this.OptoComPortNr}, Volume: {volumeLtr0}");
if (optoSerialPort != null && optoSerialPort.IsOpen) CloseOptoSerialPort();
if (!Double.IsNaN(volumeLtr0[ch]))
@ -3081,7 +3071,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
//}
log.Warn("Default NaN value returned! Data Opto stream reading failed!");
logStream.Warn("Default NaN value returned! Data Opto stream reading failed!");
return Double.NaN;
}).ConfigureAwait(false);
}
@ -3093,7 +3083,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
if (ConfigStruct == null)
{
log.Debug("ConfigStruct is null - created new in ReadSerialNr()");
logStream.Debug("ConfigStruct is null - created new in ReadSerialNr()");
ConfigStruct = new ConfigStruct();
}
@ -3103,11 +3093,11 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
return await Task.Run(() =>
{
log.Debug($"Try get ReadSerialNr! COM: {this.RfidComPortNr}");
logStream.Debug($"Try get ReadSerialNr! COM: {this.RfidComPortNr}");
SerialNr = OptoHeadTest.ReadRequest_PCB();
if (string.IsNullOrEmpty(SerialNr))
{
log.Debug("ReadSerialNr successful");
logStream.Debug("ReadSerialNr successful");
}
//optoHeadTest.CloseConnection();
@ -3933,6 +3923,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
private double[] q3CalibInitial = {Double.NaN,Double.NaN,Double.NaN};
private bool[] isChQ3CalibValid = { false,false,false};
private double[] q3CalibCh = {Double.NaN,Double.NaN,Double.NaN};
private double[] q3DiffPercentageCalibCh = {Double.NaN,Double.NaN,Double.NaN};
public bool Q3CalibValid
@ -3950,6 +3941,7 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
}
public double[] Q3CalibValue { get => q3CalibInitial; }
public double[] Q3CalibDiffPercentageValue { get => q3DiffPercentageCalibCh; }
public bool Q3Calib_Ch1Valid { get => isChQ3CalibValid[0]; }
public bool Q3Calib_Ch2Valid { get => isChQ3CalibValid[1]; }
@ -3983,10 +3975,10 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
public void CalculateQ3Calibration(double refVolume, double refTime)
{
GetQ3Calibration(refVolume, refTime, q3CalibInitial, ref isChQ3CalibValid, ref q3CalibCh);
GetQ3Calibration(refVolume, refTime, q3CalibInitial, ref isChQ3CalibValid,ref q3DiffPercentageCalibCh, ref q3CalibCh);
}
public void GetQ3Calibration(double refVolume, double refTime, double[] initCalibFactor, ref bool[] isChQ3CalibValid, ref double[] q3CalibCh)
public void GetQ3Calibration(double refVolume, double refTime, double[] initCalibFactor, ref bool[] isChQ3CalibValid, ref double[] calibDiffPercent, ref double[] q3CalibCh)
{
log.Debug("=== Q3 CALIBRATION START ===");
@ -4096,9 +4088,9 @@ namespace TBF.Rig.RegisterReaders.GenesisRegReader.implementations
q3CalibCh[iChannel] = (refVolume / recalculatedDeltaVolume) * initCalibFactor[iChannel];
double diffPercent = Math.Abs((initCalibFactor[iChannel] - q3CalibCh[iChannel] ) / initCalibFactor[iChannel]) * 100.0;
isChQ3CalibValid[iChannel] = diffPercent <= 5.0;
isChQ3CalibValid[iChannel] = diffPercent <= 5.0 && diffPercent >= -5.0;
calibDiffPercent[iChannel] = diffPercent;
log.Debug($"Calculated Q3Calib Ch[{iChannel}] ={q3CalibCh[iChannel]} DiffPercent={diffPercent}% isValid[{isChQ3CalibValid[iChannel]}] IninitCalibFactor={initCalibFactor}");
}
log.Debug("=== Q3 CALIBRATION END ===");

View File

@ -50,6 +50,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.communication
if (decoded.IsOk)
{
string asciiPayload = decoded.GetAsciiPayload();
iHead.SerialNr = asciiPayload;
if (iHead.ConfigStruct != null) // store mechanism
{
iHead.ConfigStruct.PCBNumberString = asciiPayload;

View File

@ -65,6 +65,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
FailedSetActiveMode, /// 1AH = 26
FailedWriteCalibrationFactor,/// 1BH = 27
FailedWriteRegister,/// 1CH = 28
FailedPrepare, /// 1DH = 29
}
@ -818,7 +819,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
else if (currentActivity.ToLower().Equals(SlotSetActiveModeStr.ToLower()))error = SlotSetActiveMode(threadID, ihead, ref resultStr);
else if (currentActivity.ToLower().Equals(SlotDisconnectStr.ToLower())) error = SlotDisconnect(threadID, ihead, ref resultStr);
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, 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);
else if (currentActivity.ToLower().Contains(ReadSerialNrStr.ToLower())) error = ReadSerialNr(threadID, ihead, ref resultStr);
@ -876,9 +877,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
(error == CommErr.FailedSetTestMode)||
(error == CommErr.FailedSetActiveMode)||
(error == CommErr.FailedWriteRegister)||
(error == CommErr.FailedWriteCalibrationFactor))
(error == CommErr.FailedWriteCalibrationFactor) ||
(error == CommErr.FailedPrepare)
)
{
OnCommCompleted(null, new CommCompletedEventArgs(threadID, wmNr0, ihead, wm, resultStr, CommErr.FailedInit));
OnCommCompleted(null, new CommCompletedEventArgs(threadID, wmNr0, ihead, wm, resultStr, error));
}
else if (ihead.CommFailed || (error == CommErr.CommFailed))
{
@ -1024,57 +1027,104 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
private CommErr PrepareSlotQ3Calibration(int threadId, GenesisSmartReader iHead, WaterMeter wm,
Test currentTest, IList<Test> tests, ref string resultStr)
{
CommErr error = CommErr.FailedLogin;
CommErr error = CommErr.FailedPrepare;
//TODO BUMI get Next test method
Test NextTest = null;
bool bNextChatch = false;
foreach (Test test in tests)
log.InfoFormat("PrepareSlotQ3Calibration() threadId={0}", threadId);
try
{
if (test.Equals(currentTest))
Test NextTest = null;
bool bNextChatch = false;
foreach (Test test in tests)
{
bNextChatch = true;
continue;
if (test.Equals(currentTest))
{
bNextChatch = true;
continue;
}
if (bNextChatch)
{
NextTest = test;
break;
}
}
if (bNextChatch)
if (NextTest == null)
{
NextTest = test;
break;
log.Error("No next test method found, we use the current test method");
NextTest = currentTest;
}
}
var gciFullLoginResult = iHead.OptoHeadTest.PrepareQ3Calibration(cfg,NextTest);
if (!string.IsNullOrEmpty(resultStr) && resultStr.Equals(TBF.Rig.RegisterReaders.GenesisRegReader.communication.OptoHeadTest.ResultOk))
var gciFullLoginResult = iHead.OptoHeadTest.PrepareQ3Calibration(cfg, NextTest, wm);
if (!string.IsNullOrEmpty(resultStr) &&
resultStr.Equals(TBF.Rig.RegisterReaders.GenesisRegReader.communication.OptoHeadTest.ResultOk))
{
log.DebugFormat("PrepareQ3Calibration successfull threadId={0}", threadId);
resultStr = string.Format($"Write Q3 Calibration: OK");
// note Q3 calibration is done
error = CommErr.None;
}
else
{
resultStr = "Write Q3 Calibration: Failed";
}
return error;
}catch (Exception ex)
{
log.Debug("SlotLogin successful");
resultStr = string.Format($"Write Q3 Calibration: OK");
// note Q3 calibration is done
error = CommErr.None;
log.ErrorFormat("PrepareSlotQ3Calibration() threadId={0}, Error: {1}", threadId, ex.Message);
return CommErr.FailedPrepare;
}
else
{
resultStr = "Write Q3 Calibration: Failed";
}
return error;
}
private CommErr WriteSlotQ3Calibration(int threadId, GenesisSmartReader iHead, ref string resultStr)
private CommErr WriteSlotQ3Calibration(int threadId, GenesisSmartReader iHead, WaterMeter wm,
Test currentTest, IList<Test> tests, ref string resultStr)
{
CommErr error = CommErr.FailedWriteCalibrationFactor;
var gciFullLoginResult = iHead.OptoHeadTest.WriteQ3Calibration();
if (!string.IsNullOrEmpty(resultStr) && resultStr.Equals(TBF.Rig.RegisterReaders.GenesisRegReader.communication.OptoHeadTest.ResultOk))
log.DebugFormat("WriteSlotQ3Calibration() threadId={0}, iHead: {1}, wm: {2}, currentTest: {3}, tests: {4}", threadId, iHead?.Name, wm?.Id, currentTest?.Name, tests?.Count);
//TODO BUMI get Before test method
try
{
log.Debug("SlotLogin successful");
resultStr = string.Format($"Write Q3 Calibration: OK");
// note Q3 calibration is done
error = CommErr.None;
Test BeforeTest = null;
foreach (Test test in tests)
{
if (test.Equals(currentTest))
{
break;
}
BeforeTest = test;
}
if (BeforeTest == null)
{
BeforeTest = currentTest;
}
var gciFullLoginResult = iHead.OptoHeadTest.WriteQ3Calibration(cfg, BeforeTest, wm);
if (!string.IsNullOrEmpty(resultStr) &&
resultStr.Equals(TBF.Rig.RegisterReaders.GenesisRegReader.communication.OptoHeadTest.ResultOk))
{
log.Debug("SlotLogin successful");
resultStr = string.Format($"Write Q3 Calibration: OK");
// note Q3 calibration is done
error = CommErr.None;
}
else
{
resultStr = "Write Q3 Calibration: Failed";
}
return error;
}
else
catch (Exception ex)
{
resultStr = "Write Q3 Calibration: Failed";
log.ErrorFormat("WriteSlotQ3Calibration() threadId={0}, Error: {1}", threadId, ex.Message);
return CommErr.FailedWriteCalibrationFactor;
}
return error;
}
private CommErr SlotGroupedLogin(int threadId, GenesisSmartReader iHead, ref string resultStr)
@ -1083,8 +1133,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
var gciFullLoginResult = iHead.OptoHeadTest.GroupedLoginSlot();
if (gciFullLoginResult.Success)
{
log.Debug("SlotLogin successful");
log.Debug($"SlotLogin Head:{iHead.Name} successful, PCB: {gciFullLoginResult?.PcbResult?.Result?.PcbId}");
resultStr = string.Format($"Login OK - Serial No: {gciFullLoginResult?.PcbResult?.Result?.PcbId}");
log.Debug($"Setting PCB: {gciFullLoginResult?.PcbResult?.Result?.PcbId} for Head: {iHead.Name}");
iHead.SerialNr = gciFullLoginResult?.PcbResult?.Result?.PcbId;
if (iHead.ConfigStruct != null)
{
@ -1190,8 +1241,16 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
PcbReadResult pcbReadSlot = iHead.OptoHeadTest.PCB_ReadSlot();
if (pcbReadSlot.Success)
{
log.Debug("SlotPCBSlot successful");
resultStr = string.Format($"SlotPCBSlot: {pcbReadSlot.PcbId}");
var pcbId = pcbReadSlot?.PcbId;
log.Debug($"SlotPCBSlot Head:{iHead.Name} successful, PCB:{pcbId}");
resultStr = string.Format($"SlotPCBSlot: {pcbId}");
if (!string.IsNullOrWhiteSpace(pcbId))
{
log.Debug($"Setting PCB: {pcbId} for Head: {iHead.Name}");
iHead.SerialNr = pcbId;
if (iHead.ConfigStruct != null) iHead.ConfigStruct.PCBNumberString = pcbId;
}
error = CommErr.None;
}
else
@ -1256,7 +1315,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
CommErr error = CommErr.Read;
var result = ihead.OptoHeadTest.ReadRequest_PCB();
if (string.IsNullOrEmpty(result))
if (!string.IsNullOrEmpty(result))
{
log.Debug("ReadSerialNr successful");
resultStr = string.Format($"Serial No: {result}");
@ -1612,6 +1671,17 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
checkBoxes[data.WMNr0].Checked = true;
checkBoxes[data.WMNr0].Enabled = false;
}
// else if (data.WMNr0 >= 0 && data.CommErr != CommErr.None)
// {
// //disable if error
// ckbState[data.WMNr0] = false;
// checkBoxes[data.WMNr0].Checked = false;
// checkBoxes[data.WMNr0].Enabled = false;
// if (data.Ihead != null) data.Ihead.Disabled = true;
// if (data.Wm != null) data.Wm.Disabled = true;
// //color
// if (counters.Length > data.WMNr0) counters[data.WMNr0].BackColor = OptoNokColor;
// }
///
/// Update opto-communication indication

View File

@ -107,6 +107,7 @@ namespace TBFTests
CalibFactorIndex = 1,
BaseCalibFactor = 15625,
CalculatedCalibFactor = 17969,
IsCalibFactorValid = true,
Stored = true,
ErrorStr = "OK",
TimeStart = 1.1,
@ -142,6 +143,7 @@ namespace TBFTests
Assert.AreEqual(1, loadedCalib.CalibFactorIndex);
Assert.AreEqual(15625, loadedCalib.BaseCalibFactor);
Assert.AreEqual(17969, loadedCalib.CalculatedCalibFactor);
Assert.IsTrue(loadedCalib.IsCalibFactorValid);
Assert.IsTrue(loadedCalib.Stored);
Assert.AreEqual("OK", loadedCalib.ErrorStr);
}

View File

@ -1,14 +1,11 @@
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Config.Entities;
using GenesisCordonelInterface.API;
using JetBrains.Annotations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TBF.Rig.BridgeComponents.GciBridge;
using Results.Entities;
using TBF.Rig.RegisterReaders.GenesisRegReader.communication;
using TBF.Rig.RegisterReaders.GenesisRegReader.implementations;
using TBF.Rig.Sequences;
using TBF.Rig.TestMethods.GenesisCommunication;
namespace TBFTests.Rig.RegisterReaders.GenesisRegReader.communication
@ -91,34 +88,50 @@ namespace TBFTests.Rig.RegisterReaders.GenesisRegReader.communication
[TestMethod]
public void PrepareQ3Calibration_SimulateMode_ReturnsOk()
{
// ARRANGE
GenesisSmartReader reader = new GenesisSmartReader
{
DebugLevel = Common.DebugMode.Simulate
};
Factory factory = new Factory();
GenesisSmartReader reader = new GenesisSmartReader(factory.DefaultConfig());
reader.DebugLevel = Common.DebugMode.Simulate;
OptoHeadTest optoHeadTest = new OptoHeadTest(reader);
TestMethodCfg cfg = new TestMethodCfg(null)
{
CalibFactor6InchCh1 = 17969,
CalibFactor6InchCh2 = 17969,
CalibFactor6InchCh3 = 17969
};
string result = optoHeadTest.PrepareQ3Calibration(null, null, null);
Test test = new Test
{
Name = "Q3Channel",
Part = 1
};
// ACT
string result = optoHeadTest.PrepareQ3Calibration(cfg, test);
// ASSERT
Assert.AreEqual(OptoHeadTest.ResultOk, result);
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(
OptoHeadTest.ResultOk,
result);
}
[TestMethod]
public void PrepareQ3Calibration_TestStoreDB()
{
GenesisSmartReader reader = new GenesisSmartReader();
Results.Entities.TestRslt tstRslt = new Results.Entities.TestRslt();
Assert.IsNotNull(tstRslt.CalibFactorResultsToSave);
tstRslt.CalibFactorResultsToSave.Clear();
Assert.AreEqual(0, tstRslt.CalibFactorResultsToSave.Count);
if (tstRslt?.CalibFactorResultsToSave?.Count == 0)
{
for (int i = 0; i < reader.ChannelsCount; i++)
{
tstRslt.CalibFactorResultsToSave.Add(new TestRsltCalibFactor()
{
Stored = false,
CalibFactorIndex = i
});
}
}
Assert.AreEqual(reader.ChannelsCount, tstRslt.CalibFactorResultsToSave.Count);
for (int i = 0; i < reader.ChannelsCount; i++)
{
Assert.IsFalse(tstRslt.CalibFactorResultsToSave[i].Stored);
Assert.AreEqual(i, tstRslt.CalibFactorResultsToSave[i].CalibFactorIndex);
}
}
}
}

View File

@ -22,12 +22,15 @@ namespace TBFTests.Rig.RegisterReaders.GenesisRegReader.implementations
var valid = new bool[3];
var calib = new double[3];
var calibDiff = new double[3];
sut.SetQ3Calibration(ValidInitFactors);
sut.GetQ3Calibration(
refVolume: 1000.0,
refTime: 120.0,
initCalibFactor: ValidInitFactors,
200.0,
120.0,
ValidInitFactors,
ref valid,
ref calibDiff,
ref calib);
Assert.IsFalse(sut.Q3CalibValid);
@ -47,12 +50,15 @@ namespace TBFTests.Rig.RegisterReaders.GenesisRegReader.implementations
var valid = new bool[3];
var calib = new double[3];
var calibDiff = new double[3];
sut.SetQ3Calibration(ValidInitFactors);
sut.GetQ3Calibration(
refVolume: 1000.0,
refTime: 120.0,
initCalibFactor: ValidInitFactors,
200.0,
120.0,
ValidInitFactors,
ref valid,
ref calibDiff,
ref calib);
Assert.IsFalse(sut.Q3CalibValid);
@ -70,13 +76,16 @@ namespace TBFTests.Rig.RegisterReaders.GenesisRegReader.implementations
var valid = new bool[3];
var calib = new double[3];
var calibDiff = new double[3];
sut.GetQ3Calibration(
refVolume: 0.0,
refTime: 120.0,
initCalibFactor: ValidInitFactors,
ref valid,
ref calib);
ref calibDiff,
ref calib
);
Assert.IsFalse(sut.Q3CalibValid);
CollectionAssert.AreEqual(new[] { false, false, false }, valid);
@ -93,13 +102,17 @@ namespace TBFTests.Rig.RegisterReaders.GenesisRegReader.implementations
var valid = new bool[3];
var calib = new double[3];
var calibDiff = new double[3];
sut.SetQ3Calibration(ValidInitFactors);
sut.GetQ3Calibration(
refVolume: 1000.0,
refTime: 0.0,
initCalibFactor: ValidInitFactors,
ref valid,
ref calib);
ref calibDiff,
ref calib
);
Assert.IsFalse(sut.Q3CalibValid);
CollectionAssert.AreEqual(new[] { false, false, false }, valid);
@ -117,13 +130,17 @@ namespace TBFTests.Rig.RegisterReaders.GenesisRegReader.implementations
var init = new[] { 0.0, 0.0, 0.0 };
var valid = new bool[3];
var calib = new double[3];
var calibDiff = new double[3];
sut.SetQ3Calibration(ValidInitFactors);
sut.GetQ3Calibration(
refVolume: 1000.0,
refTime: 120.0,
initCalibFactor: init,
ref valid,
ref calib);
ref calibDiff,
ref calib
);
Assert.IsFalse(sut.Q3CalibValid);
CollectionAssert.AreEqual(new[] { false, false, false }, valid);
@ -173,14 +190,19 @@ namespace TBFTests.Rig.RegisterReaders.GenesisRegReader.implementations
var init = new[] { 15625.0, 15625.0, 15625.0 };
var valid = new bool[3];
var calib = new double[3];
var calibDiff = new double[3];
sut.SetQ3Calibration(init);
sut.GetQ3Calibration(
refVolume: 200.0,
refTime: 120.0,
initCalibFactor: init,
ref valid,
ref calib);
ref calibDiff,
ref calib
);
double expectedCh1 = (200.0 / 600.0) * 15625.0;
double expectedCh2 = (200.0 / 600.0) * 15625.0;
double expectedCh3 = (200.0 / 560.0) * 15625.0;
@ -220,12 +242,15 @@ namespace TBFTests.Rig.RegisterReaders.GenesisRegReader.implementations
var init = new[] { 15625.0, 15625.0, 15625.0 };
var valid = new bool[3];
var calib = new double[3];
var calibDiff = new double[3];
sut.SetQ3Calibration(init);
sut.GetQ3Calibration(
refVolume: 200.0,
refTime: 120.0,
initCalibFactor: init,
200.0,
120.0,
init,
ref valid,
ref calibDiff,
ref calib);
Assert.IsTrue(valid[0], $"Ch1 invalid, value={calib[0]}");