From 450493069c0ecdadb46c54cc2855192571ee9c4d Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Fri, 26 Oct 2018 10:19:33 +0200 Subject: [PATCH] (1) SequenceBase.DrainTheTank( ) : DrainValve2 is open first, DrainValve in the 2nd half, (2) Two phase draining in MainSeq when bench is started, ver. 2.18.1047 --- TBF/BenchControl/Sequences/MainSeq.cs | 138 +++++++++++++-------- TBF/BenchControl/Sequences/SequenceBase.cs | 87 ++++++------- TBF/Properties/AssemblyInfo.cs | 4 +- 3 files changed, 128 insertions(+), 101 deletions(-) diff --git a/TBF/BenchControl/Sequences/MainSeq.cs b/TBF/BenchControl/Sequences/MainSeq.cs index 5a72a4883..9b916f955 100644 --- a/TBF/BenchControl/Sequences/MainSeq.cs +++ b/TBF/BenchControl/Sequences/MainSeq.cs @@ -195,72 +195,104 @@ namespace TBF.BenchControl.Sequences } } + /// - /// Drain tanks for the first time, use defined drain times + /// Enable stop draining buttons /// Bridge.Bench2UI(((StateMachine.DrainValve1 != null) ? ButtonsEtc.DrainTankBtn1Hi : 0) | ((StateMachine.DrainValve2 != null) ? ButtonsEtc.DrainTankBtn2Hi : 0) | ((StateMachine.DrainValve3 != null) ? ButtonsEtc.DrainTankBtn3Hi : 0)); - - IntBox remainingTime = new IntBox(); - State startNew = State.Create("MainSeq : Drain tanks") - .AddOperation(checkUiOp); + + /// + /// Determine lists of drain valves and drain times (max. of all tank drain times) + /// + IList fullDrainValves = new List(); + IList secondHalfDrainValves = new List(); IList allDrainValves = new List(); - if (StateMachine.DrainValve1 != null) allDrainValves.Add(StateMachine.DrainValve1); - if (StateMachine.DrainValve2 != null) allDrainValves.Add(StateMachine.DrainValve2); - if (StateMachine.DrainValve3 != null) allDrainValves.Add(StateMachine.DrainValve3); - - // Determine the tank emptying time (the maximum for all balances) - int maxTankDrainTime = 0; - if (StateMachine.Tank1 != null && StateMachine.Tank1.EmptyTimeSec > maxTankDrainTime) + int totalDrainTime = 0; + int maxDrainTimeFor2VlvTanks = 0; + bool areTwoDrainPhases = false; + foreach (IScaleOrTank tank in new IScaleOrTank[] { StateMachine.Tank1, StateMachine.Tank2, StateMachine.Tank3 }) { - maxTankDrainTime = StateMachine.Tank1.EmptyTimeSec; - } - if (StateMachine.Tank2 != null && StateMachine.Tank2.EmptyTimeSec > maxTankDrainTime) - { - maxTankDrainTime = StateMachine.Tank2.EmptyTimeSec; - } - if (StateMachine.Tank3 != null && StateMachine.Tank3.EmptyTimeSec > maxTankDrainTime) - { - maxTankDrainTime = StateMachine.Tank3.EmptyTimeSec; - } - if (maxTankDrainTime > 0) - { - startNew.AddOperation(new TimerOp(maxTankDrainTime, remainingTime)) - .AddOperation(StateMachine.ControlBoard.SetValvesOp(allDrainValves, null)); - } - - startNew.EnterState(); - do - { - Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Emptying_tank, remainingTime.Val / 60, "min", remainingTime.Val % 60, Strings.sec)); - - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) goto error; - bool stopDrainingCmd = e.Contains(Event.UiCmdStopDrainingTank1) || e.Contains(Event.UiCmdStopDrainingTank2) || e.Contains(Event.UiCmdStopDrainingTank3); - if (stopDrainingCmd && !e.Contains(Event.ValvesBusy) && !e.Contains(Event.CameraBusy)) + if (tank != null && tank.DrainValve != null) { - goto stop_draining; + if (tank.EmptyTimeSec > totalDrainTime) totalDrainTime = tank.EmptyTimeSec; + if (tank.DrainValve2 != null) + { + areTwoDrainPhases = true; + if (tank.EmptyTimeSec > maxDrainTimeFor2VlvTanks) maxDrainTimeFor2VlvTanks = tank.EmptyTimeSec; + + if (!secondHalfDrainValves.Contains(tank.DrainValve)) secondHalfDrainValves.Add(tank.DrainValve); + if (!fullDrainValves.Contains(tank.DrainValve2)) fullDrainValves.Add(tank.DrainValve2); + if (!allDrainValves.Contains(tank.DrainValve)) allDrainValves.Add(tank.DrainValve); + if (!allDrainValves.Contains(tank.DrainValve2)) allDrainValves.Add(tank.DrainValve2); + } + else + { + if (!fullDrainValves.Contains(tank.DrainValve)) fullDrainValves.Add(tank.DrainValve); + if (!allDrainValves.Contains(tank.DrainValve)) allDrainValves.Add(tank.DrainValve); + } } } - while (e.Contains(Event.TimerBusy) || - e.Contains(Event.CameraBusy) || - e.Contains(Event.ValvesBusy)); - Bridge.OnActivity(this, Strings.Emptying_tank); - - stop_draining: - - State stopDraining = State.Create("MainSeq : Stop draining water tanks") - .AddOperation(checkUiOp) - .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, allDrainValves)) - .EnterState(); - do + /// + /// Drain the tanks, two phases if necessary + /// + if (totalDrainTime > 0) { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.Error)) goto error; + IntBox timerTime = new IntBox(); /// Contains remaining time in each phase + int firstPhaseTime = maxDrainTimeFor2VlvTanks / 2; + + State.Create(areTwoDrainPhases ? "MainSeq : Drain tanks - phase 1" : "MainSeq : Drain tanks") + .AddOperation(checkUiOp) + .AddOperation(new TimerOp(areTwoDrainPhases ? firstPhaseTime : totalDrainTime, timerTime)) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(fullDrainValves, null)) + .EnterState(); + do + { + int remTime = areTwoDrainPhases ? (timerTime.Val + totalDrainTime - firstPhaseTime) : timerTime.Val; + Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Emptying_tank, remTime / 60, "min", remTime % 60, Strings.sec)); + + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) goto error; + bool stopDrainingCmd = e.Contains(Event.UiCmdStopDrainingTank1) || e.Contains(Event.UiCmdStopDrainingTank2) || e.Contains(Event.UiCmdStopDrainingTank3); + if (stopDrainingCmd && !e.Contains(Event.ValvesBusy) && !e.Contains(Event.CameraBusy)) break; + } + while (e.Contains(Event.TimerBusy) || e.Contains(Event.CameraBusy) || e.Contains(Event.ValvesBusy)); + + if (areTwoDrainPhases) + { + State.Create("MainSeq : Drain tanks - phase 2") + .AddOperation(checkUiOp) + .AddOperation(new TimerOp(totalDrainTime - firstPhaseTime, timerTime)) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(secondHalfDrainValves, null)) + .EnterState(); + do + { + int remTime = timerTime.Val; + Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", Strings.Emptying_tank, remTime / 60, "min", remTime % 60, Strings.sec)); + + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) goto error; + bool stopDrainingCmd = e.Contains(Event.UiCmdStopDrainingTank1) || e.Contains(Event.UiCmdStopDrainingTank2) || e.Contains(Event.UiCmdStopDrainingTank3); + if (stopDrainingCmd && !e.Contains(Event.ValvesBusy) && !e.Contains(Event.CameraBusy)) break; + } + while (e.Contains(Event.TimerBusy) || e.Contains(Event.CameraBusy) || e.Contains(Event.ValvesBusy)); + } + + Bridge.OnActivity(this, Strings.Emptying_tank); + + State stopDraining = State.Create("MainSeq : Stop draining water tanks") + .AddOperation(checkUiOp) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(null, allDrainValves)) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) goto error; + } + while (e.Contains(Event.ValvesBusy)); } - while (e.Contains(Event.ValvesBusy)); //-------------------------------------------------------------------------------------------- Bridge.OnActivity(this, Strings.Resetting_scales); diff --git a/TBF/BenchControl/Sequences/SequenceBase.cs b/TBF/BenchControl/Sequences/SequenceBase.cs index aa78f17da..f7144ab0f 100644 --- a/TBF/BenchControl/Sequences/SequenceBase.cs +++ b/TBF/BenchControl/Sequences/SequenceBase.cs @@ -201,41 +201,30 @@ namespace TBF.BenchControl.Sequences /// Event.Done or Event.Error protected Event DrainTheTank(IScaleOrTank tank, IList extraOperations) { - bool stopped = false; - IntBox remainingTimeSec = new IntBox(tank.EmptyTimeSec); - - if (tank is IScale) - { - Bridge.OnActivity(this, TBF.Resources.Strings.Emptying_tank); - } - else - { - Bridge.OnActivity(this, string.Format("{0} ... {1} {2} {3} {4}", - Strings.Emptying_tank, - remainingTimeSec.Val / 60, "min", - remainingTimeSec.Val % 60, Strings.sec)); - } - - IList e; - Bridge.Bench2UI(ButtonsEtc.StopBtnEn); - - - State.Create("SequenceBase : Open the drain valve") - .AddOperation(checkUiOp) - .AddOperation(StateMachine.ControlBoard.SetValvesOp(tank.DrainValve, null)) - .AddOperations(extraOperations) - .EnterState(); - do - { - e = StateMachine.WaitRunDevsRunOps(); - } - while (!e.Contains(Event.ValvesSet)); + IList e; + bool stopped = false; + Bridge.Bench2UI(ButtonsEtc.StopBtnEn); + IntBox remainingTimeSec = new IntBox(); + Bridge.OnActivity(this, TBF.Resources.Strings.Emptying_tank); if (tank.DrainValve2 == null) { - IOperation timer = new TimerOp(tank.EmptyTimeSec, remainingTimeSec); - + /// + /// Draining with 1 valve 'DrainValve' + /// + State.Create("SequenceBase : Open the drain valve") + .AddOperation(checkUiOp) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(tank.DrainValve, null)) + .AddOperations(extraOperations) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + } + while (!e.Contains(Event.ValvesSet)); + + IOperation timer = new TimerOp(tank.EmptyTimeSec, remainingTimeSec); do { State.Create("SequenceBase : Draining the tank") @@ -263,19 +252,31 @@ namespace TBF.BenchControl.Sequences remainingTimeSec.Val / 60, "min", remainingTimeSec.Val % 60, Strings.sec)); } - } while ((tank is IScale) && !e.Contains(Event.BalanceDone)); - if (stopped) break; } while (!tank.IsEmpty() && !e.Contains(Event.TimerExpired)); } else { - /// - /// 1st half of time + /// + /// Draining with 2 valves: 'DrainValve' is open in the 2nd half of time, 'DrainValve2' is open all the time + /// + State.Create("SequenceBase : Open the drain valve") + .AddOperation(checkUiOp) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(tank.DrainValve2, null)) + .AddOperations(extraOperations) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + } + while (!e.Contains(Event.ValvesSet)); + + /// + /// 1st half /// IOperation timer1 = new TimerOp(tank.EmptyTimeSec / 2, remainingTimeSec); do @@ -305,32 +306,29 @@ namespace TBF.BenchControl.Sequences (remainingTimeSec.Val + tank.EmptyTimeSec / 2) / 60, "min", (remainingTimeSec.Val + tank.EmptyTimeSec / 2) % 60, Strings.sec)); } - } while ((tank is IScale) && !e.Contains(Event.BalanceDone)); - if (stopped) break; } while (!tank.IsEmpty() && !e.Contains(Event.TimerExpired)); /// - /// 2nd half of time + /// 2nd half /// if (!tank.IsEmpty()) { State.Create("SequenceBase : Open the 2nd drain valve") .AddOperation(checkUiOp) - .AddOperation(StateMachine.ControlBoard.SetValvesOp(tank.DrainValve2, null)) + .AddOperation(StateMachine.ControlBoard.SetValvesOp(tank.DrainValve, null)) .AddOperations(extraOperations) .EnterState(); do - { - e = StateMachine.WaitRunDevsRunOps(); - } + { + e = StateMachine.WaitRunDevsRunOps(); + } while (!e.Contains(Event.ValvesSet)); - IOperation timer2 = new TimerOp(tank.EmptyTimeSec / 2, remainingTimeSec); do { @@ -363,14 +361,12 @@ namespace TBF.BenchControl.Sequences } while ((tank is IScale) && !e.Contains(Event.BalanceDone)); - if (stopped) break; } while (!tank.IsEmpty() && !e.Contains(Event.TimerExpired)); } } - // // Quit emptying, close the drain valve // @@ -407,7 +403,6 @@ namespace TBF.BenchControl.Sequences while (!e.Contains(Event.ValvesSet) || ((tank is IScale) && !e.Contains(Event.BalanceDone))); } - if (tank is IScale) { State.Create("SequenceBase : Updating the mass") diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 06e7e88b7..03dc3f2c2 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.18.1046.0")] -[assembly: AssemblyFileVersion("2.18.1046.0")] +[assembly: AssemblyVersion("2.18.1047.0")] +[assembly: AssemblyFileVersion("2.18.1047.0")]