2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2016-02-13 07:18:49 +00:00
|
|
|
|
/// Copyright (c) 2013-2016 Sensus Metering Systems
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-09-16 19:05:54 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.Boxes;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.Elde.FixedStartRegisterReader
|
|
|
|
|
|
{
|
2016-02-13 07:18:49 +00:00
|
|
|
|
public class RegisterReader : ComponentBase, GenericDevices.IRegisterReader, IOperation
|
2014-09-16 19:05:54 +00:00
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(RegisterReader));
|
2014-12-31 12:46:33 +00:00
|
|
|
|
public override string ToString() { return string.Format("FixedStartRegisterReader({0})", Cfg.ToString(1)); }
|
|
|
|
|
|
|
|
|
|
|
|
readonly RegisterReaderCfg registerReaderCfg;
|
2017-03-10 13:31:08 +00:00
|
|
|
|
readonly ControlBoardDev controlBoard;
|
2014-09-16 19:05:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-02-13 07:18:49 +00:00
|
|
|
|
public double PulsesPerLtr { get { return (double)registerReaderCfg.ProcParams.PulsesPerLtr; } }
|
2017-03-10 13:31:08 +00:00
|
|
|
|
public double LtrsPerPulse { get { return (PulsesPerLtr <= float.Epsilon) ? 1.0 : (1 / PulsesPerLtr); } }
|
2016-02-13 07:18:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
2017-03-10 13:31:08 +00:00
|
|
|
|
double beginWMState;
|
|
|
|
|
|
public double BeginWMState
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return beginWMState; }
|
|
|
|
|
|
set { beginWMState = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double endWMState;
|
|
|
|
|
|
public double EndWMState
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return endWMState; }
|
|
|
|
|
|
set { endWMState = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public double WMVolume { get { return endWMState - beginWMState; } }
|
|
|
|
|
|
|
|
|
|
|
|
public int WMPulses { get { return (int)(WMVolume / LtrsPerPulse); } }
|
|
|
|
|
|
|
2016-02-13 07:18:49 +00:00
|
|
|
|
int wmRefPulses;
|
2017-03-10 13:31:08 +00:00
|
|
|
|
public int WMRefPulses { get { return wmRefPulses; } }
|
2016-02-13 07:18:49 +00:00
|
|
|
|
|
2014-09-16 19:05:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
2015-06-29 09:14:33 +00:00
|
|
|
|
public RegisterReader()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-05 12:32:36 +00:00
|
|
|
|
public RegisterReader(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
2014-09-16 19:05:54 +00:00
|
|
|
|
: base(cfg)
|
|
|
|
|
|
{
|
2016-08-05 12:32:36 +00:00
|
|
|
|
registerReaderCfg = cfg as RegisterReaderCfg;
|
2014-09-16 19:05:54 +00:00
|
|
|
|
|
2017-07-27 09:15:54 +00:00
|
|
|
|
/// Control board is used to read reference flowmeter pulses
|
2016-02-13 07:18:49 +00:00
|
|
|
|
controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components);
|
|
|
|
|
|
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
|
2014-09-16 19:05:54 +00:00
|
|
|
|
|
2017-03-10 13:31:08 +00:00
|
|
|
|
Clear();
|
2014-09-16 19:05:54 +00:00
|
|
|
|
|
|
|
|
|
|
log.Debug(this.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-13 07:18:49 +00:00
|
|
|
|
public void Clear()
|
|
|
|
|
|
{
|
2017-07-24 05:58:13 +00:00
|
|
|
|
log.DebugFormat("{0}:Clear()", Name);
|
2017-03-10 13:31:08 +00:00
|
|
|
|
beginWMState = 0;
|
|
|
|
|
|
endWMState = 0;
|
2016-02-13 07:18:49 +00:00
|
|
|
|
wmRefPulses = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-03-10 13:31:08 +00:00
|
|
|
|
|
2016-02-13 07:18:49 +00:00
|
|
|
|
public void TestCompleted()
|
|
|
|
|
|
{
|
2017-07-24 05:58:13 +00:00
|
|
|
|
log.DebugFormat("{0}:TestCompleted()", Name);
|
2016-02-13 07:18:49 +00:00
|
|
|
|
ReadPulses();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-09-16 19:05:54 +00:00
|
|
|
|
/// <summary>
|
2017-07-27 09:15:54 +00:00
|
|
|
|
/// Events: Event.ReadRegisterDone
|
2014-09-16 19:05:54 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>ReadWaterMeter instance reference casted to IOperaton</returns>
|
2016-02-13 15:47:15 +00:00
|
|
|
|
public IOperation ReadRegisterOp()
|
2014-09-16 19:05:54 +00:00
|
|
|
|
{
|
2016-02-13 07:18:49 +00:00
|
|
|
|
return this;
|
2014-09-16 19:05:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-13 07:18:49 +00:00
|
|
|
|
private void ReadPulses()
|
|
|
|
|
|
{
|
|
|
|
|
|
wmRefPulses = (int)controlBoard.EtPulses(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()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2014-09-16 19:05:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|