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 { /// /// IdcCamera object represents all IDC cameras. /// Camera ID is an argument of most methods. /// public class CameraRoi : ComponentBase, GenericDevices.ICameraRoi, GenericDevices.IRegisterReader { private static readonly ILog log = LogManager.GetLogger(typeof(CameraRoi)); 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 cameraRoiCfg.ProcParams.GradPerLtr; } } public CameraRoi(CameraRoiCfg cfg, IList components) : base(cfg) { 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"); } } log.Debug(this.ToString()); } /// /// Events: Event.ReadRegisterDone, Event.Error /// /// Reference to a variable for the water meter pulses /// ReadWaterMeter instance reference casted to IOperaton public IOperation ReadRegisterOp(ref IntBox pulses) { return new ReadRegisterOp(this, ref pulses); } /// /// Events: Event.ReadRegisterDone, Event.Error /// /// Reference to a variable for the water meter pulses /// Reference to a variable for the related reference flow meter pulses /// ReadWaterMeter instance reference casted to IOperaton public IOperation ReadRegisterOp(ref IntBox pulses, ref IntBox refPulses) { return new ReadRegisterOp(this, ref pulses, ref refPulses); } /// /// Events: ReadReferenceDone, Error /// /// Reference to a variable for the water meter pulses /// ReadWaterMeter instance reference casted to IOperaton public IOperation ReadReferenceForRegisterOp(ref IntBox pulses, ref IntBox refPulses) { return null; /// not implemented } /// /// Watermeter wheel/arrow detection process. /// /// Region of interest (1..4) /// Reference to operation object instance public IOperation DetectOp() { 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, pp.Ang1, pp.Ang2, pp.AngStep, pp.CCW, (pp.CCW ? -30 : 30), pp.SequenceLen, pp.SequenceTiming, pp.BackgroundCorr, pp.BrightnessRoi * camera.Brightness)); } /// /// Watermeter wheel/arrow angle measurement process. /// /// Region of interest (1..4) /// Reference to operation object instance public IOperation MeasureOp() { 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, pp.BrightnessRoi * camera.Brightness)); } } }