75 lines
2.4 KiB
C#
75 lines
2.4 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
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;
|
|
|
|
public int Idx1 { get { return flowMeterCfg.Idx1; } }
|
|
|
|
public readonly ControlBoardDev ControlBoard;
|
|
|
|
public float NominalFlow { get { return flowMeterCfg.NominalFlow; } }
|
|
|
|
public float LtrPerPulse { get { return flowMeterCfg.NominalFlow / 7200.0f; } }
|
|
|
|
public float LtrPerPulseCorrected(float flow)
|
|
{
|
|
//return LtrPerPulse; /// TODO: apply correction
|
|
float correctedFlow = BenchControl.Formulas.CorrectedValue(flow, Corrections);
|
|
return LtrPerPulse * correctedFlow / flow;
|
|
}
|
|
|
|
|
|
public FlowMeter()
|
|
{
|
|
}
|
|
|
|
public FlowMeter(FlowMeterCfg cfg, IList<Generic.IComponent> components)
|
|
: base(cfg)
|
|
{
|
|
flowMeterCfg = cfg;
|
|
|
|
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());
|
|
}
|
|
|
|
/// <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 FloatBox flow)
|
|
{
|
|
return new ReadFlowOp(this, 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 FloatBox flow, Event flowDone)
|
|
{
|
|
return new ReadFlowOp(this, ref flow, flowDone);
|
|
}
|
|
}
|
|
}
|