113 lines
4.2 KiB
C#
113 lines
4.2 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using log4net;
|
|
using TBF.BenchControl;
|
|
using TBF.BenchControl.Generic;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.BenchControl.Cameras.CameraRoi
|
|
{
|
|
/// <summary>
|
|
/// IdcCamera object represents all IDC cameras.
|
|
/// Camera ID is an argument of most methods.
|
|
/// </summary>
|
|
public class CameraRoi : ComponentBase, IComponent, 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()
|
|
{
|
|
}
|
|
|
|
readonly CameraRoiCfg cameraRoiCfg;
|
|
|
|
readonly GenericDevices.ICamera camera;
|
|
public GenericDevices.ICamera Camera { get { return camera; } }
|
|
|
|
public float PulsesPerLtr
|
|
{
|
|
get { return (ProcedureParams as RoiProcedureParams).GradPerLtr; }
|
|
}
|
|
|
|
public CameraRoi(CameraRoiCfg cfg, IList<Generic.IComponent> components)
|
|
: base(cfg)
|
|
{
|
|
if (cfg == null) throw new ArgumentNullException("cfg");
|
|
this.cameraRoiCfg = cfg;
|
|
if (cfg.DebugLevel != Entities.DebugMode.Off)
|
|
{
|
|
camera = TbfComponents.FindComponent(cfg.ParentName, components) as GenericDevices.ICamera;
|
|
if ((camera == null) && (cfg.DebugLevel != Entities.DebugMode.Inherit))
|
|
{
|
|
throw new Exception("Cannot find " + Name + " parent");
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Events: Event.ReadRegisterDone, Event.Error
|
|
/// </summary>
|
|
/// <param name="pulses">Reference to a variable for the water meter pulses</param>
|
|
/// <returns>ReadWaterMeter instance reference casted to IOperaton</returns>
|
|
public IOperation ReadRegisterOp(ref IntBox pulses)
|
|
{
|
|
return new ReadRegisterOp(this, ref pulses);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Events: Event.ReadRegisterDone, Event.Error
|
|
/// </summary>
|
|
/// <param name="pulses">Reference to a variable for the water meter pulses</param>
|
|
/// <param name="pulses">Reference to a variable for the related reference flow meter pulses</param>
|
|
/// <returns>ReadWaterMeter instance reference casted to IOperaton</returns>
|
|
public IOperation ReadRegisterOp(ref IntBox pulses, ref IntBox refPulses)
|
|
{
|
|
return new ReadRegisterOp(this, ref pulses, ref refPulses);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Events: ReadReferenceDone, Error
|
|
/// </summary>
|
|
/// <param name="pulses">Reference to a variable for the water meter pulses</param>
|
|
/// <returns>ReadWaterMeter instance reference casted to IOperaton</returns>
|
|
public IOperation ReadReferenceForRegisterOp(ref IntBox pulses, ref IntBox refPulses)
|
|
{
|
|
return null; /// not implemented
|
|
}
|
|
|
|
/// <summary>
|
|
/// Watermeter wheel/arrow detection process.
|
|
/// </summary>
|
|
/// <param name="roiId">Region of interest (1..4)</param>
|
|
/// <returns>Reference to operation object instance</returns>
|
|
public IOperation DetectOp()
|
|
{
|
|
RoiProcedureParams pp = ProcedureParams as RoiProcedureParams;
|
|
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,
|
|
pp.Ang1, pp.Ang2, pp.AngStep, pp.CCW, (pp.CCW ? -30 : 30),
|
|
pp.SequenceLen, pp.SequenceTiming, pp.BackgroundCorr,
|
|
pp.BrightnessRoi * camera.Brightness));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Watermeter wheel/arrow angle measurement process.
|
|
/// </summary>
|
|
/// <param name="roiId">Region of interest (1..4)</param>
|
|
/// <returns>Reference to operation object instance</returns>
|
|
public IOperation MeasureOp()
|
|
{
|
|
RoiProcedureParams pp = ProcedureParams as RoiProcedureParams;
|
|
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,
|
|
pp.BrightnessRoi * camera.Brightness));
|
|
}
|
|
}
|
|
}
|