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
{
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;
public SchematicDrawing.IDrawingItem DrawingItem { get { return pumpCfg as SchematicDrawing.IDrawingItem; } }
public int Delay { get { return pumpCfg.Delay; } }
public ValveCategory Category { get { return ValveCategory.Feeding; } } /// Pump category is Feeding
public GenericDevices.IValve CoupledTo { get { return null; } }
public bool InvertCouple { get { return false; } }
public int LagOpening { 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; } }
readonly IControlBoard controlBoard;
readonly int bitPosition; /// 0 .. 127
public readonly UInt128 Mask; /// derived from bitPosition in the constructor
public Pump()
{
}
public Pump() { }
public Pump(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
@@ -52,10 +47,5 @@ namespace TBF.Rig.BuiltIn.Pump
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
{
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;
@@ -23,6 +23,13 @@ namespace TBF.Rig.BuiltIn.PumpTandem
readonly GenericDevices.IPumpFM pumpFm2;
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 ValveCategory Category { get { return ValveCategory.Feeding; } } /// Pump category is Feeding
public GenericDevices.IValve CoupledTo { get { return null; } }
@@ -30,23 +37,13 @@ namespace TBF.Rig.BuiltIn.PumpTandem
public int LagOpening { 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 mask2;
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)
: base(cfg)
+2 -4
View File
@@ -15,7 +15,7 @@ namespace TBF.Rig.BuiltIn.Valve
public class Valve : ValveBase, IValve, SchematicDrawing.IDrawingItCmpnt
{
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;
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 Valve()
{
}
public Valve() { }
public Valve(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: 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.Collections.Generic;
@@ -12,7 +12,7 @@ namespace TBF.Rig.BuiltIn.ValveEx
public class Valve : ComponentBase, Generic.IComponent
{
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;
@@ -20,9 +20,8 @@ namespace TBF.Rig.BuiltIn.ValveEx
///
public readonly IValve[] InputValves;
public Valve()
{
}
public Valve() { }
public Valve(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
+18 -21
View File
@@ -31,7 +31,7 @@ namespace TBF.Rig.ControlBoard.Papouch
///
UInt128 benchModelRoute;
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;
@@ -48,9 +48,7 @@ namespace TBF.Rig.ControlBoard.Papouch
bool opCompleted; /// true = Operation was completed and waits for Stop();
public PapouchCB()
{
}
public PapouchCB() { }
/// <summary>
/// Constructor
@@ -63,6 +61,22 @@ namespace TBF.Rig.ControlBoard.Papouch
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
log.Warn(this.ToString());
}
public void SpecifyInvertedValves(UInt128 valvesToInvert)
{
this.valvesToInvert = valvesToInvert;
this.benchModelRoute = valvesToInvert;
}
///
/// IDevice interface
///
public void Initialize()
{
outputsInitialized = false;
runningOp = SelectedOp.None;
routeMask = 0;
for (int i = 0; i < 128; i++)
{
@@ -84,23 +98,6 @@ namespace TBF.Rig.ControlBoard.Papouch
benchModelRoute &= (~mask);
}
};
log.Warn(this.ToString());
}
public void SpecifyInvertedValves(UInt128 valvesToInvert)
{
this.valvesToInvert = valvesToInvert;
this.benchModelRoute = valvesToInvert;
}
///
/// IDevice interface
///
public void Initialize()
{
outputsInitialized = false;
runningOp = SelectedOp.None;
}
public void RunDeviceBefore()
+35 -35
View File
@@ -20,7 +20,7 @@ namespace TBF.Rig.ControlBoard.Uni
public class UniCB : ComponentBase, IAdvancedControlBoard, SchematicDrawing.IDrawingItCmpntWithMeasuredVal
{
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
readonly UniCBCfg cbCfg;
@@ -95,7 +95,7 @@ namespace TBF.Rig.ControlBoard.Uni
///
/// 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
/// Depends on the control board configuration
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).
/// Initialize(), RunDeviceXY() and StopDevice() methods of the created object will not be called.
/// </summary>
public UniCB()
{
devices = new OutputPath(string.Empty, 0);
}
public UniCB() { }
/// <summary>
/// Constructor invoked when starting the test bench and creating components.
@@ -169,23 +166,7 @@ namespace TBF.Rig.ControlBoard.Uni
: base(cfg)
{
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();
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());
}
@@ -205,10 +186,36 @@ namespace TBF.Rig.ControlBoard.Uni
/// </summary>
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
lastSentTime = 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)
{
buffer = new byte[BUFFER_SIZE];
@@ -221,21 +228,14 @@ namespace TBF.Rig.ControlBoard.Uni
serialPort.WriteTimeout = 4000;
serialPort.ParityReplace = 0xFF;
serialPort.Open();
}
/// 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);
}
else
{
serialPort = null;
log.FatalFormat("{0} - Device simulated", Name);
}
}
/// <summary>
/// Reecive and process data from the control board serial port
+26 -40
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,43 +150,37 @@ 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);
TBF.UiBridge.Bridge.SetpointChangeHandler += delegate(object sndr, TBF.UiBridge.SetpointChangeArgs args)
{
if (args.Name == Name)
{
if (args.Increase) IncreaseSetpoint();
else DecreaseSetpoint();
}
};
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("Successfully initialized device {0}", ToString());
log.FatalFormat("{0} - Device successfully initialized", Name);
}
else
{
serialPort = null;
log.FatalFormat("{0} - Device simulated", Name);
}
}
/// <summary>Run this device</summary>
+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.IO.Ports;