Working on 2Hz correction

This commit is contained in:
Milan Hanajik
2016-02-15 15:16:44 +01:00
parent e22d58101c
commit 92bcd46549
2 changed files with 107 additions and 1 deletions
@@ -1106,6 +1106,62 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
}
/// <summary>
/// Write the calculated 2Hz correction factor to the memory.
/// </summary>
/// <param name="wm">Water meter object</param>
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
static CommErr Write2HzCorrection(WaterMeters.iPerl.WaterMeter wm, ref string resultStr)
{
if (wm.CommFailed) return CommErr.CommFailed;
/// Write Q2 corrections
double hz2CorrectionFactor = wm.Hz2CorrectionFactor();
if (hz2CorrectionFactor == 0)
{
resultStr = string.Format("2Hz factors = 0 (writing bypassed)");
return CommErr.None;
}
if (OpenPort(wm) != 0) return CommErr.OpenPort; /// Open RFID port
CommErr error = CommErr.Write;
Byte hz2CorrectionByte = (byte)((int)Math.Round(hz2CorrectionFactor) & 0x000000FF);
byte[] wrData = new byte[1] { hz2CorrectionByte };
///
for (int j = 0; j < cfg.MaxCommRetries; j++)
{
if (0 == WriteRequestPort(wm, MessageID.MetrologyMemory, Hz2CorrFactorsAddr, 1, wrData, cfg.CommTimeout)) { error = CommErr.None; break; }
}
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, Hz2CorrFactorsAddr, 1, out rdData, cfg.CommTimeout)) &&
(rdData != null) && (rdData.Length == 2) && (rdData[0] == hz2CorrectionByte))
{
error = CommErr.None;
resultStr = string.Format("2Hz factor = {0}", (SByte)hz2CorrectionByte);
rfidDataLogger.Warn(wm.Name + ": " + resultStr);
wm.Current2HzCorrection = hz2CorrectionFactor;
break;
}
}
}
ClosePort(wm); /// Close RFID port
return error;
}
/// <summary>
/// Called when communication with one watermeter is completed
/// </summary>