diff --git a/TestBenchFramework/BenchControl/Elde/Valve/SetValvesOp.cs b/TestBenchFramework/BenchControl/Elde/Valve/SetValvesOp.cs index 2978c2f85..4650e32cb 100644 --- a/TestBenchFramework/BenchControl/Elde/Valve/SetValvesOp.cs +++ b/TestBenchFramework/BenchControl/Elde/Valve/SetValvesOp.cs @@ -14,18 +14,38 @@ namespace TBF.BenchControl.Elde.Valve class SwitchPoint { - public int TimeSec; /// Time [s] - public IList VOpen; /// List of valves to open in this point of time - public IList VClose; /// List of valves to close in this point of time + public int TimeSec; /// Relative time in [s] from the start of the operation + public IList VOpen; /// List of valves to open in this point of time + public IList VClose; /// List of valves to close in this point of time public ulong MasksOpen; /// OR-ed bitmasks of valves to open in this point of time public ulong MasksClose; /// OR-ed bitmasks of valves to close in this point of time - public int MaxDelay; /// Max. delay in [s] of all valves to be opened or closed + + public SwitchPoint(int time, IList vOpen, IList vClose) + { + this.TimeSec = time; + this.VOpen = (vOpen == null) ? new List() : vOpen; + this.VClose = (vClose == null) ? new List() : vClose; + } + + /// Max. delay in [s] of all valves to be opened or closed + public int MaxDelay + { + get + { + int max = 0; + foreach (var vlv in VOpen) if (vlv.Delay > max) max = vlv.Delay; + foreach (var vlv in VClose) if (vlv.Delay > max) max = vlv.Delay; + return max; + } + } } IList switchPointsRaw; IList switchPoints; int nextIx; int swStartTime; + int maxDelayTime; /// Max. delay from all valve/pump switches. + /// Relative time in [s] from the start of the operation /// /// Processes coupled valves and creates switch points. @@ -36,7 +56,7 @@ namespace TBF.BenchControl.Elde.Valve IList CollectSwitchPoints(IList valvesOpen, IList valvesClose) { IList result = new List(); - result.Add(new SwitchPoint { TimeSec = 0, VOpen = valvesOpen, VClose = valvesClose }); + result.Add(new SwitchPoint(0, valvesOpen, valvesClose)); foreach (var valve in StateMachine.CoupledValves) { @@ -51,9 +71,7 @@ namespace TBF.BenchControl.Elde.Valve } else { - result.Add(new SwitchPoint { TimeSec = time, - VOpen = ValveBase.MakeList(valve), - VClose = new List() }); + result.Add(new SwitchPoint(time, ValveBase.MakeList(valve), null)); } } else if ((!valve.InvertCouple && valvesClose.Contains(valve.CoupledTo)) || @@ -67,9 +85,7 @@ namespace TBF.BenchControl.Elde.Valve } else { - result.Add(new SwitchPoint { TimeSec = time, - VOpen = new List(), - VClose = ValveBase.MakeList(valve) }); + result.Add(new SwitchPoint(time, null, ValveBase.MakeList(valve))); } } } @@ -169,7 +185,8 @@ namespace TBF.BenchControl.Elde.Valve { controlBoard.SetValves(switchPoints[0].MasksOpen, switchPoints[0].MasksClose); swStartTime = StateMachine.Time; - nextIx = 1; + maxDelayTime = switchPoints[0].MaxDelay; + nextIx = 1; } /// Run this operation @@ -178,13 +195,22 @@ namespace TBF.BenchControl.Elde.Valve /// public Event Run() { - if (nextIx >= switchPoints.Count) return Event.ValvesSet; + if (nextIx >= switchPoints.Count) + { + if (StateMachine.Time >= swStartTime + maxDelayTime) return Event.ValvesSet; + else return Event.None; + } if (StateMachine.Time >= swStartTime + switchPoints[nextIx].TimeSec) { - controlBoard.SetValves(switchPoints[nextIx].MasksOpen, switchPoints[nextIx].MasksClose); - nextIx++; + if (switchPoints[nextIx].TimeSec + switchPoints[nextIx].MaxDelay > maxDelayTime) + { + maxDelayTime = switchPoints[nextIx].TimeSec + switchPoints[nextIx].MaxDelay; + } + controlBoard.SetValves(switchPoints[nextIx].MasksOpen, switchPoints[nextIx].MasksClose); + nextIx++; } + return Event.None; }