diff --git a/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index b207f58bf..0f4d99d19 100644 --- a/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TestBenchFramework/BenchControl/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -232,6 +232,7 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication const string SetActiveModeStr = "Set Active mode"; const string ReadCalibrationStr = "Read calibration"; const string WriteCalibrationFactorStr = "Write calibration factor"; + const string NormalizeCalibrationFactorStr = "Normalize calibration factor"; const string ResetQ2CorrectionStr = "Reset Q2 correction"; const string WriteQ2CorrectionStr = "Write Q2 correction"; const string Reset2HzCorrectionStr = "Reset 2Hz correction"; @@ -662,7 +663,8 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication else if (activity.ToLower().Equals(SetActiveModeStr.ToLower())) error = SetActiveMode(wm, ref resultStr); else if (activity.ToLower().Equals(ReadCalibrationStr.ToLower())) error = ReadCalibration(wm, ref resultStr); else if (activity.ToLower().Contains(WriteCalibrationFactorStr.ToLower())) error = WriteCalibrationFactor(wm, ref resultStr); - else if (activity.ToLower().Equals(ResetQ2CorrectionStr.ToLower())) error = ResetQ2Correction(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(Reset2HzCorrectionStr.ToLower())) error = Reset2HzCorrection(wm, ref resultStr); else if (activity.ToLower().Equals(Write2HzCorrectionStr.ToLower())) error = Write2HzCorrection(wm, ref resultStr); @@ -1040,6 +1042,79 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication return error; } + + /// + /// Normalize calibration factor in case ti is close to value 8000. + /// + /// Water meter object + /// String passed to caller + /// true on success + static CommErr NormalizeCalibrationFactor(WaterMeters.iPerl.WaterMeter wm, ref string resultStr) + { + if (wm.CommFailed) return CommErr.CommFailed; + + if (wm.CalibrationFactor <= 5000) + { + resultStr = "Calibratin factor is OK"; + return CommErr.None; /// No need to update the calibration factor + } + + if (OpenPort(wm) != 0) return CommErr.OpenPort; /// Open RFID port + + CommErr error = CommErr.Write; + + /// Determine the new calibration factor + UInt16 newCalibFactor = 0; + switch (wm.CalibrationStruct.MeterType) + { + case MeterType.DN15: newCalibFactor = 2650; break; + case MeterType.DN20: newCalibFactor = 3746; break; + case MeterType.DN25: newCalibFactor = 3300; break; + case MeterType.DN32: newCalibFactor = 2500; break; + case MeterType.DN40: newCalibFactor = 3000; break; + + case MeterType.DN26: + case MeterType.CoaxManifold: + default: + newCalibFactor = 3040; + break; + } + + byte[] data = new byte[2] { (byte)(newCalibFactor & 0x00FF), (byte)((newCalibFactor >> 8) & 0x00FF) }; + for (int j = 0; j < cfg.MaxCommRetries; j++) + { + if (0 == WriteRequestPort(wm, MessageID.Calibration, 2, 2, data, cfg.CommTimeout)) + { + error = CommErr.None; + wm.CalibrationStruct.Update(data, 2); + break; + } + } + + if (error == CommErr.None) + { + error = CommErr.Verify; + + /// Read calibration + byte[] calib_2_3 = null; + for (int j = 0; j < cfg.MaxCommRetries; j++) + { + if (0 == ReadRequestPort(wm, MessageID.Calibration, 2, 2, out calib_2_3, cfg.CommTimeout)) + { + error = CommErr.None; + wm.CalibrationStruct.Update(calib_2_3, 2); + resultStr = wm.CalibrationStruct.ToString(); + break; + } + } + } + + ClosePort(wm); /// Close RFID port + + return error; + } + + const int Hz2CorrFactorsAddr = 0x1875; /// Used by Reset2HzCorrection(...) and Write2HzCorrection(...) const int Q2CorrFactorsAddr = 0x1878; /// Used by ResetQ2Correction(...) and WriteQ2Correction(...) diff --git a/TestBenchFramework/Resources/Strings.cs.resx b/TestBenchFramework/Resources/Strings.cs.resx index 0d8d1167f..6243974d0 100644 --- a/TestBenchFramework/Resources/Strings.cs.resx +++ b/TestBenchFramework/Resources/Strings.cs.resx @@ -1117,7 +1117,7 @@ Sériová čísla vodoměru a stavy - Stav vodoměru + Stav vodoměrů Typy vodoměrů