From a9d6fa631ca5c508b8377f0a86516e3ccd6ab2fa Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Wed, 24 Feb 2021 15:27:35 +0100 Subject: [PATCH] Various changes done when adding new components (parents, etc.) --- .../MettlerToledo/Standard/BalanceDev.cs | 6 ++--- .../Modbus/PumpFM/DanfossVLT/Pump.cs | 9 +++++-- .../Modbus/TempMeter/Groch/TempMeter.cs | 27 +++++++------------ .../TempMeter/Groch/TempMeterCfgCtrl.cs | 2 +- TBF/BenchControl/Uni/Diverter/DiverterCfg.cs | 2 +- TBF/BenchControl/Uni/Diverter/Factory.cs | 2 +- TBF/BenchControl/Uni/FlowMeter/Factory.cs | 2 +- .../Uni/FlowMeter/FlowMeterCfg.cs | 2 +- TBF/BenchControl/Uni/RegValve/Factory.cs | 2 +- TBF/BenchControl/Uni/RegValve/RegValveCfg.cs | 2 +- .../Bench/Components/ComponentsManagerDlg.cs | 4 +-- 11 files changed, 29 insertions(+), 31 deletions(-) diff --git a/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs b/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs index f366557e1..8b9d11172 100644 --- a/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs +++ b/TBF/BenchControl/MettlerToledo/Standard/BalanceDev.cs @@ -122,7 +122,9 @@ namespace TBF.BenchControl.MettlerToledo.Standard public void Initialize() { - base.Initalize(); + if (balanceCfg.DebugLevel == DebugMode.Simulate) return; + + base.Initalize(); if (balanceCfg.CalibValidDate != DateTime.MinValue && balanceCfg.CalibValidDate.Date < DateTime.Now.Date) { @@ -133,8 +135,6 @@ namespace TBF.BenchControl.MettlerToledo.Standard msrmntState = MsrmntState.Failed; /// Data not valid yet MsrmntTime = 0; - if (balanceCfg.DebugLevel == DebugMode.Simulate) return; - stringBuilder = new StringBuilder(40); string comPortName = "COM" + balanceCfg.ComPortNr.ToString(); serialPort = new SerialPort(comPortName, balanceCfg.BaudRate, balanceCfg.Parity, balanceCfg.DataBits, balanceCfg.StopBits); diff --git a/TBF/BenchControl/Modbus/PumpFM/DanfossVLT/Pump.cs b/TBF/BenchControl/Modbus/PumpFM/DanfossVLT/Pump.cs index 84d68868f..8d18234ec 100644 --- a/TBF/BenchControl/Modbus/PumpFM/DanfossVLT/Pump.cs +++ b/TBF/BenchControl/Modbus/PumpFM/DanfossVLT/Pump.cs @@ -148,8 +148,13 @@ namespace TBF.BenchControl.Modbus.PumpFM.DanfossVLT modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components); if (modbus == null) throw new Exception("Cannot find " + Name + " parent"); - controlBoard = TbfComponents.FindComponent("CB", components) as IControlBoard; /// TODO: replace "CB" - if (controlBoard == null) throw new Exception("Cannot find a control board"); + controlBoard = null; + foreach (var name in new string[] { "CB", "UniCB" }) + { + if ((controlBoard = TbfComponents.FindComponent(name, components) as IControlBoard) != null) + break; + } + if (controlBoard == null) throw new Exception("Cannot find a control board"); bitNr = pumpCfg.BitNr; Mask = (((UInt128)1) << bitNr); diff --git a/TBF/BenchControl/Modbus/TempMeter/Groch/TempMeter.cs b/TBF/BenchControl/Modbus/TempMeter/Groch/TempMeter.cs index 4ce596bb6..300a0e595 100644 --- a/TBF/BenchControl/Modbus/TempMeter/Groch/TempMeter.cs +++ b/TBF/BenchControl/Modbus/TempMeter/Groch/TempMeter.cs @@ -19,14 +19,14 @@ namespace TBF.BenchControl.Modbus.TempMeter.Groch readonly TempMeterCfg tempMtrCfg; public SchematicDrawing.IDrawingItem DrawingItem { get { return tempMtrCfg as SchematicDrawing.IDrawingItem; } } - public readonly CBoard ControlBoard; + readonly Common.Modbus modbus; - public int Idx0 { get { return tempMtrCfg.Idx0; } } /// 0..15 - public double A1 { get { return tempMtrCfg.A1; } } - public double A2 { get { return tempMtrCfg.A2; } } - public double A3 { get { return tempMtrCfg.A3; } } - public double A4 { get { return tempMtrCfg.A4; } } - public double A5 { get { return tempMtrCfg.A5; } } + int Idx0 { get { return tempMtrCfg.Idx0; } } /// 0..15 + double A1 { get { return tempMtrCfg.A1; } } + double A2 { get { return tempMtrCfg.A2; } } + double A3 { get { return tempMtrCfg.A3; } } + double A4 { get { return tempMtrCfg.A4; } } + double A5 { get { return tempMtrCfg.A5; } } public TempMeter() { @@ -37,15 +37,8 @@ namespace TBF.BenchControl.Modbus.TempMeter.Groch { tempMtrCfg = cfg as TempMeterCfg; - ControlBoard = (CBoard)TbfComponents.FindComponent(cfg.ParentName, components); - if (ControlBoard == null) throw new Exception("Cannot find " + Name + " parent"); - - /// Prepare data for SendCalibData() control board component method - ControlBoard.TempCalibData[Idx0, 0] = (float)A1; - ControlBoard.TempCalibData[Idx0, 1] = (float)A2; - ControlBoard.TempCalibData[Idx0, 2] = (float)A3; - ControlBoard.TempCalibData[Idx0, 3] = (float)A4; - ControlBoard.TempCalibData[Idx0, 4] = (float)A5; + modbus = TbfComponents.FindComponent(cfg.ParentName, components) as Common.Modbus; + if (modbus == null) throw new Exception("Cannot find " + Name + " parent"); log.Warn(this.ToString()); } @@ -86,7 +79,7 @@ namespace TBF.BenchControl.Modbus.TempMeter.Groch { if (Cfg.DebugLevel == Config.Entities.DebugMode.Normal) { - return Config.Formulas.CorrectedValue((double)ControlBoard.Temperature(Idx0), Corrections); + return 0; // Config.Formulas.CorrectedValue((double)ControlBoard.Temperature(Idx0), Corrections); } else if (Cfg.DebugLevel == Config.Entities.DebugMode.Simulate) { diff --git a/TBF/BenchControl/Modbus/TempMeter/Groch/TempMeterCfgCtrl.cs b/TBF/BenchControl/Modbus/TempMeter/Groch/TempMeterCfgCtrl.cs index 97af2cbab..44ff98977 100644 --- a/TBF/BenchControl/Modbus/TempMeter/Groch/TempMeterCfgCtrl.cs +++ b/TBF/BenchControl/Modbus/TempMeter/Groch/TempMeterCfgCtrl.cs @@ -43,7 +43,7 @@ namespace TBF.BenchControl.Modbus.TempMeter.Groch { foreach (var cmpnt in parent.CmpntEntities) { - if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is ControlBoard.Legacy.ControlBoardFactory) + if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Modbus.Common.Factory) { parentNameComboBox.Items.Add(cmpnt.Name); } diff --git a/TBF/BenchControl/Uni/Diverter/DiverterCfg.cs b/TBF/BenchControl/Uni/Diverter/DiverterCfg.cs index 0fef1b1b2..58219483d 100644 --- a/TBF/BenchControl/Uni/Diverter/DiverterCfg.cs +++ b/TBF/BenchControl/Uni/Diverter/DiverterCfg.cs @@ -67,7 +67,7 @@ namespace TBF.BenchControl.Uni.Diverter Factory = factory; Name = "Div"; - ParentName = "CB"; + ParentName = "UniCB"; DivNr1 = 1; BitNr = 0; AdcNr = 5; /// Div1: AdcNr=5 , Div2: AdcNr=6 diff --git a/TBF/BenchControl/Uni/Diverter/Factory.cs b/TBF/BenchControl/Uni/Diverter/Factory.cs index 5616c976a..79cf88bd9 100644 --- a/TBF/BenchControl/Uni/Diverter/Factory.cs +++ b/TBF/BenchControl/Uni/Diverter/Factory.cs @@ -8,7 +8,7 @@ namespace TBF.BenchControl.Uni.Diverter { public class Factory : IComponentFactory { - public string ClassName { get { return this.GetType().Namespace.Substring(17); } } + public string ClassName { get { return this.GetType().Namespace.Substring(17 + 4); } } public override string ToString() { return ClassName; } public void ResetStaticProperties() { Diverter.ResetStaticProperties(); } diff --git a/TBF/BenchControl/Uni/FlowMeter/Factory.cs b/TBF/BenchControl/Uni/FlowMeter/Factory.cs index 8fb9f7e3e..645bb19d6 100644 --- a/TBF/BenchControl/Uni/FlowMeter/Factory.cs +++ b/TBF/BenchControl/Uni/FlowMeter/Factory.cs @@ -8,7 +8,7 @@ namespace TBF.BenchControl.Uni.FlowMeter { public class Factory : IComponentFactory { - public string ClassName { get { return this.GetType().Namespace.Substring(17); } } + public string ClassName { get { return this.GetType().Namespace.Substring(17 + 4); } } public override string ToString() { return ClassName; } public void ResetStaticProperties() { FlowMeter.ResetStaticProperties(); } diff --git a/TBF/BenchControl/Uni/FlowMeter/FlowMeterCfg.cs b/TBF/BenchControl/Uni/FlowMeter/FlowMeterCfg.cs index 3e3bc1184..0b1fa7e39 100644 --- a/TBF/BenchControl/Uni/FlowMeter/FlowMeterCfg.cs +++ b/TBF/BenchControl/Uni/FlowMeter/FlowMeterCfg.cs @@ -252,7 +252,7 @@ namespace TBF.BenchControl.Uni.FlowMeter Factory = factory; Name = "FlowMeter"; - ParentName = "CB"; + ParentName = "UniCB"; Idx1 = 1; NominalFlow = 1; } diff --git a/TBF/BenchControl/Uni/RegValve/Factory.cs b/TBF/BenchControl/Uni/RegValve/Factory.cs index 3c0cfe6c7..450eebf8a 100644 --- a/TBF/BenchControl/Uni/RegValve/Factory.cs +++ b/TBF/BenchControl/Uni/RegValve/Factory.cs @@ -8,7 +8,7 @@ namespace TBF.BenchControl.Uni.RegValve { public class Factory : IComponentFactory { - public string ClassName { get { return this.GetType().Namespace.Substring(17); } } + public string ClassName { get { return this.GetType().Namespace.Substring(17 + 4); } } public override string ToString() { return ClassName; } public void ResetStaticProperties() { RegValve.ResetStaticProperties(); } diff --git a/TBF/BenchControl/Uni/RegValve/RegValveCfg.cs b/TBF/BenchControl/Uni/RegValve/RegValveCfg.cs index 7f305731f..daaa6fb5e 100644 --- a/TBF/BenchControl/Uni/RegValve/RegValveCfg.cs +++ b/TBF/BenchControl/Uni/RegValve/RegValveCfg.cs @@ -69,7 +69,7 @@ namespace TBF.BenchControl.Uni.RegValve Name = name; Factory = factory; - ParentName = "CB"; + ParentName = "UniCB"; Category = ValveCategory.Output; Idx1 = 1; AdcValueClosed = 100; diff --git a/TBF/UI/Bench/Components/ComponentsManagerDlg.cs b/TBF/UI/Bench/Components/ComponentsManagerDlg.cs index f8919e522..5d780aaf7 100644 --- a/TBF/UI/Bench/Components/ComponentsManagerDlg.cs +++ b/TBF/UI/Bench/Components/ComponentsManagerDlg.cs @@ -740,13 +740,13 @@ namespace TBF.UI.Bench.Components else if (cfg is BenchControl.Modbus.TempMeter.Groch.TempMeterCfg) { (cfg as IChildComponentCfg).ParentName = "CB"; - (cfg as BenchControl.Elde.TempMeter.TempMeterCfg).Idx0 = zeroBasedIdx; + (cfg as BenchControl.Modbus.TempMeter.Groch.TempMeterCfg).Idx0 = zeroBasedIdx; return true; } else if (cfg is BenchControl.Modbus.PressureMeter.Meret.PressureMeterCfg) { (cfg as IChildComponentCfg).ParentName = "CB"; - (cfg as BenchControl.Elde.PressureMeter.PressureMeterCfg).Idx0 = zeroBasedIdx; + (cfg as BenchControl.Modbus.PressureMeter.Meret.PressureMeterCfg).ModbusAddress = (byte)(zeroBasedIdx + 1); return true; } else if (cfg is BenchControl.RegisterReaders.PulsesFromUniCB.RRCfg)