DEWA Q2 correction modified, Results.Entities.WaterMeter columns added (iPerl only).
This commit is contained in:
@@ -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
|
||||
|
||||
+3
-1
@@ -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
|
||||
|
||||
+60
-96
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user