tbf/TBF/BenchControl/Elde/FlowMeterTwins/FlowMeter.cs

86 lines
3.2 KiB
C#

///
/// Copyright (c) 2013-2019 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using log4net;
using TBF.BenchControl;
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 Elde.FlowMeter.FlowMeter FlowMeter1;
public readonly Elde.FlowMeter.FlowMeter FlowMeter2;
public int Idx1 { get { return 0; } }
public double NominalFlow { get { return flowMeterCfg.NominalFlow; } }
/// The nominal flowed of a pair of flow meters is reached at 4000Hz
public double LtrPerPulse { get { return flowMeterCfg.NominalFlow / 14400.0; } }
/// Calculates the average of values of two flowmeters. Assumes the flow is divided evenly.
public double LtrPerPulseCorrected(double flow, int rangeIx)
{
double flow2 = flow / 2.0;
return (FlowMeter1.LtrPerPulseCorrected(flow2, rangeIx) + FlowMeter2.LtrPerPulseCorrected(flow2, rangeIx)) / 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 = TbfComponents.FindComponent(flowMeterCfg.FlowMeter1, components) as Elde.FlowMeter.FlowMeter;
if (FlowMeter1 == null) throw new Exception("Cannot find FlowMeter1 component");
FlowMeter2 = TbfComponents.FindComponent(flowMeterCfg.FlowMeter2, components) as Elde.FlowMeter.FlowMeter;
if (FlowMeter2 == null) throw new Exception("Cannot find FlowMeter2 component");
controlBoard.EtCalib[Idx1] = (float)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);
}
}
}