From 4f70997a38e1fd1558f740112cfb6decb7405107 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Thu, 7 Apr 2022 15:07:40 +0200 Subject: [PATCH] PumpTandem bug fix : Error handling when one of two pumps was renamed. --- TBF/Rig/BuiltIn/PumpTandem/Pump.cs | 48 +++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/TBF/Rig/BuiltIn/PumpTandem/Pump.cs b/TBF/Rig/BuiltIn/PumpTandem/Pump.cs index 19f5048e5..b98191176 100644 --- a/TBF/Rig/BuiltIn/PumpTandem/Pump.cs +++ b/TBF/Rig/BuiltIn/PumpTandem/Pump.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using Dirichlet.Numerics; using log4net; +using Common; namespace TBF.Rig.BuiltIn.PumpTandem { @@ -15,8 +16,8 @@ namespace TBF.Rig.BuiltIn.PumpTandem readonly PumpCfg pumpCfg; - readonly GenericDevices.IPump pump1; - readonly GenericDevices.IPump pump2; + GenericDevices.IPump pump1; + GenericDevices.IPump pump2; GenericDevices.IPumpFM pumpFm1; GenericDevices.IPumpFM pumpFm2; @@ -48,30 +49,37 @@ namespace TBF.Rig.BuiltIn.PumpTandem : base(cfg) { pumpCfg = cfg as PumpCfg; - - pump1 = TbfComponents.FindComponent(pumpCfg.Pump1, components) as GenericDevices.IPump; - if (pump1 == null) throw new Exception("Cannot find component Pump 1"); - - pump2 = TbfComponents.FindComponent(pumpCfg.Pump2, components) as GenericDevices.IPump; - if (pump2 == null) throw new Exception("Cannot find component Pump 2"); - - log.Warn(this.ToString()); } public override void Initialize() { - pumpFm1 = pump1 as GenericDevices.IPumpFM; - pumpFm2 = pump2 as GenericDevices.IPumpFM; + if (pumpCfg.DebugLevel == DebugMode.Normal) + { + pump1 = TbfComponents.FindComponent(pumpCfg.Pump1, StateMachine.Components) as GenericDevices.IPump; + if (pump1 == null) throw new Exception(string.Format("Cannot find component {0}", pumpCfg.Pump1 != null ? pumpCfg.Pump1 : "")); - if (pump1 is BuiltIn.Pump.Pump) { mask1 = (pump1 as BuiltIn.Pump.Pump).Mask; } - else if (pump1 is Danfoss.VLT2800.Pump) { mask1 = (pump1 as Danfoss.VLT2800.Pump).Mask; } - else if (pump1 is Modbus.PumpFM.DanfossVLT.Pump) { mask1 = (pump1 as Modbus.PumpFM.DanfossVLT.Pump).Mask; } - else { mask1 = 0; } + pump2 = TbfComponents.FindComponent(pumpCfg.Pump2, StateMachine.Components) as GenericDevices.IPump; + if (pump2 == null) throw new Exception(string.Format("Cannot find component {0}", pumpCfg.Pump2 != null ? pumpCfg.Pump2 : "")); - if (pump2 is BuiltIn.Pump.Pump) { mask2 = (pump2 as BuiltIn.Pump.Pump).Mask; } - else if (pump2 is Danfoss.VLT2800.Pump) { mask2 = (pump2 as Danfoss.VLT2800.Pump).Mask; } - else if (pump2 is Modbus.PumpFM.DanfossVLT.Pump) { mask2 = (pump2 as Modbus.PumpFM.DanfossVLT.Pump).Mask; } - else { mask2 = 0; } + pumpFm1 = pump1 as GenericDevices.IPumpFM; + pumpFm2 = pump2 as GenericDevices.IPumpFM; + + if (pump1 is BuiltIn.Pump.Pump) { mask1 = (pump1 as BuiltIn.Pump.Pump).Mask; } + else if (pump1 is Danfoss.VLT2800.Pump) { mask1 = (pump1 as Danfoss.VLT2800.Pump).Mask; } + else if (pump1 is Modbus.PumpFM.DanfossVLT.Pump) { mask1 = (pump1 as Modbus.PumpFM.DanfossVLT.Pump).Mask; } + else { mask1 = 0; } + + if (pump2 is BuiltIn.Pump.Pump) { mask2 = (pump2 as BuiltIn.Pump.Pump).Mask; } + else if (pump2 is Danfoss.VLT2800.Pump) { mask2 = (pump2 as Danfoss.VLT2800.Pump).Mask; } + else if (pump2 is Modbus.PumpFM.DanfossVLT.Pump) { mask2 = (pump2 as Modbus.PumpFM.DanfossVLT.Pump).Mask; } + else { mask2 = 0; } + + log.FatalFormat("{0} initialized: {1}", Name, this); + } + else + { + log.FatalFormat("{0} simulated: {1}", Name, this); + } }