Q2 correction

This commit is contained in:
Milan Hanajik 2015-08-22 06:32:55 +02:00
parent d390705df8
commit f3dabcbcc1
3 changed files with 45 additions and 7 deletions

View File

@ -447,15 +447,17 @@ namespace TBF.BenchControl.TestMethods.FlyingStartCollectionMethod
tstRslt.TimeDivEnd5 = 0;
for (int i = 0; i < Program.WMsCount; i++)
{
WaterMeters.iPerl.WaterMeter iPerl = (sensPath.RegisterReaders[i] as WaterMeters.iPerl.WaterMeter); /// != null for iPerl
if ((sensPath.RegisterReaders[i] != null) && (WaterMeters.Count > i) && !WaterMeters[i].Disabled)
{
tstRslt.Meters[i].SerialNr = (WaterMeters.Count > i) ? WaterMeters[i].SerialNr : string.Empty;
tstRslt.Meters[i].VolumeStart = 0; /// liter
tstRslt.Meters[i].VolumeEnd = 0; /// liter
tstRslt.Meters[i].PulsesPerLiter = (sensPath.RegisterReaders[i] == null ? 1.0f : sensPath.RegisterReaders[i].PulsesPerLtr);
if (sensPath.RegisterReaders[i] is WaterMeters.iPerl.WaterMeter)
tstRslt.Meters[i].PulsesPerLiter = (sensPath.RegisterReaders[i] == null ? 1.0f : sensPath.RegisterReaders[i].PulsesPerLtr);
if (iPerl != null)
{
WaterMeters.iPerl.WaterMeter iPerl = (sensPath.RegisterReaders[i] as WaterMeters.iPerl.WaterMeter);
tstRslt.Meters[i].VolumeMeter = (float)Math.Abs(iPerl.VolumeLtrEnd - iPerl.VolumeLtrStart);
tstRslt.Meters[i].VolumeRef = tstRslt.VolumeCTV * (float)(iPerl.TimestampSecEnd - iPerl.TimestampSecStart) / tstRslt.Time;
iPerl.VolumeLtrRef = (double)tstRslt.Meters[i].VolumeRef;
@ -466,6 +468,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartCollectionMethod
else tstRslt.Meters[i].VolumeMeter = Convert.ToSingle(WMPulses[i]) / sensPath.RegisterReaders[i].PulsesPerLtr;
tstRslt.Meters[i].VolumeRef = tstRslt.ConstMaster * WMRefPulses[i]; /// liter
}
tstRslt.Meters[i].PulsesMeter = WMPulses[i];
tstRslt.Meters[i].PulsesMaster = WMRefPulses[i];
tstRslt.Meters[i].Time = cBrd.TTime;
@ -487,6 +490,12 @@ namespace TBF.BenchControl.TestMethods.FlyingStartCollectionMethod
{
tstRslt.Meters[i].Disabled = true;
}
if (iPerl != null)
{
iPerl.LastTestResult = tstRslt.Meters[i]; /// Save this water meter test result to iPerl WM
iPerl.NominalTestFlow = 500.0 * (double)(test.Qfrom + test.Qto); /// Ave. + convert to liter/hour
}
}
/// Add data - end

View File

@ -861,8 +861,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
CommErr error = CommErr.Write;
/// Write zero Q2 correction
Byte q2CorrRFlow = 0;
Byte q2CorrLFlow = 0;
double q2CorrectionFactor = wm.Q2CorrectionFactor();
Byte q2CorrRFlow = (byte)((int)(q2CorrectionFactor / 2 + 0.5) & 0x000000FF);
Byte q2CorrLFlow = (byte)((int)(q2CorrectionFactor + 0.5) & 0x000000FF);
byte[] wrData = new byte[2] { q2CorrRFlow, q2CorrLFlow };
for (int j = 0; j < MaxCommRetries; j++)

View File

@ -90,9 +90,19 @@ namespace TBF.BenchControl.WaterMeters.iPerl
}
CalibrationStruct calibrationStruct;
public ushort CalibrationFactor { get { return CalibrationStruct.Calibration; } }
public ushort CalibrationFactor { get { return CalibrationStruct.Calibration; } }
/// <summary> Result of the last test used to calculate Q2 correction factors, etc </summary>
public Entities.MeterTestResult LastTestResult;
public double NominalTestFlow; /// liter per hour
/// <summary>
/// New calibration factor calculated from the original factor (argument)
/// and results of the last test.
/// </summary>
/// <param name="originalCalibrationFactor">Original calibration factor</param>
/// <returns>New calibration factor</returns>
public UInt16 CalculateNewCalibFactor(UInt16 originalCalibrationFactor)
{
double volumeMeter = Math.Abs(VolumeLtrEnd - VolumeLtrStart);
@ -113,8 +123,23 @@ namespace TBF.BenchControl.WaterMeters.iPerl
}
}
/// <summary>
/// Q2 correction factor calculated from the last test (Q2).
/// This factors should be used only for R800 meters.
/// </summary>
/// <returns>Q2 correction factor</returns>
public double Q2CorrectionFactor()
{
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
const double C = B * 60.0; /// Raw units per hour, 480
double D = C / A; /// ml correction per hour
double F = D / (NominalTestFlow * 10.0); /// Error corrected with 8 Raw Units per minute [%]
double G = F / B; /// Error corrected with 1 Raw Unit per minute [%]
return (-1) * (LastTestResult.VolumeErrorPct / G) * (LastTestResult.VolumeRef / LastTestResult.VolumeMeter);
}
int sampleNr;
///
/// Volume of water from the opto telegram
@ -299,6 +324,8 @@ namespace TBF.BenchControl.WaterMeters.iPerl
}
int sampleNr; /// This is to determine when the test start sample should be taken
/// <summary>Start this operation</summary>
public void Start()
{
@ -327,6 +354,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
ReadPulses();
if (sampleNr == 3)
{
/// Take the test start sample
VolumeLtrStart = volumeLtr;
TimestampSecStart = timestampSec;
}