PumpTandem bug fix : Error handling when one of two pumps was renamed.

This commit is contained in:
Milan Hanajik
2022-04-07 15:08:06 +02:00
parent f3a61411f5
commit 4f70997a38
+28 -20
View File
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Dirichlet.Numerics; using Dirichlet.Numerics;
using log4net; using log4net;
using Common;
namespace TBF.Rig.BuiltIn.PumpTandem namespace TBF.Rig.BuiltIn.PumpTandem
{ {
@@ -15,8 +16,8 @@ namespace TBF.Rig.BuiltIn.PumpTandem
readonly PumpCfg pumpCfg; readonly PumpCfg pumpCfg;
readonly GenericDevices.IPump pump1; GenericDevices.IPump pump1;
readonly GenericDevices.IPump pump2; GenericDevices.IPump pump2;
GenericDevices.IPumpFM pumpFm1; GenericDevices.IPumpFM pumpFm1;
GenericDevices.IPumpFM pumpFm2; GenericDevices.IPumpFM pumpFm2;
@@ -48,30 +49,37 @@ namespace TBF.Rig.BuiltIn.PumpTandem
: base(cfg) : base(cfg)
{ {
pumpCfg = cfg as PumpCfg; 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() public override void Initialize()
{ {
pumpFm1 = pump1 as GenericDevices.IPumpFM; if (pumpCfg.DebugLevel == DebugMode.Normal)
pumpFm2 = pump2 as GenericDevices.IPumpFM; {
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 : "<null>"));
if (pump1 is BuiltIn.Pump.Pump) { mask1 = (pump1 as BuiltIn.Pump.Pump).Mask; } pump2 = TbfComponents.FindComponent(pumpCfg.Pump2, StateMachine.Components) as GenericDevices.IPump;
else if (pump1 is Danfoss.VLT2800.Pump) { mask1 = (pump1 as Danfoss.VLT2800.Pump).Mask; } if (pump2 == null) throw new Exception(string.Format("Cannot find component {0}", pumpCfg.Pump2 != null ? pumpCfg.Pump2 : "<null>"));
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; } pumpFm1 = pump1 as GenericDevices.IPumpFM;
else if (pump2 is Danfoss.VLT2800.Pump) { mask2 = (pump2 as Danfoss.VLT2800.Pump).Mask; } pumpFm2 = pump2 as GenericDevices.IPumpFM;
else if (pump2 is Modbus.PumpFM.DanfossVLT.Pump) { mask2 = (pump2 as Modbus.PumpFM.DanfossVLT.Pump).Mask; }
else { mask2 = 0; } 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);
}
} }