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 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 : "<null>"));
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 : "<null>"));
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);
}
}