DEWA Q2 correction modified, Results.Entities.WaterMeter columns added (iPerl only).
This commit is contained in:
parent
dcf6df293f
commit
049bbc8655
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Config.Entities;
|
||||
|
||||
@ -27,8 +26,10 @@ namespace Results.Entities
|
||||
public virtual double CalibFactor { get; set; } /// iPerl calibration factor used during the test
|
||||
public virtual double Q2ErrWOCorrection { get; set; }
|
||||
public virtual bool Q2CorrectionDone { get; set; } /// true = iPerl Q2 correction was done
|
||||
public virtual double Q2Correction { get; set; } /// iPerl Q2 correction used during the test
|
||||
public virtual int Q2CorrFlowRight { get; set; } /// 1 = right to left
|
||||
public virtual double Q2Correction { get; set; } /// !!! obsolete
|
||||
public virtual int Q2CorrRFlow { get; set; } /// iPerl Q2 correction for the R-flow written to iPerl
|
||||
public virtual int Q2CorrLFlow { get; set; } /// iPerl Q2 correction for the L-flow written to iPerl
|
||||
public virtual int Q2CorrFlowRight { get; set; } /// 1 = right to left
|
||||
public virtual double Diff2Hz8Hz { get; set; }
|
||||
public virtual bool Hz2CorrectionDone { get; set; } /// true = iPerl Q2 correction was done
|
||||
public virtual int Hz2Correction { get; set; } /// iPerl Q2 correction used during the test
|
||||
|
||||
@ -30,7 +30,9 @@ namespace Results.Mappings
|
||||
Map(x => x.Q2ErrWOCorrection);
|
||||
Map(x => x.Q2CorrectionDone);
|
||||
Map(x => x.Q2Correction);
|
||||
Map(x => x.Q2CorrFlowRight);
|
||||
Map(x => x.Q2CorrRFlow);
|
||||
Map(x => x.Q2CorrLFlow);
|
||||
Map(x => x.Q2CorrFlowRight);
|
||||
Map(x => x.Diff2Hz8Hz);
|
||||
Map(x => x.Hz2CorrectionDone);
|
||||
Map(x => x.Hz2Correction);
|
||||
|
||||
@ -533,8 +533,8 @@ namespace TBF.BenchControl.DB.SensusOracle
|
||||
logger.WriteLine(string.Format("JustierWert=0,2")); /// 0,2
|
||||
logger.WriteLine(string.Format("Corrected2Hz={0}", wMtr.Hz2CorrectionDone ? 1 : 0));
|
||||
logger.WriteLine(string.Format("Q2Corrected={0}", wMtr.Q2CorrectionDone ? 1 : 0));
|
||||
logger.WriteLine(string.Format("Q2CorrectionRight={0}", (int)Math.Round(wMtr.Q2Correction / 2)));
|
||||
logger.WriteLine(string.Format("Q2CorrectionLeft={0}", (int)Math.Round(wMtr.Q2Correction)));
|
||||
logger.WriteLine(string.Format("Q2CorrectionRight={0}", wMtr.Q2CorrRFlow));
|
||||
logger.WriteLine(string.Format("Q2CorrectionLeft={0}", wMtr.Q2CorrLFlow));
|
||||
logger.WriteLine(string.Format("Q2CorrectionFlowRight={0}", wMtr.Q2CorrFlowRight));
|
||||
logger.WriteLine(string.Format("FlowDirectionRight={0}", wMtr.Q2CorrFlowRight));
|
||||
logger.WriteLine(string.Format("Position={0}", wMtr.WMPosition));
|
||||
@ -1102,8 +1102,8 @@ namespace TBF.BenchControl.DB.SensusOracle
|
||||
parm = new OracleParameter("WITHQ2CORRECTION", OracleDbType.Int32); parm.Value = wm.Q2CorrectionDone ? 1 : 0; cmd.Parameters.Add(parm); ///:7
|
||||
parm = new OracleParameter("ERRQ2", OracleDbType.Double); parm.Value = q2ErrWOCorrection; cmd.Parameters.Add(parm); ///:8
|
||||
parm = new OracleParameter("Q2CORRECTIONFLOWRIGHT", OracleDbType.Int32);parm.Value = wm.Q2CorrFlowRight;/*1=right to left*/ cmd.Parameters.Add(parm); ///:9
|
||||
parm = new OracleParameter("Q2CORRECTIONLEFT", OracleDbType.Int32); parm.Value = (int)Math.Round(wm.Q2Correction); cmd.Parameters.Add(parm); ///:10
|
||||
parm = new OracleParameter("Q2CORRECTIONRIGHT", OracleDbType.Int32); parm.Value = (int)Math.Round(wm.Q2Correction / 2); cmd.Parameters.Add(parm); ///:11
|
||||
parm = new OracleParameter("Q2CORRECTIONLEFT", OracleDbType.Int32); parm.Value = wm.Q2CorrLFlow; cmd.Parameters.Add(parm); ///:10
|
||||
parm = new OracleParameter("Q2CORRECTIONRIGHT", OracleDbType.Int32); parm.Value = wm.Q2CorrRFlow; cmd.Parameters.Add(parm); ///:11
|
||||
|
||||
int rowsUpdated = cmd.ExecuteNonQuery();
|
||||
log.InfoFormat("VT_IP_ZAEHLER_PINDEX_PD inserted, PcbNr={0}, pruefix={1}", wm.SerialNr, max_Pruefindex);
|
||||
|
||||
@ -242,8 +242,10 @@ namespace TBF.BenchControl.DataEntry.iPerl
|
||||
wm.CalibFactor = iPerl.CalibrationFactor;
|
||||
wm.Q2ErrWOCorrection = iPerl.Q2ErrorWOCorrection;
|
||||
wm.Q2CorrectionDone = iPerl.Q2CorrectionDone;
|
||||
wm.Q2Correction = iPerl.Q2CorrectionFactor;
|
||||
wm.Diff2Hz8Hz = iPerl.Diff2Hz8Hz;
|
||||
wm.Q2Correction = iPerl.Q2Correction;
|
||||
wm.Q2CorrRFlow = iPerl.Q2CorrRFlow;
|
||||
wm.Q2CorrLFlow = iPerl.Q2CorrLFlow;
|
||||
wm.Diff2Hz8Hz = iPerl.Diff2Hz8Hz;
|
||||
wm.Hz2CorrectionDone = iPerl.Hz2CorrectionDone;
|
||||
wm.Hz2Correction = iPerl.Hz2CorrectionFactor;
|
||||
|
||||
|
||||
@ -585,7 +585,9 @@ namespace TBF.BenchControl.TestMethods.FlyingStart
|
||||
iPerl.VolumeLtrRef = meterRslt.VolumeRef;
|
||||
#if IPERL
|
||||
meterRslt.WaterMeter.CalibFactor = (iPerl.CalibrationStruct != null) ? iPerl.CalibrationStruct.Calibration : 0;
|
||||
meterRslt.WaterMeter.Q2Correction = iPerl.Q2CorrectionFactor;
|
||||
meterRslt.WaterMeter.Q2Correction = iPerl.Q2Correction;
|
||||
meterRslt.WaterMeter.Q2CorrRFlow = iPerl.Q2CorrRFlow;
|
||||
meterRslt.WaterMeter.Q2CorrLFlow = iPerl.Q2CorrLFlow;
|
||||
#endif
|
||||
iPerl.LastTestResult2 = iPerl.LastTestResult; /// Save shift previous test result
|
||||
iPerl.LastTestResult = meterRslt; /// Save this test result
|
||||
|
||||
@ -929,7 +929,9 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection
|
||||
iPerl.VolumeLtrRef = meterRslt.VolumeRef;
|
||||
#if IPERL
|
||||
meterRslt.WaterMeter.CalibFactor = (iPerl.CalibrationStruct != null) ? iPerl.CalibrationStruct.Calibration : 0;
|
||||
meterRslt.WaterMeter.Q2Correction = iPerl.Q2CorrectionFactor;
|
||||
meterRslt.WaterMeter.Q2Correction = iPerl.Q2Correction;
|
||||
meterRslt.WaterMeter.Q2CorrRFlow = iPerl.Q2CorrRFlow;
|
||||
meterRslt.WaterMeter.Q2CorrLFlow = iPerl.Q2CorrLFlow;
|
||||
#endif
|
||||
iPerl.LastTestResult2 = iPerl.LastTestResult; /// Save shift previous test result
|
||||
iPerl.LastTestResult = meterRslt; /// Save this test result
|
||||
|
||||
@ -675,8 +675,8 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
else if (activity.ToLower().Contains(WriteCalibrationFactorStr.ToLower())) error = WriteCalibrationFactor(wm, ref resultStr);
|
||||
else if (activity.ToLower().Equals(NormalizeCalibrationFactorStr.ToLower())) error = NormalizeCalibrationFactor(wm, ref resultStr);
|
||||
else if (activity.ToLower().Equals(ResetQ2CorrectionStr.ToLower())) error = ResetQ2Correction(wm, ref resultStr);
|
||||
else if (activity.ToLower().Equals(WriteQ2CorrectionStr.ToLower())) error = WriteQ2Correction(wm, ref resultStr);
|
||||
else if (activity.ToLower().Equals(WriteQ2CorrectionAltStr.ToLower())) error = WriteQ2CorrectionAlt(wm, ref resultStr);
|
||||
else if (activity.ToLower().Equals(WriteQ2CorrectionStr.ToLower())) error = WriteQ2Correction(wm, ref resultStr, false); /// standard iPerl
|
||||
else if (activity.ToLower().Equals(WriteQ2CorrectionAltStr.ToLower())) error = WriteQ2Correction(wm, ref resultStr, true); /// DEWA iPerl
|
||||
else if (activity.ToLower().Equals(Reset2HzCorrectionStr.ToLower())) error = Reset2HzCorrection(wm, ref resultStr);
|
||||
else if (activity.ToLower().Equals(Write2HzCorrectionStr.ToLower())) error = Write2HzCorrection(wm, ref resultStr);
|
||||
else
|
||||
@ -1190,7 +1190,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
if (error == CommErr.None)
|
||||
{
|
||||
resultStr = "Q2 corrections reset to 0";
|
||||
wm.Q2CorrectionFactor = 0;
|
||||
wm.Q2CorrRFlow = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1270,28 +1270,70 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
/// <param name="wm">Water meter object</param>
|
||||
/// <param name="resultStr">String passed to caller</param>
|
||||
/// <returns>true on success</returns>
|
||||
static CommErr WriteQ2Correction(WaterMeters.iPerl.WaterMeter wm, ref string resultStr)
|
||||
static CommErr WriteQ2Correction(WaterMeters.iPerl.WaterMeter wm, ref string resultStr, bool DEWA)
|
||||
{
|
||||
if (wm.CommFailed) return CommErr.CommFailed;
|
||||
if (wm.CommFailed) return CommErr.CommFailed;
|
||||
if (wm.LastTestResult == null) return CommErr.CommFailed; /// This should never happen
|
||||
|
||||
wm.Q2ErrorWOCorrection = wm.LastTestResult.Error;
|
||||
wm.Q2CorrectionDone = false;
|
||||
wm.Q2CorrRFlow = 0;
|
||||
|
||||
double q2CorrectionFactor;
|
||||
bool wmOK = wm.CalculateQ2CorrectionFactor(wm.LastTestResult, out q2CorrectionFactor);
|
||||
double q2Correction = 0;
|
||||
Byte q2CorrRFlow = 0;
|
||||
Byte q2CorrLFlow = 0;
|
||||
|
||||
if (q2CorrectionFactor == 0)
|
||||
{
|
||||
resultStr = string.Format("Q2 correction = 0 (writing bypassed)");
|
||||
return CommErr.None;
|
||||
}
|
||||
if (DEWA == false)
|
||||
{
|
||||
///
|
||||
/// Standard process
|
||||
///
|
||||
if (Math.Abs(wm.LastTestResult.Error) <= 0.5)
|
||||
{
|
||||
resultStr = string.Format("Q2 correction = 0 (writing bypassed)");
|
||||
return CommErr.None;
|
||||
}
|
||||
|
||||
if (!wm.CalculateQ2CorrectionFactor(wm.LastTestResult, out q2Correction))
|
||||
{
|
||||
return CommErr.None; /// Q2 error is too large, water meter failed anyhow
|
||||
}
|
||||
|
||||
q2CorrRFlow = (byte)((int)Math.Round(0.5 * q2Correction) & 0x000000FF);
|
||||
q2CorrLFlow = (byte)((int)Math.Round(q2Correction) & 0x000000FF);
|
||||
}
|
||||
else
|
||||
{
|
||||
///
|
||||
/// DEWA process
|
||||
///
|
||||
if (wm.LastTestResult.Error >= 0 && wm.LastTestResult.Error <= 1.0)
|
||||
{
|
||||
resultStr = string.Format("Q2 correction = 0 (writing bypassed)");
|
||||
return CommErr.None;
|
||||
}
|
||||
|
||||
if (!wm.CalculateQ2CorrectionFactor(wm.LastTestResult, out q2Correction))
|
||||
{
|
||||
return CommErr.None; /// Q2 error is too large, water meter failed anyhow
|
||||
}
|
||||
|
||||
if (wm.LastTestResult.Error < 0)
|
||||
{
|
||||
q2CorrRFlow = (byte)((int)Math.Round(1.1 * q2Correction) & 0x000000FF);
|
||||
q2CorrLFlow = (byte)((int)Math.Round(1.1 * q2Correction) & 0x000000FF);
|
||||
}
|
||||
else /// if (wm.LastTestResult.Error > 1.0)
|
||||
{
|
||||
q2CorrRFlow = (byte)((int)Math.Round(0.5 * q2Correction) & 0x000000FF);
|
||||
q2CorrLFlow = (byte)((int)Math.Round(0.5 * q2Correction) & 0x000000FF);
|
||||
}
|
||||
}
|
||||
|
||||
if (OpenPort(wm) != 0) return CommErr.OpenPort; /// Open RFID port
|
||||
|
||||
CommErr error = CommErr.Write;
|
||||
|
||||
Byte q2CorrRFlow = (byte)((int)Math.Round(q2CorrectionFactor / 2) & 0x000000FF);
|
||||
Byte q2CorrLFlow = (byte)((int)Math.Round(q2CorrectionFactor) & 0x000000FF);
|
||||
byte[] wrData = new byte[2] { q2CorrRFlow, q2CorrLFlow };
|
||||
///
|
||||
for (int j = 0; j < cfg.MaxCommRetries; j++)
|
||||
@ -1333,8 +1375,10 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
resultStr = string.Format("Q2 correction: R-flow={0}, L-flow={1}", (SByte)q2CorrRFlow, (SByte)q2CorrLFlow);
|
||||
rfidDataLogger.Warn(wm.Name + ": " + resultStr);
|
||||
wm.Q2CorrectionDone = true;
|
||||
wm.Q2CorrectionFactor = q2CorrectionFactor;
|
||||
}
|
||||
wm.Q2Correction = q2Correction;
|
||||
wm.Q2CorrRFlow = (int)q2CorrRFlow;
|
||||
wm.Q2CorrLFlow = (int)q2CorrLFlow;
|
||||
}
|
||||
#endif
|
||||
|
||||
ClosePort(wm); /// Close RFID port
|
||||
@ -1343,86 +1387,6 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Write the calculated Q2 correction factors to the memory.
|
||||
/// Read them back to verify factors were written correctly.
|
||||
/// </summary>
|
||||
/// <param name="wm">Water meter object</param>
|
||||
/// <param name="resultStr">String passed to caller</param>
|
||||
/// <returns>true on success</returns>
|
||||
static CommErr WriteQ2CorrectionAlt(WaterMeters.iPerl.WaterMeter wm, ref string resultStr)
|
||||
{
|
||||
if (wm.CommFailed) return CommErr.CommFailed;
|
||||
|
||||
wm.Q2ErrorWOCorrection = wm.LastTestResult.Error;
|
||||
wm.Q2CorrectionDone = false;
|
||||
|
||||
double q2CorrectionFactor;
|
||||
bool wmOK = wm.CalculateQ2CorrectionFactor(wm.LastTestResult, out q2CorrectionFactor);
|
||||
|
||||
if (q2CorrectionFactor == 0)
|
||||
{
|
||||
resultStr = string.Format("Q2 correction = 0 (writing bypassed)");
|
||||
return CommErr.None;
|
||||
}
|
||||
|
||||
if (OpenPort(wm) != 0) return CommErr.OpenPort; /// Open RFID port
|
||||
|
||||
CommErr error = CommErr.Write;
|
||||
|
||||
Byte q2CorrRFlow = (byte)((int)Math.Round(q2CorrectionFactor) & 0x000000FF);
|
||||
Byte q2CorrLFlow = (byte)((int)Math.Round(q2CorrectionFactor) & 0x000000FF);
|
||||
byte[] wrData = new byte[2] { q2CorrRFlow, q2CorrLFlow };
|
||||
///
|
||||
for (int j = 0; j < cfg.MaxCommRetries; j++)
|
||||
{
|
||||
if (0 == WriteRequestPort(wm, MessageID.MetrologyMemory, Q2CorrFactorsAddr, wrData.Length, wrData, cfg.CommTimeout))
|
||||
{
|
||||
error = CommErr.None;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Verification disabled on 16.02.2016
|
||||
///
|
||||
#if false
|
||||
if (error == CommErr.None)
|
||||
{
|
||||
error = CommErr.Verify;
|
||||
|
||||
/// Read calibration
|
||||
byte[] rdData = null;
|
||||
for (int j = 0; j < cfg.MaxCommRetries; j++)
|
||||
{
|
||||
if ((0 == ReadRequestPort(wm, MessageID.MetrologyMemory, Q2CorrFactorsAddr, 2, out rdData, cfg.CommTimeout)) &&
|
||||
(rdData != null) && (rdData.Length == 2) && (rdData[0] == q2CorrRFlow) && (rdData[1] == q2CorrLFlow))
|
||||
{
|
||||
error = CommErr.None;
|
||||
resultStr = string.Format("Q2 factors: R-flow={0}, L-flow={1}", (SByte)q2CorrRFlow, (SByte)q2CorrLFlow);
|
||||
rfidDataLogger.Warn(wm.Name + ": " + resultStr);
|
||||
wm.Q2CorrectionDone = true;
|
||||
wm.Q2CorrectionFactor = q2CorrectionFactor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (error == CommErr.None)
|
||||
{
|
||||
resultStr = string.Format("Q2 correction: R-flow={0}, L-flow={1}", (SByte)q2CorrRFlow, (SByte)q2CorrLFlow);
|
||||
rfidDataLogger.Warn(wm.Name + ": " + resultStr);
|
||||
wm.Q2CorrectionDone = true;
|
||||
wm.Q2CorrectionFactor = q2CorrectionFactor;
|
||||
}
|
||||
#endif
|
||||
|
||||
ClosePort(wm); /// Close RFID port
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Write the calculated 2Hz correction factor to the memory.
|
||||
/// </summary>
|
||||
|
||||
@ -148,7 +148,9 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
|
||||
public double Q2ErrorWOCorrection;
|
||||
public bool Q2CorrectionDone;
|
||||
public double Q2CorrectionFactor;
|
||||
public double Q2Correction;
|
||||
public int Q2CorrRFlow;
|
||||
public int Q2CorrLFlow;
|
||||
|
||||
public double Diff2Hz8Hz;
|
||||
public bool Hz2CorrectionDone;
|
||||
@ -226,14 +228,14 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
{
|
||||
q2CorrectionFactor = 0;
|
||||
|
||||
if (q2TestResult == null)
|
||||
{
|
||||
return false; /// Q2 test result is missing ==> water meter failed
|
||||
}
|
||||
if (q2TestResult == null) return false; /// Q2 test result is missing ==> water meter failed
|
||||
|
||||
if (Math.Abs(q2TestResult.Error) <= 0.5)
|
||||
double errLimitLo = q2TestResult.ErrLimLo() + q2TestResult.Uncertainty();
|
||||
double errLimitHi = q2TestResult.ErrLimHi() - q2TestResult.Uncertainty();
|
||||
|
||||
if ((q2TestResult.Error < errLimitLo) || (q2TestResult.Error > errLimitHi))
|
||||
{
|
||||
return true; /// error < +/-0.5 % ==> no Q2 correction
|
||||
return false; /// Q2 error too large ==> water meter failed
|
||||
}
|
||||
|
||||
double A = 16.0 / ScalingFactor(); /// Raw units per ml: DN15=16, DN20=8, DN25=4, DN32=2, DN40=1
|
||||
@ -243,20 +245,6 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
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 [%]
|
||||
|
||||
double errLimitLo = q2TestResult.ErrLimLo() + q2TestResult.Uncertainty();
|
||||
double errLimitHi = q2TestResult.ErrLimHi() - q2TestResult.Uncertainty();
|
||||
|
||||
if ((q2TestResult.Error < errLimitLo) || (q2TestResult.Error > errLimitHi))
|
||||
{
|
||||
return false; /// Q2 error too large ==> water meter failed
|
||||
}
|
||||
|
||||
double volumeMeterErrLimLo = q2TestResult.VolumeRef * (100.0 + errLimitLo) / 100.0;
|
||||
double volumeMeterErrLimHi = q2TestResult.VolumeRef * (100.0 + errLimitHi) / 100.0;
|
||||
|
||||
double corrFactorHi = (-1) * (errLimitLo / G) * (q2TestResult.VolumeRef / volumeMeterErrLimLo); /// > 0
|
||||
double corrFactorLo = (-1) * (errLimitHi / G) * (q2TestResult.VolumeRef / volumeMeterErrLimHi); /// < 0
|
||||
|
||||
q2CorrectionFactor = (-1) * (q2TestResult.Error / G) * (q2TestResult.VolumeRef / q2TestResult.VolumeMeter);
|
||||
|
||||
log.WarnFormat("Q2 correction: Pos={0}, PCB#={1}, corrFactor={2}, error={3}% [Lo={4}%, Hi={5}%]",
|
||||
@ -420,7 +408,7 @@ namespace TBF.BenchControl.WaterMeters.iPerl
|
||||
OriginalCalibFactor = 0;
|
||||
Q2ErrorWOCorrection = 0;
|
||||
Q2CorrectionDone = false;
|
||||
Q2CorrectionFactor = 0;
|
||||
Q2CorrRFlow = 0;
|
||||
|
||||
optoDataCount = 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user