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
+3 -13
View File
@@ -12,32 +12,27 @@ namespace TBF.Rig.BuiltIn.Pump
public class Pump : ComponentBase, GenericDevices.IPump, GenericDevices.IValve, SchematicDrawing.IDrawingItCmpnt public class Pump : ComponentBase, GenericDevices.IPump, GenericDevices.IValve, SchematicDrawing.IDrawingItCmpnt
{ {
private static readonly ILog log = LogManager.GetLogger(typeof(Pump)); private static readonly ILog log = LogManager.GetLogger(typeof(Pump));
public override string ToString() { return string.Format("Pump({0})", Cfg.ToString(-1)); } public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
readonly PumpCfg pumpCfg; readonly PumpCfg pumpCfg;
public SchematicDrawing.IDrawingItem DrawingItem { get { return pumpCfg as SchematicDrawing.IDrawingItem; } } public SchematicDrawing.IDrawingItem DrawingItem { get { return pumpCfg as SchematicDrawing.IDrawingItem; } }
public int Delay { get { return pumpCfg.Delay; } } public int Delay { get { return pumpCfg.Delay; } }
public ValveCategory Category { get { return ValveCategory.Feeding; } } /// Pump category is Feeding public ValveCategory Category { get { return ValveCategory.Feeding; } } /// Pump category is Feeding
public GenericDevices.IValve CoupledTo { get { return null; } } public GenericDevices.IValve CoupledTo { get { return null; } }
public bool InvertCouple { get { return false; } } public bool InvertCouple { get { return false; } }
public int LagOpening { get { return 0; } } public int LagOpening { get { return 0; } }
public int LagClosing { get { return 0; } } public int LagClosing { get { return 0; } }
public bool State { get { return (controlBoard.Route & Mask) != 0; } }
public double Power { get { return State ? 100.0 : 0; } } public double Power { get { return State ? 100.0 : 0; } }
readonly IControlBoard controlBoard; readonly IControlBoard controlBoard;
readonly int bitPosition; /// 0 .. 127 readonly int bitPosition; /// 0 .. 127
public readonly UInt128 Mask; /// derived from bitPosition in the constructor public readonly UInt128 Mask; /// derived from bitPosition in the constructor
public Pump() public Pump() { }
{
}
public Pump(Generic.IComponentCfg cfg, IList<Generic.IComponent> components) public Pump(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg) : base(cfg)
@@ -52,10 +47,5 @@ namespace TBF.Rig.BuiltIn.Pump
log.Warn(this.ToString()); log.Warn(this.ToString());
} }
public bool State
{
get { return (controlBoard.Route & Mask) != 0; }
}
} }
} }
+9 -12
View File
@@ -12,7 +12,7 @@ namespace TBF.Rig.BuiltIn.PumpTandem
public class Pump : ComponentBase, GenericDevices.IPumpFM, GenericDevices.IValve, IOperation public class Pump : ComponentBase, GenericDevices.IPumpFM, GenericDevices.IValve, IOperation
{ {
private static readonly ILog log = LogManager.GetLogger(typeof(Pump)); private static readonly ILog log = LogManager.GetLogger(typeof(Pump));
public override string ToString() { return string.Format("PumpTandem({0})", Cfg.ToString(-1)); } public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
readonly PumpCfg pumpCfg; readonly PumpCfg pumpCfg;
@@ -23,6 +23,13 @@ namespace TBF.Rig.BuiltIn.PumpTandem
readonly GenericDevices.IPumpFM pumpFm2; readonly GenericDevices.IPumpFM pumpFm2;
public bool State { get { return pump1.State || pump2.State; } } public bool State { get { return pump1.State || pump2.State; } }
/// Pump power in [%] in range 0 .. 100.0
public double Power
{
get { return (pump1.Power + pump2.Power) / 2; }
}
public int Delay { get { return Math.Max(pump1.Delay, pump2.Delay); } } public int Delay { get { return Math.Max(pump1.Delay, pump2.Delay); } }
public ValveCategory Category { get { return ValveCategory.Feeding; } } /// Pump category is Feeding public ValveCategory Category { get { return ValveCategory.Feeding; } } /// Pump category is Feeding
public GenericDevices.IValve CoupledTo { get { return null; } } public GenericDevices.IValve CoupledTo { get { return null; } }
@@ -30,23 +37,13 @@ namespace TBF.Rig.BuiltIn.PumpTandem
public int LagOpening { get { return 0; } } public int LagOpening { get { return 0; } }
public int LagClosing { get { return 0; } } public int LagClosing { get { return 0; } }
/// <summary>
/// Pump power in [%] in range 0 .. 100.0
/// </summary>
public double Power
{
get { return (pump1.Power + pump2.Power) / 2; }
}
readonly UInt128 mask1; readonly UInt128 mask1;
readonly UInt128 mask2; readonly UInt128 mask2;
public UInt128 Mask { get { return mask1 | mask2; } } /// derived from masks of two pumps public UInt128 Mask { get { return mask1 | mask2; } } /// derived from masks of two pumps
public Pump() public Pump() { }
{
}
public Pump(Generic.IComponentCfg cfg, IList<Generic.IComponent> components) public Pump(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg) : base(cfg)
+2 -4
View File
@@ -15,7 +15,7 @@ namespace TBF.Rig.BuiltIn.Valve
public class Valve : ValveBase, IValve, SchematicDrawing.IDrawingItCmpnt public class Valve : ValveBase, IValve, SchematicDrawing.IDrawingItCmpnt
{ {
private static readonly ILog log = LogManager.GetLogger(typeof(Valve)); private static readonly ILog log = LogManager.GetLogger(typeof(Valve));
public override string ToString() { return string.Format("Valve({0})", Cfg.ToString(-1)); } public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
readonly ValveCfg valveCfg; readonly ValveCfg valveCfg;
public SchematicDrawing.IDrawingItem DrawingItem { get { return valveCfg as SchematicDrawing.IDrawingItem; } } public SchematicDrawing.IDrawingItem DrawingItem { get { return valveCfg as SchematicDrawing.IDrawingItem; } }
@@ -38,9 +38,7 @@ namespace TBF.Rig.BuiltIn.Valve
public int BitPosition { get { return valveCfg.BitNr; } } public int BitPosition { get { return valveCfg.BitNr; } }
public Valve() public Valve() { }
{
}
public Valve(Generic.IComponentCfg cfg, IList<Generic.IComponent> components) public Valve(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg) : base(cfg)
+4 -5
View File
@@ -1,5 +1,5 @@
/// ///
/// Copyright (c) 2015-2016 Sensus Metering Systems /// Copyright (c) 2015-2016 Sensus Slovensko a.s.
/// ///
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -12,7 +12,7 @@ namespace TBF.Rig.BuiltIn.ValveEx
public class Valve : ComponentBase, Generic.IComponent public class Valve : ComponentBase, Generic.IComponent
{ {
private static readonly ILog log = LogManager.GetLogger(typeof(Valve)); private static readonly ILog log = LogManager.GetLogger(typeof(Valve));
public override string ToString() { return string.Format("ValveEx({0})", Cfg.ToString(-1)); } public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
readonly ValveCfg valveCfg; readonly ValveCfg valveCfg;
@@ -20,9 +20,8 @@ namespace TBF.Rig.BuiltIn.ValveEx
/// ///
public readonly IValve[] InputValves; public readonly IValve[] InputValves;
public Valve()
{ public Valve() { }
}
public Valve(Generic.IComponentCfg cfg, IList<Generic.IComponent> components) public Valve(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg) : base(cfg)
+24 -27
View File
@@ -30,8 +30,8 @@ namespace TBF.Rig.ControlBoard.Papouch
int lastStateMachineTime = 0; int lastStateMachineTime = 0;
/// ///
UInt128 benchModelRoute; UInt128 benchModelRoute;
UInt128 valvesToInvert; /// Route = valesToInvert ^ RequiredRouteWithoutInvertedVlaves UInt128 valvesToInvert; /// Route = valesToInvert ^ RequiredRouteWithoutInvertedVlaves
readonly UInt128 routeMask; /// This mask masks out virtual valves, routeMask is set in the constructor UInt128 routeMask; /// This mask masks out virtual valves, routeMask is set in the constructor
/// ///
OutputPath devices; OutputPath devices;
@@ -48,9 +48,7 @@ namespace TBF.Rig.ControlBoard.Papouch
bool opCompleted; /// true = Operation was completed and waits for Stop(); bool opCompleted; /// true = Operation was completed and waits for Stop();
public PapouchCB() public PapouchCB() { }
{
}
/// <summary> /// <summary>
/// Constructor /// Constructor
@@ -63,28 +61,6 @@ namespace TBF.Rig.ControlBoard.Papouch
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components); modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
if (modbus == null) throw new Exception("Cannot find " + Name + " parent"); if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
routeMask = 0;
for (int i = 0; i < 128; i++)
{
if (i < cbCfg.VirtualValvesRangeLo || i > cbCfg.VirtualValvesRangeHi)
{
routeMask = routeMask | ((UInt128)1 << i);
}
}
TBF.UiBridge.Bridge.RouteChangeHandler += delegate(object sndr, TBF.UiBridge.RouteChangeArgs args)
{
UInt128 mask = ((UInt128)1) << args.BitNr;
if ((benchModelRoute & mask) == 0)
{
benchModelRoute |= mask;
}
else
{
benchModelRoute &= (~mask);
}
};
log.Warn(this.ToString()); log.Warn(this.ToString());
} }
@@ -101,6 +77,27 @@ namespace TBF.Rig.ControlBoard.Papouch
{ {
outputsInitialized = false; outputsInitialized = false;
runningOp = SelectedOp.None; runningOp = SelectedOp.None;
routeMask = 0;
for (int i = 0; i < 128; i++)
{
if (i < cbCfg.VirtualValvesRangeLo || i > cbCfg.VirtualValvesRangeHi)
{
routeMask = routeMask | ((UInt128)1 << i);
}
}
TBF.UiBridge.Bridge.RouteChangeHandler += delegate(object sndr, TBF.UiBridge.RouteChangeArgs args)
{
UInt128 mask = ((UInt128)1) << args.BitNr;
if ((benchModelRoute & mask) == 0)
{
benchModelRoute |= mask;
}
else
{
benchModelRoute &= (~mask);
}
};
} }
public void RunDeviceBefore() public void RunDeviceBefore()
+35 -35
View File
@@ -20,7 +20,7 @@ namespace TBF.Rig.ControlBoard.Uni
public class UniCB : ComponentBase, IAdvancedControlBoard, SchematicDrawing.IDrawingItCmpntWithMeasuredVal public class UniCB : ComponentBase, IAdvancedControlBoard, SchematicDrawing.IDrawingItCmpntWithMeasuredVal
{ {
private static readonly ILog log = LogManager.GetLogger(typeof(UniCB)); private static readonly ILog log = LogManager.GetLogger(typeof(UniCB));
public override string ToString() { return string.Format("CBoard({0})", cbCfg != null ? cbCfg.ToString(-1) : string.Empty); } public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
/// TBF component configuration and useful wrappers /// TBF component configuration and useful wrappers
readonly UniCBCfg cbCfg; readonly UniCBCfg cbCfg;
@@ -95,7 +95,7 @@ namespace TBF.Rig.ControlBoard.Uni
/// ///
/// Digital outputs / Route / States of electromagnetic valves /// Digital outputs / Route / States of electromagnetic valves
/// ///
readonly UInt128 routeMask; /// Set in the constructor, bits of outputs that can be controlled by Action.ChangeRoute are set. UInt128 routeMask; /// Set in the constructor, bits of outputs that can be controlled by Action.ChangeRoute are set.
/// Regulation valve control outputs and diverters cannot be controlled by Action.ChangeRoute /// Regulation valve control outputs and diverters cannot be controlled by Action.ChangeRoute
/// Depends on the control board configuration /// Depends on the control board configuration
ulong valvesToInvert; /// From configurations of valve and pump components. Inversion is applied when creating ulong valvesToInvert; /// From configurations of valve and pump components. Inversion is applied when creating
@@ -157,10 +157,7 @@ namespace TBF.Rig.ControlBoard.Uni
/// Constructor for user interfaces (change settings only). /// Constructor for user interfaces (change settings only).
/// Initialize(), RunDeviceXY() and StopDevice() methods of the created object will not be called. /// Initialize(), RunDeviceXY() and StopDevice() methods of the created object will not be called.
/// </summary> /// </summary>
public UniCB() public UniCB() { }
{
devices = new OutputPath(string.Empty, 0);
}
/// <summary> /// <summary>
/// Constructor invoked when starting the test bench and creating components. /// Constructor invoked when starting the test bench and creating components.
@@ -169,23 +166,7 @@ namespace TBF.Rig.ControlBoard.Uni
: base(cfg) : base(cfg)
{ {
cbCfg = cfg as UniCBCfg; cbCfg = cfg as UniCBCfg;
devices = new OutputPath(string.Empty, 0);
actionQueue = new Queue<Action>();
actionQueue.Enqueue(Action.Stop(false)); /// Stop all
outputsInitialized = false;
Data = new GeneralData(); Data = new GeneralData();
divTransitionData = null;
scopeAnalyzerData = null;
switchCounterData = null;
routeMask = 0xFF00FFFFFF;
for (int i = 0; i < cbCfg.RegValvesCount; i++) routeMask &= ~((UInt128)3 << 2*i);
if (cbCfg.RelaysFInstalled) routeMask |= 0xFF0000000000;
if (cbCfg.RelaysGInstalled) routeMask |= 0xFF000000000000;
if (cbCfg.RelaysHInstalled) routeMask |= 0xFF00000000000000;
log.Warn(this.ToString()); log.Warn(this.ToString());
} }
@@ -205,10 +186,36 @@ namespace TBF.Rig.ControlBoard.Uni
/// </summary> /// </summary>
public void Initialize() public void Initialize()
{ {
devices = new OutputPath(string.Empty, 0);
actionQueue = new Queue<Action>();
actionQueue.Enqueue(Action.Stop(false)); /// Stop all
outputsInitialized = false;
divTransitionData = null;
scopeAnalyzerData = null;
switchCounterData = null;
routeMask = 0xFF00FFFFFF;
for (int i = 0; i < cbCfg.RegValvesCount; i++) routeMask &= ~((UInt128)3 << 2 * i);
if (cbCfg.RelaysFInstalled) routeMask |= 0xFF0000000000;
if (cbCfg.RelaysGInstalled) routeMask |= 0xFF000000000000;
if (cbCfg.RelaysHInstalled) routeMask |= 0xFF00000000000000;
lastRcvdStMTime = StateMachine.Time; /// To indicate the serial connection state lastRcvdStMTime = StateMachine.Time; /// To indicate the serial connection state
lastSentTime = DateTime.Now; lastSentTime = DateTime.Now;
lastReceivedTime = DateTime.Now; lastReceivedTime = DateTime.Now;
/// Handler handling mouse clicks on the schematc drawinng - valve or pump state changes
TBF.UiBridge.Bridge.RouteChangeHandler += delegate(object sndr, TBF.UiBridge.RouteChangeArgs args)
{
UInt128 oneBitMask = ((UInt128)1) << args.BitNr;
lock (this)
{
bitsChangedByUI |= oneBitMask;
displayedRoutePlusUI = displayedRoutePlusUI ^ oneBitMask;
}
};
if (cbCfg.DebugLevel == DebugMode.Normal) if (cbCfg.DebugLevel == DebugMode.Normal)
{ {
buffer = new byte[BUFFER_SIZE]; buffer = new byte[BUFFER_SIZE];
@@ -221,20 +228,13 @@ namespace TBF.Rig.ControlBoard.Uni
serialPort.WriteTimeout = 4000; serialPort.WriteTimeout = 4000;
serialPort.ParityReplace = 0xFF; serialPort.ParityReplace = 0xFF;
serialPort.Open(); serialPort.Open();
log.FatalFormat("{0} - Device successfully initialized", Name);
}
else
{
serialPort = null;
log.FatalFormat("{0} - Device simulated", Name);
} }
/// Handler handling mouse clicks on the schematc drawinng - valve or pump state changes
TBF.UiBridge.Bridge.RouteChangeHandler += delegate(object sndr, TBF.UiBridge.RouteChangeArgs args)
{
UInt128 oneBitMask = ((UInt128)1) << args.BitNr;
lock (this)
{
bitsChangedByUI |= oneBitMask;
displayedRoutePlusUI = displayedRoutePlusUI ^ oneBitMask;
}
};
log.FatalFormat("{0} - Device successfully initialized", Name);
} }
/// <summary> /// <summary>
+31 -45
View File
@@ -72,7 +72,7 @@ namespace TBF.Rig.Danfoss.VLT2800
public class Pump : ComponentBase, IDevice, IOperation, GenericDevices.IPumpFM, GenericDevices.IValve, IDrawingItCmpntWithSetpoint public class Pump : ComponentBase, IDevice, IOperation, GenericDevices.IPumpFM, GenericDevices.IValve, IDrawingItCmpntWithSetpoint
{ {
private static readonly ILog log = LogManager.GetLogger(typeof(Pump)); 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; private readonly PumpCfg pumpCfg;
public IDrawingItem DrawingItem { get { return pumpCfg as IDrawingItem; } } 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 /// Pump power in [%] in range 0 .. 100.0f
/// </summary> /// </summary>
private double power; private double power;
public double Power public double Power { get { return power; } }
{
get { return power; }
}
/// ///
public double SetpointVal public double SetpointVal
{ {
@@ -126,14 +123,11 @@ namespace TBF.Rig.Danfoss.VLT2800
readonly IControlBoard controlBoard; 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 public bool State { get { return (controlBoard.Route & Mask) != 0; } }
{
get { return (controlBoard.Route & Mask) != 0; }
}
/// Private fields /// Private fields
SerialPort serialPort; SerialPort serialPort;
@@ -142,9 +136,7 @@ namespace TBF.Rig.Danfoss.VLT2800
StringBuilder responseBuilder; StringBuilder responseBuilder;
public Pump() public Pump() { }
{
}
/// <summary> /// <summary>
/// Ambient temperature / humidity / pressure meter 'Greco' connected via serial interface (RS232) /// 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" controlBoard = TbfComponents.FindComponent("CB", components) as IControlBoard; /// TODO: replace "CB"
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent"); 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()); log.Warn(this.ToString());
} }
public void Initialize() public void Initialize()
{ {
if (pumpCfg.DebugLevel == DebugMode.Simulate) bitNr = pumpCfg.BitNr;
{ Mask = (((UInt128)1) << bitNr);
return;
}
string comPortName = "COM" + pumpCfg.ComPortNr.ToString(); TBF.UiBridge.Bridge.SetpointChangeHandler += delegate(object sndr, TBF.UiBridge.SetpointChangeArgs args)
serialPort = new SerialPort(comPortName, pumpCfg.BaudRate, pumpCfg.Parity, pumpCfg.DataBits, pumpCfg.StopBits); {
serialPort.Handshake = Handshake.None; if (args.Name == Name)
serialPort.Open(); {
responseBuilder = new StringBuilder(40); 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> /// <summary>Run this device</summary>
public void RunDeviceBefore() public void RunDeviceBefore()
+1 -1
View File
@@ -1,5 +1,5 @@
/// ///
/// Copyright (c) 2013-2016 Sensus Metering Systems /// Copyright (c) 2013-2016 Sensus Slovensko a.s.
/// ///
using System.Collections.Generic; using System.Collections.Generic;
using System.IO.Ports; using System.IO.Ports;