85 lines
3.2 KiB
C#
85 lines
3.2 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.BenchControl.Elde.FlowMeterTwins
|
|
{
|
|
public class FlowMeter : ComponentBase, GenericDevices.IFlowMeter
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(FlowMeter));
|
|
public override string ToString() { return string.Format("FlowMeterTwins({0})", Cfg.ToString(1)); }
|
|
|
|
readonly FlowMeterCfg flowMeterCfg;
|
|
readonly ControlBoardDev controlBoard;
|
|
public readonly TBF.BenchControl.Elde.FlowMeter.FlowMeter FlowMeter1;
|
|
public readonly TBF.BenchControl.Elde.FlowMeter.FlowMeter FlowMeter2;
|
|
|
|
public int Idx1 { get { return 0; } }
|
|
public float NominalFlow { get { return flowMeterCfg.NominalFlow; } }
|
|
|
|
/// The nominal flowed of a pair of flow meters is reached at 4000Hz
|
|
public float LtrPerPulse { get { return flowMeterCfg.NominalFlow / 14400.0f; } }
|
|
|
|
/// Calculates the average of values of two flowmeters. Assumes the flow is divided evenly.
|
|
public float LtrPerPulseCorrected(double flow)
|
|
{
|
|
double flow2 = flow / 2.0;
|
|
return (FlowMeter1.LtrPerPulseCorrected(flow2) + FlowMeter2.LtrPerPulseCorrected(flow2)) / 2;
|
|
}
|
|
|
|
|
|
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");
|
|
|
|
FlowMeter1 = (TBF.BenchControl.Elde.FlowMeter.FlowMeter)TbfComponents.FindComponent(flowMeterCfg.FlowMeter1, components);
|
|
if (FlowMeter1 == null) throw new Exception("Cannot find FlowMeter1 component");
|
|
|
|
FlowMeter2 = (TBF.BenchControl.Elde.FlowMeter.FlowMeter)TbfComponents.FindComponent(flowMeterCfg.FlowMeter2, components);
|
|
if (FlowMeter2 == null) throw new Exception("Cannot find FlowMeter2 component");
|
|
|
|
controlBoard.EtCalib[Idx1] = flowMeterCfg.NominalFlow; /// Idx1==0 for FlowMeterTwins
|
|
|
|
/// Prepare data for SendCalibData() control board component method
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|