iPerlCommunication : Sequence conditions

This commit is contained in:
Milan Hanajik
2022-09-08 12:45:54 +02:00
parent b044b00571
commit a7118935ca
9 changed files with 156 additions and 42 deletions
@@ -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);
}
}
}
@@ -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<IOperation> 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<IOperation>();
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> { 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;
}
}
}
@@ -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<Config.Entities.Test> tests;
static IList<iPerlCommunicationParams> multiTestParams;
@@ -742,8 +743,8 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
/// Constructor for one iPerlCommunication 'test'
/// </summary>
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
public iPerlCommunicationForm(TestMethodCfg cfg, Test test, iPerlCommunicationParams testParams)
: this(cfg, new List<Test> { test }, new List<iPerlCommunicationParams> { testParams })
public iPerlCommunicationForm(TestMethod testMethod, Test test, iPerlCommunicationParams testParams)
: this(testMethod, new List<Test> { test }, new List<iPerlCommunicationParams> { testParams })
{
}
@@ -751,12 +752,13 @@ namespace TBF.Rig.TestMethods.iPerlCommunication
/// Constructor for multiple iPerlCommunication 'tests'
/// </summary>
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
public iPerlCommunicationForm(TestMethodCfg cfg, IList<Test> tests, IList<iPerlCommunicationParams> multiTestParams)
public iPerlCommunicationForm(TestMethod testMethod, IList<Test> tests, IList<iPerlCommunicationParams> 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
@@ -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
@@ -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
/// </returns>
public IList<Event> Execute(Test test, int repetitionNr, TestMethodCfg cfg, iPerlCommunicationParams testParams)
public IList<Event> Execute(Test test, int repetitionNr, TestMethod method, iPerlCommunicationParams testParams)
{
TestMethodCfg cfg = method.Cfg as TestMethodCfg;
IList<Event> 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);