76 lines
2.1 KiB
C#
76 lines
2.1 KiB
C#
using System;
|
|
using log4net;
|
|
using TBF.Boxes;
|
|
|
|
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;
|
|
|
|
/// <summary>
|
|
/// Events: Event.ReadRegisterDone or Event.Error
|
|
/// </summary>
|
|
/// <param name="reader">Register reader reference</param>
|
|
/// <param name="pulses">Reference to a field with the water meter pulses</param>
|
|
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());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Events: Event.ReadRegisterDone or Event.Error
|
|
/// </summary>
|
|
/// <param name="cameraRoi">Register reader reference</param>
|
|
/// <param name="pulses">Reference to a Box with the water meter pulses</param>
|
|
/// <param name="refPulses">Reference to a Box with the reference flow meter pulses synchronized with the water meter</param>
|
|
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.Val = camera.Idc100.Pulses;
|
|
if (refPulses != null)
|
|
{
|
|
refPulses.Val = 0;
|
|
}
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
ReadPulses();
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
/// <returns>eventDone</returns>
|
|
public Event Run()
|
|
{
|
|
ReadPulses();
|
|
return Event.ReadRegisterDone;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
}
|
|
}
|
|
}
|