111 lines
3.8 KiB
C#
111 lines
3.8 KiB
C#
///
|
|
/// Copyright (c) 2013-2018 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
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 double NominalFlow { get { return flowMeterCfg.NominalFlow; } }
|
|
public double LtrPerPulse
|
|
{
|
|
get
|
|
{
|
|
if (Idx1 == 48 || Idx1 == 80 || Idx1 == 96)
|
|
{
|
|
/// 2 flow meters, nominal frequency is 4000 Hz
|
|
return flowMeterCfg.NominalFlow / 14400.0f;
|
|
}
|
|
else if (Idx1 == 112)
|
|
{
|
|
/// 3 flow meters, nominal frequency is 6000 Hz
|
|
return flowMeterCfg.NominalFlow / 21600.0f;
|
|
}
|
|
else
|
|
{
|
|
/// Nominal frequency is 2000 Hz
|
|
return flowMeterCfg.NominalFlow / 7200.0f;
|
|
}
|
|
}
|
|
}
|
|
|
|
public double LtrPerPulseCorrected(double flow, int rangeIx)
|
|
{
|
|
if (flow < 0.1 * NominalFlow) return LtrPerPulse; /// No correction for small flow
|
|
|
|
/// Apply correction
|
|
var rangeCorrections = new List<Config.Entities.MeasurementCorrection>();
|
|
foreach (var corr in Corrections)
|
|
{
|
|
if (corr.RangeIx == rangeIx) rangeCorrections.Add(corr);
|
|
}
|
|
double correctedFlow = Config.Formulas.CorrectedValue(flow, rangeCorrections);
|
|
return (LtrPerPulse * correctedFlow / flow);
|
|
}
|
|
|
|
|
|
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");
|
|
|
|
/// Prepare data for SendCalibData() control board component method
|
|
if (Idx1 < controlBoard.EtCalib.Length)
|
|
{
|
|
controlBoard.EtCalib[Idx1] = (float)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);
|
|
}
|
|
}
|
|
}
|