Everything works OK after serious changes:

- all components, componentCfg-s and parameter providers use base classes
 - less boilerplate code, simpler access to test/procedure parameters from code
 - CreateTestParams(test), CreateProcedureParams(procedure) methods added
 - TestBenchSim class is made static, it is not inheritted by any device anymore
This commit is contained in:
Milan Hanajik 2014-12-31 13:46:33 +01:00
parent 752719bd62
commit 94de991bf6
126 changed files with 1117 additions and 1629 deletions

View File

@ -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
{
/// <summary>
/// Holds information identifying the test bench.
/// </summary>
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());
}
}

View File

@ -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;

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return int.MaxValue; } }

View File

@ -13,31 +13,23 @@ namespace TBF.BenchControl.Cameras.CameraRoi
/// IdcCamera object represents all IDC cameras.
/// Camera ID is an argument of most methods.
/// </summary>
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<Generic.IComponent> 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());
}
/// <summary>
@ -86,7 +80,7 @@ namespace TBF.BenchControl.Cameras.CameraRoi
/// <returns>Reference to operation object instance</returns>
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
/// <returns>Reference to operation object instance</returns>
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,

View File

@ -9,12 +9,24 @@ namespace TBF.BenchControl.Cameras.CameraRoi
{
public int RoiNr; /// ROI number 1..4
/// Parameterless constructor
public CameraRoiCfg()
/// <summary> Procedure parameters </summary>
[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)

View File

@ -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(); }
}
}

View File

@ -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
}
}
/// <summary>
/// Parameterless constructor - sets default values of parameters.
/// </summary>
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
}
}

View File

@ -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
/// </summary>
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;
/// <summary>
/// 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<Generic.IComponent> components)
: base(cfg)
{
if (cfg == null) throw new ArgumentNullException("cfg");
this.idcCameraCfg = cfg;
idcCameraCfg = cfg;
cameraNr = nextCameraNr++;
log.Debug(this.ToString());
}
public void Initialize()

View File

@ -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));
}
}
}

View File

@ -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(); }
}
}

View File

@ -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<MeasurementCorrection> 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; } }
/// <summary>
/// Reference to an object with procedure parameters
/// </summary>
public IParamsProvider ProcedureParams;
///
public void GetProcedureParams(TBF.Entities.Procedure procedure)
{
if (Cfg.Factory.HasProcedureParams)
{
ProcedureParams = TbfComponents.GetProcedureParams(this, procedure);
}
}
/// <summary>
/// Reference to an object with test parameters
/// </summary>
public IParamsProvider TestParams;
///
public void GetTestParams(TBF.Entities.Test test)
{
if (Cfg.Factory.HasTestParams)
{
TestParams = TbfComponents.GetTestParams(this, test);
}
}
/// <summary>
/// Empty implementation, might be overriden in derived classes
/// </summary>
public static void ResetStaticProperties()
{
}
}
}

View File

@ -115,5 +115,57 @@ namespace TBF.BenchControl
return config;
}
}
}
/// <summary>
/// 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.
/// </summary>
/// <returns>Test parameters obtained by the last UpdateTestParams(test)</returns>
public virtual IParamsProvider GetTestParams()
{
return null;
}
/// <summary>
/// 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.
/// </summary>
/// <returns>Procedure parameters obtained by the last UpdateProcedureParams(procedure)</returns>
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;
}
}
}

View File

@ -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; } }
/// <summary>
/// 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;
/// <summary> Not supported in Munich </summary>
public string SerialNr(int wmNr) { return string.Empty; }
/// <summary> Not supported in Munich </summary>
public string SerialNr(int wmNr)
{
return string.Empty;
}
/// <summary> Not supported in Munich </summary>
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());
}

View File

@ -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),

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }

View File

@ -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; } }
/// <summary>
/// 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;
/// <summary> Not supported in Munich </summary>
public string SerialNr(int wmNr) { return string.Empty; }
/// <summary> Not supported in Munich </summary>
public string SerialNr(int wmNr)
{
return string.Empty;
}
/// <summary> Not supported in Munich </summary>
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());
}

View File

@ -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),

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }

View File

@ -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; } }
/// <summary>
/// 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());
}

View File

@ -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;

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }

View File

@ -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);
}
}
}

View File

@ -8,26 +8,12 @@ using log4net;
namespace TBF.BenchControl.Elde
{
public class ControlBoardDev : IComponent, IDevice, IValveControl
public class ControlBoardDev : ComponentBase, IDevice, IValveControl
{
/// <summary>
/// Info:
/// Warn:
/// Error:
/// </summary>
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
/// </summary>
public ControlBoardDev(ControlBoardCfg cfg, IList<Generic.IComponent> 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());
}
/// <summary>
/// Specific pre-initialization for control board only

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }

View File

@ -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);
}

View File

@ -4,34 +4,25 @@ using log4net;
namespace TBF.BenchControl.Elde.Diverter
{
public class Diverter : Generic.IComponent, GenericDevices.IDiverter
public class Diverter : ComponentBase, GenericDevices.IDiverter
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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<Generic.IComponent> 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; }
}
}
}

View File

@ -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);
}

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 5; } }

View File

@ -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;
}
}
/// <summary>
/// Parameterless constructor - sets default values of parameters.
/// </summary>
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;
}
}
}

View File

@ -7,35 +7,22 @@ namespace TBF.BenchControl.Elde.FixedStartRegisterReader
{
public class RegisterReader : ComponentBase, GenericDevices.IRegisterReader
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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<Generic.IComponent> 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");

View File

@ -7,11 +7,23 @@ namespace TBF.BenchControl.Elde.FixedStartRegisterReader
{
public class RegisterReaderCfg : ComponentCfgBase, Generic.IChildComponentCfg
{
/// Parameterless constructor
public RegisterReaderCfg()
/// <summary> Procedure parameters </summary>
[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)

View File

@ -64,7 +64,6 @@ namespace TBF.BenchControl.Elde.FixedStartRegisterReader
{
CfgVerifyFlags flags = CfgVerifyFlags.None;
int dummy;
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
{
flags |= CfgVerifyFlags.Error;

View File

@ -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(); }
}
}

View File

@ -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
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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<Entities.MeasurementCorrection> 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<Generic.IComponent> 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

View File

@ -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";

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 7; } }

View File

@ -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
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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<Entities.MeasurementCorrection> 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<Generic.IComponent> 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

View File

@ -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";

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }

View File

@ -6,25 +6,12 @@ using TBF.Boxes;
namespace TBF.BenchControl.Elde.PressureMeter
{
public class PressureMeter : IComponent, GenericDevices.IPressureMeter
public class PressureMeter : ComponentBase, GenericDevices.IPressureMeter
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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<Entities.MeasurementCorrection> 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<Generic.IComponent> 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");

View File

@ -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";

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 5; } }

View File

@ -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
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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<Generic.IComponent> 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());
}

View File

@ -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";

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return int.MaxValue; } }

View File

@ -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
}
}

View File

@ -6,24 +6,14 @@ namespace TBF.BenchControl.Elde.PumpWithFM
{
public class Pump : ComponentBase, GenericDevices.IPumpFM, GenericDevices.IValve, IOperation
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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<Generic.IComponent> 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());
}

View File

@ -10,14 +10,26 @@ namespace TBF.BenchControl.Elde.PumpWithFM
public int FMIndex;
public int Delay;
/// Parameterless constructor
public PumpCfg()
/// <summary> Test parameters </summary>
[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)

View File

@ -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);
}
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return int.MaxValue; } }

View File

@ -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;
}
}
/// <summary>
/// Parameterless constructor - sets default values of parameters.
/// </summary>
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
}
}

View File

@ -7,40 +7,25 @@ namespace TBF.BenchControl.Elde.RegisterReader
{
public class RegisterReader : ComponentBase, GenericDevices.IRegisterReader
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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<Generic.IComponent> 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());

View File

@ -8,13 +8,25 @@ namespace TBF.BenchControl.Elde.RegisterReader
public class RegisterReaderCfg : ComponentCfgBase, Generic.IChildComponentCfg
{
public int Position; /// 1..nrWaterMeters
/// Parameterless constructor
public RegisterReaderCfg()
/// <summary> Procedure parameters </summary>
[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)

View File

@ -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(); }
}
}

View File

@ -19,9 +19,6 @@ namespace TBF.BenchControl.Elde.RegulValve
readonly int regulValveNr;
readonly float timePulseSec;
/// Process values
bool firstRun;
/// <summary>
/// Set required water flow.
/// Events: FlowSet, FlowTimeOut
@ -49,7 +46,6 @@ namespace TBF.BenchControl.Elde.RegulValve
/// <summary>Start this operation</summary>
public void Start()
{
firstRun = true;
float positionPct = controlBoard.RValvePosition(regulValveNr);
log.WarnFormat("RV#={0}, actPos={1}%", regulValveNr, positionPct.ToString("F1"));

View File

@ -6,35 +6,23 @@ using TBF.Boxes;
namespace TBF.BenchControl.Elde.RegulValve
{
public class RegulValve : IComponent, GenericDevices.IRegulValve
public class RegulValve : ComponentBase, GenericDevices.IRegulValve
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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<float, float> dict;
public IDictionary<float, float> 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<Generic.IComponent> 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<float, float>();
this.controlBoard.RegValveCalib[Idx1 - 1, 0] = (uint)DacValueClosed;

View File

@ -20,8 +20,8 @@ namespace TBF.BenchControl.Elde.RegulValve
/// </summary>
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";

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 5; } }

View File

@ -6,49 +6,30 @@ using TBF.Boxes;
namespace TBF.BenchControl.Elde.TempMeter
{
public class TempMeter : IComponent, GenericDevices.ITempMeter
public class TempMeter : ComponentBase, GenericDevices.ITempMeter
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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<Generic.IComponent> 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;

View File

@ -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";

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 8; } }

View File

@ -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
{
/// <summary>
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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<Generic.IComponent> 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());

View File

@ -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";

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return int.MaxValue; } }

View File

@ -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; }
}
}

View File

@ -39,8 +39,25 @@ namespace TBF.BenchControl.Generic
/// </summary>
IList<Entities.MeasurementCorrection> Corrections { get; set; }
/// <summary>
/// Creates a new database entity 'Component' from the parameters
/// </summary>
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);
}
}

View File

@ -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
/// <summary>
/// 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
/// </summary>
IComponentCfg CmpntCfgFromCmpntEntity(Entities.Component component);
IParamsProvider GetTestParams(Entities.ComponentTest testParams);
IParamsProvider GetProcedureParams(Entities.ComponentProcedure procedureParams);
void ResetStaticProperties();
}

View File

@ -20,7 +20,12 @@ namespace TBF.BenchControl.Generic
/// Parameter values in string form
/// </summary>
/// <param name="ix">Zero based index of the parameter</param>
string ToString(int i);
string ToString(int ix);
/// <summary>
/// Initialize values of all parameters
/// </summary>
void InitializeAll();
/// <summary>
/// Validates the string representation of a parameter

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -5,8 +5,15 @@ using System.Text;
namespace TBF.BenchControl.GenericDevices
{
public class ValveBase
public class ValveBase : ComponentBase
{
/// <summary>
/// Invokes ComponentBase constructor
/// </summary>
public ValveBase(Generic.IComponentCfg cfg) : base(cfg)
{
}
/// <summary>
/// Process the list of components and return all valves (masters and coupled)
/// </summary>

View File

@ -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.
/// </summary>
public class Ambient : TestBenchSim, IComponent, IDevice, IOperation, GenericDevices.IAmbient
public class Ambient : ComponentBase, IDevice, IOperation, GenericDevices.IAmbient
{
/// <summary>
/// Info: Successful measurement
/// Warn: Invalid serial response format
/// </summary>
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.
/// </summary>
public Ambient(AmbientCfg cfg, IList<Generic.IComponent> 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;
}

View File

@ -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);
}
}

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }

View File

@ -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);
}
}

View File

@ -15,71 +15,63 @@ namespace TBF.BenchControl.MettlerToledo
/// <note>
/// Implemented and tested on 15.10.2013 by Milan Hanajik
/// </note>
public class BalanceDev : TestBenchSim, IComponent, IDevice, GenericDevices.IBalance
public class BalanceDev : ComponentBase, IDevice, GenericDevices.IBalance
{
/// <summary>
/// Info: StartMassMeasurement() and "Balnce response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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)); }
/// <summary>
protected readonly BalanceCfg balanceCfg;
/// <summary>
/// Enumeration of balances via static fields and methods
/// </summary>
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<Entities.MeasurementCorrection> Corrections { get { return balanceCfg.Corrections; } }
/// <summary>The state of the mass measurement</summary>
public MsrmntState MsrmntState
{
get { return msrmntState; }
}
public MsrmntState MsrmntState { get { return msrmntState; } }
protected MsrmntState msrmntState;
/// <summary>The mass after StartMassMeasurement() when MsrmntState == MsrmntState.Valid</summary>
public float Mass
{
get { return mass; }
}
public float Mass { get { return mass; } }
protected float mass;
/// <summary>The time stamp after StartMassMeasurement() when MsrmntState == MsrmntState.Valid</summary>
public int MsrmntTimeStamp
{
get { return msrmntTimeStamp; }
}
public int MsrmntTimeStamp { get { return msrmntTimeStamp; } }
protected int msrmntTimeStamp;
/// <summary>
/// Constructor
/// </summary>
/// <param name="balanceEntity">Balance properties</param>
/// <param name="cfg">Balance properties</param>
/// <param components="cfg">A list of components loaded so far</param>
public BalanceDev(BalanceCfg cfg, IList<Generic.IComponent> 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;

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 5; } }

View File

@ -14,28 +14,24 @@ namespace TBF.BenchControl.MettlerToledo
/// <note>
/// Implemented and tested on 15.10.2013 by Milan Hanajik
/// </note>
public class BalanceNewDev : BalanceDev, IComponent, IDevice, GenericDevices.IBalance2
public class BalanceNewDev : BalanceDev, IDevice, GenericDevices.IBalance2
{
/// <summary>
/// Info: StartMassMeasurement() and "Balnce response = .., Mass = ..."
/// Warn: Start measurement when busy is true
/// </summary>
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)); }
/// <summary>Serial number after GetSerialNumber() when MsrmntState == MsrmntState.Valid</summary>
public string SerialNumber
{
get { return serialNumber; }
}
public string SerialNumber { get { return serialNumber; } }
string serialNumber;
public BalanceNewDev(BalanceCfg cfg, IList<Generic.IComponent> components)
: base(cfg, components)
{
}
log.Debug(this.ToString());
}
/// <summary>
/// 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;

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 5; } }

View File

@ -17,7 +17,6 @@ namespace TBF.BenchControl.Operations
IntBox[] pulses;
IntBox[] refPulses;
IOperation[] readRegOps;
Event[] events;
/// <summary>
/// Events: eventDone (default=Event.ReadRegisterDone) or Event.Error

View File

@ -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;
/// <summary>
/// Parameterless constructor required for serialization
/// </summary>
public ProcedureParamsBase()
{
InitializeAll();
}
/// <summary> To be overridden </summary>
public virtual void InitializeAll()
{
}
/// <summary> To be overridden </summary>
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();
}
}
}

View File

@ -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; } }
/// <summary>
/// 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());
}
/// <summary>

View File

@ -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;

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }

View File

@ -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;
/// <summary>
/// Data to print
@ -19,32 +21,17 @@ namespace TBF.BenchControl.ResultsPrinters.Munich
public IList<GenericDevices.IWaterMeter> WaterMeters;
public IList<Entities.TestResult> 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());
}
/// <summary>Events: ResultsPrinted</summary>

View File

@ -7,11 +7,23 @@ namespace TBF.BenchControl.ResultsPrinters.Munich
{
public class PrinterCfg : ComponentCfgBase, Generic.IComponentCfg
{
/// Parameterless constructor
public PrinterCfg()
/// <summary> Procedure parameters </summary>
[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)

View File

@ -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);
}
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }

View File

@ -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;
}
}
}

View File

@ -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; } }
/// <summary>
/// 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());
}
/// <summary>

View File

@ -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;

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -7,7 +7,7 @@ namespace TBF.BenchControl
/// Test bench model inherited by all classes for the simulation of devices.
/// Define DN100, MUNICH or nothing.
/// </summary>
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
/// <summary>Run this device</summary>
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")
)
);
}
/// <summary>
/// Calculate the mass change from the flow and the time period
/// </summary>
/// <param name="flowM3H">Flow in [m3/h]</param>
/// <param name="timeSec">Time period in [s]</param>
/// <returns>Mass change in [kg]</returns>
float DiffKg(float flowM3H, float timeSec)
static float DiffKg(float flowM3H, float timeSec)
{
return timeSec * flowM3H / 3.6f;
}
/// <summary>
/// Get the simulated mass. Use the balance range to distinguish the balances.
/// </summary>
/// <param name="balanceNr">0-based balance number</param>
/// <returns>Simulated mass reading [kg]</returns>
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;
}
/// <summary>
/// Set the simulated diverter. Use the nominal flow to distinguish the path.
/// </summary>
/// <param name="toTank">Diverter state: true = to the tank</param>
/// <param name="nominalFlow">Nominal flow of the path [m3/h]</param>
public void SetSimDiverter(bool toTank)
public static void SetSimDiverter(bool toTank)
{
#if DN100
switch (regulValveNo)
@ -343,60 +377,12 @@ namespace TBF.BenchControl
return;
}
/// <summary>
/// Determine which autput section is used
/// </summary>
/// <param name="nominalFlow"></param>
/// <returns></returns>
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
}
/// <summary>
/// Get the simulated flow in [m3/h].
/// </summary>
/// <returns>Simulated flow [m3/h]</returns>
public float GetSimFlow()
public static float GetSimFlow()
{
switch (refFlowmtrNo)
{
@ -409,12 +395,13 @@ namespace TBF.BenchControl
}
}
/// <summary>
/// Update simulated flow. Use the nominal flow to distinguish the path.
/// </summary>
/// <param name="targetFlow">Target flow [m3/h]</param>
/// <param name="nominalFlow">Nominal flow of the path [m3/h]</param>
public void UpdateSimFlow(float targetFlow)
public static void UpdateSimFlow(float targetFlow)
{
float A = 0.7f; /// higher value -> slower regulation
float B = 1.0f - A;

View File

@ -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<Event> Execute(Entities.Test test)

View File

@ -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;

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }

View File

@ -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<Event> Execute(Entities.Test test)

View File

@ -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;

View File

@ -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; }
/// <summary>Max. number of components of this class in the system</summary>
public int MaxCount { get { return 1; } }

View File

@ -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
/// <summary>
/// Parameterless constructor initializes the parameters
/// </summary>
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
}
}

Some files were not shown because too many files have changed in this diff Show More