using System; using log4net; namespace TBF.BenchControl.Cameras.CameraRoi { public class ReadRegisterOp : IOperation { private static readonly ILog log = LogManager.GetLogger(typeof(ReadRegisterOp)); public override string ToString() { return string.Format("ReadRegisterOp({0})", cameraRoi.Cfg.Name); } /// Set by the constructor readonly GenericDevices.ICameraRoi cameraRoi; readonly BenchControl.Cameras.IdcCamera.IdcCamera camera; IntBox pulses; IntBox refPulses; /// /// Events: Event.ReadRegisterDone or Event.Error /// /// Register reader reference /// Reference to a field with the water meter pulses public ReadRegisterOp(GenericDevices.ICameraRoi cameraRoi, ref IntBox pulses) { this.cameraRoi = cameraRoi; if (cameraRoi == null) throw new ArgumentNullException("reader is null or it is not IdcCamera"); camera = cameraRoi.Camera as BenchControl.Cameras.IdcCamera.IdcCamera; this.pulses = pulses; log.Debug(this.ToString()); } /// /// Events: Event.ReadRegisterDone or Event.Error /// /// Register reader reference /// Reference to a Box with the water meter pulses /// Reference to a Box with the reference flow meter pulses synchronized with the water meter public ReadRegisterOp(GenericDevices.ICameraRoi cameraRoi, ref IntBox pulses, ref IntBox refPulses) : this(cameraRoi, ref pulses) { this.refPulses = refPulses; log.Debug(this.ToString()); } private void ReadPulses() { pulses.N = camera.Idc100.Pulses; if (refPulses != null) { refPulses.N = 0; } } /// Start this operation public void Start() { ReadPulses(); } /// Run this operation /// eventDone public Event Run() { ReadPulses(); return Event.ReadRegisterDone; } /// Stop this operation public void Stop() { } } }