348 lines
9.8 KiB
C#
348 lines
9.8 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.Various.ErrorFlags
|
|
{
|
|
public class TestParams : TestParamsBase, IParamsProvider, ITestParams
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TestParams) })[0];
|
|
protected override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public ErrorFlagsMode Mode; /// 0 = Off, 1 = Info (show only), 2 = On (show and evaluate)
|
|
public bool E1;
|
|
public bool E2;
|
|
public bool E3;
|
|
public bool E4;
|
|
public bool E5;
|
|
public bool E6;
|
|
public bool E7;
|
|
public bool E8;
|
|
public bool E9;
|
|
public bool E10;
|
|
public bool E11;
|
|
public bool E12;
|
|
public bool E13;
|
|
public bool E14;
|
|
public bool E15;
|
|
public bool E16;
|
|
|
|
public float Delta_Q_pct; /// [%] max deviation from the mean flow
|
|
public float Delta_T; /// [°C] max. T_up or T_down deviation from the mean temperature
|
|
public float Delta_Tup_Tdn; /// [°C] max. difference abs(T_up - T_down)
|
|
public float TestTime_min; /// [s]
|
|
public float TestTime_max; /// [s]
|
|
public float AmbTemp_min; /// [°C] min. ambient temperature
|
|
public float AmbTemp_max; /// [°C] max. ambient temperature
|
|
public float Pressure_min; /// [bar] min. water pressure
|
|
public float Pressure_max; /// [bar] max. water pressure
|
|
|
|
public float Coef_E9; /// Coefficient used in E9, default 0.025
|
|
public float Coef_E10; /// Coefficient used in E10, default 0.04
|
|
public float Coef_E11; /// Coefficient used in E11, default 0.1
|
|
public float Coef_E12; /// Coefficient used in E12, default 1
|
|
|
|
public override void InitializeAll()
|
|
{
|
|
Mode = ErrorFlagsMode.On;
|
|
E1 = true;
|
|
E2 = true;
|
|
E3 = true;
|
|
E4 = true;
|
|
E5 = true;
|
|
E6 = true;
|
|
E7 = true;
|
|
E8 = true;
|
|
E9 = true;
|
|
E10 = true;
|
|
E11 = true;
|
|
E12 = true;
|
|
E13 = true;
|
|
E14 = true;
|
|
E15 = true;
|
|
E16 = true;
|
|
|
|
Delta_Q_pct = 2.5f; /// [%]
|
|
Delta_T = 10.0f; /// [°C]
|
|
Delta_Tup_Tdn = 10.0f; /// [°C]
|
|
TestTime_min = 0; /// [s]
|
|
TestTime_max = 99999; /// [s]
|
|
AmbTemp_min = 5.0f; /// [°C]
|
|
AmbTemp_max = 95.0f; /// [°C]
|
|
Pressure_min = 0; /// [bar]
|
|
Pressure_max = 16.0f; /// [bar]
|
|
|
|
Coef_E9 = 0.025f;
|
|
Coef_E10 = 0.04f;
|
|
Coef_E11 = 0.1f;
|
|
Coef_E12 = 1.0f;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
Strings.Mode,
|
|
"E1",
|
|
"E2",
|
|
"E3",
|
|
"E4",
|
|
"E5",
|
|
"E6",
|
|
"E7",
|
|
"E8",
|
|
"E9",
|
|
"E10",
|
|
"E11",
|
|
"E12",
|
|
"E13",
|
|
"E14",
|
|
"E15",
|
|
"E16",
|
|
|
|
"Delta Q [%]",
|
|
"Delta T [°C]",
|
|
"max. Abs(Tup - Tdn) [°C]",
|
|
string.Format("min. {0} [s]", Strings.Test_time_s_chdr),
|
|
string.Format("max. {0} [s]", Strings.Test_time_s_chdr),
|
|
string.Format("min. {0}", Strings.Ambient_temp_C_),
|
|
string.Format("max. {0}", Strings.Ambient_temp_C_),
|
|
string.Format("min. {0}", Strings.Pressure_bar),
|
|
string.Format("max. {0}", Strings.Pressure_bar),
|
|
|
|
"Coef.E9",
|
|
"Coef.E10",
|
|
"Coef.E11",
|
|
"Coef.E12"
|
|
};
|
|
public override string ParamName(int i) { return paramNames[i]; }
|
|
public override int ParamsCount() { return paramNames.Length; }
|
|
|
|
public override string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return Mode.ToDescription();
|
|
case 1: return (E1 ? Strings.yes : Strings.no);
|
|
case 2: return (E2 ? Strings.yes : Strings.no);
|
|
case 3: return (E3 ? Strings.yes : Strings.no);
|
|
case 4: return (E4 ? Strings.yes : Strings.no);
|
|
case 5: return (E5 ? Strings.yes : Strings.no);
|
|
case 6: return (E6 ? Strings.yes : Strings.no);
|
|
case 7: return (E7 ? Strings.yes : Strings.no);
|
|
case 8: return (E8 ? Strings.yes : Strings.no);
|
|
case 9: return (E9 ? Strings.yes : Strings.no);
|
|
case 10: return (E10 ? Strings.yes : Strings.no);
|
|
case 11: return (E11 ? Strings.yes : Strings.no);
|
|
case 12: return (E12 ? Strings.yes : Strings.no);
|
|
case 13: return (E13 ? Strings.yes : Strings.no);
|
|
case 14: return (E14 ? Strings.yes : Strings.no);
|
|
case 15: return (E15 ? Strings.yes : Strings.no);
|
|
case 16: return (E16 ? Strings.yes : Strings.no);
|
|
|
|
case 17: return Delta_Q_pct.ToString();
|
|
case 18: return Delta_T.ToString();
|
|
case 19: return Delta_Tup_Tdn.ToString();
|
|
case 20: return TestTime_min.ToString();
|
|
case 21: return TestTime_max.ToString();
|
|
case 22: return AmbTemp_min.ToString();
|
|
case 23: return AmbTemp_max.ToString();
|
|
case 24: return Pressure_min.ToString();
|
|
case 25: return Pressure_max.ToString();
|
|
case 26: return Coef_E9.ToString();
|
|
case 27: return Coef_E10.ToString();
|
|
case 28: return Coef_E11.ToString();
|
|
case 29: return Coef_E12.ToString();
|
|
|
|
default: return string.Empty;
|
|
}
|
|
}
|
|
|
|
/// Retrieves parameters from UI controls
|
|
public void UpdateParam(int i, string strValue)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
for (ErrorFlagsMode m = 0; m < ErrorFlagsMode.Count; m++)
|
|
{
|
|
if (m.ToDescription() == strValue)
|
|
{
|
|
Mode = m;
|
|
return;
|
|
}
|
|
}
|
|
return;
|
|
case 1: E1 = (strValue == Strings.yes); return;
|
|
case 2: E2 = (strValue == Strings.yes); return;
|
|
case 3: E3 = (strValue == Strings.yes); return;
|
|
case 4: E4 = (strValue == Strings.yes); return;
|
|
case 5: E5 = (strValue == Strings.yes); return;
|
|
case 6: E6 = (strValue == Strings.yes); return;
|
|
case 7: E7 = (strValue == Strings.yes); return;
|
|
case 8: E8 = (strValue == Strings.yes); return;
|
|
case 9: E9 = (strValue == Strings.yes); return;
|
|
case 10: E10 = (strValue == Strings.yes); return;
|
|
case 11: E11 = (strValue == Strings.yes); return;
|
|
case 12: E12 = (strValue == Strings.yes); return;
|
|
case 13: E13 = (strValue == Strings.yes); return;
|
|
case 14: E14 = (strValue == Strings.yes); return;
|
|
case 15: E15 = (strValue == Strings.yes); return;
|
|
case 16: E16 = (strValue == Strings.yes); return;
|
|
|
|
case 17: Delta_Q_pct = Utils.ParseUFloat(strValue); return;
|
|
case 18: Delta_T = Utils.ParseUFloat(strValue); return;
|
|
case 19: Delta_Tup_Tdn = Utils.ParseUFloat(strValue); return;
|
|
case 20: TestTime_min = Utils.ParseUFloat(strValue); return;
|
|
case 21: TestTime_max = Utils.ParseUFloat(strValue); return;
|
|
case 22: AmbTemp_min = Utils.ParseUFloat(strValue); return;
|
|
case 23: AmbTemp_max = Utils.ParseUFloat(strValue); return;
|
|
case 24: Pressure_min = Utils.ParseUFloat(strValue); return;
|
|
case 25: Pressure_max = Utils.ParseUFloat(strValue); return;
|
|
case 26: Coef_E9 = Utils.ParseUFloat(strValue); return;
|
|
case 27: Coef_E10 = Utils.ParseUFloat(strValue); return;
|
|
case 28: Coef_E11 = Utils.ParseUFloat(strValue); return;
|
|
case 29: Coef_E12 = Utils.ParseUFloat(strValue); return;
|
|
|
|
default: return;
|
|
}
|
|
}
|
|
|
|
/// Verifies whether strings in UI controls represent valid parameters
|
|
public bool ValidateParam(int i, string strValue, out string message)
|
|
{
|
|
message = string.Empty;
|
|
|
|
float fdummy;
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
for (ErrorFlagsMode m = 0; m < ErrorFlagsMode.Count; m++)
|
|
{
|
|
if (m.ToDescription() == strValue) return true;
|
|
}
|
|
break;
|
|
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
case 4:
|
|
case 5:
|
|
case 6:
|
|
case 7:
|
|
case 8:
|
|
case 9:
|
|
case 10:
|
|
case 11:
|
|
case 12:
|
|
case 13:
|
|
case 14:
|
|
case 15:
|
|
case 16:
|
|
if (strValue == Strings.yes || strValue == Strings.no) return true;
|
|
break;
|
|
|
|
case 17:
|
|
case 18:
|
|
case 19:
|
|
case 20:
|
|
case 21:
|
|
case 22:
|
|
case 23:
|
|
case 24:
|
|
case 25:
|
|
case 26:
|
|
case 27:
|
|
case 28:
|
|
case 29:
|
|
if (Utils.TryParseUFloat(strValue, out fdummy)) return true;
|
|
break;
|
|
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(TestParams prms)
|
|
{
|
|
prms.Mode = this.Mode;
|
|
prms.E1 = this.E1;
|
|
prms.E2 = this.E2;
|
|
prms.E3 = this.E3;
|
|
prms.E4 = this.E4;
|
|
prms.E5 = this.E5;
|
|
prms.E6 = this.E6;
|
|
prms.E7 = this.E7;
|
|
prms.E8 = this.E8;
|
|
prms.E9 = this.E9;
|
|
prms.E10 = this.E10;
|
|
prms.E11 = this.E11;
|
|
prms.E12 = this.E12;
|
|
prms.E13 = this.E13;
|
|
prms.E14 = this.E14;
|
|
prms.E15 = this.E15;
|
|
prms.E16 = this.E16;
|
|
|
|
prms.Delta_Q_pct = this.Delta_Q_pct;
|
|
prms.Delta_T = this.Delta_T;
|
|
prms.Delta_Tup_Tdn = this.Delta_Tup_Tdn;
|
|
prms.TestTime_min = this.TestTime_min;
|
|
prms.TestTime_max = this.TestTime_max;
|
|
prms.AmbTemp_min = this.AmbTemp_min;
|
|
prms.AmbTemp_max = this.AmbTemp_max;
|
|
prms.Pressure_min = this.Pressure_min;
|
|
prms.Pressure_max = this.Pressure_max;
|
|
prms.Coef_E9 = this.Coef_E9;
|
|
prms.Coef_E10 = this.Coef_E10;
|
|
prms.Coef_E11 = this.Coef_E11;
|
|
prms.Coef_E12 = this.Coef_E12;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
TestParams pars = new TestParams();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public override void UpdateTestParams(ComponentTest dbEntity)
|
|
{
|
|
if (dbEntity == null) return;
|
|
try
|
|
{
|
|
TestParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as TestParams;
|
|
|
|
testParamsEntity = dbEntity;
|
|
componentName = dbEntity.CmpntName;
|
|
test = dbEntity.Test;
|
|
|
|
if (tmp != null) tmp.CopyContentTo(this);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
public TestParams() { }
|
|
|
|
public TestParams(bool initialize)
|
|
{
|
|
if (initialize) InitializeAll();
|
|
}
|
|
|
|
public TestParams(ComponentProcedure procedureParamsEntity, string componentName, Test test)
|
|
{
|
|
this.testParamsEntity = testParamsEntity;
|
|
this.componentName = componentName;
|
|
this.test = test;
|
|
}
|
|
}
|
|
}
|