From 0553caac8931716ffb7dc32aeb45e521c4c58e40 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Wed, 28 Apr 2021 10:44:38 +0200 Subject: [PATCH] Bug fix in TBF.Utils.GetRegulVallvesPositions( ), TBF crashed when fn. was called from OutputPath from UI. --- TBF/BenchControl/OutputPath.cs | 9 ++++++++- TBF/BenchControl/Sequences/SequenceBase.cs | 2 +- TBF/Utils.cs | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/TBF/BenchControl/OutputPath.cs b/TBF/BenchControl/OutputPath.cs index d5afc7317..dffeb6fa4 100644 --- a/TBF/BenchControl/OutputPath.cs +++ b/TBF/BenchControl/OutputPath.cs @@ -53,7 +53,14 @@ namespace TBF.BenchControl Diverter = (IDiverter)TbfComponents.FindComponent(entity.Diverter, components); TempDiv = (ITempMeter)TbfComponents.FindComponent(entity.TempDiv, components); Scale = (IScaleOrTank)TbfComponents.FindComponent(entity.Scale, components); - RegulValvesPct = string.IsNullOrEmpty(entity.RegulValvesPct) ? new float[0] : Utils.GetRegulValvesPositions(entity.RegulValvesPct); + + int regvCount = 0; + foreach (var cmpnt in components) + { + if ((cmpnt is IRegulValve) && !(cmpnt is BenchControl.Elde.RegulValveTandem.RegulValveTandem)) regvCount++; + } + RegulValvesPct = string.IsNullOrEmpty(entity.RegulValvesPct) ? new float[0] : Utils.GetRegulValvesPositions(entity.RegulValvesPct, regvCount); + string[] svs = entity.StartValve != null ? entity.StartValve.Split(new char[] { '~' }) : new string[0]; int iTmp; /// diff --git a/TBF/BenchControl/Sequences/SequenceBase.cs b/TBF/BenchControl/Sequences/SequenceBase.cs index a8ff0965b..c5478f0ae 100644 --- a/TBF/BenchControl/Sequences/SequenceBase.cs +++ b/TBF/BenchControl/Sequences/SequenceBase.cs @@ -645,7 +645,7 @@ namespace TBF.BenchControl.Sequences } /// Get regulation valve positioning operations - IList rvPosOps = GetRegValvePositioningOps(RegulValves, Utils.GetRegulValvesPositions(step.RegulValvesPct)); + IList rvPosOps = GetRegValvePositioningOps(RegulValves, Utils.GetRegulValvesPositions(step.RegulValvesPct, RegulValves.Count)); /// Max. one SetRegulValvePositionOp can be started or stopped in one sub-step. /// Therefore SetRegulValvePositionOp operations are added and removed to subsequent states one by one. diff --git a/TBF/Utils.cs b/TBF/Utils.cs index e9809acb0..1d4de9cfb 100644 --- a/TBF/Utils.cs +++ b/TBF/Utils.cs @@ -193,9 +193,8 @@ namespace TBF /// /// String from TransitionStep entity defining all RegulValve positions /// float[] of regulation valve positions from 0 to 100.0f - public static float[] GetRegulValvesPositions(string regulValvesPct) + public static float[] GetRegulValvesPositions(string regulValvesPct, int regvCount) { - int regvCount = BenchControl.Sequences.SequenceBase.RegulValves.Count; float[] result = new float[regvCount]; string[] rvPosStr = string.IsNullOrEmpty(regulValvesPct) ? new string[0] : regulValvesPct.Split(new char[] { ';' });