94 lines
2.7 KiB
C#
94 lines
2.7 KiB
C#
///
|
|
/// Copyright (c) 2013-2020 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using TBF.BenchControl.ControlBoard.Legacy;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.BenchControl.Elde.RegisterReader
|
|
{
|
|
public class RegisterReader : ComponentBase, GenericDevices.IRegisterReader, IOperation
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(RegisterReader));
|
|
public override string ToString() { return string.Format("RegisterReader({0})", Cfg.ToString(1)); }
|
|
|
|
readonly RegisterReaderCfg registerReaderCfg;
|
|
|
|
public int Position { get { return registerReaderCfg.Position; } } /// 1 .. Config.Data.WMsCount
|
|
|
|
public Config.Entities.RegisterReaderType RegisterReaderType { get { return Config.Entities.RegisterReaderType.Pulses; } }
|
|
public double PulsesPerLtr { get { return registerReaderCfg.ProcParams.PulsesPerLtr; } }
|
|
public double LtrsPerPulse { get { return (PulsesPerLtr <= float.Epsilon) ? 1.0 : (1 / PulsesPerLtr); ; } }
|
|
public int Filter { get { return registerReaderCfg.ProcParams.Filter; } }
|
|
|
|
public int WMPulses { get { return wmPulses; } }
|
|
public int WMRefPulses { get { return wmRefPulses; } }
|
|
public double WMVolume { get { return LtrsPerPulse * (double)wmPulses; } }
|
|
|
|
public double BeginWMState { get { return 0; } } /// Always 0
|
|
public double EndWMState { get { return WMVolume; } } /// Derived from WMVolume
|
|
|
|
|
|
int wmPulses;
|
|
int wmRefPulses;
|
|
|
|
|
|
readonly TBF.BenchControl.ControlBoard.IControlBoard controlBoard;
|
|
|
|
|
|
public RegisterReader()
|
|
{
|
|
}
|
|
|
|
public RegisterReader(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
|
: base(cfg)
|
|
{
|
|
registerReaderCfg = cfg as RegisterReaderCfg;
|
|
|
|
controlBoard = TbfComponents.FindComponent(cfg.ParentName, components) as TBF.BenchControl.ControlBoard.IControlBoard;
|
|
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
|
|
|
|
/// Prepare data for SendCalibData() control board component method
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Events: Event.ReadRegisterDone, Event.Error
|
|
/// </summary>
|
|
/// <returns>ReadWaterMeter instance reference casted to IOperaton</returns>
|
|
public IOperation ReadRegisterOp()
|
|
{
|
|
return this;
|
|
}
|
|
|
|
private void ReadPulses()
|
|
{
|
|
wmPulses = controlBoard.PulsesWM(Position);
|
|
wmRefPulses = controlBoard.RefPulsesWM(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()
|
|
{
|
|
ReadPulses();
|
|
}
|
|
}
|
|
}
|