diff --git a/TBF/Rig/BuiltIn/Pump/Pump.cs b/TBF/Rig/BuiltIn/Pump/Pump.cs index 2a7bfaae2..b31f9a051 100644 --- a/TBF/Rig/BuiltIn/Pump/Pump.cs +++ b/TBF/Rig/BuiltIn/Pump/Pump.cs @@ -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 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; } - } } } diff --git a/TBF/Rig/BuiltIn/PumpTandem/Pump.cs b/TBF/Rig/BuiltIn/PumpTandem/Pump.cs index e00f51a13..b84082738 100644 --- a/TBF/Rig/BuiltIn/PumpTandem/Pump.cs +++ b/TBF/Rig/BuiltIn/PumpTandem/Pump.cs @@ -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; } } - /// - /// Pump power in [%] in range 0 .. 100.0 - /// - 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 components) : base(cfg) diff --git a/TBF/Rig/BuiltIn/Valve/Valve.cs b/TBF/Rig/BuiltIn/Valve/Valve.cs index c1b3cd04a..b4b56bc9b 100644 --- a/TBF/Rig/BuiltIn/Valve/Valve.cs +++ b/TBF/Rig/BuiltIn/Valve/Valve.cs @@ -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 components) : base(cfg) diff --git a/TBF/Rig/BuiltIn/ValveEx/Valve.cs b/TBF/Rig/BuiltIn/ValveEx/Valve.cs index b5629ca18..edd070851 100644 --- a/TBF/Rig/BuiltIn/ValveEx/Valve.cs +++ b/TBF/Rig/BuiltIn/ValveEx/Valve.cs @@ -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 components) : base(cfg) diff --git a/TBF/Rig/ControlBoard/Papouch/PapouchCB.cs b/TBF/Rig/ControlBoard/Papouch/PapouchCB.cs index 5a2e0f301..10dacfc44 100644 --- a/TBF/Rig/ControlBoard/Papouch/PapouchCB.cs +++ b/TBF/Rig/ControlBoard/Papouch/PapouchCB.cs @@ -30,8 +30,8 @@ namespace TBF.Rig.ControlBoard.Papouch int lastStateMachineTime = 0; /// UInt128 benchModelRoute; - UInt128 valvesToInvert; /// Route = valesToInvert ^ RequiredRouteWithoutInvertedVlaves - readonly UInt128 routeMask; /// This mask masks out virtual valves, routeMask is set in the constructor + UInt128 valvesToInvert; /// Route = valesToInvert ^ RequiredRouteWithoutInvertedVlaves + 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() { } /// /// Constructor @@ -63,28 +61,6 @@ namespace TBF.Rig.ControlBoard.Papouch modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components); 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()); } @@ -101,6 +77,27 @@ namespace TBF.Rig.ControlBoard.Papouch { outputsInitialized = false; 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() diff --git a/TBF/Rig/ControlBoard/Uni/UniCB.cs b/TBF/Rig/ControlBoard/Uni/UniCB.cs index 4a4f42592..131e24d37 100644 --- a/TBF/Rig/ControlBoard/Uni/UniCB.cs +++ b/TBF/Rig/ControlBoard/Uni/UniCB.cs @@ -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. /// - public UniCB() - { - devices = new OutputPath(string.Empty, 0); - } + public UniCB() { } /// /// 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(); - 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 /// public void Initialize() { + devices = new OutputPath(string.Empty, 0); + actionQueue = new Queue(); + 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,20 +228,13 @@ namespace TBF.Rig.ControlBoard.Uni serialPort.WriteTimeout = 4000; serialPort.ParityReplace = 0xFF; 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); } /// diff --git a/TBF/Rig/Danfoss/VLT2800/Pump.cs b/TBF/Rig/Danfoss/VLT2800/Pump.cs index c3deac5d9..25f5103e4 100644 --- a/TBF/Rig/Danfoss/VLT2800/Pump.cs +++ b/TBF/Rig/Danfoss/VLT2800/Pump.cs @@ -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 /// 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() { } /// /// 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); + } + } /// Run this device public void RunDeviceBefore() diff --git a/TBF/Rig/Danfoss/VLT2800/PumpCfg.cs b/TBF/Rig/Danfoss/VLT2800/PumpCfg.cs index 2f3d25793..884e37bb1 100644 --- a/TBF/Rig/Danfoss/VLT2800/PumpCfg.cs +++ b/TBF/Rig/Danfoss/VLT2800/PumpCfg.cs @@ -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;