diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index 80e79313e..595d2da92 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -91,6 +91,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication public const string Write2HzCorrectionStr = "Write 2Hz correction"; public const string DewaReworkRLStr = "DEWA rework R-L"; public const string DewaReworkLRStr = "DEWA rework L-R"; + public const string StartTestingSealedMetersStr = "Start testing sealed meters"; + public const string EndTestingSealedMetersStr = "End testing sealed meters"; public static Color DisabledColor = Color.DarkGray; public static Color OptoAndDirOKColor = Color.Green; @@ -1230,7 +1232,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication else if (currentActivity.ToLower() == GetDefaultQ2CorrectionsStr.ToLower()) error = GetQ2PreCorrectionsFormRest(threadID, ihead, wm, ref resultStr); else if (currentActivity.ToLower() == DewaReworkRLStr.ToLower()) error = DewaRework(ihead, wm, FlowDir.R_L, ref resultStr); else if (currentActivity.ToLower() == DewaReworkLRStr.ToLower()) error = DewaRework(ihead, wm, FlowDir.L_R, ref resultStr); - + else if (currentActivity.ToLower().Contains(StartTestingSealedMetersStr.ToLower())) error = StartTestingSealedMeter(ihead, wm, ref resultStr); + else if (currentActivity.ToLower().Contains(EndTestingSealedMetersStr.ToLower())) error = EndTestingSealedMeter(ihead, wm, ref resultStr); #endif else { @@ -2950,12 +2953,12 @@ namespace TBF.Rig.TestMethods.iPerlCommunication return error; } - /// /// DEWA rework. /// /// iPERL head object /// Water meter object + /// Arrow direction /// String passed to caller /// true on success static CommErr DewaRework(IperlHead ihead, Results.Entities.WaterMeter wm, FlowDir flowDir, ref string resultStr) @@ -3027,6 +3030,155 @@ namespace TBF.Rig.TestMethods.iPerlCommunication } } + /// + /// Start testing a sealed meter + /// + /// iPERL head object + /// Water meter object + /// String passed to caller + /// true on success + static CommErr StartTestingSealedMeter(IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) + { + if (ihead.CommFailed) return CommErr.CommFailed; + + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port + + Byte testModeConfig = 0xA0; /// Default value + /// + if (multiTestParams[currentActivityStep].Activity.Length > StartTestingSealedMetersStr.Length) + { + string testModeConfigStr = multiTestParams[currentActivityStep].Activity.Substring(StartTestingSealedMetersStr.Length + 1); + UInt16 byteVal; + if (UInt16.TryParse(testModeConfigStr, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out byteVal) && byteVal <= 255) + { + testModeConfig = (Byte)byteVal; /// Update with specified value + } + } + + iPerlDataWrite[] dataToBeWritten = new iPerlDataWrite[] + { + new iPerlDataWrite(MessageID.MetrologyMemory, 0x19A1, new byte[] { (byte)0xA5 }, "Open Sealing"), /// 0x5A=sealed, 0xA5=unsealed + new iPerlDataWrite(MessageID.RadioPassthrough, 0x1804, new byte[] { (byte)1 }, "System Status"), + new iPerlDataWrite(MessageID.Command, 0x0000, new byte[] { (byte)Command.SetActiveMode }, "Set active mode"), + new iPerlDataWrite(MessageID.Configuration, 0x0015, new byte[] { testModeConfig }, string.Format("Test mode config = {0:X2}", testModeConfig)), + }; + + if (ihead.ConfigStruct != null) ihead.OrigTestModeConfig = ihead.ConfigStruct.TestModeConfig; + + int successfyllyWrittenFlags = 0; /// Ones in this word represent communication failures, LSB represents the first step + int mask = 1; + foreach (var wData in dataToBeWritten) + { + bool isSuccessfullyWritten = false; + for (int j = 0; j < cfg.MaxCommRetries; j++) + { + if (0 == WriteRequestPort(ihead, wData.MessageID, wData.Offset, wData.Data.Length, wData.Data, cfg.CommTimeout)) + { + isSuccessfullyWritten = true; + break; + } + + /// Delay between retries + if (cfg.DelayBetweenRetries > 0) Thread.Sleep(cfg.DelayBetweenRetries); + } + + if (!isSuccessfullyWritten) + { + /// Communication failed in this step + successfyllyWrittenFlags = (successfyllyWrittenFlags | mask); + } + + mask = (mask << 1); /// Adjust the mask for the next step + } + + ClosePort(ihead); /// Close RFID port + + if (successfyllyWrittenFlags == 0) + { + /// Success + if (ihead.ConfigStruct != null) + { + ihead.ConfigStruct.MeterState = MeterState.Active; + ihead.ConfigStruct.TestModeConfig = (byte)0xA0; + } + + resultStr = "OK"; + return CommErr.None; + } + else + { + return CommErr.Write; + } + } + + /// + /// End testing a sealed meter + /// + /// iPERL head object + /// Water meter object + /// String passed to caller + /// true on success + static CommErr EndTestingSealedMeter(IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) + { + if (ihead.CommFailed) return CommErr.CommFailed; + + if (OpenPort(ihead) != 0) return CommErr.OpenPort; /// Open RFID port + + Byte testModeConfig = (ihead.OrigTestModeConfig != 0) ? ihead.OrigTestModeConfig : (byte)0x80; /// Restore original value (default is 0x80) + + iPerlDataWrite[] dataToBeWritten = new iPerlDataWrite[] + { + new iPerlDataWrite(MessageID.Command, 0x0000, new byte[] { (byte)Command.SetActiveMode }, "Set active mode"), + new iPerlDataWrite(MessageID.Configuration, 0x0015, new byte[] { testModeConfig }, string.Format("Test mode config = {0:X2}", testModeConfig)), + new iPerlDataWrite(MessageID.RadioPassthrough, 0x1804, new byte[] { (byte)0 }, "System Status"), + new iPerlDataWrite(MessageID.MetrologyMemory, 0x19A1, new byte[] { (byte)0x5A }, "Close Sealing"), + }; + + int successfyllyWrittenFlags = 0; /// Ones in this word represent communication failures, LSB represents the first step + int mask = 1; + foreach (var wData in dataToBeWritten) + { + bool isSuccessfullyWritten = false; + for (int j = 0; j < cfg.MaxCommRetries; j++) + { + if (0 == WriteRequestPort(ihead, wData.MessageID, wData.Offset, wData.Data.Length, wData.Data, cfg.CommTimeout)) + { + isSuccessfullyWritten = true; + break; + } + + /// Delay between retries + if (cfg.DelayBetweenRetries > 0) Thread.Sleep(cfg.DelayBetweenRetries); + } + + if (!isSuccessfullyWritten) + { + /// Communication failed in this step + successfyllyWrittenFlags = (successfyllyWrittenFlags | mask); + } + + mask = (mask << 1); /// Adjust the mask for the next step + } + + ClosePort(ihead); /// Close RFID port + + if (successfyllyWrittenFlags == 0) + { + /// Success + if (ihead.ConfigStruct != null) + { + ihead.ConfigStruct.MeterState = MeterState.Active; + ihead.ConfigStruct.TestModeConfig = (byte)0xA0; + } + + resultStr = "OK"; + return CommErr.None; + } + else + { + return CommErr.Write; + } + } static CommErr GetQ2PreCorrectionsFormRest(int threadId, IperlHead ihead, Results.Entities.WaterMeter wm, ref string resultStr) { diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs index 2817a65df..f18ab71be 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs @@ -86,6 +86,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication retVal.Add(iPerlCommunicationForm.Write2HzCorrectionStr); retVal.Add(iPerlCommunicationForm.DewaReworkRLStr); retVal.Add(iPerlCommunicationForm.DewaReworkLRStr); + retVal.Add(iPerlCommunicationForm.StartTestingSealedMetersStr); + retVal.Add(iPerlCommunicationForm.EndTestingSealedMetersStr); retVal.Add(string.Format("{0} if enabled", iPerlCommunicationForm.ReadConfigurationStr)); retVal.Add(string.Format("{0} 80", iPerlCommunicationForm.SetTestModeStr)); retVal.Add("iPerl_check prevWorkStep direction q2factors"); diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs index 0b61de753..e52700ee1 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlHead/IperlHead.cs @@ -103,6 +103,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead public CalibrationStruct CalibrationStruct; /// CalibrationStruct of WM obtained or updated by iPerlCommunication public CalibrationStructV4 CalibrationStructV4; /// CalibrationStruct of WM obtained or updated by iPerlCommunication + public Byte OrigTestModeConfig; /// Written to by StartTestingSealedMeter(), read from by EndTestingSealedMeter() + public ushort OrigCalibFactor; public ushort CalibFactor { @@ -451,6 +453,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.iPerlHead CalibrationStruct = null; CalibrationStructV4 = null; + OrigTestModeConfig = 0; + LastTestResult = null; LastTestResult2 = null; diff --git a/TBF/UI/Procedures/ProceduresCtrl.cs b/TBF/UI/Procedures/ProceduresCtrl.cs index e18db5d52..d750c4e4e 100644 --- a/TBF/UI/Procedures/ProceduresCtrl.cs +++ b/TBF/UI/Procedures/ProceduresCtrl.cs @@ -328,7 +328,9 @@ namespace TBF.UI.Procedures catch (Exception exc) { transaction.Rollback(); - log.ErrorFormat("Exception when saving Procedure '{0}' : {1}", newProcedure.Name, exc.Message); + log.ErrorFormat("Could not save procedure '{0}':", newProcedure.Name); + log.ErrorFormat("Exception: {0}", exc.Message); + if (exc.InnerException != null) log.ErrorFormat("InnerException: {0}", exc.InnerException.Message); } } } @@ -563,8 +565,10 @@ namespace TBF.UI.Procedures } catch (Exception exc) { - log.ErrorFormat("Exception when saving Procedure '{0}' : {1}", modifiedProcedure.Name, exc.Message); - transaction.Rollback(); + log.ErrorFormat("Could not save procedure '{0}':", modifiedProcedure.Name); + log.ErrorFormat("Exception: {0}", exc.Message); + if (exc.InnerException != null) log.ErrorFormat("InnerException: {0}", exc.InnerException.Message); + transaction.Rollback(); } } session.Flush(); @@ -847,7 +851,9 @@ namespace TBF.UI.Procedures catch (Exception exc) { transaction.Rollback(); - log.ErrorFormat("Exception when saving Procedure '{0}' : {1}", newProcedure.Name, exc.Message); + log.ErrorFormat("Could not save procedure '{0}':", newProcedure.Name); + log.ErrorFormat("Exception: {0}", exc.Message); + if (exc.InnerException != null) log.ErrorFormat("InnerException: {0}", exc.InnerException.Message); } } } diff --git a/TBF/UI/Procedures/TestWizard/FlowSelection.cs b/TBF/UI/Procedures/TestWizard/FlowSelection.cs index 5b56e175f..dab000ab7 100644 --- a/TBF/UI/Procedures/TestWizard/FlowSelection.cs +++ b/TBF/UI/Procedures/TestWizard/FlowSelection.cs @@ -75,13 +75,15 @@ namespace TBF.UI.Procedures.TestWizard { if (test == null) return; - foreach (var path in sensorPaths) sensorsComboBox.Items.Add(path.Name); + qFromTextBox.Text = Units.ConvertTo(flowUnit, test.Qfrom).ToString(); + qToTextBox.Text = Units.ConvertTo(flowUnit, test.Qto).ToString(); selectorComboBox.Items.Add(EmptySelector); foreach (var selector in selectorValues) selectorComboBox.Items.Add(selector); + selectorComboBox.Text = EmptySelector; + + foreach (var path in sensorPaths) sensorsComboBox.Items.Add(path.Name); - qFromTextBox.Text = Units.ConvertTo(flowUnit, test.Qfrom).ToString(); - qToTextBox.Text = Units.ConvertTo(flowUnit, test.Qto).ToString(); nextButton.Enabled = IsFormValid(); }