diff --git a/TestBenchFramework/BenchControl/BenchId/Component.cs b/TestBenchFramework/BenchControl/BenchId/Component.cs index 41f75d47b..182894a0a 100644 --- a/TestBenchFramework/BenchControl/BenchId/Component.cs +++ b/TestBenchFramework/BenchControl/BenchId/Component.cs @@ -2,33 +2,28 @@ using System.Collections.Generic; using System.Xml.Serialization; using log4net; +using TBF.Entities; using TBF.BenchControl; +using TBF.BenchControl.Generic; namespace TBF.BenchControl.BenchId { /// /// Holds information identifying the test bench. /// - public class Component : ComponentBase, Generic.IComponent + public class Component : ComponentBase { private static readonly ILog log = LogManager.GetLogger(typeof(Component)); - public override string ToString() - { - return string.Format("BenchId: Name={0}, TestBenchNr={1}", benchIdCfg.Name, TestBenchNr); - } + public override string ToString() { return string.Format("BenchId({0})", Cfg.ToString(1)); } readonly ComponentCfg benchIdCfg; - public static void ResetStaticProperties() { } - public int TestBenchNr { get { return benchIdCfg.TestBenchNr; } } public Component(ComponentCfg cfg) : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.benchIdCfg = cfg; - + benchIdCfg = cfg; log.Debug(this.ToString()); } } diff --git a/TestBenchFramework/BenchControl/BenchId/ComponentCfg.cs b/TestBenchFramework/BenchControl/BenchId/ComponentCfg.cs index a99471fbf..399d12fba 100644 --- a/TestBenchFramework/BenchControl/BenchId/ComponentCfg.cs +++ b/TestBenchFramework/BenchControl/BenchId/ComponentCfg.cs @@ -11,8 +11,8 @@ namespace TBF.BenchControl.BenchId { public int TestBenchNr; - /// Parameterless constructor, sets default values - public ComponentCfg() + /// Private parameterless constructor invoked by all other (public) constructors + ComponentCfg() { Name = "Bench-ID"; ParentName = string.Empty; diff --git a/TestBenchFramework/BenchControl/BenchId/ComponentFactory.cs b/TestBenchFramework/BenchControl/BenchId/ComponentFactory.cs index fd2aa4a4e..11a098324 100644 --- a/TestBenchFramework/BenchControl/BenchId/ComponentFactory.cs +++ b/TestBenchFramework/BenchControl/BenchId/ComponentFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.BenchId public class ComponentFactory : IComponentFactory { public string ClassName { get { return "Bench-ID"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return int.MaxValue; } } diff --git a/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoi.cs b/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoi.cs index f0e91de7b..328f6d0e8 100644 --- a/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoi.cs +++ b/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoi.cs @@ -13,31 +13,23 @@ namespace TBF.BenchControl.Cameras.CameraRoi /// IdcCamera object represents all IDC cameras. /// Camera ID is an argument of most methods. /// - public class CameraRoi : ComponentBase, IComponent, GenericDevices.ICameraRoi, GenericDevices.IRegisterReader + public class CameraRoi : ComponentBase, GenericDevices.ICameraRoi, GenericDevices.IRegisterReader { private static readonly ILog log = LogManager.GetLogger(typeof(CameraRoi)); - public override string ToString() { return string.Format("{0}, roi{1}, parent={2}", - cameraRoiCfg.Name, cameraRoiCfg.RoiNr, Cfg.ParentName); } - - public static void ResetStaticProperties() - { - } + public override string ToString() { return string.Format("CameraRoi({0})", Cfg.ToString(1)); } readonly CameraRoiCfg cameraRoiCfg; readonly GenericDevices.ICamera camera; public GenericDevices.ICamera Camera { get { return camera; } } - public float PulsesPerLtr - { - get { return (ProcedureParams as RoiProcedureParams).GradPerLtr; } - } + public float PulsesPerLtr { get { return cameraRoiCfg.ProcParams.GradPerLtr; } } public CameraRoi(CameraRoiCfg cfg, IList components) : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.cameraRoiCfg = cfg; + cameraRoiCfg = cfg; + if (cfg.DebugLevel != Entities.DebugMode.Off) { camera = TbfComponents.FindComponent(cfg.ParentName, components) as GenericDevices.ICamera; @@ -46,6 +38,8 @@ namespace TBF.BenchControl.Cameras.CameraRoi throw new Exception("Cannot find " + Name + " parent"); } } + + log.Debug(this.ToString()); } /// @@ -86,7 +80,7 @@ namespace TBF.BenchControl.Cameras.CameraRoi /// Reference to operation object instance public IOperation DetectOp() { - RoiProcedureParams pp = ProcedureParams as RoiProcedureParams; + RoiProcedureParams pp = cameraRoiCfg.ProcParams; return camera.DetectOp(cameraRoiCfg.RoiNr, new Cameras.IdcCamera.Command.Detect(cameraRoiCfg.RoiNr, 0, pp.IRoiX, pp.IRoiY, pp.IRoiW, pp.IRoiH, pp.CX, pp.CY, pp.ORoiW, pp.ORoiH, pp.R1, pp.R2, pp.R3, @@ -102,7 +96,7 @@ namespace TBF.BenchControl.Cameras.CameraRoi /// Reference to operation object instance public IOperation MeasureOp() { - RoiProcedureParams pp = ProcedureParams as RoiProcedureParams; + RoiProcedureParams pp = cameraRoiCfg.ProcParams; return camera.MeasureOp(cameraRoiCfg.RoiNr, new Cameras.IdcCamera.Command.Measure(cameraRoiCfg.RoiNr, true, 0, pp.IRoiX, pp.IRoiY, pp.IRoiW, pp.IRoiH, pp.CX, pp.CY, pp.ORoiW, pp.ORoiH, pp.MinMvmt, pp.MaxMvmt, diff --git a/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoiCfg.cs b/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoiCfg.cs index c58eab4b8..a4399650b 100644 --- a/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoiCfg.cs +++ b/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoiCfg.cs @@ -9,12 +9,24 @@ namespace TBF.BenchControl.Cameras.CameraRoi { public int RoiNr; /// ROI number 1..4 - /// Parameterless constructor - public CameraRoiCfg() + /// Procedure parameters + [XmlIgnore] + public RoiProcedureParams ProcParams; + public override IParamsProvider GetProcedureParams() { return ProcParams; } + public override IParamsProvider CreateProcedureParams(Entities.Procedure procedure) + { + RoiProcedureParams procParams = new RoiProcedureParams(); + procParams.UpdateProcedureParams(Name, procedure); + return procParams; + } + + /// Private parameterless constructor invoked by all other (public) constructors + CameraRoiCfg() { Name = "ROI"; ParentName = "Idc"; RoiNr = 1; + ProcParams = new RoiProcedureParams(); } public CameraRoiCfg(IComponentFactory factory) diff --git a/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoiFactory.cs b/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoiFactory.cs index 7880e7a8e..f3e4053d7 100644 --- a/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoiFactory.cs +++ b/TestBenchFramework/BenchControl/Cameras/CameraRoi/CameraRoiFactory.cs @@ -30,17 +30,6 @@ namespace TBF.BenchControl.Cameras.CameraRoi return ComponentCfgBase.CreateFromDbEntity(typeof(CameraRoiCfg), component, this); } - public bool HasProcedureParams { get { return true; } } - // - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) - { - return RoiProcedureParams.GetProcedureParams(procedureParams); - } - - public bool HasTestParams { get { return false; } } - // - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public void ResetStaticProperties() { CameraRoi.ResetStaticProperties(); } } } diff --git a/TestBenchFramework/BenchControl/Cameras/CameraRoi/RoiProcedureParams.cs b/TestBenchFramework/BenchControl/Cameras/CameraRoi/RoiProcedureParams.cs index 7c1db8ca6..861b35bc4 100644 --- a/TestBenchFramework/BenchControl/Cameras/CameraRoi/RoiProcedureParams.cs +++ b/TestBenchFramework/BenchControl/Cameras/CameraRoi/RoiProcedureParams.cs @@ -7,7 +7,7 @@ using TBF.Resources; namespace TBF.BenchControl.Cameras.CameraRoi { - public class RoiProcedureParams : IParamsProvider, IProcedureParams + public class RoiProcedureParams : ProcedureParamsBase, IParamsProvider, IProcedureParams { public int IRoiX; public int IRoiY; @@ -35,6 +35,36 @@ namespace TBF.BenchControl.Cameras.CameraRoi public int BackgroundCorr; public float BrightnessRoi; + + public override void InitializeAll() + { + IRoiX = 60; + IRoiY = 1; + IRoiW = 520; + IRoiH = 478; + + GradPerLtr = 40; + CCW = true; + ORoiW = 64.0f; + ORoiH = 64.0f; + CX = 31.0f; + CY = 31.0f; + + R1 = 21.0f; + R2 = 31.0f; + R3 = 0; + Ang1 = 0; + Ang2 = 400.0f; + AngStep = 40.0f; + MinMvmt = 0; + MaxMvmt = 0; + + SequenceLen = 8; + SequenceTiming = 1; + BackgroundCorr = 0; + BrightnessRoi = 1.0f; + } + string[] paramNames = new string[] { "IRoiX", @@ -63,9 +93,10 @@ namespace TBF.BenchControl.Cameras.CameraRoi "Background", "Brightness", }; - public string ParamName(int i) { return paramNames[i]; } + public override string ParamName(int i) { return paramNames[i]; } + public override int ParamsCount() { return paramNames.Length; } - public string ToString(int i) + public override string ToString(int i) { switch (i) { @@ -99,38 +130,6 @@ namespace TBF.BenchControl.Cameras.CameraRoi } } - /// - /// Parameterless constructor - sets default values of parameters. - /// - public RoiProcedureParams() - { - IRoiX = 60; - IRoiY = 1; - IRoiW = 520; - IRoiH = 478; - - GradPerLtr = 40; - CCW = true; - ORoiW = 64.0f; - ORoiH = 64.0f; - CX = 31.0f; - CY = 31.0f; - - R1 = 21.0f; - R2 = 31.0f; - R3 = 0; - Ang1 = 0; - Ang2 = 400.0f; - AngStep = 40.0f; - MinMvmt = 0; - MaxMvmt = 0; - - SequenceLen = 8; - SequenceTiming = 1; - BackgroundCorr = 0; - BrightnessRoi = 1.0f; - } - public void UpdateParam(int i, string strValue) { switch (i) @@ -222,92 +221,59 @@ namespace TBF.BenchControl.Cameras.CameraRoi return false; } - #region Boilerplate code - - public int ParamsCount() { return paramNames.Length; } - - public override string ToString() + public override void UpdateProcedureParams(Entities.ComponentProcedure dbEntity) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < ParamsCount(); i++) + if (dbEntity == null) return; + try + { + RoiProcedureParams tmp = (RoiProcedureParams)(new XmlSerializer(typeof(RoiProcedureParams))) + .Deserialize(new StringReader(dbEntity.Parameters)); + + procedureParamsEntity = dbEntity; + componentName = dbEntity.CmpntName; + procedure = dbEntity.Procedure; + + IRoiX = tmp.IRoiX; + IRoiY = tmp.IRoiY; + IRoiW = tmp.IRoiW; + IRoiH = tmp.IRoiH; + + GradPerLtr = tmp.GradPerLtr; + CCW = tmp.CCW; + ORoiW = tmp.ORoiW; + ORoiH = tmp.ORoiH; + CX = tmp.CX; + CY = tmp.CY; + + R1 = tmp.R1; + R2 = tmp.R2; + R3 = tmp.R3; + Ang1 = tmp.Ang1; + Ang2 = tmp.Ang2; + AngStep = tmp.AngStep; + MinMvmt = tmp.MinMvmt; + MaxMvmt = tmp.MaxMvmt; + + SequenceLen = tmp.SequenceLen; + SequenceTiming = tmp.SequenceTiming; + BackgroundCorr = tmp.BackgroundCorr; + BrightnessRoi = tmp.BrightnessRoi; + } + catch { - if (i != 0) sb.Append("; "); - sb.Append(ParamName(i)); - sb.Append("="); - sb.Append(ToString(i)); } - return sb.ToString(); } - [XmlIgnore] - public Entities.ComponentProcedure ProcedureParamsEntity { get { return procedureParamsEntity; } } - Entities.ComponentProcedure procedureParamsEntity; - [XmlIgnore] - public string ComponentName { get { return componentName; } } - string componentName; - - [XmlIgnore] - public Entities.Procedure Procedure { get { return procedure; } } - Entities.Procedure procedure; + public RoiProcedureParams() + { + } public RoiProcedureParams(Entities.ComponentProcedure procedureParamsEntity, string componentName, Entities.Procedure procedure) - : this() { this.procedureParamsEntity = procedureParamsEntity; this.componentName = componentName; this.procedure = procedure; } - - public TBF.Entities.ComponentProcedure ToDbEntity(IComponent component, Entities.Procedure procedure) - { - using (var writer = new StringWriter()) - { - /// Serialize this class with parameters - (new XmlSerializer(GetType())).Serialize(writer, this); - - /// Create and return the ComponentProcedure entity - TBF.Entities.ComponentProcedure entity = new TBF.Entities.ComponentProcedure(); - entity.CmpntName = component.Cfg.Name; - entity.Parameters = writer.ToString(); - entity.Procedure = procedure; - return entity; - } - } - - public void UpdateDbEntity() - { - using (var writer = new StringWriter()) - { - /// Serialize this class and update the entity - (new XmlSerializer(GetType())).Serialize(writer, this); - procedureParamsEntity.Parameters = writer.ToString(); - procedureParamsEntity.CmpntName = componentName; - procedureParamsEntity.Procedure = procedure; - - } - } - - public static IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParamsEntity) - { - if (procedureParamsEntity == null) return new RoiProcedureParams(); - - RoiProcedureParams procedureParams; - try - { - procedureParams = (RoiProcedureParams)(new XmlSerializer(typeof(RoiProcedureParams))) - .Deserialize(new StringReader(procedureParamsEntity.Parameters)); - } - catch - { - procedureParams = new RoiProcedureParams(); - } - procedureParams.procedureParamsEntity = procedureParamsEntity; - procedureParams.componentName = procedureParamsEntity.CmpntName; - procedureParams.procedure = procedureParamsEntity.Procedure; - return procedureParams; - } - - #endregion } } diff --git a/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCamera.cs b/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCamera.cs index 2d061305f..02862ca7c 100644 --- a/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCamera.cs +++ b/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCamera.cs @@ -15,9 +15,9 @@ namespace TBF.BenchControl.Cameras.IdcCamera public class IdcCamera : ComponentBase, IDevice, IOperation, GenericDevices.ICamera { private static readonly ILog log = LogManager.GetLogger(typeof(IdcCamera)); - public override string ToString() { return string.Format("{0}, com{1}, {2}, roi{3}", - idcCameraCfg.Name, idcCameraCfg.ComPortNr, - currentOp, currentRoiId); } + public override string ToString() { return string.Format("IdcCamera({0})", Cfg.ToString(1)); } + + readonly IdcCameraCfg idcCameraCfg; const int MaxRoisCount = 4; @@ -25,7 +25,7 @@ namespace TBF.BenchControl.Cameras.IdcCamera /// Enumeration of cameras via static fields and methods /// static int nextCameraNr = 0; - public static void ResetStaticProperties() + public static new void ResetStaticProperties() { nextCameraNr = 0; } @@ -35,8 +35,6 @@ namespace TBF.BenchControl.Cameras.IdcCamera public float Brightness { get { return idcCameraCfg.BrightnessCam; } } - private readonly IdcCameraCfg idcCameraCfg; - /// /// Currently running camera operation. /// ReadRegisterOp-s are not included in this list, they are independent. @@ -63,10 +61,9 @@ namespace TBF.BenchControl.Cameras.IdcCamera public IdcCamera(IdcCameraCfg cfg, IList components) : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.idcCameraCfg = cfg; - + idcCameraCfg = cfg; cameraNr = nextCameraNr++; + log.Debug(this.ToString()); } public void Initialize() diff --git a/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCameraCfg.cs b/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCameraCfg.cs index 852b4c9f5..a5164f1b2 100644 --- a/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCameraCfg.cs +++ b/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCameraCfg.cs @@ -11,8 +11,8 @@ namespace TBF.BenchControl.Cameras.IdcCamera public int BaudRate; /// Baud rate 57600 or 115200 public float BrightnessCam; /// Relative brightness 0 .. 1.0f - /// Parameterless constructor - public IdcCameraCfg() + /// Private parameterless constructor invoked by all other (public) constructors + IdcCameraCfg() { Name = "Idc"; ParentName = string.Empty; @@ -29,7 +29,11 @@ namespace TBF.BenchControl.Cameras.IdcCamera public string ToString(int i) { - return string.Format("COM{0}, {1}Bd, brightness={2}%", ComPortNr, BaudRate, (int)(100.0f * BrightnessCam)); + return string.Format("Name={0}, Com{1}, {2}Bd, brght={3}%", + Name, + ComPortNr, + BaudRate, + (int)(100.0f * BrightnessCam)); } } } diff --git a/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCameraFactory.cs b/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCameraFactory.cs index 85cda58ba..d2a7948d5 100644 --- a/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCameraFactory.cs +++ b/TestBenchFramework/BenchControl/Cameras/IdcCamera/IdcCameraFactory.cs @@ -30,12 +30,6 @@ namespace TBF.BenchControl.Cameras.IdcCamera return ComponentCfgBase.CreateFromDbEntity(typeof(IdcCameraCfg), component, this); } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - // - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public void ResetStaticProperties() { IdcCamera.ResetStaticProperties(); } } } diff --git a/TestBenchFramework/BenchControl/ComponentBase.cs b/TestBenchFramework/BenchControl/ComponentBase.cs index 8777eee58..e8b1e002b 100644 --- a/TestBenchFramework/BenchControl/ComponentBase.cs +++ b/TestBenchFramework/BenchControl/ComponentBase.cs @@ -1,46 +1,36 @@ -using TBF.BenchControl.Generic; +using System; +using System.Collections.Generic; +using TBF.Entities; +using TBF.BenchControl.Generic; namespace TBF.BenchControl { public class ComponentBase : IComponent { - Generic.IComponentCfg cfg; + readonly Generic.IComponentCfg cfg; public Generic.IComponentCfg Cfg { get { return cfg; } } + public string Name { get { return cfg.Name; } } + public string ClassName { get { return cfg.Factory.ClassName; } } + public string ParentName { get { return cfg.ParentName; } } + public Generic.IComponentFactory Factory { get { return cfg.Factory; } } + public int ItemNr { get { return cfg.ItemNr; } } + public Entities.DebugMode DebugLevel { get { return cfg.DebugLevel; } } + public Entities.LogLevel LogLevel { get { return cfg.LogLevel; } } + public IList Corrections { get { return cfg.Corrections; } } + /// Constructor - public ComponentBase(Generic.IComponentCfg cfg) + public ComponentBase(IComponentCfg cfg) { - this.cfg = cfg; + if (cfg == null) throw new ArgumentNullException("cfg"); + this.cfg = cfg; } - - public string Name { get { return Cfg.Name; } } - - - /// - /// Reference to an object with procedure parameters - /// - public IParamsProvider ProcedureParams; - /// - public void GetProcedureParams(TBF.Entities.Procedure procedure) - { - if (Cfg.Factory.HasProcedureParams) - { - ProcedureParams = TbfComponents.GetProcedureParams(this, procedure); - } - } - - /// - /// Reference to an object with test parameters - /// - public IParamsProvider TestParams; - /// - public void GetTestParams(TBF.Entities.Test test) - { - if (Cfg.Factory.HasTestParams) - { - TestParams = TbfComponents.GetTestParams(this, test); - } - } + /// + /// Empty implementation, might be overriden in derived classes + /// + public static void ResetStaticProperties() + { + } } } diff --git a/TestBenchFramework/BenchControl/ComponentCfgBase.cs b/TestBenchFramework/BenchControl/ComponentCfgBase.cs index 70610bae5..24a8c2424 100644 --- a/TestBenchFramework/BenchControl/ComponentCfgBase.cs +++ b/TestBenchFramework/BenchControl/ComponentCfgBase.cs @@ -115,5 +115,57 @@ namespace TBF.BenchControl return config; } } - } + + /// + /// Default implementation returning null - no test aprameters. + /// In case there are any test parameters, this function override should return + /// a reference to a class that implements IParamsProvider and ITestParams. + /// + /// Test parameters obtained by the last UpdateTestParams(test) + public virtual IParamsProvider GetTestParams() + { + return null; + } + + /// + /// Default implementation returning null - no procedure parameters. + /// In case there are any procedure parameters, this function override should return + /// a reference to a class that implements IParamsProvider and IProcedureParams. + /// + /// Procedure parameters obtained by the last UpdateProcedureParams(procedure) + public virtual IParamsProvider GetProcedureParams() + { + return null; + } + + + public void UpdateTestParams(Entities.Test test) + { + ITestParams tstPrms = (GetTestParams() as ITestParams); + if (tstPrms != null) + { + tstPrms.UpdateTestParams(Name, test); + } + } + + public void UpdateProcedureParams(Entities.Procedure procedure) + { + IProcedureParams procPrms = (GetProcedureParams() as IProcedureParams); + if (procPrms == null) + { + procPrms.UpdateProcedureParams(Name, procedure); + } + } + + + public virtual IParamsProvider CreateTestParams(Entities.Test test) + { + return null; + } + + public virtual IParamsProvider CreateProcedureParams(Entities.Procedure procedure) + { + return null; + } + } } diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich/EntryForm.cs b/TestBenchFramework/BenchControl/DataEntry/Munich/EntryForm.cs index 1f59f6beb..18715f75a 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich/EntryForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich/EntryForm.cs @@ -6,21 +6,12 @@ using TBF.BenchControl.GenericDevices; namespace TBF.BenchControl.DataEntry.Munich { - public class EntryForm : Generic.IComponent, IOperation, IDataEntry, IHasCycleBeginForm, IHasCycleEndForm, IHasProtocolTitle + public class EntryForm : ComponentBase, IOperation, IDataEntry, IHasCycleBeginForm, IHasCycleEndForm, IHasProtocolTitle { private static readonly ILog log = LogManager.GetLogger(typeof(EntryForm)); - public override string ToString() - { - return string.Format("Name={0}", Name); - } - + public override string ToString() { return string.Format("DataEntry.Munich({0})", Cfg.ToString(1)); } readonly EntryFormCfg entryFormCfg; - public Generic.IComponentCfg Cfg { get { return entryFormCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return entryFormCfg.Name; } } /// /// Properties set by the Begin and the End form @@ -34,18 +25,11 @@ namespace TBF.BenchControl.DataEntry.Munich public string ProtocolTitle { get { return protocolTitle; } } string protocolTitle; + /// Not supported in Munich + public string SerialNr(int wmNr) { return string.Empty; } /// Not supported in Munich - public string SerialNr(int wmNr) - { - return string.Empty; - } - - /// Not supported in Munich - public float WMState(int wmNr) - { - return 0; - } + public float WMState(int wmNr) { return 0; } System.Windows.Forms.Form modelessDlg; @@ -63,12 +47,12 @@ namespace TBF.BenchControl.DataEntry.Munich CurrentOp currentOp; - public EntryForm(EntryFormCfg cfg) - { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.entryFormCfg = cfg; - currentOp = CurrentOp.None; + public EntryForm(EntryFormCfg cfg) + : base(cfg) + { + entryFormCfg = cfg; + currentOp = CurrentOp.None; log.Debug(this.ToString()); } diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich/EntryFormCfg.cs b/TestBenchFramework/BenchControl/DataEntry/Munich/EntryFormCfg.cs index 0d6fb1f7b..81496a960 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich/EntryFormCfg.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich/EntryFormCfg.cs @@ -11,8 +11,8 @@ namespace TBF.BenchControl.DataEntry.Munich public string ProtocolTitle2; public string ProtocolTitle3; - /// Parameterless constructor - public EntryFormCfg() + /// Private parameterless constructor invoked by all other (public) constructors + EntryFormCfg() { Name = "DataEntryForm-Munich"; ParentName = string.Empty; @@ -29,7 +29,7 @@ namespace TBF.BenchControl.DataEntry.Munich public string ToString(int i) { - return string.Format("Name={0}, Protocol1={2}, Protocol2={3}, Protocol3={4}", + return string.Format("Name={0}, Protocol1={1}, Protocol2={2}, Protocol3={3}", Name, (string.IsNullOrEmpty(ProtocolTitle1) ? "-" : ProtocolTitle1), (string.IsNullOrEmpty(ProtocolTitle2) ? "-" : ProtocolTitle2), diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich/EntryFormFactory.cs b/TestBenchFramework/BenchControl/DataEntry/Munich/EntryFormFactory.cs index ad4e11388..f116eb467 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich/EntryFormFactory.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich/EntryFormFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.DataEntry.Munich public class EntryFormFactory : IComponentFactory { public string ClassName { get { return "DataEntryForm-Munich"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryForm.cs b/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryForm.cs index 3825378a1..997d391c9 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryForm.cs @@ -6,21 +6,12 @@ using TBF.BenchControl.GenericDevices; namespace TBF.BenchControl.DataEntry.Munich3 { - public class EntryForm : Generic.IComponent, IOperation, IDataEntry, IHasCycleBeginForm, IHasCycleEndForm, IHasProtocolTitle + public class EntryForm : ComponentBase, IOperation, IDataEntry, IHasCycleBeginForm, IHasCycleEndForm, IHasProtocolTitle { private static readonly ILog log = LogManager.GetLogger(typeof(EntryForm)); - public override string ToString() - { - return string.Format("Name={0}", Name); - } + public override string ToString() { return string.Format("DataEntry.Munich3({0})", Cfg.ToString(1)); } - readonly EntryFormCfg entryFormCfg; - public Generic.IComponentCfg Cfg { get { return entryFormCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return entryFormCfg.Name; } } /// /// Properties set by the Begin and the End form @@ -28,18 +19,11 @@ namespace TBF.BenchControl.DataEntry.Munich3 public string ProtocolTitle { get { return protocolTitle; } } string protocolTitle; + /// Not supported in Munich + public string SerialNr(int wmNr) { return string.Empty; } /// Not supported in Munich - public string SerialNr(int wmNr) - { - return string.Empty; - } - - /// Not supported in Munich - public float WMState(int wmNr) - { - return 0; - } + public float WMState(int wmNr) { return 0; } System.Windows.Forms.Form modelessDlg; @@ -57,12 +41,12 @@ namespace TBF.BenchControl.DataEntry.Munich3 CurrentOp currentOp; - public EntryForm(EntryFormCfg cfg) - { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.entryFormCfg = cfg; - currentOp = CurrentOp.None; + public EntryForm(EntryFormCfg cfg) + : base(cfg) + { + entryFormCfg = cfg; + currentOp = CurrentOp.None; log.Debug(this.ToString()); } diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryFormCfg.cs b/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryFormCfg.cs index 6ab36f990..b9685895a 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryFormCfg.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryFormCfg.cs @@ -11,8 +11,8 @@ namespace TBF.BenchControl.DataEntry.Munich3 public string ProtocolTitle2; public string ProtocolTitle3; - /// Parameterless constructor - public EntryFormCfg() + /// Private parameterless constructor invoked by all other (public) constructors + EntryFormCfg() { Name = "DataEntryForm-3"; ParentName = string.Empty; @@ -29,7 +29,7 @@ namespace TBF.BenchControl.DataEntry.Munich3 public string ToString(int i) { - return string.Format("Name={0}, Protocol1={2}, Protocol2={3}, Protocol3={4}", + return string.Format("Name={0}, Protocol1={1}, Protocol2={2}, Protocol3={3}", Name, (string.IsNullOrEmpty(ProtocolTitle1) ? "-" : ProtocolTitle1), (string.IsNullOrEmpty(ProtocolTitle2) ? "-" : ProtocolTitle2), diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryFormFactory.cs b/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryFormFactory.cs index 9ac936f58..dc10554f8 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryFormFactory.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryFormFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.DataEntry.Munich3 public class EntryFormFactory : IComponentFactory { public string ClassName { get { return "DataEntryForm-3"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryForm.cs b/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryForm.cs index a345e4801..e4b541511 100644 --- a/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryForm.cs @@ -6,22 +6,12 @@ using TBF.BenchControl.GenericDevices; namespace TBF.BenchControl.DataEntry.WMStates { - public class EntryForm : Generic.IComponent, IOperation, IDataEntry, IHasWMStatesForm + public class EntryForm : ComponentBase, IOperation, IDataEntry, IHasWMStatesForm { private static readonly ILog log = LogManager.GetLogger(typeof(EntryForm)); - public override string ToString() - { - return string.Format("Name={0}", Name); - } - + public override string ToString() { return string.Format("DataEntry.WMStates({0})", Cfg.ToString(1)); } readonly EntryFormCfg entryFormCfg; - public Generic.IComponentCfg Cfg { get { return entryFormCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return entryFormCfg.Name; } } - /// /// Water meter serial numbers set by forms @@ -64,14 +54,14 @@ namespace TBF.BenchControl.DataEntry.WMStates CurrentOp currentOp; + public EntryForm(EntryFormCfg cfg) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.entryFormCfg = cfg; + entryFormCfg = cfg; serialNr = new string[Program.WMsCount]; wmState = new float[Program.WMsCount]; currentOp = CurrentOp.None; - log.Debug(this.ToString()); } diff --git a/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryFormCfg.cs b/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryFormCfg.cs index 1e75770d5..1ab89388b 100644 --- a/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryFormCfg.cs +++ b/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryFormCfg.cs @@ -7,8 +7,8 @@ namespace TBF.BenchControl.DataEntry.WMStates { public class EntryFormCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - public EntryFormCfg() + /// Private parameterless constructor invoked by all other (public) constructors + EntryFormCfg() { Name = "Generic-WM-States-Form"; ParentName = string.Empty; diff --git a/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryFormFactory.cs b/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryFormFactory.cs index 955acec35..aab9cdf95 100644 --- a/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryFormFactory.cs +++ b/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryFormFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.DataEntry.WMStates public class EntryFormFactory : IComponentFactory { public string ClassName { get { return "Generic-WM-States-Form"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/Elde/ControlBoardCfg.cs b/TestBenchFramework/BenchControl/Elde/ControlBoardCfg.cs index 429ad1284..6394ff920 100644 --- a/TestBenchFramework/BenchControl/Elde/ControlBoardCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/ControlBoardCfg.cs @@ -8,8 +8,8 @@ namespace TBF.BenchControl.Elde { public int ComPortNr; - /// Parameterless constructor - public ControlBoardCfg() + /// Private parameterless constructor invoked by all other (public) constructors + ControlBoardCfg() { Name = "CB"; ParentName = string.Empty; @@ -24,7 +24,7 @@ namespace TBF.BenchControl.Elde public string ToString(int i) { - return string.Format("Name={0}, ComPortNr={1}", Name, ComPortNr); + return string.Format("Name={0}, Com{1}", Name, ComPortNr); } } } diff --git a/TestBenchFramework/BenchControl/Elde/ControlBoardDev.cs b/TestBenchFramework/BenchControl/Elde/ControlBoardDev.cs index d56fa6db8..457d445a5 100644 --- a/TestBenchFramework/BenchControl/Elde/ControlBoardDev.cs +++ b/TestBenchFramework/BenchControl/Elde/ControlBoardDev.cs @@ -8,26 +8,12 @@ using log4net; namespace TBF.BenchControl.Elde { - public class ControlBoardDev : IComponent, IDevice, IValveControl + public class ControlBoardDev : ComponentBase, IDevice, IValveControl { - /// - /// Info: - /// Warn: - /// Error: - /// private static readonly ILog log = LogManager.GetLogger(typeof(ControlBoardDev)); - public override string ToString() - { - return string.Format("ControlBoardDev: Name={0}, ComPort={1}", controlBoardCfg.Name, controlBoardCfg.ComPortNr); - } - - public static void ResetStaticProperties() { } - - ControlBoardCfg controlBoardCfg; - public Generic.IComponentCfg Cfg { get { return controlBoardCfg; } } - - public string Name { get { return controlBoardCfg.Name; } } + public override string ToString() { return string.Format("ControlBoard({0})", Cfg.ToString(1)); } + readonly ControlBoardCfg controlBoardCfg; /// /// Reference to the control board component @@ -159,9 +145,10 @@ namespace TBF.BenchControl.Elde /// Constructor /// public ControlBoardDev(ControlBoardCfg cfg, IList components) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.controlBoardCfg = cfg; + controlBoardCfg = cfg; + #if FUZHOU300 || PT200IL FMFreq = new float[6] { 0, 0, 0, 0, 0, 0 }; /// Nr. of pumps: Fuzhou150=2, Fuzhou300,PT200IL=6 #else @@ -169,7 +156,9 @@ namespace TBF.BenchControl.Elde #endif emergencyStop = false; previousEmergencyStop = false; - } + + log.Debug(this.ToString()); + } /// /// Specific pre-initialization for control board only diff --git a/TestBenchFramework/BenchControl/Elde/ControlBoardFactory.cs b/TestBenchFramework/BenchControl/Elde/ControlBoardFactory.cs index a85cfd2d0..cc0a8dcf2 100644 --- a/TestBenchFramework/BenchControl/Elde/ControlBoardFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/ControlBoardFactory.cs @@ -7,10 +7,6 @@ namespace TBF.BenchControl.Elde public class ControlBoardFactory : IComponentFactory { public string ClassName { get { return "ControlBoard"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/Elde/ControlComSim.cs b/TestBenchFramework/BenchControl/Elde/ControlComSim.cs index befb14f69..61eb19943 100644 --- a/TestBenchFramework/BenchControl/Elde/ControlComSim.cs +++ b/TestBenchFramework/BenchControl/Elde/ControlComSim.cs @@ -5,7 +5,7 @@ using log4net; namespace TBF.BenchControl.Elde { - public class ControlComSim : TestBenchSim, IControlCom + public class ControlComSim : IControlCom { private static readonly ILog log = LogManager.GetLogger(typeof(ControlComSim)); public override string ToString() { return string.Format("ControlComSim"); } @@ -149,7 +149,7 @@ namespace TBF.BenchControl.Elde this.cmd = cmd; this.refFlowmtrNr = refFlowmtrNr; this.route = route; - RouteSim = route; + TestBenchSim.RouteSim = route; this.totalRefPulses = totalRefPulses; this.testMethods = testMethods; this.filterConstant = filterConstant; @@ -201,7 +201,7 @@ namespace TBF.BenchControl.Elde public void RunDeviceBefore() { - base.RunDevice(regulValveNo, refFlowmtrNr, statusP); + TestBenchSim.RunDevice(regulValveNo, refFlowmtrNr, statusP); log.DebugFormat("refFreq=", referenceFreq); @@ -217,14 +217,14 @@ namespace TBF.BenchControl.Elde case Command.Start: if ((testMethods & TestMethods.Diverter) == TestMethods.Diverter) { - SetSimDiverter(true); + TestBenchSim.SetSimDiverter(true); } break; case Command.Stop: if ((testMethods & TestMethods.Diverter) == TestMethods.Diverter) { - SetSimDiverter(false); + TestBenchSim.SetSimDiverter(false); } break; } @@ -233,12 +233,12 @@ namespace TBF.BenchControl.Elde { case RegulValveMode.TargetFrequency: float targetFlow = ((regulValveValue[0] + regulValveValue[1]) / 2.0f) * (Qnom / 2000.0f); - UpdateSimFlow(targetFlow); + TestBenchSim.UpdateSimFlow(targetFlow); //if (referenceFreq < valveValue[0]) referenceFreq += ((float)rand.Next(20) + 10.0f) / 2.0f; //else if (referenceFreq > valveValue[1]) referenceFreq -= ((float)rand.Next(20) + 10.0f) / 2.0f; //else referenceFreq += ((float)rand.Next(10) - 5.0f) / 2.0f; - referenceFreq = GetSimFlow() * 2000.0f / Qnom; + referenceFreq = TestBenchSim.GetSimFlow() * 2000.0f / Qnom; if (referenceFreq < 0) referenceFreq = 0; if (referenceFreq > 2500) referenceFreq = 2500; break; @@ -270,7 +270,7 @@ namespace TBF.BenchControl.Elde for (int i = 1; i < Program.WMsCount; i++) { const float wmPulsesPerLiter = 10.0f; - wMeterPulsesF[i] += errFactor[i] * pwFactor * ((float)rand.Next(100) + 450.0f) * wmPulsesPerLiter * GetSimFlow() / 1800.0f; + wMeterPulsesF[i] += errFactor[i] * pwFactor * ((float)rand.Next(100) + 450.0f) * wmPulsesPerLiter * TestBenchSim.GetSimFlow() / 1800.0f; wMeterPulses[i] = (int)wMeterPulsesF[i]; } @@ -283,7 +283,7 @@ namespace TBF.BenchControl.Elde if (stopTest) { - SetSimDiverter(false); + TestBenchSim.SetSimDiverter(false); statusP = (statusP | StatusP.TestCompleted); statusP = (statusP & ~StatusP.TestInProgress); } diff --git a/TestBenchFramework/BenchControl/Elde/Diverter/Diverter.cs b/TestBenchFramework/BenchControl/Elde/Diverter/Diverter.cs index 3316c8966..b17d75806 100644 --- a/TestBenchFramework/BenchControl/Elde/Diverter/Diverter.cs +++ b/TestBenchFramework/BenchControl/Elde/Diverter/Diverter.cs @@ -4,34 +4,25 @@ using log4net; namespace TBF.BenchControl.Elde.Diverter { - public class Diverter : Generic.IComponent, GenericDevices.IDiverter + public class Diverter : ComponentBase, GenericDevices.IDiverter { - /// - /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." - /// Warn: Start measurement when busy is true - /// private static readonly ILog log = LogManager.GetLogger(typeof(Diverter)); - public override string ToString() - { - return string.Format("Diverter({0},{1})", Name, diverterCfg.BitPosition); - } + public override string ToString() { return string.Format("Diverter({0})", Cfg.ToString(1)); } - public static void ResetStaticProperties() { } - - private readonly DiverterCfg diverterCfg; - public Generic.IComponentCfg Cfg { get { return diverterCfg; } } - - public string Name { get { return diverterCfg.Name; } } - + readonly DiverterCfg diverterCfg; readonly ControlBoardDev controlBoard; - readonly ulong mask; /// derived from bitPosition in the constructor + public bool State + { + get { return (controlBoard.Route & mask) != 0; } + } + public Diverter(DiverterCfg cfg, IList components) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.diverterCfg = cfg; + diverterCfg = cfg; controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent"); @@ -41,10 +32,5 @@ namespace TBF.BenchControl.Elde.Diverter log.Debug(this.ToString()); } - - public bool State - { - get { return (controlBoard.Route & mask) != 0; } - } } } diff --git a/TestBenchFramework/BenchControl/Elde/Diverter/DiverterCfg.cs b/TestBenchFramework/BenchControl/Elde/Diverter/DiverterCfg.cs index 335d8e659..7f5eb0927 100644 --- a/TestBenchFramework/BenchControl/Elde/Diverter/DiverterCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/Diverter/DiverterCfg.cs @@ -8,8 +8,8 @@ namespace TBF.BenchControl.Elde.Diverter { public int BitPosition; - /// Parameterless constructor - public DiverterCfg() + /// Private parameterless constructor invoked by all other (public) constructors + DiverterCfg() { Name = "Div"; ParentName = "CB"; @@ -25,6 +25,7 @@ namespace TBF.BenchControl.Elde.Diverter public string ToString(int i) { return string.Format("Name={0}, Parent={1}, Bit={2}", + Name, (string.IsNullOrEmpty(ParentName) ? "-" : ParentName), BitPosition); } diff --git a/TestBenchFramework/BenchControl/Elde/Diverter/DiverterFactory.cs b/TestBenchFramework/BenchControl/Elde/Diverter/DiverterFactory.cs index 4673a5e3a..02b52e7be 100644 --- a/TestBenchFramework/BenchControl/Elde/Diverter/DiverterFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/Diverter/DiverterFactory.cs @@ -9,10 +9,6 @@ namespace TBF.BenchControl.Elde.Diverter public class DiverterFactory : IComponentFactory { public string ClassName { get { return "Diverter"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 5; } } diff --git a/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RRProcedureParams.cs b/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RRProcedureParams.cs index 1e5638e7d..3370f9a57 100644 --- a/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RRProcedureParams.cs +++ b/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RRProcedureParams.cs @@ -7,17 +7,23 @@ using TBF.Resources; namespace TBF.BenchControl.Elde.FixedStartRegisterReader { - public class RRProcedureParams : IParamsProvider, IProcedureParams + public class RRProcedureParams : ProcedureParamsBase, IParamsProvider, IProcedureParams { public float PulsesPerLtr; /// Target low limit of the flow increase or decrease + public override void InitializeAll() + { + PulsesPerLtr = 1.0f; + } + string[] paramNames = new string[] { Strings.PulsesPerLtr, }; - public string ParamName(int i) { return paramNames[i]; } + public override string ParamName(int i) { return paramNames[i]; } + public override int ParamsCount() { return paramNames.Length; } - public string ToString(int i) + public override string ToString(int i) { switch (i) { @@ -25,14 +31,6 @@ namespace TBF.BenchControl.Elde.FixedStartRegisterReader default: return string.Empty; } } - - /// - /// Parameterless constructor - sets default values of parameters. - /// - public RRProcedureParams() - { - PulsesPerLtr = 1.0f; - } /// Retrieves parameters from UI controls public void UpdateParam(int i, string strValue) @@ -64,92 +62,34 @@ namespace TBF.BenchControl.Elde.FixedStartRegisterReader return false; } - #region Boilerplate code - - public int ParamsCount() { return paramNames.Length; } - - public override string ToString() + public override void UpdateProcedureParams(Entities.ComponentProcedure dbEntity) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < ParamsCount(); i++) - { - if (i != 0) sb.Append("; "); - sb.Append(ParamName(i)); - sb.Append("="); - sb.Append(ToString(i)); - } - return sb.ToString(); - } - - [XmlIgnore] - public Entities.ComponentProcedure ProcedureParamsEntity { get { return procedureParamsEntity; } } - Entities.ComponentProcedure procedureParamsEntity; - - [XmlIgnore] - public string ComponentName { get { return componentName; } } - string componentName; - - [XmlIgnore] - public Entities.Procedure Procedure { get { return procedure; } } - Entities.Procedure procedure; - - public RRProcedureParams(Entities.ComponentProcedure procedureParamsEntity, string componentName, Entities.Procedure procedure) - : this() - { - this.procedureParamsEntity = procedureParamsEntity; - this.componentName = componentName; - this.procedure = procedure; - } - - public TBF.Entities.ComponentProcedure ToDbEntity(IComponent component, Entities.Procedure procedure) - { - using (var writer = new StringWriter()) - { - /// Serialize this class with parameters - (new XmlSerializer(GetType())).Serialize(writer, this); - - /// Create and return the ComponentProcedure entity - TBF.Entities.ComponentProcedure entity = new TBF.Entities.ComponentProcedure(); - entity.CmpntName = component.Cfg.Name; - entity.Parameters = writer.ToString(); - entity.Procedure = procedure; - return entity; - } - } - - public void UpdateDbEntity() - { - using (var writer = new StringWriter()) - { - /// Serialize this class and update the entity - (new XmlSerializer(GetType())).Serialize(writer, this); - procedureParamsEntity.Parameters = writer.ToString(); - procedureParamsEntity.CmpntName = componentName; - procedureParamsEntity.Procedure = procedure; - - } - } - - public static IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParamsEntity) - { - if (procedureParamsEntity == null) return new RRProcedureParams(); - - RRProcedureParams procedureParams; + if (dbEntity == null) return; try { - procedureParams = (RRProcedureParams)(new XmlSerializer(typeof(RRProcedureParams))) - .Deserialize(new StringReader(procedureParamsEntity.Parameters)); + RRProcedureParams tmp = (RRProcedureParams)(new XmlSerializer(typeof(RRProcedureParams))) + .Deserialize(new StringReader(dbEntity.Parameters)); + + procedureParamsEntity = dbEntity; + componentName = dbEntity.CmpntName; + procedure = dbEntity.Procedure; + + PulsesPerLtr = tmp.PulsesPerLtr; } catch { - procedureParams = new RRProcedureParams(); } - procedureParams.procedureParamsEntity = procedureParamsEntity; - procedureParams.componentName = procedureParamsEntity.CmpntName; - procedureParams.procedure = procedureParamsEntity.Procedure; - return procedureParams; } - #endregion + + public RRProcedureParams() + { + } + + public RRProcedureParams(Entities.ComponentProcedure procedureParamsEntity, string componentName, Entities.Procedure procedure) + { + this.procedureParamsEntity = procedureParamsEntity; + this.componentName = componentName; + } } } diff --git a/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReader.cs b/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReader.cs index 38a925ec1..34f7a5f2a 100644 --- a/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReader.cs +++ b/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReader.cs @@ -7,35 +7,22 @@ namespace TBF.BenchControl.Elde.FixedStartRegisterReader { public class RegisterReader : ComponentBase, GenericDevices.IRegisterReader { - /// - /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." - /// Warn: Start measurement when busy is true - /// private static readonly ILog log = LogManager.GetLogger(typeof(RegisterReader)); - public override string ToString() - { - return string.Format("Register({0})", Name); - } + public override string ToString() { return string.Format("FixedStartRegisterReader({0})", Cfg.ToString(1)); } + + readonly RegisterReaderCfg registerReaderCfg; public float BeginWMState; public float EndWMState; - public static void ResetStaticProperties() { } - - public float PulsesPerLtr - { - get - { - return (ProcedureParams is RRProcedureParams) ? (ProcedureParams as RRProcedureParams).PulsesPerLtr : 0; - } - } + public float PulsesPerLtr { get { return registerReaderCfg.ProcParams.PulsesPerLtr; } } public readonly ControlBoardDev ControlBoard; public RegisterReader(RegisterReaderCfg cfg, IList components) : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); + registerReaderCfg = cfg; ControlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (ControlBoard == null) throw new Exception("Cannot find " + Name + " parent"); diff --git a/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderCfg.cs b/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderCfg.cs index 1fd4c6306..6d84fca0b 100644 --- a/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderCfg.cs @@ -7,11 +7,23 @@ namespace TBF.BenchControl.Elde.FixedStartRegisterReader { public class RegisterReaderCfg : ComponentCfgBase, Generic.IChildComponentCfg { - /// Parameterless constructor - public RegisterReaderCfg() + /// Procedure parameters + [XmlIgnore] + public RRProcedureParams ProcParams; + public override IParamsProvider GetProcedureParams() { return ProcParams; } + public override IParamsProvider CreateProcedureParams(Entities.Procedure procedure) + { + RRProcedureParams procParams = new RRProcedureParams(); + procParams.UpdateProcedureParams(Name, procedure); + return procParams; + } + + /// Private parameterless constructor invoked by all other (public) constructors + RegisterReaderCfg() { Name = "DummyRR"; ParentName = "CB"; + ProcParams = new RRProcedureParams(); } public RegisterReaderCfg(IComponentFactory factory) diff --git a/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderCfgCtrl.cs b/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderCfgCtrl.cs index 756a7f102..0379d103d 100644 --- a/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderCfgCtrl.cs +++ b/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderCfgCtrl.cs @@ -64,7 +64,6 @@ namespace TBF.BenchControl.Elde.FixedStartRegisterReader { CfgVerifyFlags flags = CfgVerifyFlags.None; - int dummy; if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text)) { flags |= CfgVerifyFlags.Error; diff --git a/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderFactory.cs b/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderFactory.cs index c9e2bb98c..db2adb0fb 100644 --- a/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/FixedStartRegisterReader/RegisterReaderFactory.cs @@ -30,17 +30,6 @@ namespace TBF.BenchControl.Elde.FixedStartRegisterReader return ComponentCfgBase.CreateFromDbEntity(typeof(RegisterReaderCfg), component, this); } - public bool HasProcedureParams { get { return true; } } - /// - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) - { - return RRProcedureParams.GetProcedureParams(procedureParams); - } - - public bool HasTestParams { get { return false; } } - /// - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public void ResetStaticProperties() { RegisterReader.ResetStaticProperties(); } } } diff --git a/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeter.cs b/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeter.cs index dfa24ca4d..7646c4c2c 100644 --- a/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeter.cs +++ b/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeter.cs @@ -5,33 +5,20 @@ using TBF.Boxes; namespace TBF.BenchControl.Elde.FlowMeter { - public class FlowMeter : Generic.IComponent, GenericDevices.IFlowMeter + public class FlowMeter : ComponentBase, GenericDevices.IFlowMeter { - /// - /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." - /// Warn: Start measurement when busy is true - /// private static readonly ILog log = LogManager.GetLogger(typeof(FlowMeter)); - public override string ToString() - { - return string.Format("FlowMeter: Name={0}, Idx1={1}", Name, Idx1); - } + public override string ToString() { return string.Format("FlowMeter({0})", Cfg.ToString(1)); } - public static void ResetStaticProperties() { } + readonly FlowMeterCfg flowMeterCfg; - FlowMeterCfg flowMeterCfg; - public Generic.IComponentCfg Cfg { get { return flowMeterCfg; } } - - public string Name { get { return flowMeterCfg.Name; } } public int Idx1 { get { return flowMeterCfg.Idx1; } } - public IList Corrections { get { return flowMeterCfg.Corrections; } } - + public readonly ControlBoardDev ControlBoard; - public float NominalFlow { get { return nominalFlow; } } - readonly float nominalFlow; + public float NominalFlow { get { return flowMeterCfg.NominalFlow; } } - public float LtrPerPulse { get { return nominalFlow / 7200.0f; } } + public float LtrPerPulse { get { return flowMeterCfg.NominalFlow / 7200.0f; } } public float LtrPerPulseCorrected(float flow) { @@ -42,15 +29,14 @@ namespace TBF.BenchControl.Elde.FlowMeter public FlowMeter(FlowMeterCfg cfg, IList components) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.flowMeterCfg = cfg; + flowMeterCfg = cfg; ControlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (ControlBoard == null) throw new Exception("Cannot find " + Name + " parent"); - nominalFlow = cfg.NominalFlow; - ControlBoard.EtCalib[Idx1] = NominalFlow; + ControlBoard.EtCalib[Idx1] = flowMeterCfg.NominalFlow; /// Prepare data for SendCalibData() control board component method diff --git a/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeterCfg.cs b/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeterCfg.cs index 72ade2be0..76ae3ab01 100644 --- a/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeterCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeterCfg.cs @@ -9,9 +9,9 @@ namespace TBF.BenchControl.Elde.FlowMeter { public int Idx1; /// 1..5 public float NominalFlow; /// Nominal flow in m3/h at output frequency 2000 Hz - - /// Parameterless constructor - public FlowMeterCfg() + + /// Private parameterless constructor invoked by all other (public) constructors + FlowMeterCfg() { Name = "FlowMeter"; ParentName = "CB"; diff --git a/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeterFactory.cs b/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeterFactory.cs index 10e0134b1..ccd572061 100644 --- a/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeterFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeterFactory.cs @@ -9,10 +9,6 @@ namespace TBF.BenchControl.Elde.FlowMeter public class FlowMeterFactory : IComponentFactory { public string ClassName { get { return "FlowMeter"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 7; } } diff --git a/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeter.cs b/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeter.cs index ccc927a41..f83dfc262 100644 --- a/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeter.cs +++ b/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeter.cs @@ -5,26 +5,12 @@ using TBF.Boxes; namespace TBF.BenchControl.Elde.FlowMeterTwins { - public class FlowMeter : Generic.IComponent, GenericDevices.IFlowMeter + public class FlowMeter : ComponentBase, GenericDevices.IFlowMeter { - /// - /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." - /// Warn: Start measurement when busy is true - /// private static readonly ILog log = LogManager.GetLogger(typeof(FlowMeter)); - public override string ToString() - { - return string.Format("FlowMeter: Name={0}", Name); - } + public override string ToString() { return string.Format("FlowMeterTwins({0})", Cfg.ToString(1)); } - public static void ResetStaticProperties() { } - - FlowMeterCfg flowMeterCfg; - public Generic.IComponentCfg Cfg { get { return flowMeterCfg; } } - - public string Name { get { return flowMeterCfg.Name; } } - - public IList Corrections { get { return flowMeterCfg.Corrections; } } + readonly FlowMeterCfg flowMeterCfg; public int Idx1 { get { return 0; } } @@ -32,11 +18,10 @@ namespace TBF.BenchControl.Elde.FlowMeterTwins public readonly TBF.BenchControl.Elde.FlowMeter.FlowMeter FlowMeter1; public readonly TBF.BenchControl.Elde.FlowMeter.FlowMeter FlowMeter2; - public float NominalFlow { get { return nominalFlow; } } - readonly float nominalFlow; + public float NominalFlow { get { return flowMeterCfg.NominalFlow; } } /// The nominal flowed of a pair of flow meters is reached at 4000Hz - public float LtrPerPulse { get { return nominalFlow / 14400.0f; } } + public float LtrPerPulse { get { return flowMeterCfg.NominalFlow / 14400.0f; } } /// Calculates the average of values of two flowmeters. Assumes the flow is divided evenly. public float LtrPerPulseCorrected(float flow) @@ -47,9 +32,9 @@ namespace TBF.BenchControl.Elde.FlowMeterTwins public FlowMeter(FlowMeterCfg cfg, IList components) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.flowMeterCfg = cfg; + flowMeterCfg = cfg; ControlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (ControlBoard == null) throw new Exception("Cannot find " + Name + " parent"); @@ -60,8 +45,7 @@ namespace TBF.BenchControl.Elde.FlowMeterTwins FlowMeter2 = (TBF.BenchControl.Elde.FlowMeter.FlowMeter)TbfComponents.FindComponent(flowMeterCfg.FlowMeter2, components); if (FlowMeter2 == null) throw new Exception("Cannot find FlowMeter2 component"); - nominalFlow = cfg.NominalFlow; - ControlBoard.EtCalib[Idx1] = NominalFlow; + ControlBoard.EtCalib[Idx1] = flowMeterCfg.NominalFlow; /// Prepare data for SendCalibData() control board component method diff --git a/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeterCfg.cs b/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeterCfg.cs index b27ed4b91..849156acf 100644 --- a/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeterCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeterCfg.cs @@ -10,9 +10,9 @@ namespace TBF.BenchControl.Elde.FlowMeterTwins public float NominalFlow; /// Nominal flow in m3/h at output frequency 2000 Hz public string FlowMeter1; /// Name of the flow meter 1 component public string FlowMeter2; /// Name of the flow meter 2 component - - /// Parameterless constructor - public FlowMeterCfg() + + /// Private parameterless constructor invoked by all other (public) constructors + FlowMeterCfg() { Name = "FlowMeterTwins"; ParentName = "CB"; diff --git a/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeterFactory.cs b/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeterFactory.cs index 3e82bbfa3..a9df88ced 100644 --- a/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeterFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/FlowMeterTwins/FlowMeterFactory.cs @@ -9,10 +9,6 @@ namespace TBF.BenchControl.Elde.FlowMeterTwins public class FlowMeterFactory : IComponentFactory { public string ClassName { get { return "FlowMeterTwins"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeter.cs b/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeter.cs index 15e78e720..c1fed9e72 100644 --- a/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeter.cs +++ b/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeter.cs @@ -6,25 +6,12 @@ using TBF.Boxes; namespace TBF.BenchControl.Elde.PressureMeter { - public class PressureMeter : IComponent, GenericDevices.IPressureMeter + public class PressureMeter : ComponentBase, GenericDevices.IPressureMeter { - /// - /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." - /// Warn: Start measurement when busy is true - /// private static readonly ILog log = LogManager.GetLogger(typeof(PressureMeter)); - public override string ToString() - { - return string.Format("PressureMeter: Name={0}, Idx0={1}", Name, Idx0); - } - - public static void ResetStaticProperties() { } + public override string ToString() { return string.Format("PressureMeter({0})", Cfg.ToString(1)); } readonly PressureMeterCfg pressureMeterCfg; - public Generic.IComponentCfg Cfg { get { return pressureMeterCfg; } } - - public string Name { get { return pressureMeterCfg.Name; } } - public IList Corrections { get { return pressureMeterCfg.Corrections; } } public readonly ControlBoardDev ControlBoard; @@ -32,9 +19,9 @@ namespace TBF.BenchControl.Elde.PressureMeter public readonly byte RS485Address; /// 0..255 public PressureMeter(PressureMeterCfg cfg, IList components) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.pressureMeterCfg = cfg; + pressureMeterCfg = cfg; ControlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (ControlBoard == null) throw new Exception("Cannot find " + Name + " parent"); diff --git a/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeterCfg.cs b/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeterCfg.cs index 0628ebe9a..7bde1f094 100644 --- a/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeterCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeterCfg.cs @@ -9,9 +9,9 @@ namespace TBF.BenchControl.Elde.PressureMeter { public int Idx0; /// 0..3 public byte RS485Address; /// 0..255 - - /// Parameterless constructor - public PressureMeterCfg() + + /// Private parameterless constructor invoked by all other (public) constructors + PressureMeterCfg() { Name = "PressureMeter"; ParentName = "CB"; diff --git a/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeterFactory.cs b/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeterFactory.cs index 84d2509a9..f7e7b7d34 100644 --- a/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeterFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/PressureMeter/PressureMeterFactory.cs @@ -9,10 +9,6 @@ namespace TBF.BenchControl.Elde.PressureMeter public class PressureMeterFactory : IComponentFactory { public string ClassName { get { return "PressureMeter"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 5; } } diff --git a/TestBenchFramework/BenchControl/Elde/Pump/Pump.cs b/TestBenchFramework/BenchControl/Elde/Pump/Pump.cs index 094e99f71..b6f8b8caa 100644 --- a/TestBenchFramework/BenchControl/Elde/Pump/Pump.cs +++ b/TestBenchFramework/BenchControl/Elde/Pump/Pump.cs @@ -4,25 +4,13 @@ using log4net; namespace TBF.BenchControl.Elde.Pump { - public class Pump : Generic.IComponent, GenericDevices.IPump, GenericDevices.IValve + public class Pump : ComponentBase, GenericDevices.IPump, GenericDevices.IValve { - /// - /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." - /// Warn: Start measurement when busy is true - /// private static readonly ILog log = LogManager.GetLogger(typeof(Pump)); - public override string ToString() - { - return string.Format("Pump(name={0}, bit={1})", Name, bitPosition); - } - - public static void ResetStaticProperties() { } - - private readonly PumpCfg pumpCfg; - public Generic.IComponentCfg Cfg { get { return pumpCfg; } } - - public string Name { get { return pumpCfg.Name; } } + public override string ToString() { return string.Format("Pump({0})", Cfg.ToString(1)); } + readonly PumpCfg pumpCfg; + public int Delay { get { return pumpCfg.Delay; } } public ValveCategory Category { get { return ValveCategory.Feeding; } } /// Pump category is Feeding @@ -39,15 +27,15 @@ namespace TBF.BenchControl.Elde.Pump public Pump(PumpCfg cfg, IList components) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.pumpCfg = cfg; + pumpCfg = cfg; controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent"); - this.bitPosition = cfg.BitPosition; - this.Mask = (((ulong)1) << bitPosition); + bitPosition = pumpCfg.BitPosition; + Mask = (((ulong)1) << pumpCfg.BitPosition); log.Debug(this.ToString()); } diff --git a/TestBenchFramework/BenchControl/Elde/Pump/PumpCfg.cs b/TestBenchFramework/BenchControl/Elde/Pump/PumpCfg.cs index cd045e809..d6fe4272c 100644 --- a/TestBenchFramework/BenchControl/Elde/Pump/PumpCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/Pump/PumpCfg.cs @@ -9,8 +9,8 @@ namespace TBF.BenchControl.Elde.Pump public int BitPosition; public int Delay; - /// Parameterless constructor - public PumpCfg() + /// Private parameterless constructor invoked by all other (public) constructors + PumpCfg() { Name = "Pump"; ParentName = "CB"; diff --git a/TestBenchFramework/BenchControl/Elde/Pump/PumpFactory.cs b/TestBenchFramework/BenchControl/Elde/Pump/PumpFactory.cs index bb2b304b6..6039e569e 100644 --- a/TestBenchFramework/BenchControl/Elde/Pump/PumpFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/Pump/PumpFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.Elde.Pump public class PumpFactory : IComponentFactory { public string ClassName { get { return "Pump"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return int.MaxValue; } } diff --git a/TestBenchFramework/BenchControl/Elde/PumpWithFM/FMPumpTestParams.cs b/TestBenchFramework/BenchControl/Elde/PumpWithFM/FMPumpTestParams.cs index 04d3356a1..34a7b9046 100644 --- a/TestBenchFramework/BenchControl/Elde/PumpWithFM/FMPumpTestParams.cs +++ b/TestBenchFramework/BenchControl/Elde/PumpWithFM/FMPumpTestParams.cs @@ -7,17 +7,24 @@ using TBF.Resources; namespace TBF.BenchControl.Elde.PumpWithFM { - public class FMPumpTestParams : IParamsProvider, ITestParams + public class FMPumpTestParams : TestParamsBase, IParamsProvider, ITestParams { public float Power; /// Target=terminal flow durning detection when increasing or decreasing the flow + public override void InitializeAll() + { + Power = 50.0f; + } + string[] paramNames = new string[] { Strings.PowerPct, }; - public string ParamName(int i) { return paramNames[i]; } + public override string ParamName(int i) { return paramNames[i]; } + public override int ParamsCount() { return paramNames.Length; } - public string ToString(int i) + + public override string ToString(int i) { switch (i) { @@ -54,98 +61,35 @@ namespace TBF.BenchControl.Elde.PumpWithFM return false; } - #region Boilerplate code - - public int ParamsCount() { return paramNames.Length; } - - public override string ToString() + public override void UpdateTestParams(Entities.ComponentTest dbEntity) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < ParamsCount(); i++) + if (dbEntity == null) return; + try + { + FMPumpTestParams tmp = (FMPumpTestParams)(new XmlSerializer(typeof(FMPumpTestParams))) + .Deserialize(new StringReader(dbEntity.Parameters)); + + testParamsEntity = dbEntity; + componentName = dbEntity.CmpntName; + test = dbEntity.Test; + + Power = tmp.Power; + } + catch { - if (i != 0) sb.Append("; "); - sb.Append(ParamName(i)); - sb.Append("="); - sb.Append(ToString(i)); } - return sb.ToString(); } - [XmlIgnore] - public Entities.ComponentTest TestParamsEntity { get { return testParamsEntity; } } - Entities.ComponentTest testParamsEntity; - - [XmlIgnore] - public string ComponentName { get { return componentName; } } - string componentName; - - [XmlIgnore] - public Entities.Test Test { get { return test; } } - Entities.Test test; - /// Parameterless constructor public FMPumpTestParams() { - Power = 50.0f; } public FMPumpTestParams(Entities.ComponentTest testParamsEntity, string componentName, Entities.Test test) - : this() { this.testParamsEntity = testParamsEntity; this.componentName = componentName; this.test = test; } - - public TBF.Entities.ComponentTest ToDbEntity(IComponent component, Entities.Test test) - { - using (var writer = new StringWriter()) - { - /// Serialize this class with parameters - (new XmlSerializer(GetType())).Serialize(writer, this); - - /// Create and return the ComponentTest entity - TBF.Entities.ComponentTest entity = new TBF.Entities.ComponentTest(); - entity.CmpntName = component.Cfg.Name; - entity.Parameters = writer.ToString(); - entity.Test = test; - return entity; - } - } - - public void UpdateDbEntity() - { - using (var writer = new StringWriter()) - { - /// Serialize this class and update the entity - (new XmlSerializer(GetType())).Serialize(writer, this); - testParamsEntity.Parameters = writer.ToString(); - testParamsEntity.CmpntName = componentName; - testParamsEntity.Test = test; - - } - } - - public static IParamsProvider GetTestParams(Entities.ComponentTest testParamsEntity) - { - if (testParamsEntity == null) return new FMPumpTestParams(); - - FMPumpTestParams testParams; - try - { - testParams = (FMPumpTestParams)(new XmlSerializer(typeof(FMPumpTestParams))) - .Deserialize(new StringReader(testParamsEntity.Parameters)); - } - catch - { - testParams = new FMPumpTestParams(); - } - testParams.testParamsEntity = testParamsEntity; - testParams.componentName = testParamsEntity.CmpntName; - testParams.test = testParamsEntity.Test; - return testParams; - } - - #endregion } } diff --git a/TestBenchFramework/BenchControl/Elde/PumpWithFM/Pump.cs b/TestBenchFramework/BenchControl/Elde/PumpWithFM/Pump.cs index ff9a6b4f0..e76e30fd0 100644 --- a/TestBenchFramework/BenchControl/Elde/PumpWithFM/Pump.cs +++ b/TestBenchFramework/BenchControl/Elde/PumpWithFM/Pump.cs @@ -6,24 +6,14 @@ namespace TBF.BenchControl.Elde.PumpWithFM { public class Pump : ComponentBase, GenericDevices.IPumpFM, GenericDevices.IValve, IOperation { - /// - /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." - /// Warn: Start measurement when busy is true - /// - private static readonly ILog log = LogManager.GetLogger(typeof(Pump)); - public override string ToString() - { - return string.Format("Pump(name={0}, bit={1}, idx={2})", Name, bitPosition, FMIndex); - } + private static readonly ILog log = LogManager.GetLogger(typeof(Pump)); + public override string ToString() { return string.Format("PumpWithFM({0})", Cfg.ToString(1)); } - public static void ResetStaticProperties() { } - - public int Delay { get { return (Cfg as PumpCfg).Delay; } } + readonly PumpCfg pumpCfg; + public int Delay { get { return pumpCfg.Delay; } } public ValveCategory Category { get { return ValveCategory.Feeding; } } /// Pump category is Feeding - - public float Power { get { return (TestParams is FMPumpTestParams) ? (TestParams as FMPumpTestParams).Power : 0; } } - + public float Power { get { return pumpCfg.TestParams.Power; } } public GenericDevices.IValve CoupledTo { get { return null; } } public bool InvertCouple { get { return false; } } public int LagOpening { get { return 0; } } @@ -45,14 +35,14 @@ namespace TBF.BenchControl.Elde.PumpWithFM public Pump(PumpCfg cfg, IList components) : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); + pumpCfg = cfg; controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent"); - this.bitPosition = cfg.BitPosition; - this.Mask = (((ulong)1) << bitPosition); - this.FMIndex = cfg.FMIndex; + bitPosition = pumpCfg.BitPosition; + Mask = (((ulong)1) << pumpCfg.BitPosition); + FMIndex = pumpCfg.FMIndex; log.Debug(this.ToString()); } diff --git a/TestBenchFramework/BenchControl/Elde/PumpWithFM/PumpCfg.cs b/TestBenchFramework/BenchControl/Elde/PumpWithFM/PumpCfg.cs index 48a8fbbca..325fe22a8 100644 --- a/TestBenchFramework/BenchControl/Elde/PumpWithFM/PumpCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/PumpWithFM/PumpCfg.cs @@ -10,14 +10,26 @@ namespace TBF.BenchControl.Elde.PumpWithFM public int FMIndex; public int Delay; - /// Parameterless constructor - public PumpCfg() + /// Test parameters + [XmlIgnore] + public FMPumpTestParams TestParams; + public override IParamsProvider GetTestParams() { return TestParams; } + public override IParamsProvider CreateTestParams(Entities.Test test) + { + FMPumpTestParams testParams = new FMPumpTestParams(); + testParams.UpdateTestParams(Name, test); + return testParams; + } + + /// Private parameterless constructor invoked by all other (public) constructors + PumpCfg() { Name = "Pump"; ParentName = "CB"; BitPosition = 0; FMIndex = 0; Delay = 1; + TestParams = new FMPumpTestParams(); } public PumpCfg(IComponentFactory factory) diff --git a/TestBenchFramework/BenchControl/Elde/PumpWithFM/PumpFactory.cs b/TestBenchFramework/BenchControl/Elde/PumpWithFM/PumpFactory.cs index 2785f1e59..dfede77c5 100644 --- a/TestBenchFramework/BenchControl/Elde/PumpWithFM/PumpFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/PumpWithFM/PumpFactory.cs @@ -6,13 +6,6 @@ namespace TBF.BenchControl.Elde.PumpWithFM public class PumpFactory : IComponentFactory { public string ClassName { get { return "PumpWithFM"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return true; } } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) - { - return FMPumpTestParams.GetTestParams(testParams); - } /// Max. number of components of this class in the system public int MaxCount { get { return int.MaxValue; } } diff --git a/TestBenchFramework/BenchControl/Elde/RegisterReader/RRProcedureParams.cs b/TestBenchFramework/BenchControl/Elde/RegisterReader/RRProcedureParams.cs index 30a90f4c0..0a025dad1 100644 --- a/TestBenchFramework/BenchControl/Elde/RegisterReader/RRProcedureParams.cs +++ b/TestBenchFramework/BenchControl/Elde/RegisterReader/RRProcedureParams.cs @@ -7,17 +7,23 @@ using TBF.Resources; namespace TBF.BenchControl.Elde.RegisterReader { - public class RRProcedureParams : IParamsProvider, IProcedureParams + public class RRProcedureParams : ProcedureParamsBase, IParamsProvider, IProcedureParams { public float PulsesPerLtr; /// Target low limit of the flow increase or decrease + public override void InitializeAll() + { + PulsesPerLtr = 1.0f; + } + string[] paramNames = new string[] { Strings.PulsesPerLtr, }; - public string ParamName(int i) { return paramNames[i]; } + public override string ParamName(int i) { return paramNames[i]; } + public override int ParamsCount() { return paramNames.Length; } - public string ToString(int i) + public override string ToString(int i) { switch (i) { @@ -25,14 +31,6 @@ namespace TBF.BenchControl.Elde.RegisterReader default: return string.Empty; } } - - /// - /// Parameterless constructor - sets default values of parameters. - /// - public RRProcedureParams() - { - PulsesPerLtr = 1.0f; - } /// Retrieves parameters from UI controls public void UpdateParam(int i, string strValue) @@ -64,92 +62,35 @@ namespace TBF.BenchControl.Elde.RegisterReader return false; } - #region Boilerplate code - - public int ParamsCount() { return paramNames.Length; } - - public override string ToString() + public override void UpdateProcedureParams(Entities.ComponentProcedure dbEntity) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < ParamsCount(); i++) + if (dbEntity == null) return; + try { - if (i != 0) sb.Append("; "); - sb.Append(ParamName(i)); - sb.Append("="); - sb.Append(ToString(i)); + RRProcedureParams tmp = (RRProcedureParams)(new XmlSerializer(typeof(RRProcedureParams))) + .Deserialize(new StringReader(dbEntity.Parameters)); + + procedureParamsEntity = dbEntity; + componentName = dbEntity.CmpntName; + procedure = dbEntity.Procedure; + + PulsesPerLtr = tmp.PulsesPerLtr; } - return sb.ToString(); + catch + { + } + } + + + public RRProcedureParams() + { } - [XmlIgnore] - public Entities.ComponentProcedure ProcedureParamsEntity { get { return procedureParamsEntity; } } - Entities.ComponentProcedure procedureParamsEntity; - - [XmlIgnore] - public string ComponentName { get { return componentName; } } - string componentName; - - [XmlIgnore] - public Entities.Procedure Procedure { get { return procedure; } } - Entities.Procedure procedure; - public RRProcedureParams(Entities.ComponentProcedure procedureParamsEntity, string componentName, Entities.Procedure procedure) - : this() { this.procedureParamsEntity = procedureParamsEntity; this.componentName = componentName; this.procedure = procedure; } - - public TBF.Entities.ComponentProcedure ToDbEntity(IComponent component, Entities.Procedure procedure) - { - using (var writer = new StringWriter()) - { - /// Serialize this class with parameters - (new XmlSerializer(GetType())).Serialize(writer, this); - - /// Create and return the ComponentProcedure entity - TBF.Entities.ComponentProcedure entity = new TBF.Entities.ComponentProcedure(); - entity.CmpntName = component.Cfg.Name; - entity.Parameters = writer.ToString(); - entity.Procedure = procedure; - return entity; - } - } - - public void UpdateDbEntity() - { - using (var writer = new StringWriter()) - { - /// Serialize this class and update the entity - (new XmlSerializer(GetType())).Serialize(writer, this); - procedureParamsEntity.Parameters = writer.ToString(); - procedureParamsEntity.CmpntName = componentName; - procedureParamsEntity.Procedure = procedure; - - } - } - - public static IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParamsEntity) - { - if (procedureParamsEntity == null) return new RRProcedureParams(); - - RRProcedureParams procedureParams; - try - { - procedureParams = (RRProcedureParams)(new XmlSerializer(typeof(RRProcedureParams))) - .Deserialize(new StringReader(procedureParamsEntity.Parameters)); - } - catch - { - procedureParams = new RRProcedureParams(); - } - procedureParams.procedureParamsEntity = procedureParamsEntity; - procedureParams.componentName = procedureParamsEntity.CmpntName; - procedureParams.procedure = procedureParamsEntity.Procedure; - return procedureParams; - } - - #endregion } } diff --git a/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReader.cs b/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReader.cs index 5fc9da5dc..cab5b3472 100644 --- a/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReader.cs +++ b/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReader.cs @@ -7,40 +7,25 @@ namespace TBF.BenchControl.Elde.RegisterReader { public class RegisterReader : ComponentBase, GenericDevices.IRegisterReader { - /// - /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." - /// Warn: Start measurement when busy is true - /// private static readonly ILog log = LogManager.GetLogger(typeof(RegisterReader)); - public override string ToString() - { - return string.Format("Register({0},{1})", Name, Position); - } + public override string ToString() { return string.Format("RegisterReader({0})", Cfg.ToString(1)); } - public static void ResetStaticProperties() { } + readonly RegisterReaderCfg registerReaderCfg; - public float PulsesPerLtr - { - get - { - return (ProcedureParams is RRProcedureParams) ? (ProcedureParams as RRProcedureParams).PulsesPerLtr : 0; - } - } + public int Position { get { return registerReaderCfg.Position; } } /// 1 .. inf + public float PulsesPerLtr { get { return registerReaderCfg.ProcParams.PulsesPerLtr; } } public readonly ControlBoardDev ControlBoard; - public readonly int Position; /// 1 .. inf public RegisterReader(RegisterReaderCfg cfg, IList components) : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); + registerReaderCfg = cfg; ControlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (ControlBoard == null) throw new Exception("Cannot find " + Name + " parent"); - Position = cfg.Position; - /// Prepare data for SendCalibData() control board component method log.Debug(this.ToString()); diff --git a/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReaderCfg.cs b/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReaderCfg.cs index b25470886..c656d66fb 100644 --- a/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReaderCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReaderCfg.cs @@ -8,13 +8,25 @@ namespace TBF.BenchControl.Elde.RegisterReader public class RegisterReaderCfg : ComponentCfgBase, Generic.IChildComponentCfg { public int Position; /// 1..nrWaterMeters - - /// Parameterless constructor - public RegisterReaderCfg() + + /// Procedure parameters + [XmlIgnore] + public RRProcedureParams ProcParams; + public override IParamsProvider GetProcedureParams() { return ProcParams; } + public override IParamsProvider CreateProcedureParams(Entities.Procedure procedure) + { + RRProcedureParams procParams = new RRProcedureParams(); + procParams.UpdateProcedureParams(Name, procedure); + return procParams; + } + + /// Private parameterless constructor invoked by all other (public) constructors + RegisterReaderCfg() { Name = "Sick"; ParentName = "CB"; Position = 1; + ProcParams = new RRProcedureParams(); } public RegisterReaderCfg(IComponentFactory factory) diff --git a/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReaderFactory.cs b/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReaderFactory.cs index 416f5a865..8f2458cd5 100644 --- a/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReaderFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReaderFactory.cs @@ -30,17 +30,6 @@ namespace TBF.BenchControl.Elde.RegisterReader return ComponentCfgBase.CreateFromDbEntity(typeof(RegisterReaderCfg), component, this); } - public bool HasProcedureParams { get { return true; } } - /// - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) - { - return RRProcedureParams.GetProcedureParams(procedureParams); - } - - public bool HasTestParams { get { return false; } } - /// - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public void ResetStaticProperties() { RegisterReader.ResetStaticProperties(); } } } diff --git a/TestBenchFramework/BenchControl/Elde/RegulValve/ChangeValvePositionOp.cs b/TestBenchFramework/BenchControl/Elde/RegulValve/ChangeValvePositionOp.cs index 80426ba41..b92df2ddd 100644 --- a/TestBenchFramework/BenchControl/Elde/RegulValve/ChangeValvePositionOp.cs +++ b/TestBenchFramework/BenchControl/Elde/RegulValve/ChangeValvePositionOp.cs @@ -19,9 +19,6 @@ namespace TBF.BenchControl.Elde.RegulValve readonly int regulValveNr; readonly float timePulseSec; - /// Process values - bool firstRun; - /// /// Set required water flow. /// Events: FlowSet, FlowTimeOut @@ -49,7 +46,6 @@ namespace TBF.BenchControl.Elde.RegulValve /// Start this operation public void Start() { - firstRun = true; float positionPct = controlBoard.RValvePosition(regulValveNr); log.WarnFormat("RV#={0}, actPos={1}%", regulValveNr, positionPct.ToString("F1")); diff --git a/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValve.cs b/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValve.cs index 4a2d33625..5ab7164df 100644 --- a/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValve.cs +++ b/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValve.cs @@ -6,35 +6,23 @@ using TBF.Boxes; namespace TBF.BenchControl.Elde.RegulValve { - public class RegulValve : IComponent, GenericDevices.IRegulValve + public class RegulValve : ComponentBase, GenericDevices.IRegulValve { - /// - /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." - /// Warn: Start measurement when busy is true - /// private static readonly ILog log = LogManager.GetLogger(typeof(RegulValve)); - public override string ToString() - { - return string.Format("RegulationValve({0},{1})", Name, Idx1); - } + public override string ToString() { return string.Format("RegulValve({0})", Cfg.ToString(1)); } - public static void ResetStaticProperties() { } - - public RegulValveCfg RegulValveCfg; - public Generic.IComponentCfg Cfg { get { return RegulValveCfg; } } - - public string Name { get { return Cfg.Name; } } + public readonly RegulValveCfg RegulValveCfg; IDictionary dict; public IDictionary Dict { get { return dict; } } readonly ControlBoardDev controlBoard; - public readonly int Idx1; /// 1..7 - public readonly int DacValueClosed; /// 0..1023 - public readonly int DacValueOpen; /// 0..1023 - public readonly int StableTime; /// 0=200ms, step=50ms, max. 1500ms (max.26) - public readonly int FlowStableSec; /// 0..60 sec + public int Idx1 { get { return RegulValveCfg.Idx1; } } /// 1..7 + public int DacValueClosed { get { return RegulValveCfg.DacValueClosed; } } /// 0..1023 + public int DacValueOpen { get { return RegulValveCfg.DacValueOpen; } } /// 0..1023 + public int StableTime { get { return RegulValveCfg.StableTime; } } /// 0=200ms, step=50ms, max. 1500ms (max.26) + public int FlowStableSec { get { return RegulValveCfg.FlowStableSec; } } /// 0..60 sec /// public float Position { @@ -42,19 +30,13 @@ namespace TBF.BenchControl.Elde.RegulValve } public RegulValve(RegulValveCfg cfg, IList components) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.RegulValveCfg = cfg; + RegulValveCfg = cfg; controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent"); - this.Idx1 = cfg.Idx1; - this.DacValueClosed = cfg.DacValueClosed; - this.DacValueOpen = cfg.DacValueOpen; - this.StableTime = cfg.StableTime; - this.FlowStableSec = cfg.FlowStableSec; - this.dict = new Dictionary(); this.controlBoard.RegValveCalib[Idx1 - 1, 0] = (uint)DacValueClosed; diff --git a/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValveCfg.cs b/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValveCfg.cs index 298dcd21d..e43eee635 100644 --- a/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValveCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValveCfg.cs @@ -20,8 +20,8 @@ namespace TBF.BenchControl.Elde.RegulValve /// public int StableTime { get { return (StableTimeMs - 200) / 50; } } - /// Parameterless constructor - public RegulValveCfg() + /// Private parameterless constructor invoked by all other (public) constructors + RegulValveCfg() { Name = "RegulationValve"; ParentName = "CB"; diff --git a/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValveFactory.cs b/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValveFactory.cs index 668b202c1..37bdc26e5 100644 --- a/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValveFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValveFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.Elde.RegulValve public class RegulValveFactory : IComponentFactory { public string ClassName { get { return "RegulationValve"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 5; } } diff --git a/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeter.cs b/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeter.cs index f24956521..d4b1664d5 100644 --- a/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeter.cs +++ b/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeter.cs @@ -6,49 +6,30 @@ using TBF.Boxes; namespace TBF.BenchControl.Elde.TempMeter { - public class TempMeter : IComponent, GenericDevices.ITempMeter + public class TempMeter : ComponentBase, GenericDevices.ITempMeter { - /// - /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." - /// Warn: Start measurement when busy is true - /// private static readonly ILog log = LogManager.GetLogger(typeof(TempMeter)); - public override string ToString() - { - return string.Format("TempMeter({0},{1})", Name, Idx0); - } + public override string ToString() { return string.Format("TempMeter({0})", Cfg.ToString(1)); } - public static void ResetStaticProperties() { } - - TempMeterCfg tempMeterCfg; - public Generic.IComponentCfg Cfg { get { return tempMeterCfg; } } - - public string Name { get { return tempMeterCfg.Name; } } + readonly TempMeterCfg tempMtrCfg; public readonly ControlBoardDev ControlBoard; - public readonly int Idx0; /// 0..7 - public readonly float A1; - public readonly float A2; - public readonly float A3; - public readonly float A4; - public readonly float A5; + public int Idx0 { get { return tempMtrCfg.Idx0; } } /// 0..7 + public float A1 { get { return tempMtrCfg.A1; } } + public float A2 { get { return tempMtrCfg.A2; } } + public float A3 { get { return tempMtrCfg.A3; } } + public float A4 { get { return tempMtrCfg.A4; } } + public float A5 { get { return tempMtrCfg.A5; } } public TempMeter(TempMeterCfg cfg, IList components) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.tempMeterCfg = cfg; + tempMtrCfg = cfg; ControlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (ControlBoard == null) throw new Exception("Cannot find " + Name + " parent"); - Idx0 = cfg.Idx0; - A1 = cfg.A1; - A2 = cfg.A2; - A3 = cfg.A3; - A4 = cfg.A4; - A5 = cfg.A5; - /// Prepare data for SendCalibData() control board component method ControlBoard.TempCalibData[Idx0, 0] = A1; ControlBoard.TempCalibData[Idx0, 1] = A2; diff --git a/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeterCfg.cs b/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeterCfg.cs index 063a164fa..6266088a9 100644 --- a/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeterCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeterCfg.cs @@ -15,8 +15,8 @@ namespace TBF.BenchControl.Elde.TempMeter public float A4; public float A5; - /// Parameterless constructor - public TempMeterCfg() + /// Private parameterless constructor invoked by all other (public) constructors + TempMeterCfg() { Name = "TempMeter"; ParentName = "CB"; diff --git a/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeterFactory.cs b/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeterFactory.cs index c2130e476..95dfc1102 100644 --- a/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeterFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/TempMeter/TempMeterFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.Elde.TempMeter public class TempMeterFactory : IComponentFactory { public string ClassName { get { return "TempMeter"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 8; } } diff --git a/TestBenchFramework/BenchControl/Elde/Valve/Valve.cs b/TestBenchFramework/BenchControl/Elde/Valve/Valve.cs index 823dc334a..83c9a24a7 100644 --- a/TestBenchFramework/BenchControl/Elde/Valve/Valve.cs +++ b/TestBenchFramework/BenchControl/Elde/Valve/Valve.cs @@ -5,32 +5,22 @@ using TBF.BenchControl.GenericDevices; namespace TBF.BenchControl.Elde.Valve { - public class Valve : GenericDevices.ValveBase, Generic.IComponent, IValve + public class Valve : GenericDevices.ValveBase, IValve { - /// - /// Info: StartMassMeasurement() and "Balance response = .., Mass = ..." - /// Warn: Start measurement when busy is true - /// private static readonly ILog log = LogManager.GetLogger(typeof(Valve)); - public override string ToString() - { - return string.Format("Valve({0},{1},{2})", Name, bitPosition, (CoupledTo != null ? CoupledTo.Cfg.Name : "-")); - } - - public static void ResetStaticProperties() { } + public override string ToString() { return string.Format("Valve({0})", Cfg.ToString(1)); } readonly ValveCfg valveCfg; - public Generic.IComponentCfg Cfg { get { return valveCfg; } } - readonly IValve coupledTo; readonly ControlBoardDev controlBoard; - readonly int bitPosition; /// 0 .. 63 - public string Name { get { return valveCfg.Name; } } public ValveCategory Category { get { return valveCfg.Category; } } public int Delay { get { return valveCfg.OpenCloseTime; } } public bool Inverted { get { return valveCfg.Inverted; } } + public IValve CoupledTo { get { return coupledTo; } } + readonly IValve coupledTo; + public bool InvertCouple { get { return valveCfg.InvertCouple; } } public int LagOpening { get { return valveCfg.LagOpening; } } public int LagClosing { get { return valveCfg.LagClosing; } } @@ -39,20 +29,22 @@ namespace TBF.BenchControl.Elde.Valve public Valve(ValveCfg cfg, IList components) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.valveCfg = cfg; + valveCfg = cfg; controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent"); - if (bitPosition < 0 || bitPosition >= 64) throw new ArgumentOutOfRangeException("position"); - this.bitPosition = cfg.BitPosition; - this.Mask = (((ulong)1) << bitPosition); + if (valveCfg.BitPosition < 0 || valveCfg.BitPosition >= 64) + { + throw new ArgumentOutOfRangeException("position"); + } + this.Mask = (((ulong)1) << valveCfg.BitPosition); if (cfg.CoupledToName != null) { - this.coupledTo = (IValve)TbfComponents.FindComponent(cfg.CoupledToName, components); + coupledTo = (IValve)TbfComponents.FindComponent(cfg.CoupledToName, components); } log.Debug(this.ToString()); diff --git a/TestBenchFramework/BenchControl/Elde/Valve/ValveCfg.cs b/TestBenchFramework/BenchControl/Elde/Valve/ValveCfg.cs index b487025de..9a9b2933a 100644 --- a/TestBenchFramework/BenchControl/Elde/Valve/ValveCfg.cs +++ b/TestBenchFramework/BenchControl/Elde/Valve/ValveCfg.cs @@ -17,8 +17,8 @@ namespace TBF.BenchControl.Elde.Valve public int LagClosing; /// Delay (referred to the master valve) when closing this valve in [s] /// Negative values of delays mean an earlier function of the coupled valve. - /// Parameterless constructor - public ValveCfg() + /// Private parameterless constructor invoked by all other (public) constructors + ValveCfg() { Name = "V"; ParentName = "CB"; diff --git a/TestBenchFramework/BenchControl/Elde/Valve/ValveFactory.cs b/TestBenchFramework/BenchControl/Elde/Valve/ValveFactory.cs index 38599f182..c14932e45 100644 --- a/TestBenchFramework/BenchControl/Elde/Valve/ValveFactory.cs +++ b/TestBenchFramework/BenchControl/Elde/Valve/ValveFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.Elde.Valve public class ValveFactory : IComponentFactory { public string ClassName { get { return "Valve"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return int.MaxValue; } } diff --git a/TestBenchFramework/BenchControl/Generic/IComponent.cs b/TestBenchFramework/BenchControl/Generic/IComponent.cs index d80c1a45e..a7acc62bd 100644 --- a/TestBenchFramework/BenchControl/Generic/IComponent.cs +++ b/TestBenchFramework/BenchControl/Generic/IComponent.cs @@ -3,6 +3,16 @@ namespace TBF.BenchControl.Generic { public interface IComponent { + string Name { get; } + + string ClassName { get; } + + string ParentName { get; } + + Entities.DebugMode DebugLevel { get; } + + Entities.LogLevel LogLevel { get; } + IComponentCfg Cfg { get; } } } diff --git a/TestBenchFramework/BenchControl/Generic/IComponentCfg.cs b/TestBenchFramework/BenchControl/Generic/IComponentCfg.cs index d3a16a3f3..7077c4e0e 100644 --- a/TestBenchFramework/BenchControl/Generic/IComponentCfg.cs +++ b/TestBenchFramework/BenchControl/Generic/IComponentCfg.cs @@ -39,8 +39,25 @@ namespace TBF.BenchControl.Generic /// IList Corrections { get; set; } + /// + /// Creates a new database entity 'Component' from the parameters + /// TBF.Entities.Component CreateDbEntity(); + /// + /// Procedure parameters provider support + /// + IParamsProvider GetProcedureParams(); + void UpdateProcedureParams(Entities.Procedure procedure); + IParamsProvider CreateProcedureParams(Entities.Procedure procedure); + + /// + /// Test parameters provider support + /// + IParamsProvider GetTestParams(); + void UpdateTestParams(Entities.Test test); + IParamsProvider CreateTestParams(Entities.Test test); + string ToString(int i); } } diff --git a/TestBenchFramework/BenchControl/Generic/IComponentFactory.cs b/TestBenchFramework/BenchControl/Generic/IComponentFactory.cs index 7e5b0091b..2a85d12a8 100644 --- a/TestBenchFramework/BenchControl/Generic/IComponentFactory.cs +++ b/TestBenchFramework/BenchControl/Generic/IComponentFactory.cs @@ -5,8 +5,6 @@ namespace TBF.BenchControl.Generic public interface IComponentFactory { string ClassName { get; } /// Name of the class of components (for instance "Valve") - bool HasProcedureParams { get; } /// true = create an entity with component specific procedure parameters - bool HasTestParams { get; } /// true = create an entity with component specific test parameters /// /// Max. number of components of this class in the system: 1, some integer value or int.MaxValue @@ -33,9 +31,6 @@ namespace TBF.BenchControl.Generic /// IComponentCfg CmpntCfgFromCmpntEntity(Entities.Component component); - IParamsProvider GetTestParams(Entities.ComponentTest testParams); - IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams); - void ResetStaticProperties(); } diff --git a/TestBenchFramework/BenchControl/Generic/IParamsProvider.cs b/TestBenchFramework/BenchControl/Generic/IParamsProvider.cs index 9e021d852..7d16aafed 100644 --- a/TestBenchFramework/BenchControl/Generic/IParamsProvider.cs +++ b/TestBenchFramework/BenchControl/Generic/IParamsProvider.cs @@ -20,7 +20,12 @@ namespace TBF.BenchControl.Generic /// Parameter values in string form /// /// Zero based index of the parameter - string ToString(int i); + string ToString(int ix); + + /// + /// Initialize values of all parameters + /// + void InitializeAll(); /// /// Validates the string representation of a parameter diff --git a/TestBenchFramework/BenchControl/Generic/IProcedureParams.cs b/TestBenchFramework/BenchControl/Generic/IProcedureParams.cs index 53e1e6274..5acb19e6f 100644 --- a/TestBenchFramework/BenchControl/Generic/IProcedureParams.cs +++ b/TestBenchFramework/BenchControl/Generic/IProcedureParams.cs @@ -3,7 +3,7 @@ namespace TBF.BenchControl.Generic { public interface IProcedureParams { - Entities.ComponentProcedure ProcedureParamsEntity { get; } - TBF.Entities.ComponentProcedure ToDbEntity(IComponent component, Entities.Procedure procedure); + void UpdateProcedureParams(string componentName, Entities.Procedure procedure); + TBF.Entities.ComponentProcedure ToDbEntity(string componentName, Entities.Procedure procedure); } } diff --git a/TestBenchFramework/BenchControl/Generic/ITestParams.cs b/TestBenchFramework/BenchControl/Generic/ITestParams.cs index b9a34dcc1..60386e026 100644 --- a/TestBenchFramework/BenchControl/Generic/ITestParams.cs +++ b/TestBenchFramework/BenchControl/Generic/ITestParams.cs @@ -3,7 +3,7 @@ namespace TBF.BenchControl.Generic { public interface ITestParams { - Entities.ComponentTest TestParamsEntity { get; } - TBF.Entities.ComponentTest ToDbEntity(IComponent component, Entities.Test test); + void UpdateTestParams(string componentName, Entities.Test test); + TBF.Entities.ComponentTest ToDbEntity(string componentName, Entities.Test test); } } diff --git a/TestBenchFramework/BenchControl/GenericDevices/ValveBase.cs b/TestBenchFramework/BenchControl/GenericDevices/ValveBase.cs index 94ca500dc..08ff35884 100644 --- a/TestBenchFramework/BenchControl/GenericDevices/ValveBase.cs +++ b/TestBenchFramework/BenchControl/GenericDevices/ValveBase.cs @@ -5,8 +5,15 @@ using System.Text; namespace TBF.BenchControl.GenericDevices { - public class ValveBase + public class ValveBase : ComponentBase { + /// + /// Invokes ComponentBase constructor + /// + public ValveBase(Generic.IComponentCfg cfg) : base(cfg) + { + } + /// /// Process the list of components and return all valves (masters and coupled) /// diff --git a/TestBenchFramework/BenchControl/Greco/Ambient.cs b/TestBenchFramework/BenchControl/Greco/Ambient.cs index edc211d34..6aff02310 100644 --- a/TestBenchFramework/BenchControl/Greco/Ambient.cs +++ b/TestBenchFramework/BenchControl/Greco/Ambient.cs @@ -13,20 +13,12 @@ namespace TBF.BenchControl.Greco /// Ambient temperature / humidity / pressure meter 'Greco' connected via serial interface (RS232) /// Connection settings: 19200 Bd 8-bits No-parity 1-stop-bit Flow control: none or hardware. /// - public class Ambient : TestBenchSim, IComponent, IDevice, IOperation, GenericDevices.IAmbient + public class Ambient : ComponentBase, IDevice, IOperation, GenericDevices.IAmbient { - /// - /// Info: Successful measurement - /// Warn: Invalid serial response format - /// private static readonly ILog log = LogManager.GetLogger(typeof(Ambient)); - - public static void ResetStaticProperties() { } + public override string ToString() { return string.Format("Ambient({0})", Cfg.ToString(1)); } private readonly AmbientCfg ambientCfg; - public Generic.IComponentCfg Cfg { get { return ambientCfg; } } - - public string Name { get { return ambientCfg.Name; } } /// Private fields SerialPort serialPort; @@ -52,12 +44,13 @@ namespace TBF.BenchControl.Greco /// Connection settings: 19200 Bd 8-bits No-parity 1-stop-bit Flow control: none or hardware. /// public Ambient(AmbientCfg cfg, IList components) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.ambientCfg = cfg; + ambientCfg = cfg; + log.Debug(this.ToString()); } - public new void Initialize() + public void Initialize() { if (ambientCfg.DebugLevel == Entities.DebugMode.Simulate) { @@ -65,7 +58,7 @@ namespace TBF.BenchControl.Greco humidity = 40.0f; pressure = 1.0f; msrmntTimeStamp = StateMachine.Time; - msrmntState = BenchControl.MsrmntState.Valid; + msrmntState = MsrmntState.Valid; return; } diff --git a/TestBenchFramework/BenchControl/Greco/AmbientCfg.cs b/TestBenchFramework/BenchControl/Greco/AmbientCfg.cs index b476b53bb..7f6ba3fea 100644 --- a/TestBenchFramework/BenchControl/Greco/AmbientCfg.cs +++ b/TestBenchFramework/BenchControl/Greco/AmbientCfg.cs @@ -14,8 +14,8 @@ namespace TBF.BenchControl.Greco public StopBits StopBits; public Handshake Handshake; - /// Parameterless constructor - public AmbientCfg() + /// Private parameterless constructor invoked by all other (public) constructors + AmbientCfg() { Name = "Ambient"; ParentName = string.Empty; @@ -35,7 +35,7 @@ namespace TBF.BenchControl.Greco public string ToString(int i) { - return string.Format("Name={0}, COM{1}, {2}Bd, {3}-bits, parity={4}, stopBits={5}, {6}", + return string.Format("Name={0}, Com{1}, {2}Bd, {3}-bits, parity={4}, stopBits={5}, {6}", Name, ComPortNr, BaudRate, DataBits, Parity, StopBits, Handshake); } } diff --git a/TestBenchFramework/BenchControl/Greco/AmbientFactory.cs b/TestBenchFramework/BenchControl/Greco/AmbientFactory.cs index 958d86414..24852ef52 100644 --- a/TestBenchFramework/BenchControl/Greco/AmbientFactory.cs +++ b/TestBenchFramework/BenchControl/Greco/AmbientFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.Greco public class AmbientFactory : IComponentFactory { public string ClassName { get { return "Greco Ambient"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/MettlerToledo/BalanceCfg.cs b/TestBenchFramework/BenchControl/MettlerToledo/BalanceCfg.cs index 9a78946fa..89fcab8b3 100644 --- a/TestBenchFramework/BenchControl/MettlerToledo/BalanceCfg.cs +++ b/TestBenchFramework/BenchControl/MettlerToledo/BalanceCfg.cs @@ -17,8 +17,8 @@ namespace TBF.BenchControl.MettlerToledo public float Empty; /// 'Empty' water mass in 'kg' or volume in 'l' public int EmptyTimeSec; /// s - /// Parameterless constructor - public BalanceCfg() + /// Private parameterless constructor invoked by all other (public) constructors + BalanceCfg() { Name = "Balance"; ParentName = string.Empty; @@ -41,7 +41,7 @@ namespace TBF.BenchControl.MettlerToledo public string ToString(int i) { - return string.Format("Name={0}, COM{1}, {2}Bd, {3}-bits, parity={4}, stopBits={5}, {6}, capacity={7}kg, empty={8}kg, emptyTime={9}s", + return string.Format("Name={0}, Com{1}, {2}Bd, {3}-bits, parity={4}, stopBits={5}, {6}, capacity={7}kg, empty={8}kg, emptyTime={9}s", Name, ComPortNr, BaudRate, DataBits, Parity, StopBits, Handshake, Capacity, Empty, EmptyTimeSec); } } diff --git a/TestBenchFramework/BenchControl/MettlerToledo/BalanceDev.cs b/TestBenchFramework/BenchControl/MettlerToledo/BalanceDev.cs index 9759f5797..dfbbdbd2f 100644 --- a/TestBenchFramework/BenchControl/MettlerToledo/BalanceDev.cs +++ b/TestBenchFramework/BenchControl/MettlerToledo/BalanceDev.cs @@ -15,71 +15,63 @@ namespace TBF.BenchControl.MettlerToledo /// /// Implemented and tested on 15.10.2013 by Milan Hanajik /// - public class BalanceDev : TestBenchSim, IComponent, IDevice, GenericDevices.IBalance + public class BalanceDev : ComponentBase, IDevice, GenericDevices.IBalance { /// /// Info: StartMassMeasurement() and "Balnce response = .., Mass = ..." /// Warn: Start measurement when busy is true /// private static readonly ILog log = LogManager.GetLogger(typeof(BalanceDev)); - public override string ToString() { return string.Format("{0} - Mettler-Toledo Balance", balanceCfg.Name); } + public override string ToString() { return string.Format("MettlerToledo.Balance({0})", Cfg.ToString(1)); } - /// + protected readonly BalanceCfg balanceCfg; + + /// /// Enumeration of balances via static fields and methods /// static int nextBalanceIdx = 0; - public static void ResetStaticProperties() { nextBalanceIdx = 0; } + public static new void ResetStaticProperties() + { + nextBalanceIdx = 0; + } public static int BalancesCount { get { return nextBalanceIdx; } } public static BalanceDev[] Balances; public static float[] Masses; /// protected int balanceNr; /// 0-based balance number - protected readonly BalanceCfg balanceCfg; - public Generic.IComponentCfg Cfg { get { return balanceCfg; } } - protected SerialPort serialPort; protected StringBuilder stringBuilder; - public string Name { get { return balanceCfg.Name; } } public int BalanceNr { get { return balanceNr; } } public float Capacity { get { return balanceCfg.Capacity; } } public int EmptyTimeSec { get { return balanceCfg.EmptyTimeSec; } } - public IList Corrections { get { return balanceCfg.Corrections; } } - + /// The state of the mass measurement - public MsrmntState MsrmntState - { - get { return msrmntState; } - } + public MsrmntState MsrmntState { get { return msrmntState; } } protected MsrmntState msrmntState; /// The mass after StartMassMeasurement() when MsrmntState == MsrmntState.Valid - public float Mass - { - get { return mass; } - } + public float Mass { get { return mass; } } protected float mass; /// The time stamp after StartMassMeasurement() when MsrmntState == MsrmntState.Valid - public int MsrmntTimeStamp - { - get { return msrmntTimeStamp; } - } + public int MsrmntTimeStamp { get { return msrmntTimeStamp; } } protected int msrmntTimeStamp; /// /// Constructor /// - /// Balance properties + /// Balance properties + /// A list of components loaded so far public BalanceDev(BalanceCfg cfg, IList components) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.balanceCfg = cfg; + balanceCfg = cfg; balanceNr = nextBalanceIdx++; Masses = new float[nextBalanceIdx]; /// (re)initialize the static array of masses of all balances - + /// if (Balances == null || Balances.Length < nextBalanceIdx) { BalanceDev[] balancesSoFar = Balances; @@ -87,9 +79,11 @@ namespace TBF.BenchControl.MettlerToledo if (balancesSoFar != null) for (int i = 0; i < balancesSoFar.Length; i++) Balances[i] = balancesSoFar[i]; Balances[nextBalanceIdx - 1] = this; } + + log.Debug(this.ToString()); } - public new void Initialize() + public void Initialize() { msrmntState = MsrmntState.Failed; /// Data not valid yet @@ -228,7 +222,7 @@ namespace TBF.BenchControl.MettlerToledo { if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) { - mass = GetSimMass(balanceNr); + mass = TestBenchSim.GetSimMass(balanceNr); Masses[balanceNr] = mass; msrmntState = MsrmntState.Valid; msrmntTimeStamp = StateMachine.Time; diff --git a/TestBenchFramework/BenchControl/MettlerToledo/BalanceFactory.cs b/TestBenchFramework/BenchControl/MettlerToledo/BalanceFactory.cs index aadae2fcd..1f440a15d 100644 --- a/TestBenchFramework/BenchControl/MettlerToledo/BalanceFactory.cs +++ b/TestBenchFramework/BenchControl/MettlerToledo/BalanceFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.MettlerToledo public class BalanceFactory : IComponentFactory { public string ClassName { get { return "MettlerToledo Balance"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 5; } } diff --git a/TestBenchFramework/BenchControl/MettlerToledo/BalanceNewDev.cs b/TestBenchFramework/BenchControl/MettlerToledo/BalanceNewDev.cs index 8a3927f5c..0bf56acb4 100644 --- a/TestBenchFramework/BenchControl/MettlerToledo/BalanceNewDev.cs +++ b/TestBenchFramework/BenchControl/MettlerToledo/BalanceNewDev.cs @@ -14,28 +14,24 @@ namespace TBF.BenchControl.MettlerToledo /// /// Implemented and tested on 15.10.2013 by Milan Hanajik /// - public class BalanceNewDev : BalanceDev, IComponent, IDevice, GenericDevices.IBalance2 + public class BalanceNewDev : BalanceDev, IDevice, GenericDevices.IBalance2 { /// /// Info: StartMassMeasurement() and "Balnce response = .., Mass = ..." /// Warn: Start measurement when busy is true /// private static readonly ILog log = LogManager.GetLogger(typeof(BalanceNewDev)); - public override string ToString() { return string.Format("{0} - Mettler-Toledo Balance with SN", balanceCfg.Name); } - - public static void ResetStaticProperties() { } + public override string ToString() { return string.Format("MettlerToledo.BalanceNew({0})", Cfg.ToString(1)); } /// Serial number after GetSerialNumber() when MsrmntState == MsrmntState.Valid - public string SerialNumber - { - get { return serialNumber; } - } + public string SerialNumber { get { return serialNumber; } } string serialNumber; public BalanceNewDev(BalanceCfg cfg, IList components) : base(cfg, components) { - } + log.Debug(this.ToString()); + } /// /// Get the serial number @@ -64,7 +60,7 @@ namespace TBF.BenchControl.MettlerToledo { if (balanceCfg.DebugLevel == Entities.DebugMode.Simulate) { - mass = GetSimMass(balanceNr); + mass = TestBenchSim.GetSimMass(balanceNr); Masses[balanceNr] = mass; serialNumber = "1234567890"; msrmntState = MsrmntState.Valid; diff --git a/TestBenchFramework/BenchControl/MettlerToledo/BalanceNewFactory.cs b/TestBenchFramework/BenchControl/MettlerToledo/BalanceNewFactory.cs index 06fd7a2ae..8085d2359 100644 --- a/TestBenchFramework/BenchControl/MettlerToledo/BalanceNewFactory.cs +++ b/TestBenchFramework/BenchControl/MettlerToledo/BalanceNewFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.MettlerToledo public class BalanceNewFactory : IComponentFactory { public string ClassName { get { return "MettlerToledoBalanceSN"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 5; } } diff --git a/TestBenchFramework/BenchControl/Operations/ReadMoreRegistersOp.cs b/TestBenchFramework/BenchControl/Operations/ReadMoreRegistersOp.cs index e54c1d492..92fbec1ed 100644 --- a/TestBenchFramework/BenchControl/Operations/ReadMoreRegistersOp.cs +++ b/TestBenchFramework/BenchControl/Operations/ReadMoreRegistersOp.cs @@ -17,7 +17,6 @@ namespace TBF.BenchControl.Operations IntBox[] pulses; IntBox[] refPulses; IOperation[] readRegOps; - Event[] events; /// /// Events: eventDone (default=Event.ReadRegisterDone) or Event.Error diff --git a/TestBenchFramework/BenchControl/ProcedureParamsBase.cs b/TestBenchFramework/BenchControl/ProcedureParamsBase.cs new file mode 100644 index 000000000..22d50f735 --- /dev/null +++ b/TestBenchFramework/BenchControl/ProcedureParamsBase.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Xml.Serialization; + +namespace TBF.BenchControl +{ + public class ProcedureParamsBase : Generic.IProcedureParams + { + protected Entities.ComponentProcedure procedureParamsEntity; + + public string ComponentName { get { return componentName; } } + protected string componentName; + + public Entities.Procedure Procedure { get { return procedure; } } + protected Entities.Procedure procedure; + + /// + /// Parameterless constructor required for serialization + /// + public ProcedureParamsBase() + { + InitializeAll(); + } + + /// To be overridden + public virtual void InitializeAll() + { + } + + /// To be overridden + public virtual void UpdateProcedureParams(Entities.ComponentProcedure dbEntity) + { + } + + public void UpdateProcedureParams(string cmpntName, Entities.Procedure procedure) + { + /// Search for an existing matching entity + foreach (var procPrms in procedure.MoreParams) + { + if (procPrms.CmpntName.Equals(cmpntName)) + { + UpdateProcedureParams(procPrms); + return; + } + } + + /// Create a new entity and add it to the list test.MoreParams + InitializeAll(); + Entities.ComponentProcedure componentTest = ToDbEntity(cmpntName, procedure); + procedure.MoreParams.Add(componentTest); + } + + public TBF.Entities.ComponentProcedure ToDbEntity(string componentName, Entities.Procedure procedure) + { + using (var writer = new StringWriter()) + { + /// Serialize this class with parameters + (new XmlSerializer(GetType())).Serialize(writer, this); + + /// Create and return the ComponentProcedure entity + TBF.Entities.ComponentProcedure entity = new TBF.Entities.ComponentProcedure(); + entity.CmpntName = componentName; + entity.Parameters = writer.ToString(); + entity.Procedure = procedure; + return entity; + } + } + + public void UpdateDbEntity() + { + using (var writer = new StringWriter()) + { + /// Serialize this class and update the entity + (new XmlSerializer(GetType())).Serialize(writer, this); + procedureParamsEntity.Parameters = writer.ToString(); + procedureParamsEntity.CmpntName = componentName; + procedureParamsEntity.Procedure = procedure; + } + } + + public virtual string ParamName(int i) { return string.Empty; } + + public virtual int ParamsCount() { return 0; } + + public virtual string ToString(int i) { return string.Empty; } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < ParamsCount(); i++) + { + if (i != 0) sb.Append("; "); + sb.Append(ParamName(i)); + sb.Append("="); + sb.Append(ToString(i)); + } + return sb.ToString(); + } + } +} diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/Printer.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/Printer.cs index e282b5565..75876d352 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/Printer.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/Printer.cs @@ -2,18 +2,17 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Printing; +using log4net; using TBF.BenchControl; namespace TBF.BenchControl.ResultsPrinters.Basic { - public class Printer : Generic.IComponent, IOperation, GenericDevices.IResultsPrinter + public class Printer : ComponentBase, IOperation, GenericDevices.IResultsPrinter { + private static readonly ILog log = LogManager.GetLogger(typeof(Printer)); + public override string ToString() { return string.Format("ResultsPrinters.Basic({0})", Cfg.ToString(1)); } + readonly PrinterCfg printerCfg; - public Generic.IComponentCfg Cfg { get { return printerCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return printerCfg.Name; } } /// /// Data to print @@ -24,9 +23,10 @@ namespace TBF.BenchControl.ResultsPrinters.Basic string title; public Printer(PrinterCfg cfg) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.printerCfg = cfg; + printerCfg = cfg; + log.Debug(this.ToString()); } /// diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfg.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfg.cs index 8bd7f2865..4d6027dcb 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfg.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfg.cs @@ -7,8 +7,8 @@ namespace TBF.BenchControl.ResultsPrinters.Basic { public class PrinterCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - public PrinterCfg() + /// Private parameterless constructor invoked by all other (public) constructors + PrinterCfg() { Name = "BasicResultsPrinter"; ParentName = string.Empty; diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterFactory.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterFactory.cs index eaa0207ce..ec4605b2b 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterFactory.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.ResultsPrinters.Basic public class PrinterFactory : IComponentFactory { public string ClassName { get { return "BasicResultsPrinter"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Munich/Printer.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Munich/Printer.cs index 72eb449d4..9c5c8fc09 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Munich/Printer.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Munich/Printer.cs @@ -2,15 +2,17 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Printing; +using log4net; using TBF.BenchControl; namespace TBF.BenchControl.ResultsPrinters.Munich { - public class Printer : ComponentBase, Generic.IComponent, IOperation, GenericDevices.IResultsPrinter + public class Printer : ComponentBase, IOperation, GenericDevices.IResultsPrinter { - readonly PrinterCfg printerCfg; + private static readonly ILog log = LogManager.GetLogger(typeof(Printer)); + public override string ToString() { return string.Format("ResultsPrinters.Munich({0})", Cfg.ToString(1)); } - public static void ResetStaticProperties() { } + readonly PrinterCfg printerCfg; /// /// Data to print @@ -19,32 +21,17 @@ namespace TBF.BenchControl.ResultsPrinters.Munich public IList WaterMeters; public IList Results; public string Title; + public string Version { get { return printerCfg. ProcParams.Version; } } + public string Zaehlertyp { get { return printerCfg. ProcParams.Zaehlertyp; } } + public string Pruefvorlage { get { return printerCfg. ProcParams.Pruefvorlage; } } + public string Eichjahr { get { return printerCfg. ProcParams.Eichjahr; } } - public string Version - { - get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Version : ""; } - } - - public string Zaehlertyp - { - get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Zaehlertyp : ""; } - } - - public string Pruefvorlage - { - get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Pruefvorlage : ""; } - } - - public string Eichjahr - { - get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Eichjahr : ""; } - } public Printer(PrinterCfg cfg) : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.printerCfg = cfg; + printerCfg = cfg; + log.Debug(this.ToString()); } /// Events: ResultsPrinted diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Munich/PrinterCfg.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Munich/PrinterCfg.cs index 938596c8f..b558f0e2d 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Munich/PrinterCfg.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Munich/PrinterCfg.cs @@ -7,11 +7,23 @@ namespace TBF.BenchControl.ResultsPrinters.Munich { public class PrinterCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - public PrinterCfg() + /// Procedure parameters + [XmlIgnore] + public ProcParams ProcParams; + public override IParamsProvider GetProcedureParams() { return ProcParams; } + public override IParamsProvider CreateProcedureParams(Entities.Procedure procedure) + { + ProcParams procParams = new ProcParams(); + procParams.UpdateProcedureParams(Name, procedure); + return procParams; + } + + /// Private parameterless constructor invoked by all other (public) constructors + PrinterCfg() { Name = "PrintedProtocol"; ParentName = string.Empty; + ProcParams = new ProcParams(); } public PrinterCfg(IComponentFactory factory) diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Munich/PrinterFactory.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Munich/PrinterFactory.cs index e8133c4fd..707b4b758 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Munich/PrinterFactory.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Munich/PrinterFactory.cs @@ -6,13 +6,6 @@ namespace TBF.BenchControl.ResultsPrinters.Munich public class PrinterFactory : IComponentFactory { public string ClassName { get { return "ResultsPrinter4Munich"; } } - public bool HasProcedureParams { get { return true; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) - { - return ProcParams.GetProcedureParams(procedureParams); - } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Munich/ProcParams.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Munich/ProcParams.cs index c5b75ba30..c8807f0ae 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Munich/ProcParams.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Munich/ProcParams.cs @@ -6,13 +6,21 @@ using TBF.Resources; namespace TBF.BenchControl.ResultsPrinters.Munich { - public class ProcParams : IParamsProvider, IProcedureParams + public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams { public string Version; public string Zaehlertyp; public string Pruefvorlage; public string Eichjahr; + public override void InitializeAll() + { + Version = "4/13"; + Zaehlertyp = ""; + Pruefvorlage = ""; + Eichjahr = "2014"; + } + string[] paramNames = new string[] { Strings.Version, @@ -20,9 +28,10 @@ namespace TBF.BenchControl.ResultsPrinters.Munich "Prüfvorlage", "Eichjahr", }; - public string ParamName(int i) { return paramNames[i]; } + public override string ParamName(int i) { return paramNames[i]; } + public override int ParamsCount() { return paramNames.Length; } - public string ToString(int i) + public override string ToString(int i) { switch (i) { @@ -63,101 +72,38 @@ namespace TBF.BenchControl.ResultsPrinters.Munich } } - #region Boilerplate code - - public int ParamsCount() { return paramNames.Length; } - - public override string ToString() + public override void UpdateProcedureParams(Entities.ComponentProcedure dbEntity) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < ParamsCount(); i++) - { - if (i != 0) sb.Append("; "); - sb.Append(ParamName(i)); - sb.Append("="); - sb.Append(ToString(i)); - } - return sb.ToString(); - } - - [XmlIgnore] - public Entities.ComponentProcedure ProcedureParamsEntity { get { return procParamsEntity; } } - Entities.ComponentProcedure procParamsEntity; - - [XmlIgnore] - public string ComponentName { get { return componentName; } } - string componentName; - - [XmlIgnore] - public Entities.Procedure Test { get { return test; } } - Entities.Procedure test; - - /// Parameterless constructor - public ProcParams() - { - Version = "4/13"; - Zaehlertyp = ""; - Pruefvorlage = ""; - Eichjahr = "2014"; - } - - public ProcParams(Entities.ComponentProcedure procParamsEntity, string componentName, Entities.Procedure test) - : this() - { - this.procParamsEntity = procParamsEntity; - this.componentName = componentName; - this.test = test; - } - - public TBF.Entities.ComponentProcedure ToDbEntity(IComponent component, Entities.Procedure procedure) - { - using (var writer = new StringWriter()) - { - /// Serialize this class with parameters - (new XmlSerializer(GetType())).Serialize(writer, this); - - /// Create and return the ComponentProcedure entity - TBF.Entities.ComponentProcedure entity = new TBF.Entities.ComponentProcedure(); - entity.CmpntName = component.Cfg.Name; - entity.Parameters = writer.ToString(); - entity.Procedure = procedure; - return entity; - } - } - - public void UpdateDbEntity() - { - using (var writer = new StringWriter()) - { - /// Serialize this class and update the entity - (new XmlSerializer(GetType())).Serialize(writer, this); - procParamsEntity.Parameters = writer.ToString(); - procParamsEntity.CmpntName = componentName; - procParamsEntity.Procedure = test; - - } - } - - public static IParamsProvider GetProcedureParams(Entities.ComponentProcedure procParamsEntity) - { - if (procParamsEntity == null) return new ProcParams(); - - ProcParams procParams; + if (dbEntity == null) return; try { - procParams = (ProcParams)(new XmlSerializer(typeof(ProcParams))) - .Deserialize(new StringReader(procParamsEntity.Parameters)); + ProcParams tmp = (ProcParams)(new XmlSerializer(typeof(ProcParams))) + .Deserialize(new StringReader(dbEntity.Parameters)); + + procedureParamsEntity = dbEntity; + componentName = dbEntity.CmpntName; + procedure = dbEntity.Procedure; + + Version = tmp.Version; + Zaehlertyp = tmp.Zaehlertyp; + Pruefvorlage = tmp.Pruefvorlage; + Eichjahr = tmp.Eichjahr; } catch { - procParams = new ProcParams(); } - procParams.procParamsEntity = procParamsEntity; - procParams.componentName = procParamsEntity.CmpntName; - procParams.test = procParamsEntity.Procedure; - return procParams; } - #endregion + + public ProcParams() + { + } + + public ProcParams(Entities.ComponentProcedure procParamsEntity, string componentName, Entities.Procedure procedure) + { + this.procedureParamsEntity = procParamsEntity; + this.componentName = componentName; + this.procedure = procedure; + } } } diff --git a/TestBenchFramework/BenchControl/ResultsWriters/Basic/Writer.cs b/TestBenchFramework/BenchControl/ResultsWriters/Basic/Writer.cs index b84610af3..b7f8bbb15 100644 --- a/TestBenchFramework/BenchControl/ResultsWriters/Basic/Writer.cs +++ b/TestBenchFramework/BenchControl/ResultsWriters/Basic/Writer.cs @@ -1,18 +1,17 @@ using System; using System.Collections.Generic; using System.IO; +using log4net; using TBF.BenchControl; namespace TBF.BenchControl.ResultsWriters.Basic { - public class Writer : Generic.IComponent, IOperation, GenericDevices.IResultsWriter + public class Writer : ComponentBase, IOperation, GenericDevices.IResultsWriter { + private static readonly ILog log = LogManager.GetLogger(typeof(Writer)); + public override string ToString() { return string.Format("ResultsWriters.Basic({0})", Cfg.ToString(1)); } + readonly WriterCfg writerCfg; - public Generic.IComponentCfg Cfg { get { return writerCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return writerCfg.Name; } } /// /// Results to print @@ -22,9 +21,10 @@ namespace TBF.BenchControl.ResultsWriters.Basic StreamWriter writer; public Writer(WriterCfg cfg) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.writerCfg = cfg; + writerCfg = cfg; + log.Debug(this.ToString()); } /// diff --git a/TestBenchFramework/BenchControl/ResultsWriters/Basic/WriterCfg.cs b/TestBenchFramework/BenchControl/ResultsWriters/Basic/WriterCfg.cs index c9fe02d2b..cdc98d97c 100644 --- a/TestBenchFramework/BenchControl/ResultsWriters/Basic/WriterCfg.cs +++ b/TestBenchFramework/BenchControl/ResultsWriters/Basic/WriterCfg.cs @@ -7,8 +7,8 @@ namespace TBF.BenchControl.ResultsWriters.Basic { public class WriterCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - public WriterCfg() + /// Private parameterless constructor invoked by all other (public) constructors + WriterCfg() { Name = "BasicResultsWriter"; ParentName = string.Empty; diff --git a/TestBenchFramework/BenchControl/ResultsWriters/Basic/WriterFactory.cs b/TestBenchFramework/BenchControl/ResultsWriters/Basic/WriterFactory.cs index 7f7bd9011..72c0d34d6 100644 --- a/TestBenchFramework/BenchControl/ResultsWriters/Basic/WriterFactory.cs +++ b/TestBenchFramework/BenchControl/ResultsWriters/Basic/WriterFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.ResultsWriters.Basic public class WriterFactory : IComponentFactory { public string ClassName { get { return "BasicResultsWriter"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/StateMachine.cs b/TestBenchFramework/BenchControl/StateMachine.cs index 13de8e6a9..171f4d5c7 100644 --- a/TestBenchFramework/BenchControl/StateMachine.cs +++ b/TestBenchFramework/BenchControl/StateMachine.cs @@ -321,7 +321,7 @@ namespace TBF.BenchControl { foreach (var cmpnt in components) { - if (cmpnt is ComponentBase) (cmpnt as ComponentBase).GetProcedureParams(procedure); + cmpnt.Cfg.UpdateProcedureParams(procedure); } } @@ -329,7 +329,7 @@ namespace TBF.BenchControl { foreach (var cmpnt in components) { - if (cmpnt is ComponentBase) (cmpnt as ComponentBase).GetTestParams(test); + cmpnt.Cfg.UpdateTestParams(test); } } diff --git a/TestBenchFramework/BenchControl/TbfComponents.cs b/TestBenchFramework/BenchControl/TbfComponents.cs index e4c7996a7..c02f2b41c 100644 --- a/TestBenchFramework/BenchControl/TbfComponents.cs +++ b/TestBenchFramework/BenchControl/TbfComponents.cs @@ -93,9 +93,11 @@ namespace TBF.BenchControl if (cmpntFactory == null) continue; IComponent cmpnt = cmpntFactory - .ComponentFromCmpntCfg(BenchControl.TbfComponents.CmpntCfgFromCmpntEntity(entity), components); + .ComponentFromCmpntCfg(cmpntFactory.CmpntCfgFromCmpntEntity(entity), components); + /// /// Inherit DebugMode from the parent (if any) + /// if ((cmpnt.Cfg.DebugLevel == Entities.DebugMode.Inherit) && (cmpnt.Cfg is IChildComponentCfg) && !string.IsNullOrEmpty(cmpnt.Cfg.ParentName)) @@ -140,42 +142,5 @@ namespace TBF.BenchControl { return FindComponent(name, StateMachine.Components); } - - - public static IParamsProvider GetTestParams(IComponent cmpnt, Entities.Test test) - { - if (cmpnt == null || cmpnt.Cfg == null || !cmpnt.Cfg.Factory.HasTestParams) return null; - - /// Search for an existing matching entity - foreach (var tstPrms in test.MoreParams) - { - if (tstPrms.CmpntName.Equals(cmpnt.Cfg.Name)) return cmpnt.Cfg.Factory.GetTestParams(tstPrms); - } - - /// Create a new entity and add it to the list test.MoreParams - Entities.ComponentTest testParams = new Entities.ComponentTest { CmpntName = cmpnt.Cfg.Name, Test = test }; - test.MoreParams.Add(testParams); - return cmpnt.Cfg.Factory.GetTestParams(testParams); - } - - - public static IParamsProvider GetProcedureParams(IComponent cmpnt, Entities.Procedure procedure) - { - if (cmpnt == null || cmpnt.Cfg == null || !cmpnt.Cfg.Factory.HasProcedureParams) return null; - - /// Search for an existing matching entity - foreach (var procPrms in procedure.MoreParams) - { - if (procPrms.CmpntName.Equals(cmpnt.Cfg.Name)) - { - return cmpnt.Cfg.Factory.GetProcedureParams(procPrms); - } - } - - /// Create a new entity and add it to the list procedure.MoreParams - Entities.ComponentProcedure procParams = new Entities.ComponentProcedure { CmpntName = cmpnt.Cfg.Name, Procedure = procedure }; - procedure.MoreParams.Add(procParams); - return cmpnt.Cfg.Factory.GetProcedureParams(procParams); - } } } diff --git a/TestBenchFramework/BenchControl/TestBenchSim.cs b/TestBenchFramework/BenchControl/TestBenchSim.cs index 2b24692a2..d505f8937 100644 --- a/TestBenchFramework/BenchControl/TestBenchSim.cs +++ b/TestBenchFramework/BenchControl/TestBenchSim.cs @@ -7,7 +7,7 @@ namespace TBF.BenchControl /// Test bench model inherited by all classes for the simulation of devices. /// Define DN100, MUNICH or nothing. /// - public class TestBenchSim + public static class TestBenchSim { private static readonly ILog log = LogManager.GetLogger(typeof(TestBenchSim)); @@ -34,10 +34,10 @@ namespace TBF.BenchControl public static bool Div2sim; public static bool Div3sim; - int regulValveNo; /// 0=undefined, 1..5 - int refFlowmtrNo; /// 0=undefined, 1..4 + static int regulValveNo; /// 0=undefined, 1..5 + static int refFlowmtrNo; /// 0=undefined, 1..4 - public void Initialize() + public static void Initialize() { Mass1sim = 0.0f; /// Initialize tanks Mass2sim = 0.0f; @@ -226,10 +226,10 @@ namespace TBF.BenchControl const ulong Path5 = 0; #endif /// Run this device - public void RunDevice(int regulValveNo, int refFlowmtrNo, Elde.StatusP statusP) + public static void RunDevice(int regulValveNo, int refFlowmtrNo, Elde.StatusP statusP) { - this.regulValveNo = regulValveNo; - this.refFlowmtrNo = refFlowmtrNo; + TestBenchSim.regulValveNo = regulValveNo; + TestBenchSim.refFlowmtrNo = refFlowmtrNo; float time = 1.0f; #if DN100 @@ -239,14 +239,36 @@ namespace TBF.BenchControl if (Div2sim && (RouteSim & Path4) == Path4) Mass2sim += DiffKg(Flow4sim, time); if (Div1sim && (RouteSim & Path5) == Path5) Mass1sim += DiffKg(Flow5sim, time); #elif MUNICH || FUZHOU150 || FUZHOU300 - if (Div1sim && (RouteSim & Path1) == Path1) Mass1sim += DiffKg(Flow1sim, time); - if (Div1sim && (RouteSim & Path2) == Path2) Mass1sim += DiffKg(Flow2sim, time); + if (Div1sim && (RouteSim & Path1) == Path1) + { + float diff = DiffKg(Flow1sim, time); + Mass1sim += diff; + log.WarnFormat("Path1: Div1, Mass1+={0}kg, flow={1}m3/h, Mass1={2}kg", diff, Flow1sim, Mass1sim); + } + if (Div1sim && (RouteSim & Path2) == Path2) + { + float diff = DiffKg(Flow2sim, time); + Mass1sim += diff; + log.WarnFormat("Path2: Div1, Mass1 += {0}kg, flow={1}m3/h, Mass1={2}kg", diff, Flow1sim, Mass1sim); + } if (Div2sim && (RouteSim & Path3) == Path3) { - Mass2sim += DiffKg(Flow3sim, time); + float diff = DiffKg(Flow3sim, time); + Mass2sim += diff; + log.WarnFormat("Path3: Div2, Mass2 += {0}kg, flow={1}m3/h, Mass2={2}kg", diff, Flow1sim, Mass2sim); + } + if (Div3sim && (RouteSim & Path4) == Path4) + { + float diff = DiffKg(Flow4sim, time); + Mass2sim += diff; + log.WarnFormat("Path4: Div3, Mass2 += {0}kg, flow={1}m3/h, Mass2={2}kg", diff, Flow1sim, Mass2sim); + } + if (Div3sim && (RouteSim & Path5) == Path5) + { + float diff = DiffKg(Flow5sim, time); + Mass2sim += diff; + log.WarnFormat("Path5: Div3, Mass2 += {0}kg, flow={1}m3/h, Mass2={2}kg", diff, Flow1sim, Mass2sim); } - if (Div3sim && (RouteSim & Path4) == Path4) Mass2sim += DiffKg(Flow4sim, time); - if (Div3sim && (RouteSim & Path5) == Path5) Mass2sim += DiffKg(Flow5sim, time); #else if (Div1sim && (RouteSim & Path1) == Path1) Mass1sim += DiffKg(Flow1sim, time); if (Div2sim && (RouteSim & Path2) == Path2) Mass2sim += DiffKg(Flow2sim, time); @@ -258,43 +280,55 @@ namespace TBF.BenchControl if ((RouteSim & EmptyValve2) == EmptyValve2) Mass2sim -= DiffKg(10.0f, time); if (Mass2sim < 0) Mass2sim = 0; - UiBridge.Bridge.OnLog(this, string.Format("I{1}/RV{2}: q1={3}, q2={4}, q3={5}, q4={6}, q5={7}, D123={8}{9}{10}, m1={11}, m2={12}, S={13}\r\n", - time, - refFlowmtrNo, regulValveNo, - Flow1sim.ToString("F1"), Flow2sim.ToString("F1"), Flow3sim.ToString("F1"), Flow4sim.ToString("F1"), Flow5sim.ToString("F1"), - (Div1sim ? "o" : "x"), (Div2sim ? "o" : "x"), (Div3sim ? "o" : "x"), - Mass1sim.ToString("F1"), Mass2sim.ToString("F1"), ((ulong)statusP).ToString("X"))); + UiBridge.Bridge.OnLog(null, string.Format("I{1}/RV{2}: q1={3}, q2={4}, q3={5}, q4={6}, q5={7}, D123={8}{9}{10}, m1={11}, m2={12}, S={13}\r\n", + time, refFlowmtrNo, regulValveNo, + Flow1sim.ToString("F1"), + Flow2sim.ToString("F1"), + Flow3sim.ToString("F1"), + Flow4sim.ToString("F1"), + Flow5sim.ToString("F1"), + (Div1sim ? "o" : "x"), + (Div2sim ? "o" : "x"), + (Div3sim ? "o" : "x"), + Mass1sim.ToString("F1"), + Mass2sim.ToString("F1"), + ((ulong)statusP).ToString("X") + ) + ); } + /// /// Calculate the mass change from the flow and the time period /// /// Flow in [m3/h] /// Time period in [s] /// Mass change in [kg] - float DiffKg(float flowM3H, float timeSec) + static float DiffKg(float flowM3H, float timeSec) { return timeSec * flowM3H / 3.6f; } + /// /// Get the simulated mass. Use the balance range to distinguish the balances. /// /// 0-based balance number /// Simulated mass reading [kg] - public float GetSimMass(int balanceNr) + public static float GetSimMass(int balanceNr) { if (balanceNr == 0) return Mass1sim; else if (balanceNr == 1) return Mass2sim; else return 0; } + /// /// Set the simulated diverter. Use the nominal flow to distinguish the path. /// /// Diverter state: true = to the tank /// Nominal flow of the path [m3/h] - public void SetSimDiverter(bool toTank) + public static void SetSimDiverter(bool toTank) { #if DN100 switch (regulValveNo) @@ -343,60 +377,12 @@ namespace TBF.BenchControl return; } - /// - /// Determine which autput section is used - /// - /// - /// - int OutputPathId(float nominalFlow) - { -#if DN100 - // - // Qn1=0.3, Qn2=2.5, Qn3=25, Qn4=250, Qn5=0.2 - // - if (nominalFlow < 0.25f) return 5; - else if (nominalFlow < 1.0f) return 1; - else if (nominalFlow < 10.0f) return 2; - else if (nominalFlow < 100.0f) return 3; - else return 4; -#elif MUNICH - // - // Qn1=200, Qn2=20, Qn3=3, Qn4=0.25 - // - if (nominalFlow <= 0.25f) return 4; - else if (nominalFlow <= 3.0f) return 3; - else if (nominalFlow <= 20.0f) return 2; - else return 1; -#elif FUZHOU150 - // - // Qn1=350, Qn2=50, Qn3=7, Qn4=0.5 - // - if (nominalFlow <= 0.5f) return 4; - else if (nominalFlow <= 7.0f) return 3; - else if (nominalFlow <= 50.0f) return 2; - else return 1; -#elif FUZHOU300 - // - // Qn1=350, Qn2=50, Qn3=7, Qn4=0.5 - // - if (nominalFlow <= 0.5f) return 4; - else if (nominalFlow <= 7.0f) return 3; - else if (nominalFlow <= 50.0f) return 2; - else return 1; -#else - // - // Qn1=1, Qn2=10 - // - if (nominalFlow < 3.0f) return 1; - else return 2; -#endif - } /// /// Get the simulated flow in [m3/h]. /// /// Simulated flow [m3/h] - public float GetSimFlow() + public static float GetSimFlow() { switch (refFlowmtrNo) { @@ -409,12 +395,13 @@ namespace TBF.BenchControl } } + /// /// Update simulated flow. Use the nominal flow to distinguish the path. /// /// Target flow [m3/h] /// Nominal flow of the path [m3/h] - public void UpdateSimFlow(float targetFlow) + public static void UpdateSimFlow(float targetFlow) { float A = 0.7f; /// higher value -> slower regulation float B = 1.0f - A; diff --git a/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetection.cs b/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetection.cs index c8e272785..97784c821 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetection.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetection.cs @@ -1,22 +1,19 @@ using System; using System.Collections.Generic; +using log4net; using TBF.BenchControl; namespace TBF.BenchControl.TestMethods.CameraRoiDetection { - public class RoiDetection : Generic.IComponent, GenericDevices.ITestMethod, ISequence + public class RoiDetection : ComponentBase, GenericDevices.ITestMethod, ISequence { - readonly RoiDetectionCfg roiDetectionCfg; - public Generic.IComponentCfg Cfg { get { return roiDetectionCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return roiDetectionCfg.Name; } } + private static readonly ILog log = LogManager.GetLogger(typeof(RoiDetection)); + public override string ToString() { return string.Format("TestMethods.CameraRoiDetection({0})", Cfg.ToString(1)); } public RoiDetection(RoiDetectionCfg cfg) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.roiDetectionCfg = cfg; + log.Debug(this.ToString()); } public IList Execute(Entities.Test test) diff --git a/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetectionCfg.cs b/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetectionCfg.cs index 9f726f393..5b1ab5d14 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetectionCfg.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetectionCfg.cs @@ -7,8 +7,8 @@ namespace TBF.BenchControl.TestMethods.CameraRoiDetection { public class RoiDetectionCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - public RoiDetectionCfg() + /// Private parameterless constructor invoked by all other (public) constructors + RoiDetectionCfg() { Name = "RoiDetection"; ParentName = string.Empty; diff --git a/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetectionFactory.cs b/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetectionFactory.cs index 0568f0b0e..c4c40349d 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetectionFactory.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CameraRoiDetection/RoiDetectionFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.TestMethods.CameraRoiDetection public class RoiDetectionFactory : IComponentFactory { public string ClassName { get { return "ROI Detection"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethod.cs b/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethod.cs index 7d3d5c3b7..6ddb067d4 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethod.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethod.cs @@ -1,22 +1,19 @@ using System; using System.Collections.Generic; +using log4net; using TBF.BenchControl; namespace TBF.BenchControl.TestMethods.CombinedMeters { - public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence + public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence { - readonly TestMethodCfg testMethodCfg; - public Generic.IComponentCfg Cfg { get { return testMethodCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return testMethodCfg.Name; } } + private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); + public override string ToString() { return string.Format("TestMethods.CombinedMeters({0})", Cfg.ToString(1)); } public TestMethod(TestMethodCfg cfg) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.testMethodCfg = cfg; + log.Debug(this.ToString()); } public IList Execute(Entities.Test test) diff --git a/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethodCfg.cs b/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethodCfg.cs index 6f53050bf..f3ce41943 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethodCfg.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethodCfg.cs @@ -7,8 +7,8 @@ namespace TBF.BenchControl.TestMethods.CombinedMeters { public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - public TestMethodCfg() + /// Private parameterless constructor invoked by all other (public) constructors + TestMethodCfg() { Name = "CombinedMeters"; ParentName = string.Empty; diff --git a/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethodFactory.cs b/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethodFactory.cs index 16aee3890..05122fbfc 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethodFactory.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/TestMethodFactory.cs @@ -7,11 +7,6 @@ namespace TBF.BenchControl.TestMethods.CombinedMeters { public string ClassName { get { return "CombinedMeters"; } } - public bool HasProcedureParams { get { return false; } } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetTestParams.cs b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetTestParams.cs index b0f0bb76f..a773aaab5 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetTestParams.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetTestParams.cs @@ -7,14 +7,23 @@ using TBF.Resources; namespace TBF.BenchControl.TestMethods.CombinedWithDetection { - public class CombinedWithDetTestParams : IParamsProvider, ITestParams + public class CombinedWithDetTestParams : TestParamsBase, IParamsProvider, ITestParams { public float TargetQ; /// Target=terminal flow durning detection when increasing or decreasing the flow public float RelativeQfrom; /// Tested flow low range related to the detected flow public float RelativeQto; /// Tested flow high range related to the detected flow public float RateOfChange; /// Each step is calculated as (TargetQfrom - Qfrom) * RateOfChange, text form is displayed in % (*100) public float DetectionThreshold;/// Drop of frequency for the detection, text form is displayed in % (*100) - public int SupressTrills; + public int SupressTrills; + + public override void InitializeAll() + { + TargetQ = 3.0f; + RelativeQfrom = -0.4f; + RelativeQto = -0.2f; + RateOfChange = 0.05f; + DetectionThreshold = 0.25f; + } string[] paramNames = new string[] { @@ -25,9 +34,10 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection Strings.DetectionThresholdPct, Strings.SupressWMTrills, }; - public string ParamName(int i) { return paramNames[i]; } + public override string ParamName(int i) { return paramNames[i]; } + public override int ParamsCount() { return paramNames.Length; } - public string ToString(int i) + public override string ToString(int i) { switch (i) { @@ -84,102 +94,43 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection return false; } - #region Boilerplate code - - public int ParamsCount() { return paramNames.Length; } - - public override string ToString() + public override void UpdateTestParams(Entities.ComponentTest dbEntity) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < ParamsCount(); i++) + if (dbEntity == null) return; + try + { + CombinedWithDetTestParams tmp = (CombinedWithDetTestParams)(new XmlSerializer(typeof(CombinedWithDetTestParams))) + .Deserialize(new StringReader(dbEntity.Parameters)); + + testParamsEntity = dbEntity; + componentName = dbEntity.CmpntName; + test = dbEntity.Test; + + TargetQ = tmp.TargetQ; + RelativeQfrom = tmp.RelativeQfrom; + RelativeQto = tmp.RelativeQto; + RateOfChange = tmp.RateOfChange; + DetectionThreshold = tmp.DetectionThreshold; + SupressTrills = tmp.SupressTrills; + + } + catch { - if (i != 0) sb.Append("; "); - sb.Append(ParamName(i)); - sb.Append("="); - sb.Append(ToString(i)); } - return sb.ToString(); } - [XmlIgnore] - public Entities.ComponentTest TestParamsEntity { get { return testParamsEntity; } } - Entities.ComponentTest testParamsEntity; - - [XmlIgnore] - public string ComponentName { get { return componentName; } } - string componentName; - - [XmlIgnore] - public Entities.Test Test { get { return test; } } - Entities.Test test; - - /// Parameterless constructor + /// + /// Parameterless constructor initializes the parameters + /// public CombinedWithDetTestParams() { - TargetQ = 3.0f; - RelativeQfrom = -0.4f; - RelativeQto = -0.2f; - RateOfChange = 0.05f; - DetectionThreshold = 0.25f; } public CombinedWithDetTestParams(Entities.ComponentTest testParamsEntity, string componentName, Entities.Test test) - : this() { this.testParamsEntity = testParamsEntity; this.componentName = componentName; this.test = test; } - - public TBF.Entities.ComponentTest ToDbEntity(IComponent component, Entities.Test test) - { - using (var writer = new StringWriter()) - { - /// Serialize this class with parameters - (new XmlSerializer(GetType())).Serialize(writer, this); - - /// Create and return the ComponentTest entity - TBF.Entities.ComponentTest entity = new TBF.Entities.ComponentTest(); - entity.CmpntName = component.Cfg.Name; - entity.Parameters = writer.ToString(); - entity.Test = test; - return entity; - } - } - - public void UpdateDbEntity() - { - using (var writer = new StringWriter()) - { - /// Serialize this class and update the entity - (new XmlSerializer(GetType())).Serialize(writer, this); - testParamsEntity.Parameters = writer.ToString(); - testParamsEntity.CmpntName = componentName; - testParamsEntity.Test = test; - - } - } - - public static IParamsProvider GetTestParams(Entities.ComponentTest testParamsEntity) - { - if (testParamsEntity == null) return new CombinedWithDetTestParams(); - - CombinedWithDetTestParams testParams; - try - { - testParams = (CombinedWithDetTestParams)(new XmlSerializer(typeof(CombinedWithDetTestParams))) - .Deserialize(new StringReader(testParamsEntity.Parameters)); - } - catch - { - testParams = new CombinedWithDetTestParams(); - } - testParams.testParamsEntity = testParamsEntity; - testParams.componentName = testParamsEntity.CmpntName; - testParams.test = testParamsEntity.Test; - return testParams; - } - - #endregion } } diff --git a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethod.cs b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethod.cs index 5ab52ad41..8b2428c38 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethod.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethod.cs @@ -1,29 +1,27 @@ using System; using System.Collections.Generic; +using log4net; using TBF.BenchControl; -using TBF.BenchControl.Generic; namespace TBF.BenchControl.TestMethods.CombinedWithDetection { - public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence + public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence { + private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); + public override string ToString() { return string.Format("TestMethods.CombinedWithDetection({0})", Cfg.ToString(1)); } + readonly TestMethodCfg testMethodCfg; - public Generic.IComponentCfg Cfg { get { return testMethodCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return testMethodCfg.Name; } } public TestMethod(TestMethodCfg cfg) + : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.testMethodCfg = cfg; + testMethodCfg = cfg; + log.Debug(this.ToString()); } public IList Execute(Entities.Test test) { - IParamsProvider testParams = BenchControl.TbfComponents.GetTestParams(this, test); - return (new CombinedWithDetectionSeq()).Execute(test, testParams as CombinedWithDetTestParams); + return (new CombinedWithDetectionSeq()).Execute(test, testMethodCfg.TestParams); } } } diff --git a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethodCfg.cs b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethodCfg.cs index 308e6226c..cacf9241e 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethodCfg.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethodCfg.cs @@ -7,11 +7,23 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection { public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - public TestMethodCfg() + /// Test parameters + [XmlIgnore] + public CombinedWithDetTestParams TestParams; + public override IParamsProvider GetTestParams() { return TestParams; } + public override IParamsProvider CreateTestParams(Entities.Test test) + { + CombinedWithDetTestParams testParams = new CombinedWithDetTestParams(); + testParams.UpdateTestParams(Name, test); + return testParams; + } + + /// Private parameterless constructor invoked by all other (public) constructors + TestMethodCfg() { Name = "CombinedWithDetection"; ParentName = string.Empty; + TestParams = new CombinedWithDetTestParams(); } public TestMethodCfg(IComponentFactory factory) diff --git a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethodFactory.cs b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethodFactory.cs index 64347ce6f..1372e64c2 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethodFactory.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/TestMethodFactory.cs @@ -31,15 +31,6 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection return ComponentCfgBase.CreateFromDbEntity(typeof(TestMethodCfg), component, this); } - public bool HasProcedureParams { get { return false; } } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } - - public bool HasTestParams { get { return true; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) - { - return CombinedWithDetTestParams.GetTestParams(testParams); - } - public void ResetStaticProperties() { TestMethod.ResetStaticProperties(); } } } diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethod.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethod.cs index 853051311..b12938904 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethod.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethod.cs @@ -1,22 +1,19 @@ using System; using System.Collections.Generic; +using log4net; using TBF.BenchControl; namespace TBF.BenchControl.TestMethods.FixedStartMassCollection { - public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence + public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence { - readonly TestMethodCfg testMethodCfg; - public Generic.IComponentCfg Cfg { get { return testMethodCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return testMethodCfg.Name; } } + private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); + public override string ToString() { return string.Format("TestMethods.FixedStartMassCollection({0})", Cfg.ToString(1)); } public TestMethod(TestMethodCfg cfg) - { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.testMethodCfg = cfg; + : base(cfg) + { + log.Debug(this.ToString()); } public IList Execute(Entities.Test test) diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethodCfg.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethodCfg.cs index 128a2a074..9733a1f44 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethodCfg.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethodCfg.cs @@ -7,8 +7,8 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection { public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - public TestMethodCfg() + /// Private parameterless constructor invoked by all other (public) constructors + TestMethodCfg() { Name = "FixedStartMassCollection"; ParentName = string.Empty; diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethodFactory.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethodFactory.cs index dd8d7da69..cdc97a7ea 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethodFactory.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/TestMethodFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection public class TestMethodFactory : IComponentFactory { public string ClassName { get { return "FixedStartMassCollection"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethod.cs b/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethod.cs index 07b82fa74..740179641 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethod.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethod.cs @@ -1,22 +1,19 @@ using System; using System.Collections.Generic; +using log4net; using TBF.BenchControl; namespace TBF.BenchControl.TestMethods.FlyingStart { - public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence + public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence { - readonly TestMethodCfg testMethodCfg; - public Generic.IComponentCfg Cfg { get { return testMethodCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return testMethodCfg.Name; } } + private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); + public override string ToString() { return string.Format("TestMethods.FlyingStart({0})", Cfg.ToString(1)); } public TestMethod(TestMethodCfg cfg) - { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.testMethodCfg = cfg; + : base(cfg) + { + log.Debug(this.ToString()); } public IList Execute(Entities.Test test) diff --git a/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethodCfg.cs b/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethodCfg.cs index ea79a622a..7b6bce81a 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethodCfg.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethodCfg.cs @@ -7,8 +7,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStart { public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - public TestMethodCfg() + /// Private parameterless constructor invoked by all other (public) constructors + TestMethodCfg() { Name = "FlyingStart"; ParentName = string.Empty; diff --git a/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethodFactory.cs b/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethodFactory.cs index bcf6f07c8..ac6661cd1 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethodFactory.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FlyingStart/TestMethodFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.TestMethods.FlyingStart public class TestMethodFactory : IComponentFactory { public string ClassName { get { return "FlyingStart"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethod.cs b/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethod.cs index 8439cad6d..4cbd0ae51 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethod.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethod.cs @@ -1,22 +1,19 @@ using System; using System.Collections.Generic; +using log4net; using TBF.BenchControl; namespace TBF.BenchControl.TestMethods.FlyingStartCollectionMethod { - public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence + public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence { - readonly TestMethodCfg testMethodCfg; - public Generic.IComponentCfg Cfg { get { return testMethodCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return testMethodCfg.Name; } } + private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); + public override string ToString() { return string.Format("TestMethods.FlyingStartCollectionMethod({0})", Cfg.ToString(1)); } public TestMethod(TestMethodCfg cfg) - { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.testMethodCfg = cfg; + : base(cfg) + { + log.Debug(this.ToString()); } public IList Execute(Entities.Test test) diff --git a/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethodCfg.cs b/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethodCfg.cs index 896a338e9..ddca2ab17 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethodCfg.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethodCfg.cs @@ -7,9 +7,8 @@ namespace TBF.BenchControl.TestMethods.FlyingStartCollectionMethod { public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - /// Parameterless constructor - public TestMethodCfg() + /// Private parameterless constructor invoked by all other (public) constructors + TestMethodCfg() { Name = "FlyingStartCollection"; ParentName = string.Empty; diff --git a/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethodFactory.cs b/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethodFactory.cs index 010ed3249..93e40acd9 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethodFactory.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/TestMethodFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.TestMethods.FlyingStartCollectionMethod public class TestMethodFactory : IComponentFactory { public string ClassName { get { return "Flying-Start-Collection"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethod.cs b/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethod.cs index 7e5369efb..9e6f13faf 100644 --- a/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethod.cs +++ b/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethod.cs @@ -1,22 +1,19 @@ using System; using System.Collections.Generic; +using log4net; using TBF.BenchControl; namespace TBF.BenchControl.TestMethods.ReferenceFlowmeterCalibration { - public class TestMethod : Generic.IComponent, GenericDevices.ITestMethod, ISequence + public class TestMethod : ComponentBase, GenericDevices.ITestMethod, ISequence { - readonly TestMethodCfg testMethodCfg; - public Generic.IComponentCfg Cfg { get { return testMethodCfg; } } - - public static void ResetStaticProperties() { } - - public string Name { get { return testMethodCfg.Name; } } + private static readonly ILog log = LogManager.GetLogger(typeof(TestMethod)); + public override string ToString() { return string.Format("TestMethods.ReferenceFlowmeterCalibration({0})", Cfg.ToString(1)); } public TestMethod(TestMethodCfg cfg) - { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.testMethodCfg = cfg; + : base(cfg) + { + log.Debug(this.ToString()); } public IList Execute(Entities.Test test) diff --git a/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethodCfg.cs b/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethodCfg.cs index 572ec09c9..bf9f56ea2 100644 --- a/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethodCfg.cs +++ b/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethodCfg.cs @@ -7,8 +7,8 @@ namespace TBF.BenchControl.TestMethods.ReferenceFlowmeterCalibration { public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - public TestMethodCfg() + /// Private parameterless constructor invoked by all other (public) constructors + TestMethodCfg() { Name = "ReferenceFlowmeterCalibration"; ParentName = string.Empty; diff --git a/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethodFactory.cs b/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethodFactory.cs index 7d2057703..88d7cc85f 100644 --- a/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethodFactory.cs +++ b/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/TestMethodFactory.cs @@ -6,10 +6,6 @@ namespace TBF.BenchControl.TestMethods.ReferenceFlowmeterCalibration public class TestMethodFactory : IComponentFactory { public string ClassName { get { return "ReferenceFlowmeterCalibration"; } } - public bool HasProcedureParams { get { return false; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) { return null; } /// Max. number of components of this class in the system public int MaxCount { get { return 1; } } diff --git a/TestBenchFramework/BenchControl/TestParamsBase.cs b/TestBenchFramework/BenchControl/TestParamsBase.cs new file mode 100644 index 000000000..377773411 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestParamsBase.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Xml.Serialization; + +namespace TBF.BenchControl +{ + public class TestParamsBase : Generic.ITestParams + { + protected Entities.ComponentTest testParamsEntity; + + public string ComponentName { get { return componentName; } } + protected string componentName; + + public Entities.Test Test { get { return test; } } + protected Entities.Test test; + + /// + /// Parameterless constructor required for serialization + /// + public TestParamsBase() + { + InitializeAll(); + } + + /// To be overridden + public virtual void InitializeAll() + { + } + + /// To be overridden + public virtual void UpdateTestParams(Entities.ComponentTest dbEntity) + { + } + + public void UpdateTestParams(string cmpntName, Entities.Test test) + { + /// Search for an existing matching entity + foreach (var tstPrms in test.MoreParams) + { + if (tstPrms.CmpntName.Equals(cmpntName)) + { + UpdateTestParams(tstPrms); + return; + } + } + + /// Create a new entity and add it to the list test.MoreParams + InitializeAll(); + Entities.ComponentTest componentTest = ToDbEntity(cmpntName, test); + test.MoreParams.Add(componentTest); + } + + public TBF.Entities.ComponentTest ToDbEntity(string componentName, Entities.Test test) + { + using (var writer = new StringWriter()) + { + /// Serialize this class with parameters + (new XmlSerializer(GetType())).Serialize(writer, this); + + /// Create and return the ComponentTest entity + TBF.Entities.ComponentTest entity = new TBF.Entities.ComponentTest(); + entity.CmpntName = componentName; + entity.Parameters = writer.ToString(); + entity.Test = test; + return entity; + } + } + + public void UpdateDbEntity() + { + using (var writer = new StringWriter()) + { + /// Serialize this class and update the entity + (new XmlSerializer(GetType())).Serialize(writer, this); + testParamsEntity.Parameters = writer.ToString(); + testParamsEntity.CmpntName = componentName; + testParamsEntity.Test = test; + } + } + + public virtual string ParamName(int i) { return string.Empty; } + + public virtual int ParamsCount() { return 0; } + + public virtual string ToString(int i) { return string.Empty; } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < ParamsCount(); i++) + { + if (i != 0) sb.Append("; "); + sb.Append(ParamName(i)); + sb.Append("="); + sb.Append(ToString(i)); + } + return sb.ToString(); + } + } +} diff --git a/TestBenchFramework/BenchControl/WaterMeter/ProcParams.cs b/TestBenchFramework/BenchControl/WaterMeter/ProcParams.cs index ba2fff3de..663384452 100644 --- a/TestBenchFramework/BenchControl/WaterMeter/ProcParams.cs +++ b/TestBenchFramework/BenchControl/WaterMeter/ProcParams.cs @@ -7,13 +7,21 @@ using TBF.Resources; namespace TBF.BenchControl.WaterMeter { - public class ProcParams : IParamsProvider, IProcedureParams + public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams { public string Producer; /// Hersteller public float Qn; public string ApprovalInfo; /// Zulassungszeichen public string MetrologicalClass; /// Metr. Klasse + public override void InitializeAll() + { + Producer = ""; + Qn = 2.5f; + ApprovalInfo = ""; + MetrologicalClass = "A"; + } + string[] paramNames = new string[] { Strings.Producer, @@ -21,9 +29,10 @@ namespace TBF.BenchControl.WaterMeter Strings.Approval_info, Strings.Metrological_class, }; - public string ParamName(int i) { return paramNames[i]; } + public override string ParamName(int i) { return paramNames[i]; } + public override int ParamsCount() { return paramNames.Length; } - public string ToString(int i) + public override string ToString(int i) { switch (i) { @@ -70,101 +79,38 @@ namespace TBF.BenchControl.WaterMeter return false; } - #region Boilerplate code - - public int ParamsCount() { return paramNames.Length; } - - public override string ToString() + public override void UpdateProcedureParams(Entities.ComponentProcedure dbEntity) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < ParamsCount(); i++) - { - if (i != 0) sb.Append("; "); - sb.Append(ParamName(i)); - sb.Append("="); - sb.Append(ToString(i)); - } - return sb.ToString(); - } - - [XmlIgnore] - public Entities.ComponentProcedure ProcedureParamsEntity { get { return procParamsEntity; } } - Entities.ComponentProcedure procParamsEntity; - - [XmlIgnore] - public string ComponentName { get { return componentName; } } - string componentName; - - [XmlIgnore] - public Entities.Procedure Test { get { return test; } } - Entities.Procedure test; - - /// Parameterless constructor - public ProcParams() - { - Producer = ""; - Qn = 2.5f; - ApprovalInfo = ""; - MetrologicalClass = "A"; - } - - public ProcParams(Entities.ComponentProcedure procParamsEntity, string componentName, Entities.Procedure test) - : this() - { - this.procParamsEntity = procParamsEntity; - this.componentName = componentName; - this.test = test; - } - - public TBF.Entities.ComponentProcedure ToDbEntity(IComponent component, Entities.Procedure procedure) - { - using (var writer = new StringWriter()) - { - /// Serialize this class with parameters - (new XmlSerializer(GetType())).Serialize(writer, this); - - /// Create and return the ComponentProcedure entity - TBF.Entities.ComponentProcedure entity = new TBF.Entities.ComponentProcedure(); - entity.CmpntName = component.Cfg.Name; - entity.Parameters = writer.ToString(); - entity.Procedure = procedure; - return entity; - } - } - - public void UpdateDbEntity() - { - using (var writer = new StringWriter()) - { - /// Serialize this class and update the entity - (new XmlSerializer(GetType())).Serialize(writer, this); - procParamsEntity.Parameters = writer.ToString(); - procParamsEntity.CmpntName = componentName; - procParamsEntity.Procedure = test; - - } - } - - public static IParamsProvider GetProcedureParams(Entities.ComponentProcedure procParamsEntity) - { - if (procParamsEntity == null) return new ProcParams(); - - ProcParams procParams; + if (dbEntity == null) return; try { - procParams = (ProcParams)(new XmlSerializer(typeof(ProcParams))) - .Deserialize(new StringReader(procParamsEntity.Parameters)); + ProcParams tmp = (ProcParams)(new XmlSerializer(typeof(ProcParams))) + .Deserialize(new StringReader(dbEntity.Parameters)); + + procedureParamsEntity = dbEntity; + componentName = dbEntity.CmpntName; + procedure = dbEntity.Procedure; + + Producer = tmp.Producer; + Qn = tmp.Qn; + ApprovalInfo = tmp.ApprovalInfo; + MetrologicalClass = tmp.MetrologicalClass; } catch { - procParams = new ProcParams(); } - procParams.procParamsEntity = procParamsEntity; - procParams.componentName = procParamsEntity.CmpntName; - procParams.test = procParamsEntity.Procedure; - return procParams; } - #endregion + + public ProcParams() + { + } + + public ProcParams(Entities.ComponentProcedure procParamsEntity, string componentName, Entities.Procedure procedure) + { + this.procedureParamsEntity = procParamsEntity; + this.componentName = componentName; + this.procedure = procedure; + } } } diff --git a/TestBenchFramework/BenchControl/WaterMeter/WaterMeter.cs b/TestBenchFramework/BenchControl/WaterMeter/WaterMeter.cs index a4aa72cbd..ca3e03cf6 100644 --- a/TestBenchFramework/BenchControl/WaterMeter/WaterMeter.cs +++ b/TestBenchFramework/BenchControl/WaterMeter/WaterMeter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using log4net; using TBF.BenchControl; namespace TBF.BenchControl.WaterMeter @@ -7,35 +8,24 @@ namespace TBF.BenchControl.WaterMeter /// /// This component = instance of this class is a placeholder for a combined main watermeter /// - public class WaterMeter : ComponentBase, Generic.IComponent, GenericDevices.IWaterMeter + public class WaterMeter : ComponentBase, GenericDevices.IWaterMeter { - readonly WaterMeterCfg combinedMainCfg; + private static readonly ILog log = LogManager.GetLogger(typeof(WaterMeter)); + public override string ToString() { return string.Format("WaterMeter({0})", Cfg.ToString(1)); } - public static void ResetStaticProperties() { } + readonly WaterMeterCfg waterMeterCfg; /// WaterMeter producer - public string Producer - { - get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Producer : ""; } - } + public string Producer { get { return waterMeterCfg. ProcParams.Producer; } } /// Nominal water flow in [m3/h] - public float Qn - { - get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).Qn : 0; } - } + public float Qn { get { return waterMeterCfg. ProcParams.Qn; } } /// WaterMeter approval information or signature - public string ApprovalInfo - { - get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).ApprovalInfo : ""; } - } + public string ApprovalInfo { get { return waterMeterCfg. ProcParams.ApprovalInfo; } } /// Metrological class - public string MetrologicalClass - { - get { return (ProcedureParams is ProcParams) ? (ProcedureParams as ProcParams).MetrologicalClass : ""; } - } + public string MetrologicalClass { get { return waterMeterCfg. ProcParams.MetrologicalClass; } } /// Properties set by the Begin and the End form public string SerialNr @@ -62,8 +52,8 @@ namespace TBF.BenchControl.WaterMeter public WaterMeter(WaterMeterCfg cfg) : base(cfg) { - if (cfg == null) throw new ArgumentNullException("cfg"); - this.combinedMainCfg = cfg; + waterMeterCfg = cfg; + log.Debug(this.ToString()); } } } diff --git a/TestBenchFramework/BenchControl/WaterMeter/WaterMeterCfg.cs b/TestBenchFramework/BenchControl/WaterMeter/WaterMeterCfg.cs index 29362c58b..06107a8d8 100644 --- a/TestBenchFramework/BenchControl/WaterMeter/WaterMeterCfg.cs +++ b/TestBenchFramework/BenchControl/WaterMeter/WaterMeterCfg.cs @@ -8,12 +8,24 @@ namespace TBF.BenchControl.WaterMeter { public class WaterMeterCfg : ComponentCfgBase, Generic.IComponentCfg { - /// Parameterless constructor - public WaterMeterCfg() + /// Procedure parameters + [XmlIgnore] + public ProcParams ProcParams; + public override IParamsProvider GetProcedureParams() { return ProcParams; } + public override IParamsProvider CreateProcedureParams(Entities.Procedure procedure) + { + ProcParams procParams = new ProcParams(); + procParams.UpdateProcedureParams(Name, procedure); + return procParams; + } + + /// Private parameterless constructor invoked by all other (public) constructors + WaterMeterCfg() { Name = "WaterMeter"; ParentName = string.Empty; - } + ProcParams = new ProcParams(); + } public WaterMeterCfg(IComponentFactory factory) : this() diff --git a/TestBenchFramework/BenchControl/WaterMeter/WaterMeterFactory.cs b/TestBenchFramework/BenchControl/WaterMeter/WaterMeterFactory.cs index 19d2422f7..3dd8b9ee5 100644 --- a/TestBenchFramework/BenchControl/WaterMeter/WaterMeterFactory.cs +++ b/TestBenchFramework/BenchControl/WaterMeter/WaterMeterFactory.cs @@ -6,13 +6,6 @@ namespace TBF.BenchControl.WaterMeter public class WaterMeterFactory : IComponentFactory { public string ClassName { get { return "WaterMeter"; } } - public bool HasProcedureParams { get { return true; } } - public bool HasTestParams { get { return false; } } - public IParamsProvider GetTestParams(Entities.ComponentTest testParams) { return null; } - public IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams) - { - return ProcParams.GetProcedureParams(procedureParams); - } /// Max. number of components of this class in the system public int MaxCount { get { return int.MaxValue; } } diff --git a/TestBenchFramework/Entities/ComponentProcedure.cs b/TestBenchFramework/Entities/ComponentProcedure.cs index 399a1c693..4f3d43d48 100644 --- a/TestBenchFramework/Entities/ComponentProcedure.cs +++ b/TestBenchFramework/Entities/ComponentProcedure.cs @@ -13,6 +13,7 @@ namespace TBF.Entities ComponentProcedure result = new ComponentProcedure(); result.CmpntName = CmpntName; result.Parameters = Parameters; + result.Procedure = Procedure; return result; } } diff --git a/TestBenchFramework/Entities/ComponentTest.cs b/TestBenchFramework/Entities/ComponentTest.cs index c9d43a15e..6fa5f7e6c 100644 --- a/TestBenchFramework/Entities/ComponentTest.cs +++ b/TestBenchFramework/Entities/ComponentTest.cs @@ -13,6 +13,7 @@ namespace TBF.Entities ComponentTest result = new ComponentTest(); result.CmpntName = CmpntName; result.Parameters = Parameters; + result.Test = Test; return result; } } diff --git a/TestBenchFramework/ProcedureDlg.cs b/TestBenchFramework/ProcedureDlg.cs index 9ba7c6b54..595af508b 100644 --- a/TestBenchFramework/ProcedureDlg.cs +++ b/TestBenchFramework/ProcedureDlg.cs @@ -133,7 +133,7 @@ namespace TBF testParamsCtrls = new List(); foreach (var method in UsedTestMethods) { - if (method.Cfg.Factory.HasTestParams) + if (method.Cfg.GetTestParams() != null) { TabPage nwTab = new TabPage(method.Cfg.Name); TestParamsCtrl testParamsCtrl = new TestParamsCtrl(this, method, true); @@ -205,7 +205,7 @@ namespace TBF /// Create a control for another component with Test parameters which was not handled yet foreach (var cmpnt in TbfComponents) { - if (cmpnt.Cfg.Factory.HasTestParams && !(cmpnt is ITestMethod)) + if ((cmpnt.Cfg.GetTestParams() != null) && !(cmpnt is ITestMethod)) { newTab = new TabPage(cmpnt.Cfg.Name); TestParamsCtrl testParamsCtrl = new TestParamsCtrl(this, cmpnt, true); diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index 2a748b113..cf6cb0b6c 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -381,6 +381,7 @@ + @@ -485,6 +486,7 @@ TestMethodCfgCtrl.cs + diff --git a/TestBenchFramework/UiControls/ProcedureParamsCtrl.cs b/TestBenchFramework/UiControls/ProcedureParamsCtrl.cs index 538e49a2b..1711242ac 100644 --- a/TestBenchFramework/UiControls/ProcedureParamsCtrl.cs +++ b/TestBenchFramework/UiControls/ProcedureParamsCtrl.cs @@ -6,8 +6,8 @@ using TBF.Resources; namespace TBF.UiControls { - /// /---------------\ - /// / Path or other \ + /// --------------- + /// / Path or other \ /// |------------------------------ /// | param1 param2 param3 ... /// Component1 | @@ -64,20 +64,10 @@ namespace TBF.UiControls foreach (var cmpnt in selectedCmpnts) { - if (cmpnt != null && cmpnt.Cfg.Factory.HasProcedureParams) + if (cmpnt != null && (cmpnt.Cfg.GetProcedureParams() != null)) { - IParamsProvider procedureParams = BenchControl.TbfComponents.GetProcedureParams(cmpnt, parent.LoadedProcedure); - if (procedureParams != null) - { - if (sampleToCreateHeader == null) sampleToCreateHeader = procedureParams; - } - else - { - Entities.ComponentProcedure entity = new Entities.ComponentProcedure(); - entity.CmpntName = cmpnt.Cfg.Name; - entity.Procedure = parent.LoadedProcedure; - procedureParams = cmpnt.Cfg.Factory.GetProcedureParams(entity); - } + IParamsProvider procedureParams = cmpnt.Cfg.CreateProcedureParams(parent.LoadedProcedure); + if (sampleToCreateHeader == null) sampleToCreateHeader = procedureParams; cmpntsParams.Add(procedureParams); } else diff --git a/TestBenchFramework/UiControls/TestParamsCtrl.cs b/TestBenchFramework/UiControls/TestParamsCtrl.cs index 76beb53d2..afa3525b1 100644 --- a/TestBenchFramework/UiControls/TestParamsCtrl.cs +++ b/TestBenchFramework/UiControls/TestParamsCtrl.cs @@ -6,8 +6,8 @@ using TBF.Resources; namespace TBF.UiControls { - // /-----------\ - // / Component \ + // ----------- + // / Component \ // |------------------------------ // | param1 param2 param3 ... // Test1 | @@ -20,7 +20,7 @@ namespace TBF.UiControls bool showTestsColumn; BenchControl.Generic.IComponent cmpnt; - IList testsParams; + IList testParamsProviders; int paramsCount; @@ -32,7 +32,7 @@ namespace TBF.UiControls public TestParamsCtrl() { InitializeComponent(); - testsParams = new List(); + testParamsProviders = new List(); } public TestParamsCtrl(ProcedureDlg parent, BenchControl.Generic.IComponent cmpnt, bool showTestsColumn) @@ -64,27 +64,18 @@ namespace TBF.UiControls /// For each test (with an appropriate method in case of ITestMethod-s) foreach (var test in parent.LoadedProcedure.Tests) { - if (!(cmpnt is BenchControl.GenericDevices.ITestMethod) || test.Method == cmpnt.Cfg.Name) + if ((cmpnt.Cfg.GetTestParams() != null) && + (!(cmpnt is BenchControl.GenericDevices.ITestMethod) || (test.Method == cmpnt.Cfg.Name))) { /// Load ComponentTest entity or create it if it does not exist - IParamsProvider testParams = BenchControl.TbfComponents.GetTestParams(cmpnt, test); - if (testParams != null) - { - if (sampleToCreateHeader == null) sampleToCreateHeader = testParams; - } - else - { - Entities.ComponentTest entity = new Entities.ComponentTest(); - entity.CmpntName = cmpnt.Cfg.Name; - entity.Test = test; - testParams = cmpnt.Cfg.Factory.GetTestParams(entity); - } - testsParams.Add(testParams); + IParamsProvider testParams = cmpnt.Cfg.CreateTestParams(test); + if (sampleToCreateHeader == null) sampleToCreateHeader = testParams; + testParamsProviders.Add(testParams); } else { /// In case of ITestMethod: Insert null for a test without an appropriate method. - testsParams.Add(null); + testParamsProviders.Add(null); } } @@ -131,9 +122,9 @@ namespace TBF.UiControls public void RedrawAll() { listViewEx.Items.Clear(); - for (int i = 0; i < testsParams.Count && i < parent.LoadedProcedure.Tests.Count; i++) + for (int i = 0; i < testParamsProviders.Count && i < parent.LoadedProcedure.Tests.Count; i++) { - DrawOne(testsParams[i], parent.LoadedProcedure.Tests[i].Name); + DrawOne(testParamsProviders[i], parent.LoadedProcedure.Tests[i].Name); } } @@ -170,12 +161,12 @@ namespace TBF.UiControls entity.Test = test; IParamsProvider testParams = new BenchControl.TestMethods.CombinedWithDetection.CombinedWithDetTestParams(entity, cmpnt.Cfg.Name, test); - testsParams.Add(testParams); + testParamsProviders.Add(testParams); DrawOne(testParams, test.Name); } else { - testsParams.Add(null); + testParamsProviders.Add(null); DrawOne(null, null); } }