tbf/TestBenchFramework/BenchControl/Elde/FlowMeter/FlowMeter.cs

76 lines
2.6 KiB
C#
Raw Normal View History

///
/// Copyright (c) 2013-2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using log4net;
2014-07-31 15:04:09 +00:00
using TBF.Boxes;
namespace TBF.BenchControl.Elde.FlowMeter
{
public class FlowMeter : ComponentBase, GenericDevices.IFlowMeter
{
private static readonly ILog log = LogManager.GetLogger(typeof(FlowMeter));
public override string ToString() { return string.Format("FlowMeter({0})", Cfg.ToString(1)); }
readonly FlowMeterCfg flowMeterCfg;
readonly ControlBoardDev controlBoard;
public int Idx1 { get { return flowMeterCfg.Idx1; } }
public float NominalFlow { get { return flowMeterCfg.NominalFlow; } }
public float LtrPerPulse { get { return flowMeterCfg.NominalFlow / 7200.0f; } }
public float LtrPerPulseCorrected(double flow)
{
if (flow < 0.1 * NominalFlow) return LtrPerPulse; /// No correction for small flow
/// Apply correction
double correctedFlow = BenchControl.Formulas.CorrectedValue(flow, Corrections);
return (float)(LtrPerPulse * correctedFlow / flow);
}
public FlowMeter()
{
}
public FlowMeter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
flowMeterCfg = cfg as FlowMeterCfg;
controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components);
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
/// Prepare data for SendCalibData() control board component method
if (Idx1 >= controlBoard.EtCalib.Length) throw new Exception("Flowmeter " + Name + " parameter 'Idx1' is out of range");
controlBoard.EtCalib[Idx1] = flowMeterCfg.NominalFlow;
log.Debug(this.ToString());
}
public double ReadFlow() { return controlBoard.ReferenceFlow; }
public double ReadFrequency() { return controlBoard.ReferenceFreq; }
/// <summary>
/// Events: FlowDone, Error
/// </summary>
/// <param name="flow">Reference to a variable for the flow in Bar</param>
/// <returns>ReadFlowOp instance reference casted to IOperaton</returns>
public IOperation ReadFlowOp(ref DoubleBox flow)
{
return new ReadFlowOp(this, controlBoard, ref flow);
}
/// <summary>
/// Events: flowDone, Error
/// </summary>
/// <param name="flow">Reference to a variable for the flow in Bar</param>
/// <param name="flowDone">Event returned when measurement done</param>
/// <returns>ReadFlowOp instance reference casted to IOperaton</returns>
public IOperation ReadFlowOp(ref DoubleBox flow, Event flowDone)
{
return new ReadFlowOp(this, controlBoard, ref flow, flowDone);
}
}
}