90 lines
2.4 KiB
C#
90 lines
2.4 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using log4net;
|
|
using TBF.BenchControl;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.BenchControl.Operations
|
|
{
|
|
public class ReadMoreRegistersOp : IOperation
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(ReadMoreRegistersOp));
|
|
public override string ToString() { return string.Format("ReadAllRegistersOp()"); }
|
|
|
|
/// Set by the constructor
|
|
int readersCount;
|
|
IOperation[] readRegOps;
|
|
|
|
/// <summary>
|
|
/// Events: eventDone (default=Event.ReadRegisterDone) or Event.Error
|
|
/// </summary>
|
|
/// <param name="register">Register reader reference</param>
|
|
/// <param name="pulses">Reference to the water meter register state in pulses</param>
|
|
public ReadMoreRegistersOp(GenericDevices.IRegisterReader[] readers)
|
|
{
|
|
if (readers == null) throw new ArgumentNullException("readers");
|
|
|
|
readersCount = readers.Length;
|
|
|
|
readRegOps = new IOperation[readersCount];
|
|
for (int i = 0; i < readersCount; i++)
|
|
{
|
|
if (readers[i] != null) readRegOps[i] = readers[i].ReadRegisterOp();
|
|
}
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
int oriRefPulses = Sequences.ProcessData.RefPulses;
|
|
Sequences.ProcessData.RefPulses = StateMachine.ControlBoard.EtPulses(0);
|
|
Sequences.ProcessData.RefPulsesDelta = Sequences.ProcessData.RefPulses - oriRefPulses;
|
|
|
|
for (int i = 0; i < readersCount; i++)
|
|
{
|
|
if (readRegOps[i] != null) readRegOps[i].Start();
|
|
}
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
public Event Run()
|
|
{
|
|
bool allDone = true;
|
|
bool anyError = false;
|
|
|
|
int oriRefPulses = Sequences.ProcessData.RefPulses;
|
|
Sequences.ProcessData.RefPulses = StateMachine.ControlBoard.EtPulses(0);
|
|
Sequences.ProcessData.RefPulsesDelta = Sequences.ProcessData.RefPulses - oriRefPulses;
|
|
|
|
for (int i = 0; i < readersCount; i++)
|
|
{
|
|
if (readRegOps[i] != null)
|
|
{
|
|
Event evnt = readRegOps[i].Run();
|
|
|
|
if (evnt == Event.Error) anyError = true;
|
|
if (evnt != Event.ReadRegisterDone) allDone = false;
|
|
}
|
|
}
|
|
|
|
if (anyError) return Event.Error;
|
|
if (allDone) return Event.ReadAllRegistersDone;
|
|
return Event.None;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
for (int i = 0; i < readersCount; i++)
|
|
{
|
|
if (readRegOps[i] != null) readRegOps[i].Stop();
|
|
}
|
|
}
|
|
}
|
|
}
|