112 lines
4.9 KiB
C#
112 lines
4.9 KiB
C#
///
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using TBF.Boxes;
|
|
using TBF.BenchControl.GenericDevices;
|
|
|
|
namespace TBF.BenchControl.Elde.FlowMeterDewa
|
|
{
|
|
public class FlowMeter : ComponentBase, 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;
|
|
readonly IFlowMeter flowMeter1;
|
|
readonly IFlowMeter flowMeter2;
|
|
readonly IFlowMeter flowMeter3;
|
|
readonly double nominalFlow;
|
|
readonly double ltrPerPulse;
|
|
readonly int flowMetersCount;
|
|
readonly int flowMetersBitfield;
|
|
|
|
public int Idx1 { get { return flowMetersBitfield; } }
|
|
public double NominalFlow { get { return nominalFlow; } }
|
|
public double LtrPerPulse { get { return ltrPerPulse; } }
|
|
|
|
double[] refFreq;
|
|
|
|
public double LtrPerPulseCorrected(double flow, int rangeIx)
|
|
{
|
|
if (flow < 0.1 * NominalFlow) return LtrPerPulse; /// No correction for small flow
|
|
|
|
refFreq[0] = controlBoard.ReferenceFreqs(0);
|
|
refFreq[2] = controlBoard.ReferenceFreqs(2);
|
|
refFreq[3] = controlBoard.ReferenceFreqs(3);
|
|
refFreq[1] = refFreq[0] - refFreq[2] - refFreq[3];
|
|
|
|
double ltrPerPulseCorrected = 0;
|
|
if (flowMeter1 != null) ltrPerPulseCorrected += refFreq[1] * flowMeter1.LtrPerPulseCorrected(flow * refFreq[1] / refFreq[0], rangeIx);
|
|
if (flowMeter2 != null) ltrPerPulseCorrected += refFreq[2] * flowMeter2.LtrPerPulseCorrected(flow * refFreq[2] / refFreq[0], rangeIx);
|
|
if (flowMeter3 != null) ltrPerPulseCorrected += refFreq[3] * flowMeter3.LtrPerPulseCorrected(flow * refFreq[3] / refFreq[0], rangeIx);
|
|
return ltrPerPulseCorrected / refFreq[0];
|
|
}
|
|
|
|
|
|
public bool RangeEnabled(int ix) { return flowMeterCfg.RangeEnabled(ix); }
|
|
public double GetTempLo(int ix) { return flowMeterCfg.GetTempLo(ix); }
|
|
public double GetTempHi(int ix) { return flowMeterCfg.GetTempHi(ix); }
|
|
public double GetPressLo(int ix) { return flowMeterCfg.GetPressLo(ix); }
|
|
public double GetPressHi(int ix) { return flowMeterCfg.GetPressHi(ix); }
|
|
|
|
|
|
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");
|
|
|
|
if (!string.IsNullOrEmpty(flowMeterCfg.Flowmeter1)) flowMeter1 = TbfComponents.FindComponent(flowMeterCfg.Flowmeter1, components) as IFlowMeter;
|
|
if (!string.IsNullOrEmpty(flowMeterCfg.Flowmeter2)) flowMeter2 = TbfComponents.FindComponent(flowMeterCfg.Flowmeter2, components) as IFlowMeter;
|
|
if (!string.IsNullOrEmpty(flowMeterCfg.Flowmeter3)) flowMeter3 = TbfComponents.FindComponent(flowMeterCfg.Flowmeter3, components) as IFlowMeter;
|
|
|
|
nominalFlow = 0;
|
|
flowMetersCount = 0;
|
|
flowMetersBitfield = 0;
|
|
if (flowMeter1 != null) { nominalFlow += flowMeter1.NominalFlow; flowMetersBitfield |= (8 << flowMeter1.Idx1); flowMetersCount++; }
|
|
if (flowMeter2 != null) { nominalFlow += flowMeter2.NominalFlow; flowMetersBitfield |= (8 << flowMeter2.Idx1); flowMetersCount++; }
|
|
if (flowMeter3 != null) { nominalFlow += flowMeter3.NominalFlow; flowMetersBitfield |= (8 << flowMeter3.Idx1); flowMetersCount++; }
|
|
if (flowMetersCount == 0) throw new Exception("Missing flowmeters");
|
|
ltrPerPulse = nominalFlow / (flowMetersCount * 7200.0); /// Nominal freq. is flowMetersCount * 2000 Hz (2000, 4000 or 6000 Hz)
|
|
|
|
refFreq = new double[4];
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|