fix precision correct factor (Mexico), added diff, correction in percentage in Result Configuration

This commit is contained in:
2026-09-07 14:07:07 +02:00
parent d3c8813012
commit 88b8bc5534
23 changed files with 265 additions and 0 deletions
@@ -48,6 +48,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
public const int EndOptoDataCount = OptoDataBufferSize - StartOptoDataCount;
public const int StartEndFilterSamplesCount2 = 1; //20 /// StartEndFilterSamplesCount = 2 * StartEndFilterSamplesCount2 + 1
public const int FeatureVectorSize = 9;
/// <summary>Default raw ViewCalibration value which represents 100 % according to the iPerl ASIC protocol.</summary>
public const double DefaultCalibFactorNominal = 4096.0;
private const int StartSampleDelaySec = 5;
private const int EndSampleDelayCount = 2;
@@ -94,6 +96,15 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
public string QuantityUnits { get; set; }
public double CalibTarget { get { return iperlHeadCfg.ProcParams.CalibTarget; } }
public double CalibFactorNominal
{
get
{
return iperlHeadCfg != null && iperlHeadCfg.CalibFactorNominal > 0.0
? iperlHeadCfg.CalibFactorNominal
: DefaultCalibFactorNominal;
}
}
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; } }
@@ -157,6 +168,27 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
}
}
/// <summary>Converts the raw two-byte ViewCalibration factor to its percentage representation.</summary>
public static double CalculateCalibFactorPercentage(ushort rawCalibFactor)
{
return CalculateCalibFactorPercentage(rawCalibFactor, DefaultCalibFactorNominal);
}
public static double CalculateCalibFactorPercentage(ushort rawCalibFactor, double nominalCalibFactor)
{
return nominalCalibFactor > 0.0 ? rawCalibFactor * 100.0 / nominalCalibFactor : 0.0;
}
public double CalibFactorPercentage
{
get { return CalculateCalibFactorPercentage(CalibFactor, CalibFactorNominal); }
}
public double CalibFactorCorrectionPercentage
{
get { return CalibFactorPercentage - 100.0; }
}
public ushort OrigCalibFactorLNA;
public ushort CalibFactorLNA { get { return (CalibrationStructV4 != null) ? CalibrationStructV4.CalibrationLNA : (ushort)0; } }
@@ -27,6 +27,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
public int MuxBoardNr; /// 0 = use RfidComPort(Nr), otherwise mux. board nr. 1 .. 4
public int Group; /// Number written to QuidoRS to connct the watermeter to RfidComPort, 1 .. 10
public CommunicationInterface CommunicationInterface; /// Communication Interface: RFID or NFC
public double CalibFactorNominal; /// Raw calibration factor representing 100 % in the results calculation
/// <summary> Procedure parameters </summary>
[XmlIgnore]
@@ -49,6 +50,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
ProcParams = CreateProcParamsProvider() as ProcParams;
CommunicationInterface = CommunicationInterface.RFID;
HeadCommunicationComPortNr = 0;
CalibFactorNominal = IperlHead.DefaultCalibFactorNominal;
}
public IperlHeadCfg(IComponentFactory factory)
@@ -2,6 +2,7 @@
/// Copyright (c) 2015-2017 Sensus Metering Systems
///
using System;
using System.Globalization;
using System.Net;
using System.Windows.Forms;
using Common;
@@ -33,6 +34,10 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
private void WaterMeterCfgCtrl_Load(object sender, EventArgs e)
{
nameLabel.Text = Strings.Name;
calibFactorNominalLabel.Text = GetLocalizedString("IperlCalibFactorNominal", "Default calibration factor:");
string calibFactorNominalTooltip = GetLocalizedString("IperlCalibFactorNominalTooltip", "Raw calibration factor representing 100 %. This value is used to calculate 'iPerl CalibFactor (%)' in the results configuration.");
calibFactorNominalToolTip.SetToolTip(calibFactorNominalLabel, calibFactorNominalTooltip);
calibFactorNominalToolTip.SetToolTip(calibFactorNominalTextBox, calibFactorNominalTooltip);
classNameLabel.Text = config.Factory.ClassName;
Redraw();
}
@@ -55,6 +60,10 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
muxBoardNrTextBox.Text = config.MuxBoardNr.ToString();
groupTextBox.Text = config.Group.ToString();
comboBoxCommunicationInterface.SelectedItem = config.CommunicationInterface.ToString();
double nominalCalibFactor = config.CalibFactorNominal > 0.0
? config.CalibFactorNominal
: IperlHead.DefaultCalibFactorNominal;
calibFactorNominalTextBox.Text = nominalCalibFactor.ToString(CultureInfo.CurrentCulture);
tabPage2.Controls.Add(new IperlHeadTestCtrl(config));
}
@@ -71,6 +80,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
muxBoardNrTextBox.Enabled = true;
groupTextBox.Enabled = true;
comboBoxCommunicationInterface.Enabled = true;
calibFactorNominalTextBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
@@ -127,6 +137,13 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
message += Environment.NewLine + string.Format(Strings.Invalid_0, groupLabel.Text);
}
double nominalCalibFactor;
if (!TryParseDouble(calibFactorNominalTextBox.Text, out nominalCalibFactor) || nominalCalibFactor <= 0.0)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + string.Format(Strings.Invalid_0, calibFactorNominalLabel.Text);
}
return flags;
}
@@ -155,8 +172,22 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
config.Group = int.Parse(groupTextBox.Text);
config.CommunicationInterface = (CommunicationInterface)comboBoxCommunicationInterface.SelectedIndex;
config.HeadCommunicationComPortNr = int.Parse(headPortNrTextBox.Text);
double nominalCalibFactor;
if (TryParseDouble(calibFactorNominalTextBox.Text, out nominalCalibFactor))
config.CalibFactorNominal = nominalCalibFactor;
return flags;
}
private static bool TryParseDouble(string value, out double result)
{
return double.TryParse(value, NumberStyles.Float, CultureInfo.CurrentCulture, out result) ||
double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out result);
}
private static string GetLocalizedString(string resourceName, string fallback)
{
return Strings.ResourceManager.GetString(resourceName, Strings.Culture) ?? fallback;
}
}
}
@@ -31,6 +31,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.label4 = new System.Windows.Forms.Label();
@@ -60,6 +61,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label();
this.headPortNrTextBox = new System.Windows.Forms.TextBox();
this.calibFactorNominalLabel = new System.Windows.Forms.Label();
this.calibFactorNominalTextBox = new System.Windows.Forms.TextBox();
this.calibFactorNominalToolTip = new System.Windows.Forms.ToolTip(this.components);
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.groupBox1.SuspendLayout();
@@ -80,6 +84,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
// tabPage1
//
this.tabPage1.Controls.Add(this.groupBox2);
this.tabPage1.Controls.Add(this.calibFactorNominalTextBox);
this.tabPage1.Controls.Add(this.calibFactorNominalLabel);
this.tabPage1.Controls.Add(this.label4);
this.tabPage1.Controls.Add(this.label3);
this.tabPage1.Controls.Add(this.groupBox1);
@@ -364,6 +370,23 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
this.groupBox2.TabIndex = 26;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Head Communication";
//
// calibFactorNominalLabel
//
this.calibFactorNominalLabel.AutoSize = true;
this.calibFactorNominalLabel.Location = new System.Drawing.Point(290, 76);
this.calibFactorNominalLabel.Name = "calibFactorNominalLabel";
this.calibFactorNominalLabel.Size = new System.Drawing.Size(142, 16);
this.calibFactorNominalLabel.TabIndex = 27;
this.calibFactorNominalLabel.Text = "Default calibration factor:";
//
// calibFactorNominalTextBox
//
this.calibFactorNominalTextBox.Enabled = false;
this.calibFactorNominalTextBox.Location = new System.Drawing.Point(290, 96);
this.calibFactorNominalTextBox.Name = "calibFactorNominalTextBox";
this.calibFactorNominalTextBox.Size = new System.Drawing.Size(92, 22);
this.calibFactorNominalTextBox.TabIndex = 28;
//
// label2
//
@@ -437,5 +460,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox headPortNrTextBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label calibFactorNominalLabel;
private System.Windows.Forms.TextBox calibFactorNominalTextBox;
private System.Windows.Forms.ToolTip calibFactorNominalToolTip;
}
}