tbf/TestBenchFramework/BenchControl/Elde/RegisterReader/ReadRegisterOp.cs

73 lines
2.0 KiB
C#
Raw Normal View History

using System;
using log4net;
2014-07-31 15:04:09 +00:00
using TBF.Boxes;
namespace TBF.BenchControl.Elde.RegisterReader
{
public class ReadRegisterOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(ReadRegisterOp));
public override string ToString() { return string.Format("ReadRegisterOp({0})", reader.Name); }
/// Set by the constructor
readonly RegisterReader reader;
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.IRegisterReader reader, ref IntBox pulses)
{
this.reader = reader as RegisterReader;
if (reader == null) throw new ArgumentNullException("reader is null or it is not Elde");
this.pulses = pulses;
log.Debug(this.ToString());
}
/// <summary>
/// Events: Event.ReadRegisterDone or Event.Error
/// </summary>
/// <param name="reader">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.IRegisterReader reader, ref IntBox pulses, ref IntBox refPulses)
: this(reader, ref pulses)
{
this.refPulses = refPulses;
log.Debug(this.ToString());
}
private void ReadPulses()
{
2014-07-31 15:04:09 +00:00
pulses.Val = (int)reader.ControlBoard.WMeterPulses(reader.Position);
if (refPulses != null)
{
2014-07-31 15:04:09 +00:00
refPulses.Val = (int)reader.ControlBoard.EtPulses(reader.Position);
}
}
/// <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()
{
}
}
}