/// /// Copyright (c) 2015 Sensus Metering Systems /// Author: Milan Hanajík /// using System; using System.Collections.Generic; using System.Text; using log4net; using TBF.BenchControl; using TBF.Boxes; using TBF.Resources; using TBF.UiBridge; namespace TBF.BenchControl.TestMethods.iPerlCommunication { public class iPerlCommunicationSeq : Sequences.SequenceBase { private static readonly ILog log = LogManager.GetLogger(typeof(iPerlCommunicationSeq)); System.Windows.Forms.Form modelessDlg; /// delegate void ICommFormFormDlgt(iPerlCommunicationSeq myRef, string activity); /// void OpenIPerlCommForm(iPerlCommunicationSeq myRef, string activity) { myRef.modelessDlg = new iPerlCommunicationForm(WaterMeters, activity); modelessDlg.Show(); } /// /// Flying start mass collection method sequence /// /// Test entity /// /// Event.Done . . . . . . . OK /// Event.UiCmdStop . . . . Stopped by the user using the on-screen button STOP /// Event.OpArgumentError . Target flow is out of range /// Event.Error . . . . . . Unspecified error /// public IList Execute(Entities.Test test, iPerlCommunicationParams testParams) { IList e = new List(); /// Events from currently running operations Event retVal = Event.Done; checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state processDataLoggingOp = new TBF.BenchControl.Operations.ProcessDataLoggingOp(processDataLogger, this); //==================================== // Transition or SetRoute - Start //==================================== switch (Transition(transitionBefore, TransitionContext.BeforeTest)) { case Event.Error: { retVal = Event.Error; goto stopTest; } case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } } if (testParams.Activity.Contains("Simulate")) { IList rList = new List(1); Entities.TestResult tstRslt = new Entities.TestResult(test, 1, Entities.MetersKind.Single); if (testParams.Activity.Contains("Q1")) { tstRslt.VolumeMaster = tstRslt.VolumeCTV = 5; for (int i = 0; i < WaterMeters.Count; i++) { tstRslt.Meters[i].VolumeMeter = 5; tstRslt.Meters[i].VolumeRef = tstRslt.VolumeCTV; } AddOrOverwriteResult(tstRslt); } else if (testParams.Activity.Contains("Q2")) { tstRslt.VolumeMaster = tstRslt.VolumeCTV = 5; for (int i = 0; i < WaterMeters.Count; i++) { tstRslt.Meters[i].VolumeMeter = 5; tstRslt.Meters[i].VolumeRef = tstRslt.VolumeCTV; } AddOrOverwriteResult(tstRslt); } else if (testParams.Activity.Contains("Q3")) { tstRslt.VolumeMaster = tstRslt.VolumeCTV = 5; for (int i = 0; i < WaterMeters.Count; i++) { tstRslt.Meters[i].VolumeMeter = 5; tstRslt.Meters[i].VolumeRef = tstRslt.VolumeCTV; } AddOrOverwriteResult(tstRslt); } rList.Add(Event.Done); return rList; } else { /// /// Show the modeless dialog with error indication /// Program.MainWnd.Invoke(new ICommFormFormDlgt(OpenIPerlCommForm), new object[] { this, testParams.Activity }); } loop: //------------------------------------------------ Bridge.OnActivity(this, Strings.Test_in_progress); //------------------------------------------------ /// Make sure the CycleBeginForm is closed so that water meter data (s/n) can be copied into results if (UIFlowControl.Stop == WaitBeginFormClosed()) goto stopTest; /// Test 'Quit' if ((modelessDlg is GenericDevices.IHasCompleted) && !(modelessDlg as GenericDevices.IHasCompleted).Completed) { goto loop; /// Modeless dilaog not closed, keep looping } modelessDlg = null; /// Modeless dialog is closed now stopTest: /// Transition sequence at the end of test /// Prevent overwriting 'retVal' in case it was set to non-default value earlier switch (Transition(transitionAfter, TransitionContext.AfterTest)) { case Event.Error: { if (retVal == Event.Done) retVal = Event.Error; break; } case Event.UiCmdStop: { if (retVal == Event.Done) retVal = Event.UiCmdStop; break; } } /// Create a list with one item 'retVal' (default is Event.Done) and return it IList retList = new List(1); retList.Add(retVal); return retList; } } }