diff --git a/Results/Entities/WaterMeter.cs b/Results/Entities/WaterMeter.cs index 9170ace6b..e5bf0eb96 100644 --- a/Results/Entities/WaterMeter.cs +++ b/Results/Entities/WaterMeter.cs @@ -134,8 +134,10 @@ namespace Results.Entities public virtual double Q3_Qn_Aux() { return WaterMeterData.Q3_Qn_Aux; } public virtual string MetrologicalClassAux() { return WaterMeterData.MetrologicalClassAux; } public virtual string ApprovalInfoAux() { return WaterMeterData.ApprovalInfoAux; } - - public virtual int BatchNr() { return Batch.BatchNr; } +#if ORACLE_DB + public virtual int WMTypeId() { return WaterMeterData.WMTypeId; } +#endif + public virtual int BatchNr() { return Batch.BatchNr; } public virtual int BenchId() { return Batch.TestBenchId; } public virtual string ProcedureName() { return Batch.ProcedureName; } public virtual int ProcedureRevision() { return Batch.ProcedureRevision; } diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index 97947fef1..6d3555224 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2015-2021 Sensus Slovensko a.s. +/// Copyright (c) 2015-2023 Sensus Slovensko a.s. /// //#define VERIFY_ACTIVE_MODE //#define VERIFY_Q2_CORR_RESET @@ -8,25 +8,22 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Globalization; -using System.Runtime.InteropServices; -using System.Text; +using System.Linq; +using System.Text.RegularExpressions; using System.Threading; using System.Windows.Forms; using log4net; using Common; -using Config; using Config.Entities; using TBF.Resources; using TBF.Rig.Sequences; using TBF.Rig.TestMethods.iPerlCommunication.iPerlHead; +using Sensus.iPerl.RfidCom; using Sensus.iPerl.RfidCom.Exceptions; using Sensus.iPerl.RfidCom.Helper; -using Sensus.iPerl.RfidCom; -using System.Text.RegularExpressions; -using Sensus.iPerl.RfidCom.Services; -using System.Threading.Tasks; -using Sensus.iPerl.RfidCom.Structures; using Sensus.iPerl.RfidCom.Model.Enums; +using Sensus.iPerl.RfidCom.Services; +using Sensus.iPerl.RfidCom.Structures; namespace TBF.Rig.TestMethods.iPerlCommunication { @@ -2003,6 +2000,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } } + var q3mtr = wm.MeterTestRslts.FirstOrDefault(x => x.Name() == "Q3"); + double q3error = (q3mtr != null) ? q3mtr.Error : 0; Results.Entities.MeterTestRslt q2adjResult2 = null; /// 2nd test name for a test in L-R direction Results.Entities.TestData q2adjTestData2 = null; @@ -2069,12 +2068,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication (q2adjResult2 != null && (q2adjResult2.Error < errLimitLo || errLimitHi < q2adjResult2.Error))) { /// At least one of Q2 errors is out of range for Q2 correction - log.WarnFormat("OoR => no Q2 correction: Pos={0}, PCB#={1}, ***Q2_RL err={2}%***, ***Q2_LR err={3}%***, CalTarget={4}%, [Lo={5}%, Hi={6}%]", + log.WarnFormat("OoR => no Q2 correction: Pos={0}, PCB#={1}, ***Q2_RL err={2}%***, ***Q2_LR err={3}%***, [Lo={4}%, Hi={5}%]", ihead.Name, ihead.SerialNr, q2adjResult.Error.ToString("F2"), q2adjResult2 != null ? q2adjResult2.Error.ToString("F2") : string.Empty, - ihead.CalibTargetQ2.ToString("F1"), errLimitLo.ToString("F2"), errLimitHi.ToString("F2")); @@ -2099,14 +2097,14 @@ namespace TBF.Rig.TestMethods.iPerlCommunication if (q2CorrType == Q2CorrType.Update || q2CorrType == Q2CorrType.ConditionalUpdate) { /// Calculate two Q2 correction factors from two tests done in both directions - q2Correction = ihead.CalculateQ2CorrectionFactor(q2adjResult, ihead.CalibTargetQ2, q2adjTestData.Qfrom, q2adjResult.Q2CorrRL); - q2Correction2 = ihead.CalculateQ2CorrectionFactor(q2adjResult2, ihead.CalibTargetQ2, q2adjTestData2.Qfrom, q2adjResult2.Q2CorrLR); + q2Correction = ihead.CalculateQ2CorrectionFactor(q2adjResult, q2adjTestData.Qfrom, q2adjResult.Q2CorrRL); + q2Correction2 = ihead.CalculateQ2CorrectionFactor(q2adjResult2, q2adjTestData2.Qfrom, q2adjResult2.Q2CorrLR); } else { /// Calculate Q2 correction factors from a single test - q2Correction = ihead.CalculateQ2CorrectionFactor(q2adjResult, ihead.CalibTargetQ2, q2adjTestData.Qfrom, q2adjResult.Q2CorrRL); - q2Correction2 = ihead.CalculateQ2CorrectionFactor(q2adjResult, ihead.CalibTargetQ2, q2adjTestData.Qfrom, q2adjResult.Q2CorrLR); + q2Correction = ihead.CalculateQ2CorrectionFactor(q2adjResult, q2adjTestData.Qfrom, q2adjResult.Q2CorrRL); + q2Correction2 = ihead.CalculateQ2CorrectionFactor(q2adjResult, q2adjTestData.Qfrom, q2adjResult.Q2CorrLR); } @@ -2121,7 +2119,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// /// Standard process /// - if (q2CorrType == Q2CorrType.Standard && Math.Abs(q2adjResult.Error - ihead.CalibTargetQ2) <= 0.5) + if (q2CorrType == Q2CorrType.Standard && Math.Abs(q2adjResult.Error) <= 0.5) { resultStr = string.Format("Q2 correction = 0 (writing bypassed)"); return CommErr.None; @@ -2137,7 +2135,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// /// Process for DEWA /// - if (q2CorrType == Q2CorrType.Dewa && Math.Abs(q2adjResult.Error - ihead.CalibTargetQ2) <= 0.5) + if (q2CorrType == Q2CorrType.Dewa && Math.Abs(q2adjResult.Error) <= 0.5) { resultStr = string.Format("Q2 correction = 0 (writing bypassed)"); return CommErr.None; @@ -2152,7 +2150,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// /// Process for Greece /// - if (q2CorrType == Q2CorrType.Greece && Math.Abs(q2adjResult.Error - ihead.CalibTargetQ2) <= 0.5) + if (q2CorrType == Q2CorrType.Greece && Math.Abs(q2adjResult.Error) <= 0.5) { resultStr = string.Format("Q2 correction = 0 (writing bypassed)"); return CommErr.None; @@ -2163,7 +2161,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } else if (q2CorrType == Q2CorrType.RL || q2CorrType == Q2CorrType.RL_incl_05 || q2CorrType == Q2CorrType.ConditionalUpdateRL) /// RL only { - if (q2CorrType == Q2CorrType.RL && Math.Abs(q2adjResult.Error - ihead.CalibTargetQ2) <= 0.5) + if (q2CorrType == Q2CorrType.RL && Math.Abs(q2adjResult.Error) <= 0.5) { resultStr = string.Format("Q2 correction = 0 (writing bypassed)"); return CommErr.None; @@ -2173,7 +2171,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } else if (q2CorrType == Q2CorrType.LR || q2CorrType == Q2CorrType.LR_incl_05 || q2CorrType == Q2CorrType.ConditionalUpdateLR) /// LR only { - if (q2CorrType == Q2CorrType.LR && Math.Abs(q2adjResult.Error - ihead.CalibTargetQ2) <= 0.5) + if (q2CorrType == Q2CorrType.LR && Math.Abs(q2adjResult.Error) <= 0.5) { resultStr = string.Format("Q2 correction = 0 (writing bypassed)"); return CommErr.None; @@ -2570,16 +2568,10 @@ namespace TBF.Rig.TestMethods.iPerlCommunication if (!ProcessData.IsQ2PreCorrectionCalculated) { ProcessData.IsQ2PreCorrectionCalculated = true; - commonWMType = ihead.WMType_ID; - bool success = iPerlCommunicationSeq.GetQ2PreCorrectionsOrBackups(cfg, commonWMType, + bool success = iPerlCommunicationSeq.GetQ2PreCorrectionsOrBackups(cfg, wm.WMTypeId(), out ProcessData.CalculatedQ2PreCorrectionLR, out ProcessData.CalculatedQ2PreCorrectionRL); } - else if (ihead.WMType_ID != commonWMType) - { - resultStr = string.Format("Different WZ_Typ: {0} ({1} expected)", ihead.WMType_ID, commonWMType); - return CommErr.WrongIPerlType; - } resultStr = string.Format("Q2 pre-corrections: LR={0} RL={1}", ProcessData.CalculatedQ2PreCorrectionLR, ProcessData.CalculatedQ2PreCorrectionRL); return CommErr.None; @@ -2765,9 +2757,6 @@ namespace TBF.Rig.TestMethods.iPerlCommunication if (meterRslt != null && iperlHeads[i] != null) { -#if ORACLE_DB - meterRslt.WaterMeter.WaterMeterData.WMTypeId = iperlHeads[i].WMType_ID; -#endif meterRslt.WaterMeter.SerialNr = iperlHeads[i].SerialNr; meterRslt.Passed = (!iperlHeads[i].CommFailed && !iperlHeads[i].Disabled); meterRslt.TestDone = true; diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs index a6535500d..ef8777621 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs @@ -11,6 +11,7 @@ using RestClient; using TBF.Rig.Sequences; using TBF.Resources; using TBF.UiBridge; +using Results; namespace TBF.Rig.TestMethods.iPerlCommunication { @@ -71,15 +72,12 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// Get 'wmType' from IperlHead procedure parameters int wmType = 0; - if (IperlHeads != null) + foreach (var wm in ProcessData.BatchRslts.Batch.WaterMeters) { - foreach (var ih in IperlHeads) + if (wm != null && !wm.Disabled && wm.WMTypeId() > 0) { - if (ih.WMType_ID > 0) - { - wmType = ih.WMType_ID; - break; - } + wmType = wm.WMTypeId(); + break; } } @@ -601,14 +599,12 @@ namespace TBF.Rig.TestMethods.iPerlCommunication else if (isPlus) { /// iPerl with Q2 correction => generate an artificial error equal to +1/10 of the original one (relative to Q2 target error) - double targetError = iPerl.CalibTargetQ2; - meterRslt.Error = targetError + 0.1 * (oriMeterRslt.Error - targetError); + meterRslt.Error = 0.1 * oriMeterRslt.Error; } else { /// iPerl with Q2 correction => generate an artificial error equal to -1/10 of the original one (relative to Q2 target error) - double targetError = iPerl.CalibTargetQ2; - meterRslt.Error = targetError - 0.1 * (oriMeterRslt.Error - targetError); + meterRslt.Error = - 0.1 * oriMeterRslt.Error; } meterRslt.VolumeMeter = meterRslt.VolumeRef * (100.0 + meterRslt.Error) / 100.0; @@ -897,14 +893,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication meterRslt.TestDone = meterRsltQ2ac.TestDone; tstRslt.TestDone = true; - double targetError = 0; - if ((sensPath != null) && (sensPath.RegisterReaders != null) && (sensPath.RegisterReaders.Length > i) && (sensPath.RegisterReaders[i] is iPerlHead.IperlHead)) - { - targetError = (sensPath.RegisterReaders[i] as iPerlHead.IperlHead).CalibTargetQ2; - } - - if ((((meterRsltQ2bc.Error - targetError) < -0.51) && (meterRsltQ2ac.Error < meterRsltQ2bc.Error)) || - (((meterRsltQ2bc.Error - targetError) > +0.51) && (meterRsltQ2ac.Error > meterRsltQ2bc.Error))) + if (((meterRsltQ2bc.Error < -0.51) && (meterRsltQ2ac.Error < meterRsltQ2bc.Error)) || + ((meterRsltQ2bc.Error > +0.51) && (meterRsltQ2ac.Error > meterRsltQ2bc.Error))) { meterRslt.Passed = false; /// Q2 correction check failed } diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs index 05fdfb139..db58c13de 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs @@ -58,11 +58,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead public double LtrsPerPulse { get { return 1 / PulsesPerLtr; } } public double CalibTarget { get { return iperlHeadCfg.ProcParams.CalibTarget; } } - public double CalibTargetQ2 { get { return iperlHeadCfg.ProcParams.CalibTargetQ2; } } public ushort FactorLimitLo { get { return (ushort)iperlHeadCfg.ProcParams.FactorLimitLo; } } public ushort FactorLimitHi { get { return (ushort)iperlHeadCfg.ProcParams.FactorLimitHi; } } public Counting InitFlowDir { get { return (iperlHeadCfg != null && iperlHeadCfg.ProcParams != null) ? iperlHeadCfg.ProcParams.Counting : Counting.Arbitrary; } } - public int WMType_ID { get { return iperlHeadCfg.ProcParams.WMType_ID; } } /// Required by Oracle DB /// Properties set by the Begin and the End form @@ -215,11 +213,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead /// Nominal flow in m3/h /// 0 or the current Q2 correction factor when updating the factor /// Calculated Q2 correction factor - public double CalculateQ2CorrectionFactor(Results.Entities.MeterTestRslt q2adjResult, double calibTarget, double nominalFlow, int currentFactor = 0) + public double CalculateQ2CorrectionFactor(Results.Entities.MeterTestRslt q2adjResult, double nominalFlow, int currentFactor = 0) { - double nominalTestFlowLph = Common.Units.ConvertTo(Common.Unit.lph, nominalFlow); - double volumeRefShiftedToTarget = q2adjResult.VolumeRef * (1.0 + calibTarget / 100.0); - double q2adjErrorShiftedToTarget = Config.Formulas.ErrorFromVolumes(q2adjResult.VolumeMeter, volumeRefShiftedToTarget); + double nominalTestFlowLph = Units.ConvertTo(Unit.lph, nominalFlow); double A = 16.0 / ScalingFactor(); /// Raw units per ml: DN15=16, DN20=8, DN25=4, DN32=2, DN40=1 const double B = 8.0; /// Raw units per minute, 8 @@ -229,13 +225,12 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead double G = F / B; /// Error corrected with 1 Raw Unit per minute [%] double q2CorrectionFactor = Convert.ToDouble(currentFactor) - - (q2adjErrorShiftedToTarget / G) * (volumeRefShiftedToTarget / q2adjResult.VolumeMeter); + - (q2adjResult.Error / G) * (q2adjResult.VolumeRef / q2adjResult.VolumeMeter); - log.WarnFormat("CalculateQ2CorrectionFactor() : Pos={0}, PCB#={1}, Error={2}%, CalTarget={3}%, Q2CorrFactor={4}", + log.WarnFormat("CalculateQ2CorrectionFactor() : Pos={0}, PCB#={1}, Error={2}%, Q2CorrFactor={3}", Name, SerialNr, q2adjResult.Error.ToString("F2"), - calibTarget.ToString("F1"), q2CorrectionFactor.ToString("F1")); return q2CorrectionFactor; diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/ProcParams.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/ProcParams.cs index 291b8b7ec..446898dd5 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/ProcParams.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/ProcParams.cs @@ -18,33 +18,27 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead public MeterType MeterType; public float CalibTarget; /// Target error after calibration in [%] - public float CalibTargetQ2; /// Target error at Q2 after Q2 correction in [%] public int FactorLimitLo; /// Lower limit for the calibration factor public int FactorLimitHi; /// Upper limit for the calibration factor public Counting Counting; /// Initial iPerl counting (Artbitrary, Positive or Negative) - public int WMType_ID; /// Required for Oracle DB: ID_WZTyp in table VT_PRUEFPUNKT_SOLL_SD public override void InitializeAll() { MeterType = MeterType.AutoDetect; CalibTarget = 0; - CalibTargetQ2 = 0; FactorLimitLo = 1000; FactorLimitHi = 8000; Counting = Counting.Arbitrary; - WMType_ID = 2; /// Value for iPerl DN15 } string[] paramNames = new string[] { "iPerl type", "Calib. target [%]", - "Calib. target at Q2 [%]", "Calib. factor Lo", "Calib. factor Hi", "Counting", - "WM type ID", }; public override string ParamName(int i) { return paramNames[i]; } public override int ParamsCount() { return paramNames.Length; } @@ -72,11 +66,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead { case 0: return MeterType.ToString(); case 1: return CalibTarget.ToString(); - case 2: return CalibTargetQ2.ToString(); - case 3: return FactorLimitLo.ToString(); - case 4: return FactorLimitHi.ToString(); - case 5: return Counting.ToString(); - case 6: return WMType_ID.ToString(); + case 2: return FactorLimitLo.ToString(); + case 3: return FactorLimitHi.ToString(); + case 4: return Counting.ToString(); default: return string.Empty; } } @@ -92,16 +84,14 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead } break; case 1: CalibTarget = Utils.ParseSFloat(strValue); return CfgUpdateFlags.None; - case 2: CalibTargetQ2 = Utils.ParseSFloat(strValue); return CfgUpdateFlags.None; - case 3: FactorLimitLo = int.Parse(strValue); return CfgUpdateFlags.None; - case 4: FactorLimitHi = int.Parse(strValue); return CfgUpdateFlags.None; - case 5: + case 2: FactorLimitLo = int.Parse(strValue); return CfgUpdateFlags.None; + case 3: FactorLimitHi = int.Parse(strValue); return CfgUpdateFlags.None; + case 4: for (Counting c = 0; c < Counting.Count; c++) { if (c.ToString().Equals(strValue)) { Counting = c; return CfgUpdateFlags.None; } } break; - case 6: WMType_ID = int.Parse(strValue); return CfgUpdateFlags.None; default: return CfgUpdateFlags.None; } @@ -121,18 +111,14 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead for (MeterType mt = 0; mt < MeterType.Count; mt++) if (mt.ToString().Equals(strValue)) return true; break; case 1: - case 2: if (Utils.TryParseSFloat(strValue, out fDummy) && fDummy >= -10.0f && fDummy <= 10.0f) return true; break; + case 2: case 3: - case 4: if (int.TryParse(strValue, out iDummy) && iDummy >= 1000 && iDummy <= 8000) return true; break; - case 5: + case 4: for (Counting c = 0; c < Counting.Count; c++) if (c.ToString().Equals(strValue)) return true; - break; - case 6: /// WMType_ID - if (int.TryParse(strValue, out iDummy)) return true; break; default: message = "Invalid index"; @@ -147,11 +133,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead { prms.MeterType = this.MeterType; prms.CalibTarget = this.CalibTarget; - prms.CalibTargetQ2 = this.CalibTargetQ2; prms.FactorLimitLo = this.FactorLimitLo; prms.FactorLimitHi = this.FactorLimitHi; prms.Counting = this.Counting; - prms.WMType_ID = this.WMType_ID; } public IParamsProvider Clone() diff --git a/TBF/UI/Procedures/ProcedureDlg.cs b/TBF/UI/Procedures/ProcedureDlg.cs index c73f99f9d..a506158d2 100644 --- a/TBF/UI/Procedures/ProcedureDlg.cs +++ b/TBF/UI/Procedures/ProcedureDlg.cs @@ -3122,7 +3122,6 @@ namespace TBF.UI.Procedures var ihpp = pp as TBF.Rig.TestMethods.iPerlCommunication.iPerlHead.ProcParams; if (ihpp != null) { - ihpp.WMType_ID = oracleDlg.WMTypeId; ihpp.MeterType = oracleDlg.MeterType; }