iPerlCommunicationForm : (1) OutOfRange / Q2OutOfRange aren't an RFID error, (2) CommFailed cleanup, (3) WriteQ2Correction(..) cleanup (updateQ2adjByCalibFactor arg.

This commit is contained in:
Milan Hanajik 2019-05-22 07:52:13 +02:00
parent 14a5721649
commit 944862dde0

View File

@ -38,10 +38,11 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
Verify, /// C = 12
WrongIPerlType, /// D = 13
OutOfRange, /// E = 14
MissingTest, /// F = 15
RFPowerRecordMissing, /// 10H = 16
HeadDisabledByUser, /// 11H = 17
WrongArguments, /// 12H = 18
Q2OutOfRange, /// F = 15
MissingTest, /// 10H = 16
RFPowerRecordMissing, /// 11H = 17
HeadDisabledByUser, /// 12H = 18
WrongArguments, /// 13H = 19
}
@ -758,7 +759,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
/// RFID communication activity call
///
if ((ihead == null) || ihead.Disabled || !ckbState[wmNr0]) error = CommErr.HeadDisabledByUser;
else if (wm == null || ihead.CommFailed) error = CommErr.CommFailed;
else if (wm == null) error = CommErr.CommFailed;
#if IPERL
else if (currentActivity.ToLower().Contains(ReadConfigurationStr.ToLower())) error = ReadConfiguration(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Contains(SetTestModeStr.ToLower())) error = SetTestMode(threadID, ihead, wm, ref resultStr);
@ -772,13 +773,13 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
else if (currentActivity.ToLower().Equals(ReadQ2CorrectionStr.ToLower())) error = ReadQ2Correction(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(ResetQ2CorrectionStr.ToLower())) error = ResetQ2Correction(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(InitOrReadQ2CorrectionStr.ToLower())) error = InitOrReadQ2Correction(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(WriteQ2CorrectionStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Standard, null, false);
else if (currentActivity.ToLower().Equals(WriteQ2CorrectionAltStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Dewa, null, false);
else if (currentActivity.ToLower().Contains(WriteQ2CorrectionGreeceStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Greece, currentActivity.Substring(WriteQ2CorrectionGreeceStr.Length).Trim(), true);
else if (currentActivity.ToLower().Contains(WriteQ2CorrectionRLStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.RL, currentActivity.Substring(WriteQ2CorrectionRLStr.Length).Trim(), true);
else if (currentActivity.ToLower().Contains(WriteQ2CorrectionLRStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.LR, currentActivity.Substring(WriteQ2CorrectionLRStr.Length).Trim(), true);
else if (currentActivity.ToLower().Contains(UpdateQ2CorrectionsStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Update, currentActivity.Substring(UpdateQ2CorrectionsStr.Length).Trim(), true);
else if (currentActivity.ToLower().Contains(ConditnlUpdateQ2CorrectionsStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.ConditionalUpdate, currentActivity.Substring(ConditnlUpdateQ2CorrectionsStr.Length).Trim(), true);
else if (currentActivity.ToLower().Equals(WriteQ2CorrectionStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Standard, null);
else if (currentActivity.ToLower().Equals(WriteQ2CorrectionAltStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Dewa, null);
else if (currentActivity.ToLower().Contains(WriteQ2CorrectionGreeceStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Greece, currentActivity.Substring(WriteQ2CorrectionGreeceStr.Length).Trim());
else if (currentActivity.ToLower().Contains(WriteQ2CorrectionRLStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.RL, currentActivity.Substring(WriteQ2CorrectionRLStr.Length).Trim());
else if (currentActivity.ToLower().Contains(WriteQ2CorrectionLRStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.LR, currentActivity.Substring(WriteQ2CorrectionLRStr.Length).Trim());
else if (currentActivity.ToLower().Contains(UpdateQ2CorrectionsStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.Update, currentActivity.Substring(UpdateQ2CorrectionsStr.Length).Trim());
else if (currentActivity.ToLower().Contains(ConditnlUpdateQ2CorrectionsStr.ToLower())) error = WriteQ2Correction(threadID, ihead, wm, currentTest, ref resultStr, Q2CorrType.ConditionalUpdate, currentActivity.Substring(ConditnlUpdateQ2CorrectionsStr.Length).Trim());
else if (currentActivity.ToLower().Equals(Reset2HzCorrectionStr.ToLower())) error = Reset2HzCorrection(threadID, ihead, wm, ref resultStr);
else if (currentActivity.ToLower().Equals(Write2HzCorrectionStr.ToLower())) error = Write2HzCorrection(threadID, ihead, wm, ref resultStr);
#endif
@ -797,29 +798,38 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
}
else if (error == CommErr.None)
{
OnCommCompleted(null, new CommCompletedEventArgs(threadID, wmNr0, ihead, wm, resultStr, error));
OnCommCompleted(null, new CommCompletedEventArgs(threadID, wmNr0, ihead, wm, resultStr, CommErr.None));
}
else if (ihead.CommFailed || error == CommErr.CommFailed)
{
if ((wm.ResultCode & (int)Results.Entities.ResultCode.RfidErrorCodeMask) == 0)
{
wm.ResultCode |= (((int)error << 16) | ((int)tests[i].ItemNr << 20));
}
else if ((error == CommErr.OutOfRange) || (error == CommErr.Q2OutOfRange))
{
OnCommCompleted(null, new CommCompletedEventArgs(threadID, wmNr0, ihead, wm, resultStr, CommErr.None));
}
else if (ihead.CommFailed || (error == CommErr.CommFailed))
{
ihead.CommFailed = true;
if ((wm.ResultCode & (int)Results.Entities.ResultCode.RfidErrorCodeMask) == 0)
{
wm.ResultCode |= (((int)error << 16) | ((int)tests[i].ItemNr << 20));
}
OnCommCompleted(null, new CommCompletedEventArgs(threadID, wmNr0, ihead, wm, Strings.RFID_communication_failed, error));
}
else
{
if ((wm.ResultCode & (int)Results.Entities.ResultCode.RfidErrorCodeMask) == 0)
{
wm.ResultCode |= (((int)error << 16) | ((int)tests[i].ItemNr << 20));
}
}
else
{
ihead.CommFailed = true;
if ((wm.ResultCode & (int)Results.Entities.ResultCode.RfidErrorCodeMask) == 0)
{
wm.ResultCode |= (((int)error << 16) | ((int)tests[i].ItemNr << 20));
}
string failureCauseLocal = string.Format(Strings.failed_0_1_exclamation, currentActivity, error);
rfidDataLogger.ErrorFormat("Group={0}, Board={1}, {2}", currentGroup, ihead.MuxBoardNrOrGroup14, failureCauseLocal);
OnCommCompleted(null, new CommCompletedEventArgs(threadID, wmNr0, ihead, wm, failureCauseLocal, error));
rfidDataLogger.ErrorFormat("Group={0}, Board={1}, {2}", currentGroup, ihead.MuxBoardNrOrGroup14, failureCauseLocal);
ihead.CommFailed = true;
}
}
break;
}
@ -1181,17 +1191,25 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
UInt16.TryParse(arguments[0], out factorLimitLo) && factorLimitLo > 0 &&
UInt16.TryParse(arguments[1], out factorLimitHi) && factorLimitHi > 0)
{
///
/// Lower and upper limits for the calibration factor are specified as iPerlCommunication activity arguments
///
if (ihead.LastTestResult == null || !ihead.LastTestResult.TestDone) return CommErr.MissingTest;
newCalibFactor = ihead.CalculateNewCalibFactor(ihead.LastTestResult, ihead.CalibFactor, factorLimitLo, factorLimitHi);
}
else if (arguments.Length == 1 && UInt16.TryParse(arguments[0], out val) && val > 0)
{
newCalibFactor = val; /// Update with specified value
///
/// Calibration factor value is specified as an iPerlCommunication activity argument
///
newCalibFactor = val; /// Update with specified value
}
else if (arguments.Length == 1 && wm.GetTestData(arguments[0]) != null)
{
/// Get test data is test name
///
/// Adjustment test name is specified as an iPerlCommunication activity argument
///
Results.Entities.TestData adjustTestData = wm.GetTestData(arguments[0]);
Results.Entities.MeterTestRslt adjustTestRslt;
if (adjustTestData == null)
@ -1223,6 +1241,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
}
else
{
///
/// Otherwise the last test is supposed to be an adjustment test
///
if (ihead.LastTestResult == null || !ihead.LastTestResult.TestDone) return CommErr.MissingTest;
newCalibFactor = ihead.CalculateNewCalibFactor(ihead.LastTestResult, ihead.CalibFactor, ihead.FactorLimitLo, ihead.FactorLimitHi);
@ -1230,6 +1251,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
}
else
{
///
/// No iPerlCommunication activity arguments --> The last test is supposed to be an adjustment test
///
if (ihead.LastTestResult == null || !ihead.LastTestResult.TestDone) return CommErr.MissingTest;
newCalibFactor = ihead.CalculateNewCalibFactor(ihead.LastTestResult, ihead.CalibFactor, ihead.FactorLimitLo, ihead.FactorLimitHi);
@ -1842,7 +1866,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
/// <param name="resultStr">String passed to caller</param>
/// <returns>true on success</returns>
static CommErr WriteQ2Correction(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, Test test, ref string resultStr,
Q2CorrType q2CorrType, string restOfLine, bool updateQ2adjByCalibFactor)
Q2CorrType q2CorrType, string restOfLine)
{
if ((q2CorrType == Q2CorrType.ConditionalUpdate) && wm.PassedFromTests())
{
@ -1892,12 +1916,6 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
q2adjResult.VolumeRef += oneMTR.VolumeRef;
}
if (updateQ2adjByCalibFactor)
{
if (wm.OrigCalibFactor == 0) return CommErr.OutOfRange;
q2adjResult.VolumeMeter *= ((double)wm.CalibFactor / (double)wm.OrigCalibFactor);
}
q2adjResult.Error = Config.Formulas.ErrorFromVolumes(q2adjResult.VolumeMeter, q2adjResult.VolumeRef);
}
}
@ -1931,12 +1949,6 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
q2adjResult2.VolumeRef += oneMTR.VolumeRef;
}
if (updateQ2adjByCalibFactor)
{
if (wm.OrigCalibFactor == 0) return CommErr.OutOfRange;
q2adjResult2.VolumeMeter *= ((double)wm.CalibFactor / (double)wm.OrigCalibFactor);
}
q2adjResult2.Error = Config.Formulas.ErrorFromVolumes(q2adjResult2.VolumeMeter, q2adjResult2.VolumeRef);
}
}
@ -1960,6 +1972,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
///
if ((q2CorrType == Q2CorrType.Update) || (q2CorrType == Q2CorrType.ConditionalUpdate))
{
///
/// Update or ConditionalUpdate: 1. Calculate updates, not corrections, 2. Use error limits from this test
///
double errLimitLo = test.ErrLimLo + test.Uncertainty;
double errLimitHi = test.ErrLimHi - test.Uncertainty;
@ -1986,11 +2001,14 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
ihead.Q2CorrRL = wm.Q2CorrRL;
ihead.Q2CorrLR = wm.Q2CorrLR;
resultStr = string.Format("Q2 error is out of range => no Q2 correction");
return CommErr.OutOfRange;
return CommErr.Q2OutOfRange;
}
}
else
{
///
/// Regular Q2 corrections: 1. Use error limits from 'q2adjResult'
///
double errLimitLo = q2adjTestData.ErrLimLo + q2adjTestData.Uncertainty;
double errLimitHi = q2adjTestData.ErrLimHi - q2adjTestData.Uncertainty;
@ -2011,7 +2029,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
errLimitHi.ToString("F1"));
resultStr = string.Format("Q2 error is out of range => no Q2 correction");
return CommErr.OutOfRange;
return CommErr.Q2OutOfRange;
}
}
@ -2081,7 +2099,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
///
/// Write calculated Q2 correction factors into the water meter
///
///
if (ihead.CommFailed) return CommErr.CommFailed;
if (OpenPort(threadId, ihead) != 0) return CommErr.OpenPort; /// Open RFID port
CommErr error = CommErr.Write;
if (q2CorrType == Q2CorrType.RL)