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:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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(); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user