diff --git a/TBF/Rig/Events.cs b/TBF/Rig/Events.cs index a51792c16..d616f574e 100644 --- a/TBF/Rig/Events.cs +++ b/TBF/Rig/Events.cs @@ -76,6 +76,7 @@ namespace TBF.Rig Busy, /// Useful when waiting in state until at least one is busy (all are done) Done, /// Useful when waiting in state until the first is done, the rest miht still be busy MakeSecondPass, /// Test completed OK but 2nd pass (evaluation) is required + EndSession, /// Test completed OK (similarly to Event.Done), 'End session' button click is automatically invoked /// ModelessFormIsOpen, ModelessFormClosed, diff --git a/TBF/Rig/Sequences/MainSeq.cs b/TBF/Rig/Sequences/MainSeq.cs index b86e9f85c..affef2faf 100644 --- a/TBF/Rig/Sequences/MainSeq.cs +++ b/TBF/Rig/Sequences/MainSeq.cs @@ -1011,6 +1011,12 @@ namespace TBF.Rig.Sequences log.InfoFormat("Test {0}: Transition({1}, {2}) returned {3}", testInst.Name, (transitionAfter == null ? "null" : transitionAfter.Name), endContext, rsltTransAfter); } } + + if (currentTestIx == StateMachine.TestInstances.Length - simultWithEvacuationCount - 1 && + e.Contains(Event.EndSession)) + { + goto save_results; + } } if (rsltTransBefore == Event.Error || rsltTransBetween == Event.Error|| e.Contains(Event.Error)) @@ -1218,6 +1224,7 @@ namespace TBF.Rig.Sequences } ///------------------------------------------------------------------------------------------------------------ + /// Cycle or test completed goto select_cycle_or_test; diff --git a/TBF/Rig/TestMethods/S640Communication/S640CommForm.cs b/TBF/Rig/TestMethods/S640Communication/S640CommForm.cs index fea2ab387..0ea7eb205 100644 --- a/TBF/Rig/TestMethods/S640Communication/S640CommForm.cs +++ b/TBF/Rig/TestMethods/S640Communication/S640CommForm.cs @@ -70,6 +70,9 @@ namespace TBF.Rig.TestMethods.S640Communication public bool Completed { get { return formCompleted; } } bool formCompleted; + public bool IsSealedOk { get { return isSealedOk; } } + bool isSealedOk; + bool forcedClose; /// Set in the forced close handler @@ -265,6 +268,8 @@ namespace TBF.Rig.TestMethods.S640Communication areValuesDisplayed = false; areNewSNsAndRadioAddressesAssigned = false; formCompleted = false; + isSealedOk = false; + StartForceCloseHandler(); } @@ -781,7 +786,7 @@ namespace TBF.Rig.TestMethods.S640Communication UpdateFirstTestResult(tests); UiBridge.Bridge.OnTestProgress(null, new TBF.UiBridge.TestProgressEventArgs(tests[currentActivityIx], Progress.Completed)); step = Step.Idle; - NormalClose(); + SealedOkClose(); } else if (File.Exists(Path.Combine(fileExchangePath, ErrorFileName))) { @@ -845,6 +850,7 @@ namespace TBF.Rig.TestMethods.S640Communication { UpdateFirstTestResult(tests); UiBridge.Bridge.OnTestProgress(null, new TBF.UiBridge.TestProgressEventArgs(tests[currentActivityIx], Progress.Completed)); + step = Step.Idle; NormalClose(); } else if (step == Step.EnterSNs) @@ -862,13 +868,15 @@ namespace TBF.Rig.TestMethods.S640Communication { UpdateFirstTestResult(tests); UiBridge.Bridge.OnTestProgress(null, new TBF.UiBridge.TestProgressEventArgs(tests[currentActivityIx], Progress.Completed)); - NormalClose(); + step = Step.Idle; + SealedOkClose(); } - else + else if (step != Step.Idle) { log.Error("User is closing this form, communication failed"); UpdateFirstTestResult(tests, true); UiBridge.Bridge.OnTestProgress(null, new TBF.UiBridge.TestProgressEventArgs(tests[currentActivityIx], Progress.Aborted)); + step = Step.Idle; NormalClose(); } } @@ -1197,6 +1205,24 @@ namespace TBF.Rig.TestMethods.S640Communication Close(); } + private void SealedOkClose() + { + if (Program.LocalSettings.S640CommFormLeft != Location.X || + Program.LocalSettings.S640CommFormTop != Location.Y) + { + /// Update local settings + Program.LocalSettings.S640CommFormLeft = Location.X; + Program.LocalSettings.S640CommFormTop = Location.Y; + Program.LocalSettings.Save(); + } + + isSealedOk = true; + formCompleted = true; + + DialogResult = DialogResult.OK; + Close(); + } + #region Forced close handling public void StartForceCloseHandler() diff --git a/TBF/Rig/TestMethods/S640Communication/S640CommSeq.cs b/TBF/Rig/TestMethods/S640Communication/S640CommSeq.cs index c1bd1b35e..f80a184e3 100644 --- a/TBF/Rig/TestMethods/S640Communication/S640CommSeq.cs +++ b/TBF/Rig/TestMethods/S640Communication/S640CommSeq.cs @@ -18,7 +18,7 @@ namespace TBF.Rig.TestMethods.S640Communication private static readonly ILog log = LogManager.GetLogger(typeof(S640CommSeq)); - System.Windows.Forms.Form modelessDlg; + S640CommForm modelessDlg; /// delegate void S640CommFormDlgt(S640CommSeq myRef, S640Activity activity, I640Cfg config, ProcParams procParams, Test test); /// @@ -64,6 +64,7 @@ namespace TBF.Rig.TestMethods.S640Communication bool stopPressed = false; /// true when STOP button pressed bool completed = false; + bool isSealedOK = false; State.Create("iPerlCommunicationSeq : Wait until the entry form is closed") .AddOperation(checkUiOp) @@ -71,8 +72,8 @@ namespace TBF.Rig.TestMethods.S640Communication do { e = StateMachine.WaitRunDevsRunOps(); stopPressed = TestAndLogUiCmdStop(test,e); - completed = (modelessDlg is GenericDevices.IHasCompleted) - && (modelessDlg as GenericDevices.IHasCompleted).Completed; + completed = modelessDlg.Completed; + isSealedOK = modelessDlg.IsSealedOk; } while (!stopPressed && !completed); @@ -89,7 +90,9 @@ namespace TBF.Rig.TestMethods.S640Communication /// Test 'Quit' modelessDlg = null; /// Modeless dialog is closed now - return new List { Event.Done }; + bool endSession = (activity == S640Activity.End) && (config is S640EndCfg) && (config as S640EndCfg).EndSessionWhenCompleted && isSealedOK; + + return endSession ? new List { Event.EndSession } : new List { Event.Done }; } } } diff --git a/TBF/Rig/TestMethods/S640Communication/S640EndCfg.cs b/TBF/Rig/TestMethods/S640Communication/S640EndCfg.cs index b639a858c..2da1e7546 100644 --- a/TBF/Rig/TestMethods/S640Communication/S640EndCfg.cs +++ b/TBF/Rig/TestMethods/S640Communication/S640EndCfg.cs @@ -34,6 +34,7 @@ namespace TBF.Rig.TestMethods.S640Communication public SerialNumbers AssignedNumbers { get; set; } /// 4 public bool SkipBadMeters { get; set; } /// 5 public bool SimultWithEvacuation { get; set; } /// 6 + public bool EndSessionWhenCompleted { get; set; } /// 7 /// Procedure parameters [XmlIgnore] @@ -67,6 +68,7 @@ namespace TBF.Rig.TestMethods.S640Communication AssignedNumbers = SerialNumbers.None; SkipBadMeters = false; SimultWithEvacuation = true; + EndSessionWhenCompleted = false; } string[] paramNames = new string[] @@ -78,6 +80,7 @@ namespace TBF.Rig.TestMethods.S640Communication "Assigned S/N-s mode", "Skip bad meters when entering s/n", "Simultaneous with evacuation", + "End session when completed OK", }; public string ParamName(int i) { return paramNames[i]; } public int ParamsCount() { return paramNames.Length; } @@ -94,6 +97,7 @@ namespace TBF.Rig.TestMethods.S640Communication SerialNumbers.FromProductionTracing.ToString() }; case 5: case 6: + case 7: return new List { Strings.yes, Strings.no }; default: return null; @@ -111,6 +115,7 @@ namespace TBF.Rig.TestMethods.S640Communication case 4: return AssignedNumbers.ToString(); case 5: return SkipBadMeters ? Strings.yes : Strings.no; case 6: return SimultWithEvacuation ? Strings.yes : Strings.no; + case 7: return EndSessionWhenCompleted ? Strings.yes : Strings.no; default: return string.Format("{0}: FileExchangePath = '{1}' FileExchangeTimeout = {2}s", Name, FileExchangePath, FileExchangeTimeout); } @@ -151,6 +156,9 @@ namespace TBF.Rig.TestMethods.S640Communication case 6: SimultWithEvacuation = (strValue == Strings.yes); return CfgUpdateFlags.RestartRqrd; + case 7: + EndSessionWhenCompleted = (strValue == Strings.yes); + return CfgUpdateFlags.RestartRqrd; default: break; } @@ -175,6 +183,7 @@ namespace TBF.Rig.TestMethods.S640Communication case 4: case 5: case 6: + case 7: if (ParamValues(i).Contains(strValue)) return true; break; default: @@ -195,6 +204,7 @@ namespace TBF.Rig.TestMethods.S640Communication prms.AssignedNumbers = this.AssignedNumbers; prms.SkipBadMeters = this.SkipBadMeters; prms.SimultWithEvacuation = this.SimultWithEvacuation; + prms.EndSessionWhenCompleted = this.EndSessionWhenCompleted; } public IParamsProvider Clone()