diff --git a/TBF/Rig/GenericDevices/ISimultTestMethod.cs b/TBF/Rig/GenericDevices/ISimultTestMethod.cs index d31c7f9cb..1629b0d13 100644 --- a/TBF/Rig/GenericDevices/ISimultTestMethod.cs +++ b/TBF/Rig/GenericDevices/ISimultTestMethod.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2015 Sensus Metering Systems +/// Copyright (c) 2015 Sensus Slovensko a.s. /// using System; diff --git a/TBF/Rig/Sequences/MainSeq.cs b/TBF/Rig/Sequences/MainSeq.cs index f31561cae..de0e557d4 100644 --- a/TBF/Rig/Sequences/MainSeq.cs +++ b/TBF/Rig/Sequences/MainSeq.cs @@ -25,27 +25,27 @@ namespace TBF.Rig.Sequences int simultWithPurgingCount; - Generic.IComponentCfg simultWithPurgingCfg; + Generic.IComponent simultWithPurging; Generic.IProcedureParams simultWithPurgingProcParams; IList simultWithPurgingTests; IList simultWithPurgingTestParams; int simultWithEvacuationCount; - Generic.IComponentCfg simultWithEvacuationCfg; + Generic.IComponent simultWithEvacuation; Generic.IProcedureParams simultWithEvacuationProcParams; IList simultWithEvacuationTests; IList simultWithEvacuationTestParams; System.Windows.Forms.Form modelessDlg; /// - delegate void CommunicationFormDlgt(MainSeq myRef, Generic.IComponentCfg cfg, Generic.IProcedureParams procParams, IList tests, IList multiTestParams); + delegate void CommunicationFormDlgt(MainSeq myRef, Generic.IComponent comp, Generic.IProcedureParams procParams, IList tests, IList multiTestParams); /// - void OpenIPerlCommForm(MainSeq myRef, Generic.IComponentCfg cfg, Generic.IProcedureParams procParams, IList tests, IList multiTestParams) + void OpenIPerlCommForm(MainSeq myRef, Generic.IComponent testMethod, Generic.IProcedureParams procParams, IList tests, IList multiTestParams) { try { /// 1nd argument - TestMethods.iPerlCommunication.TestMethodCfg iPerlCfg = cfg as TestMethods.iPerlCommunication.TestMethodCfg; + TestMethods.iPerlCommunication.TestMethodCfg iPerlCfg = testMethod.Cfg as TestMethods.iPerlCommunication.TestMethodCfg; /// 2rd argument: as is @@ -53,7 +53,8 @@ namespace TBF.Rig.Sequences IList iPerlCommParams = new List(); foreach (var tp in multiTestParams) iPerlCommParams.Add(tp as TestMethods.iPerlCommunication.iPerlCommunicationParams); - myRef.modelessDlg = new TestMethods.iPerlCommunication.iPerlCommunicationForm(iPerlCfg, tests, iPerlCommParams); + myRef.modelessDlg = new TestMethods.iPerlCommunication.iPerlCommunicationForm( + testMethod as TBF.Rig.TestMethods.iPerlCommunication.TestMethod, tests, iPerlCommParams); myRef.modelessDlg.Show(); } catch (Exception e) @@ -69,21 +70,21 @@ namespace TBF.Rig.Sequences } } /// - void OpenS640CommForm(MainSeq myRef, Generic.IComponentCfg cfg, Generic.IProcedureParams procParams, IList tests, IList multiTestParams) + void OpenS640CommForm(MainSeq myRef, Generic.IComponent testMethod, Generic.IProcedureParams procParams, IList tests, IList multiTestParams) { try { TestMethods.S640Communication.S640Activity activity; /// 1st argument TBF.Rig.TestMethods.S640Communication.I640Cfg config; /// 2nd argument - if (cfg is TestMethods.S640Communication.S640StartCfg) + if (testMethod.Cfg is TestMethods.S640Communication.S640StartCfg) { activity = TestMethods.S640Communication.S640Activity.Start; - config = (cfg as TestMethods.S640Communication.S640StartCfg); + config = (testMethod.Cfg as TestMethods.S640Communication.S640StartCfg); } - else if (cfg is TestMethods.S640Communication.S640EndCfg) + else if (testMethod.Cfg is TestMethods.S640Communication.S640EndCfg) { activity = TestMethods.S640Communication.S640Activity.End; - config = (cfg as TestMethods.S640Communication.S640EndCfg); + config = (testMethod.Cfg as TestMethods.S640Communication.S640EndCfg); } else { @@ -131,13 +132,13 @@ namespace TBF.Rig.Sequences FillState = FillState.Unknown; simultWithPurgingCount = 0; - simultWithPurgingCfg = null; + simultWithPurging = null; simultWithPurgingProcParams = null; simultWithPurgingTests = new List(); simultWithPurgingTestParams = new List(); simultWithEvacuationCount = 0; - simultWithEvacuationCfg = null; + simultWithEvacuation = null; simultWithEvacuationProcParams = null; simultWithEvacuationTests = new List(); simultWithEvacuationTestParams = new List(); @@ -588,11 +589,11 @@ namespace TBF.Rig.Sequences var firstRR = ProcessData.RegisterReaders.FirstOrDefault(x => x != null); if (firstRR is TBF.Rig.TestMethods.iPerlCommunication.iPerlHead.IperlHead) { - Program.MainWnd.Invoke(new CommunicationFormDlgt(OpenIPerlCommForm), new object[] { this, simultWithPurgingCfg, simultWithPurgingProcParams, simultWithPurgingTests, simultWithPurgingTestParams }); + Program.MainWnd.Invoke(new CommunicationFormDlgt(OpenIPerlCommForm), new object[] { this, simultWithPurging, simultWithPurgingProcParams, simultWithPurgingTests, simultWithPurgingTestParams }); } else if (firstRR is TBF.Rig.RegisterReaders.S640Stream.S640Stream) { - Program.MainWnd.Invoke(new CommunicationFormDlgt(OpenS640CommForm), new object[] { this, simultWithPurgingCfg, simultWithPurgingProcParams, simultWithPurgingTests, simultWithPurgingTestParams }); + Program.MainWnd.Invoke(new CommunicationFormDlgt(OpenS640CommForm), new object[] { this, simultWithPurging, simultWithPurgingProcParams, simultWithPurgingTests, simultWithPurgingTestParams }); } } diff --git a/TBF/Rig/Sequences/MainSeqUtils.cs b/TBF/Rig/Sequences/MainSeqUtils.cs index 9548cfd02..8dbb075ea 100644 --- a/TBF/Rig/Sequences/MainSeqUtils.cs +++ b/TBF/Rig/Sequences/MainSeqUtils.cs @@ -696,7 +696,7 @@ namespace TBF.Rig.Sequences /// Collect steps (e.g. iPerl communication) to be done simultaneously with purging /// simultWithPurgingCount = 0; - simultWithPurgingCfg = null; + simultWithPurging = null; simultWithPurgingProcParams = null; simultWithPurgingTests.Clear(); simultWithPurgingTestParams.Clear(); @@ -715,10 +715,10 @@ namespace TBF.Rig.Sequences if (simultWithPurgingCount == 0) { - simultWithPurgingCfg = simultTest.Cfg; - simultWithPurgingProcParams = simultWithPurgingCfg.GetRuntimeProcParamsProvider() as Generic.IProcedureParams; + simultWithPurging = simultTest; + simultWithPurgingProcParams = simultWithPurging.Cfg.GetRuntimeProcParamsProvider() as Generic.IProcedureParams; } - else if (simultTest.Cfg != simultWithPurgingCfg) + else if (simultTest != simultWithPurging) { break; } @@ -739,7 +739,7 @@ namespace TBF.Rig.Sequences /// Collect steps (e.g. iPerl communication) to be done simultaneously with evacuation /// simultWithEvacuationCount = 0; - simultWithEvacuationCfg = null; + simultWithEvacuation = null; simultWithEvacuationProcParams = null; simultWithEvacuationTests.Clear(); simultWithEvacuationTestParams.Clear(); @@ -760,10 +760,10 @@ namespace TBF.Rig.Sequences if (simultWithEvacuationCount == 0) { - simultWithEvacuationCfg = simultTest.Cfg; - simultWithEvacuationProcParams = simultWithEvacuationCfg.GetRuntimeProcParamsProvider() as Generic.IProcedureParams; + simultWithEvacuation = simultTest; + simultWithEvacuationProcParams = simultWithEvacuation.Cfg.GetRuntimeProcParamsProvider() as Generic.IProcedureParams; } - else if (simultTest.Cfg != simultWithEvacuationCfg) + else if (simultTest != simultWithEvacuation) { break; } @@ -801,12 +801,12 @@ namespace TBF.Rig.Sequences if (firstRR is TBF.Rig.TestMethods.iPerlCommunication.iPerlHead.IperlHead) { Program.MainWnd.Invoke(new CommunicationFormDlgt(OpenIPerlCommForm), - new object[] { this, simultWithEvacuationCfg, simultWithEvacuationProcParams, simultWithEvacuationTests, simultWithEvacuationTestParams }); + new object[] { this, simultWithEvacuation, simultWithEvacuationProcParams, simultWithEvacuationTests, simultWithEvacuationTestParams }); } else if (firstRR is TBF.Rig.RegisterReaders.S640Stream.S640Stream) { Program.MainWnd.Invoke(new CommunicationFormDlgt(OpenS640CommForm), - new object[] { this, simultWithEvacuationCfg, simultWithEvacuationProcParams, simultWithEvacuationTests, simultWithEvacuationTestParams }); + new object[] { this, simultWithEvacuation, simultWithEvacuationProcParams, simultWithEvacuationTests, simultWithEvacuationTestParams }); } } diff --git a/TBF/Rig/TestMethods/iPerlCommunication/SequenceConditionOp.cs b/TBF/Rig/TestMethods/iPerlCommunication/SequenceConditionOp.cs new file mode 100644 index 000000000..8c9f770d7 --- /dev/null +++ b/TBF/Rig/TestMethods/iPerlCommunication/SequenceConditionOp.cs @@ -0,0 +1,44 @@ +/// +/// Copyright (c) 2022 Sensus Slovensko a.s. +/// +using TBF.Resources; + +namespace TBF.Rig.TestMethods.iPerlCommunication +{ + public enum ConditionID + { + A, + B, + C, + Count, + } + + public class SequenceConditionOp : IOperation + { + public const string ConditionNameFmt = "iPERL communication milestone {0}"; + + ConditionID id; + TestMethod testMethodComponent; + + public SequenceConditionOp(TestMethod testMethodComponent, ConditionID id) + { + this.testMethodComponent = testMethodComponent; + this.id = id; + } + + public void Start() { } + + public Event Run() + { + bool conditionMet = testMethodComponent.IperlCommMilestone[(int)id]; + return conditionMet ? Event.ConditionMet : Event.ConditionNotMet; + } + + public void Stop() { } + + public override string ToString() + { + return string.Format(ConditionNameFmt, id); + } + } +} diff --git a/TBF/Rig/TestMethods/iPerlCommunication/TestMethod.cs b/TBF/Rig/TestMethods/iPerlCommunication/TestMethod.cs index 8b4849536..880fcefff 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/TestMethod.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/TestMethod.cs @@ -1,17 +1,18 @@ /// -/// Copyright (c) 2015-2021 Sensus Slovensko a.s. +/// Copyright (c) 2015-2022 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using log4net; using Common; using Config.Entities; +using TBF.Rig.GenericDevices; using TBF.Rig.Sequences; using TBF.UiBridge; namespace TBF.Rig.TestMethods.iPerlCommunication { - public class TestMethod : ComponentBase, GenericDevices.ISimultTestMethod + public class TestMethod : ComponentBase, ISimultTestMethod, ISequenceCondition { private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); protected static readonly ILog rfidDataLogger = LogManager.GetLogger("RfidData"); @@ -60,14 +61,32 @@ namespace TBF.Rig.TestMethods.iPerlCommunication readonly TestMethodCfg testMethodCfg; + + public bool[] IperlCommMilestone; + IList sequenceConditionOps; - public TestMethod() { } + public TestMethod() + { + CreateMilestonesAndConditions(); + } public TestMethod(Generic.IComponentCfg cfg) : base(cfg) { testMethodCfg = cfg as TestMethodCfg; - } + CreateMilestonesAndConditions(); + } + + void CreateMilestonesAndConditions() + { + IperlCommMilestone = new bool[(int)ConditionID.Count]; + + sequenceConditionOps = new List(); + for (ConditionID id = ConditionID.A; id < ConditionID.Count; id++) + { + sequenceConditionOps.Add(new SequenceConditionOp(this, id)); + } + } /// IDevice interface - only Initialize() is used public override void Initialize() @@ -89,7 +108,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication { if (DebugLevel == DebugMode.Normal) { - return (new iPerlCommunicationSeq()).Execute(test, repetNr, testMethodCfg, testMethodCfg.TestParams); + return (new iPerlCommunicationSeq()).Execute(test, repetNr, this, testMethodCfg.TestParams); } else { @@ -100,5 +119,18 @@ namespace TBF.Rig.TestMethods.iPerlCommunication return new List { Event.Done }; } } - } + + + public int ConditionsCount { get { return (int)ConditionID.Count; } } + + public string ConditionName(int i) + { + return (i >= 0 && i < (int)ConditionID.Count) ? ConditionOp(i).ToString() : string.Empty; + } + + public IOperation ConditionOp(int i) + { + return (i >= 0 && i < (int)ConditionID.Count) ? sequenceConditionOps[i] : null; + } + } } diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs index 595d2da92..c3f80a0c7 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationForm.cs @@ -701,6 +701,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// /// RFID multiplexer PCB / RFID serial port and worker thread related variables /// + static TestMethod testMethod; static TestMethodCfg cfg; static IList tests; static IList multiTestParams; @@ -742,8 +743,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// Constructor for one iPerlCommunication 'test' /// /// Number of text boxes for serial numbers - public iPerlCommunicationForm(TestMethodCfg cfg, Test test, iPerlCommunicationParams testParams) - : this(cfg, new List { test }, new List { testParams }) + public iPerlCommunicationForm(TestMethod testMethod, Test test, iPerlCommunicationParams testParams) + : this(testMethod, new List { test }, new List { testParams }) { } @@ -751,12 +752,13 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// Constructor for multiple iPerlCommunication 'tests' /// /// Number of text boxes for serial numbers - public iPerlCommunicationForm(TestMethodCfg cfg, IList tests, IList multiTestParams) + public iPerlCommunicationForm(TestMethod testMethod, IList tests, IList multiTestParams) : this() { checkBoxesEditMode = false; - iPerlCommunicationForm.cfg = cfg; + iPerlCommunicationForm.testMethod = testMethod; + iPerlCommunicationForm.cfg = testMethod.Cfg as TestMethodCfg; iPerlCommunicationForm.tests = tests; iPerlCommunicationForm.multiTestParams = multiTestParams; @@ -1238,7 +1240,21 @@ namespace TBF.Rig.TestMethods.iPerlCommunication else { error = CommErr.None; - resultStr = "Invalid activity"; + + ConditionID id; + for (id = ConditionID.A; id < ConditionID.Count; id++) + { + if (currentActivity.ToLower() == string.Format(SequenceConditionOp.ConditionNameFmt, id).ToLower()) + { + error = SetIperlCommMilestoneReached(testMethod, id, ref resultStr); + break; + } + } + + if (id == ConditionID.Count) + { + resultStr = "Invalid activity"; /// No activity or milestone + } } /// @@ -3200,6 +3216,19 @@ namespace TBF.Rig.TestMethods.iPerlCommunication return CommErr.None; } + static CommErr SetIperlCommMilestoneReached(TestMethod testMethod, ConditionID id, ref string resultStr) + { + if (id < ConditionID.A || id >= ConditionID.Count) + { + resultStr = Strings.Error; + return CommErr.WrongArguments; + } + + testMethod.IperlCommMilestone[(int)id] = true; + resultStr = string.Format(SequenceConditionOp.ConditionNameFmt, id); + return CommErr.None; + } + #endif /// IPERL #endregion diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs index f18ab71be..98efbfd07 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationParams.cs @@ -91,6 +91,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication retVal.Add(string.Format("{0} if enabled", iPerlCommunicationForm.ReadConfigurationStr)); retVal.Add(string.Format("{0} 80", iPerlCommunicationForm.SetTestModeStr)); retVal.Add("iPerl_check prevWorkStep direction q2factors"); + for (ConditionID id = ConditionID.A; id < ConditionID.Count; id++) + { + retVal.Add(string.Format(SequenceConditionOp.ConditionNameFmt, id)); + } + return retVal; } else diff --git a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs index 604b5c293..db3d84b8a 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/iPerlCommunicationSeq.cs @@ -26,11 +26,11 @@ namespace TBF.Rig.TestMethods.iPerlCommunication System.Windows.Forms.Form modelessDlg; /// - delegate void iPerlCommFormDlgt(iPerlCommunicationSeq myRef, TestMethodCfg cfg, Test test, iPerlCommunicationParams testParams); + delegate void iPerlCommFormDlgt(iPerlCommunicationSeq myRef, TestMethod method, Test test, iPerlCommunicationParams testParams); /// - void OpenIPerlCommForm(iPerlCommunicationSeq myRef, TestMethodCfg cfg, Test test, iPerlCommunicationParams testParams) + void OpenIPerlCommForm(iPerlCommunicationSeq myRef, TestMethod method, Test test, iPerlCommunicationParams testParams) { - myRef.modelessDlg = new iPerlCommunicationForm(cfg, test, testParams); + myRef.modelessDlg = new iPerlCommunicationForm(method, test, testParams); myRef.modelessDlg.Show(); } @@ -52,8 +52,10 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// Event.OpArgumentError . Target flow is out of range /// Event.Error . . . . . . Unspecified error /// - public IList Execute(Test test, int repetitionNr, TestMethodCfg cfg, iPerlCommunicationParams testParams) + public IList Execute(Test test, int repetitionNr, TestMethod method, iPerlCommunicationParams testParams) { + TestMethodCfg cfg = method.Cfg as TestMethodCfg; + IList e; /// Events from currently running operations checkUiOp = new Operations.CheckUIOp(true); /// Runs in more then one state modelessDlg = null; @@ -322,7 +324,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication /// /// Show the modeless dialog with error indication /// - Program.MainWnd.Invoke(new iPerlCommFormDlgt(OpenIPerlCommForm), new object[] { this, cfg, test, testParams }); + Program.MainWnd.Invoke(new iPerlCommFormDlgt(OpenIPerlCommForm), new object[] { this, method, test, testParams }); //------------------------------------------------ Bridge.OnActivity(this, Strings.iPerl_Communication_in_progress); diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 958c51e01..fc043c6f1 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -1611,6 +1611,7 @@ +