diff --git a/Config/Entities/TransitionStep.cs b/Config/Entities/TransitionStep.cs index 7e263579b..143b525e1 100644 --- a/Config/Entities/TransitionStep.cs +++ b/Config/Entities/TransitionStep.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2015 Sensus Metering Systems +/// Copyright (c) 2013-2015, 2017 Sensus Metering Systems /// using System; using System.Collections.Generic; @@ -12,7 +12,7 @@ namespace Config.Entities public virtual int ItemNr { get; set; } /// Order of the preparation step public virtual int Duration { get; set; } /// Duration in seconds public virtual string Message { get; set; } /// Message - public virtual StepCondition EndCondition { get; set; } /// Condition when transition step is finished (next to the duration) + public virtual string EndCondition { get; set; } /// Condition when transition step is finished (next to the duration) public virtual string ValvesOpen { get; set; } /// List of valves to be opened public virtual string ValvesClose { get; set; } /// List of valves to be closed public virtual string RegulValvesPct { get; set; } /// Positions of regulation valves in % separated by ';' @@ -24,8 +24,8 @@ namespace Config.Entities public TransitionStep() { - Duration = 5; /// sec. - EndCondition = (int)StepCondition.None; + Duration = 5; /// sec. + EndCondition = "None"; } public TransitionStep(int itemNr, TransitionSequence sequence) @@ -54,7 +54,7 @@ namespace Config.Entities result += indent + "ItemNr = " + ItemNr.ToString() + ", "; result += indent + "Duration = " + Duration.ToString() + ", "; result += indent + "Message = " + Message + ", "; - result += indent + "EndCondition = " + EndCondition.ToString() + ", "; + result += indent + "EndCondition = " + EndCondition + ", "; result += indent + "ValvesOpen = " + ValvesOpen + ", "; result += indent + "ValvesClose = " + ValvesClose + ", "; result += indent + "RegulValvesPct = " + RegulValvesPct + ", "; diff --git a/DeviceTest/DeviceTestDlg.cs b/DeviceTest/DeviceTestDlg.cs index 0b4339db9..84a3a5c73 100644 --- a/DeviceTest/DeviceTestDlg.cs +++ b/DeviceTest/DeviceTestDlg.cs @@ -663,7 +663,7 @@ namespace DeviceTest } else if (tbfComponent1forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector) { - operation1 = (tbfComponent1forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(1); + //operation1 = (tbfComponent1forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(1); //operation2 = (tbfComponent1forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(2); //operation3 = (tbfComponent1forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(3); //operation4 = (tbfComponent1forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(0); @@ -691,7 +691,7 @@ namespace DeviceTest } else if (tbfComponent2forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector) { - operation21 = (tbfComponent2forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(1); + //operation21 = (tbfComponent2forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(1); //operation22 = (tbfComponent2forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(2); //operation23 = (tbfComponent2forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(3); //operation24 = (tbfComponent2forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(0); @@ -719,7 +719,7 @@ namespace DeviceTest } else if (tbfComponent3forOp is TBF.BenchControl.Modbus.TankSelector.TankSelector) { - operation31 = (tbfComponent3forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(1); + //operation31 = (tbfComponent3forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(1); //operation32 = (tbfComponent3forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(2); //operation33 = (tbfComponent3forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(3); //operation34 = (tbfComponent3forOp as TBF.BenchControl.Modbus.TankSelector.TankSelector).SelectTankOp(0); diff --git a/TestBenchFramework/BenchControl/Events.cs b/TestBenchFramework/BenchControl/Events.cs index f8abeeafd..3cc04b81b 100644 --- a/TestBenchFramework/BenchControl/Events.cs +++ b/TestBenchFramework/BenchControl/Events.cs @@ -171,6 +171,10 @@ namespace TBF.BenchControl TimerBusy, SetOutputsDone, + /// Sequence conditions + ConditionNotMet, + ConditionMet, + /// Outer loop control OuterLoopStart, OuterLoopNext, diff --git a/TestBenchFramework/BenchControl/Modbus/TankSelector/SelectTankOp.cs b/TestBenchFramework/BenchControl/Modbus/TankSelector/SelectTankOp.cs new file mode 100644 index 000000000..6ca611f12 --- /dev/null +++ b/TestBenchFramework/BenchControl/Modbus/TankSelector/SelectTankOp.cs @@ -0,0 +1,52 @@ + +namespace TBF.BenchControl.Modbus.TankSelector +{ + public class SelectTankOp : IOperation + { + public enum OpSpecifier + { + None, + SelectTank, + UnselectTank, /// tankNo is ignored, the selected tank is unselected + } + + TankSelector tankSelector; + OpSpecifier currentOp; + int tankNo; + + public SelectTankOp(TankSelector tankSelector, OpSpecifier op, int tankNo) + { + this.tankSelector = tankSelector; + this.currentOp = op; + if (currentOp == OpSpecifier.SelectTank) this.tankNo = tankNo; + } + + /// Start this operation + public void Start() + { + switch (currentOp) + { + case OpSpecifier.SelectTank: + tankSelector.SetOutputs((tankNo == 1) ? 1u : ((tankNo == 2) ? 2u : ((tankNo == 3) ? 4u : 0))); + break; + case OpSpecifier.UnselectTank: + tankSelector.SetOutputs((tankNo == 1) ? 8u : ((tankNo == 2) ? 16u : ((tankNo == 3) ? 32u : 0))); + break; + default: + break; + } + } + + /// Run this operation + public Event Run() + { + tankSelector.SetOutputs(0); + return Event.ConditionMet; + } + + /// Stop this operation + public void Stop() + { + } + } +} diff --git a/TestBenchFramework/BenchControl/Modbus/TankSelector/TankSelector.cs b/TestBenchFramework/BenchControl/Modbus/TankSelector/TankSelector.cs index 4e939ad13..aa5b6e80e 100644 --- a/TestBenchFramework/BenchControl/Modbus/TankSelector/TankSelector.cs +++ b/TestBenchFramework/BenchControl/Modbus/TankSelector/TankSelector.cs @@ -5,11 +5,13 @@ using System; using System.Collections.Generic; using log4net; using TBF.BenchControl.Generic; +using TBF.BenchControl.GenericDevices; using TBF.Boxes; +using TBF.Resources; namespace TBF.BenchControl.Modbus.TankSelector { - public class TankSelector : ComponentBase, IOperation + public class TankSelector : ComponentBase, ISequenceCondition, IDevice { private static readonly ILog log = LogManager.GetLogger(typeof(TankSelector)); public override string ToString() { return string.Format("TankSelector({0})", Cfg.ToString(1)); } @@ -20,13 +22,8 @@ namespace TBF.BenchControl.Modbus.TankSelector readonly Elde.ControlBoardDev controlBoard; - public enum CurrentOp - { - None, - SelectTank, - } - - CurrentOp currentOp; + IList sequenceConditionNames; + IList sequenceConditions; /// @@ -52,6 +49,7 @@ namespace TBF.BenchControl.Modbus.TankSelector public TankSelector() { + CreateConditions(false); } public TankSelector(Generic.IComponentCfg cfg, IList components) @@ -65,9 +63,39 @@ namespace TBF.BenchControl.Modbus.TankSelector controlBoard = (Elde.ControlBoardDev)TbfComponents.FindComponent(tankSelectorCfg.ControlBoard, components); if (controlBoard == null) throw new Exception(string.Format("Cannot find control board '{0}' for the component {1}", tankSelectorCfg.ControlBoard, Name)); + CreateConditions(true); + log.Debug(this.ToString()); } + public void Initialize() { SetOutputs(0); } + public void RunDeviceBefore() { } + public void RunDeviceAfter() { } + public void StopDevice() { SetOutputs(0); } + + void CreateConditions(bool createAll) + { + sequenceConditionNames = new List(); + sequenceConditionNames.Add(Strings.Select_COLD_tank); + sequenceConditionNames.Add(Strings.Select_WARM_tank); + sequenceConditionNames.Add(Strings.Select_HOT_tank); + sequenceConditionNames.Add(Strings.Unselect_COLD_tank); + sequenceConditionNames.Add(Strings.Unselect_WARM_tank); + sequenceConditionNames.Add(Strings.Unselect_HOT_tank); + + if (createAll) + { + sequenceConditions = new List(); + sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.SelectTank, 1)); + sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.SelectTank, 2)); + sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.SelectTank, 3)); + sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.UnselectTank, 1)); + sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.UnselectTank, 2)); + sequenceConditions.Add(new SelectTankOp(this, SelectTankOp.OpSpecifier.UnselectTank, 3)); + } + } + + /// /// Set outputs of QuidoRS board /// @@ -78,69 +106,32 @@ namespace TBF.BenchControl.Modbus.TankSelector } - /// - /// Events: SetOpututsDone, Error - /// - /// Reference to a variable for the pressure in Bar - /// SetOutputsOp instance reference casted to IOperaton - //public IOperation SetOutputsOp(ushort outValue) - //{ - // return new SetOutputsOp(this, outValue); - //} + public int ConditionsCount { get { return sequenceConditions != null ? sequenceConditions.Count : 0; } } - /// - /// Events: pressureDone, Error - /// - /// Reference to a variable for the pressure in Bar - /// Event returned when SetOutput is done - /// SetOutputsOp instance reference casted to IOperaton - //public IOperation ReadPressureOp(ushort outValue, Event setOutputsDone) - //{ - // return new SetOutputsOp(this, outValue, setOutputsDone); - //} - int tankNo; - /// - public IOperation SelectTankOp(int tankNo) + /// Returned strings are added to the combo-box + public string ConditionName(int i) { - if (currentOp != CurrentOp.None) + if (sequenceConditionNames != null && i < sequenceConditionNames.Count && i >= 0) { - throw new Exception("Cannot start operation 'SelectTankOp'"); + return sequenceConditionNames[i]; } - this.tankNo = tankNo; - currentOp = CurrentOp.SelectTank; - return this; - } - - /// Start this operation - public void Start() - { - switch (currentOp) + else { - case CurrentOp.SelectTank: - SetOutputs((tankNo==1) ? 1u : ((tankNo==2) ? 2u : ((tankNo==3) ? 3u : 0))); - break; - default: - break; - } - } - - /// Run this operation - public Event Run() - { - switch (currentOp) - { - case CurrentOp.SelectTank: - return Event.Done; - default: - return Event.Done; + return string.Empty; } } - /// Stop this operation - public void Stop() + public IOperation ConditionOp(int i) { - currentOp = CurrentOp.None; + if (sequenceConditions != null && i < sequenceConditions.Count && i >= 0) + { + return sequenceConditions[i]; + } + else + { + return null; + } } } } diff --git a/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs b/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs index 4252499ee..295a9dbe9 100644 --- a/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs +++ b/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs @@ -368,6 +368,24 @@ namespace TBF.BenchControl.Sequences log.Info(activity + " " +step.Message); //------------------------------------------------ + /// + /// Fetch the condition operation, null value is allowed if there is no condition + /// + IOperation conditionOperation = null; + if (step.EndCondition != "None") + { + string[] fields = step.EndCondition.Split(new char[]{'~'}); + if (fields.Length == 2) + { + ISequenceCondition seqCondition = TbfComponents.FindComponent(fields[0]) as ISequenceCondition; + int condID; + if (int.TryParse(fields[1], out condID)) + { + conditionOperation = seqCondition.ConditionOp(condID); + } + } + } + /// FM controlled pumps are canged imediately without using any state operations log.DebugFormat("step.PumpWithFMPcts = {0}", step.PumpWithFMPcts); float[] allFMPumpPcts = Utils.GetPumpWithFMPcts(step); @@ -421,6 +439,7 @@ namespace TBF.BenchControl.Sequences State stepStrt = State .Create(string.Format("SequenceBase.Transition() : Step {0} start, opening={1}, closing={2}", step.ItemNr + 1, step.ValvesOpen, step.ValvesClose)) .AddOperation(checkUiOp) + .AddOperation(conditionOperation) .AddOperation(new MettlerToledo.KeepReadingMassesOp()) .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) .AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step))); @@ -443,6 +462,7 @@ namespace TBF.BenchControl.Sequences State stepDelay = State .Create(string.Format("SequenceBase.Transition() : Step {0} delay {1}s, opening={2}, closing={3}", step.ItemNr + 1, delay, step.ValvesOpen, step.ValvesClose)) .AddOperation(checkUiOp) + .AddOperation(conditionOperation) .AddOperation(new MettlerToledo.KeepReadingMassesOp()) .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) .AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step))) @@ -460,6 +480,8 @@ namespace TBF.BenchControl.Sequences if (e.Contains(Event.Error) || e.Contains(Event.RegulValveTimeOut)) { errorFlag = true; break; } if (TestAndLogUiCmdStop(e)) { stopFlag = true; break; } + if (e.Contains(Event.ConditionMet)) endContitionFulfilled = true; ; +/* switch (step.EndCondition) { case StepCondition.Scale1Empty: @@ -477,6 +499,7 @@ namespace TBF.BenchControl.Sequences ((StateMachine.Balance3 == null) || StateMachine.Balance3.IsEmpty()); break; } + */ } while (e.Contains(Event.ValvesBusy) || (!endContitionFulfilled && e.Contains(Event.TimerBusy) && !e.Contains(Event.Next))); } @@ -486,6 +509,7 @@ namespace TBF.BenchControl.Sequences log.DebugFormat("SequenceBase.Transition() : Step {0} stop, opening={1}, closing={2}", step.ItemNr + 1, step.ValvesOpen, step.ValvesClose); State stepStop = State.Create(string.Format("SequenceBase.Transition() : Step {0} stop, opening={1}, closing={2}", step.ItemNr + 1, step.ValvesOpen, step.ValvesClose)) .AddOperation(checkUiOp) + .AddOperation(conditionOperation) .AddOperation(new MettlerToledo.KeepReadingMassesOp()) .AddOperation(StateMachine.ControlBoard.UpdateTankWeightOp()) .AddOperation(StateMachine.ControlBoard.SetValvesOp(Utils.ValvesOpen(step), Utils.ValvesClose(step))); diff --git a/TestBenchFramework/Properties/AssemblyInfo.cs b/TestBenchFramework/Properties/AssemblyInfo.cs index ca80904cf..c371bb2ac 100644 --- a/TestBenchFramework/Properties/AssemblyInfo.cs +++ b/TestBenchFramework/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.12.460.1")] -[assembly: AssemblyFileVersion("2.12.460.1")] +[assembly: AssemblyVersion("2.12.462.1")] +[assembly: AssemblyFileVersion("2.12.462.1")] diff --git a/TestBenchFramework/Resources/Strings.Designer.cs b/TestBenchFramework/Resources/Strings.Designer.cs index 717f078f6..e32a14a13 100644 --- a/TestBenchFramework/Resources/Strings.Designer.cs +++ b/TestBenchFramework/Resources/Strings.Designer.cs @@ -3354,6 +3354,15 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Select COLD tank. + /// + internal static string Select_COLD_tank { + get { + return ResourceManager.GetString("Select_COLD_tank", resourceCulture); + } + } + /// /// Looks up a localized string similar to Select Component. /// @@ -3363,6 +3372,24 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Select HOT tank. + /// + internal static string Select_HOT_tank { + get { + return ResourceManager.GetString("Select_HOT_tank", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Select WORM tank. + /// + internal static string Select_WARM_tank { + get { + return ResourceManager.GetString("Select_WARM_tank", resourceCulture); + } + } + /// /// Looks up a localized string similar to Selected results. /// @@ -4311,6 +4338,33 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Unselect COLD tank. + /// + internal static string Unselect_COLD_tank { + get { + return ResourceManager.GetString("Unselect_COLD_tank", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unselect HOT tank. + /// + internal static string Unselect_HOT_tank { + get { + return ResourceManager.GetString("Unselect_HOT_tank", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unselect WARM tank. + /// + internal static string Unselect_WARM_tank { + get { + return ResourceManager.GetString("Unselect_WARM_tank", resourceCulture); + } + } + /// /// Looks up a localized string similar to Up. /// diff --git a/TestBenchFramework/Resources/Strings.resx b/TestBenchFramework/Resources/Strings.resx index d3d1c3d19..e58ed5b6b 100644 --- a/TestBenchFramework/Resources/Strings.resx +++ b/TestBenchFramework/Resources/Strings.resx @@ -1633,4 +1633,22 @@ Do you want to retry RoI detection? + + Select COLD tank + + + Select HOT tank + + + Select WORM tank + + + Unselect COLD tank + + + Unselect HOT tank + + + Unselect WARM tank + \ No newline at end of file diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index 95e13877c..24e5ac4c3 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -529,6 +529,7 @@ + @@ -2341,7 +2342,9 @@ - + + Designer + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/TestBenchFramework/UiControls/TransitionStepsCtrl.cs b/TestBenchFramework/UiControls/TransitionStepsCtrl.cs index 2b602e479..a2320b210 100644 --- a/TestBenchFramework/UiControls/TransitionStepsCtrl.cs +++ b/TestBenchFramework/UiControls/TransitionStepsCtrl.cs @@ -38,9 +38,17 @@ namespace TBF.UiControls int regvCount; /// Number of regulating valves int vCount; /// Number of valves + IList conditionNames; + IList conditionComponents; + IList conditionIDs; + + public TransitionStepsCtrl() : base() { + conditionNames = new List(); + conditionComponents = new List(); + conditionIDs = new List(); } public void Initialize(TransitionSequence sequence, TransitionsDlg parent, Control parentControl) @@ -103,13 +111,29 @@ namespace TBF.UiControls tb.Visible = false; parent.Controls.Add(tb); + /// End condition editors[(int)Column.Condition] = cb = new ComboBox(); cb.Visible = false; cb.Items.Add("---"); - for (int i = 1; i < (int)StepCondition.Count; i++) cb.Items.Add(((StepCondition)i).ToString()); + ///for (int i = 1; i < (int)StepCondition.Count; i++) cb.Items.Add(((StepCondition)i).ToString()); + foreach (var cmpnt in parent.TbfComponents) + { + if (cmpnt is ISequenceCondition) + { + ISequenceCondition c = cmpnt as ISequenceCondition; + for (int i = 0; i < c.ConditionsCount; i++) + { + cb.Items.Add(c.ConditionName(i)); + conditionNames.Add(c.ConditionName(i)); + conditionComponents.Add(cmpnt.Name); + conditionIDs.Add(i); + } + } + } parent.Controls.Add(cb); + /// FM controlled pumps for (int i = fixedCount; i < fixedCount + fmPumpCount; i++) { @@ -280,7 +304,32 @@ namespace TBF.UiControls lvi.UseItemStyleForSubItems = false; lvi.SubItems.Add(string.IsNullOrEmpty(step.Message) ? string.Empty : step.Message); - lvi.SubItems.Add((step.EndCondition == StepCondition.None) ? "---" : step.EndCondition.ToString()); + + if (step.EndCondition == "None") + { + lvi.SubItems.Add("---"); + } + else + { + string[] fields = step.EndCondition.Split( new char[] { '~' } ); + if (fields.Length == 2) + { + ISequenceCondition cmpnt = TbfComponents.FindComponent(fields[0], parent.TbfComponents) as ISequenceCondition; + int id; + if (cmpnt != null && int.TryParse(fields[1], out id) && id >= 0 && id < cmpnt.ConditionsCount) + { + lvi.SubItems.Add(cmpnt.ConditionName(id)); + } + else + { + lvi.SubItems.Add("---"); + } + } + else + { + lvi.SubItems.Add("---"); + } + } string[] fmPumpsStr = (step.PumpWithFMPcts != null) ? step.PumpWithFMPcts.Split(new char[] { ';' }) : new string[0]; @@ -347,12 +396,12 @@ namespace TBF.UiControls /// /// Condition /// - step.EndCondition = StepCondition.None; /// When item text is "---" or a wrong value - for (int cond = 1; cond < (int)StepCondition.Count; cond++) + step.EndCondition = "None"; /// When item text is "---" or a wrong value + for (int cix = 0; cix < conditionNames.Count; cix++) { - if (lvi.SubItems[(int)Column.Condition].Text.Equals(((StepCondition)cond).ToString())) + if (lvi.SubItems[(int)Column.Condition].Text.Equals(conditionNames[cix])) { - step.EndCondition = (StepCondition)cond; + step.EndCondition = string.Format("{0}~{1}", conditionComponents[cix], conditionIDs[cix]); break; } }