Components initialization clean-up.

This commit is contained in:
Milan Hanajik
2021-04-02 17:28:15 +02:00
parent dd08ca770d
commit 4fda48f7e7
8 changed files with 109 additions and 142 deletions
+31 -45
View File
@@ -72,7 +72,7 @@ namespace TBF.Rig.Danfoss.VLT2800
public class Pump : ComponentBase, IDevice, IOperation, GenericDevices.IPumpFM, GenericDevices.IValve, IDrawingItCmpntWithSetpoint
{
private static readonly ILog log = LogManager.GetLogger(typeof(Pump));
public override string ToString() { return string.Format("Pump-Danfoss-VLT2800({0})", Cfg.ToString(-1)); }
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
private readonly PumpCfg pumpCfg;
public IDrawingItem DrawingItem { get { return pumpCfg as IDrawingItem; } }
@@ -88,10 +88,7 @@ namespace TBF.Rig.Danfoss.VLT2800
/// Pump power in [%] in range 0 .. 100.0f
/// </summary>
private double power;
public double Power
{
get { return power; }
}
public double Power { get { return power; } }
///
public double SetpointVal
{
@@ -126,14 +123,11 @@ namespace TBF.Rig.Danfoss.VLT2800
readonly IControlBoard controlBoard;
readonly int bitNr; /// 0 .. 63
public readonly UInt128 Mask; /// derived from bitPosition in the constructor
int bitNr; /// 0 .. 127
public UInt128 Mask; /// derived from bitPosition in the constructor
public bool State
{
get { return (controlBoard.Route & Mask) != 0; }
}
public bool State { get { return (controlBoard.Route & Mask) != 0; } }
/// Private fields
SerialPort serialPort;
@@ -142,9 +136,7 @@ namespace TBF.Rig.Danfoss.VLT2800
StringBuilder responseBuilder;
public Pump()
{
}
public Pump() { }
/// <summary>
/// Ambient temperature / humidity / pressure meter 'Greco' connected via serial interface (RS232)
@@ -158,44 +150,38 @@ namespace TBF.Rig.Danfoss.VLT2800
controlBoard = TbfComponents.FindComponent("CB", components) as IControlBoard; /// TODO: replace "CB"
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
bitNr = pumpCfg.BitNr;
Mask = (((UInt128)1) << bitNr);
#if MUNICH
Mask |= (((UInt128)1) << (bitNr + 1));
#endif
TBF.UiBridge.Bridge.SetpointChangeHandler += delegate(object sndr, TBF.UiBridge.SetpointChangeArgs args)
{
if (args.Name == Name)
{
if (args.Increase)
{
IncreaseSetpoint();
}
else
{
DecreaseSetpoint();
}
}
};
log.Warn(this.ToString());
}
public void Initialize()
{
if (pumpCfg.DebugLevel == DebugMode.Simulate)
{
return;
}
bitNr = pumpCfg.BitNr;
Mask = (((UInt128)1) << bitNr);
string comPortName = "COM" + pumpCfg.ComPortNr.ToString();
serialPort = new SerialPort(comPortName, pumpCfg.BaudRate, pumpCfg.Parity, pumpCfg.DataBits, pumpCfg.StopBits);
serialPort.Handshake = Handshake.None;
serialPort.Open();
responseBuilder = new StringBuilder(40);
TBF.UiBridge.Bridge.SetpointChangeHandler += delegate(object sndr, TBF.UiBridge.SetpointChangeArgs args)
{
if (args.Name == Name)
{
if (args.Increase) IncreaseSetpoint();
else DecreaseSetpoint();
}
};
log.FatalFormat("Successfully initialized device {0}", ToString());
}
if (pumpCfg.DebugLevel == DebugMode.Normal)
{
string comPortName = "COM" + pumpCfg.ComPortNr.ToString();
serialPort = new SerialPort(comPortName, pumpCfg.BaudRate, pumpCfg.Parity, pumpCfg.DataBits, pumpCfg.StopBits);
serialPort.Handshake = Handshake.None;
serialPort.Open();
responseBuilder = new StringBuilder(40);
log.FatalFormat("{0} - Device successfully initialized", Name);
}
else
{
serialPort = null;
log.FatalFormat("{0} - Device simulated", Name);
}
}
/// <summary>Run this device</summary>
public void RunDeviceBefore()