93 lines
3.4 KiB
C#
93 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.BenchControl.Elde.FlowMeterTwins
|
|
{
|
|
public class FlowMeter : Generic.IComponent, GenericDevices.IFlowMeter
|
|
{
|
|
/// <summary>
|
|
/// Info: StartMassMeasurement() and "Balance response = .., Mass = ..."
|
|
/// Warn: Start measurement when busy is true
|
|
/// </summary>
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(FlowMeter));
|
|
public override string ToString()
|
|
{
|
|
return string.Format("FlowMeter: Name={0}", Name);
|
|
}
|
|
|
|
public static void ResetStaticProperties() { }
|
|
|
|
FlowMeterCfg flowMeterCfg;
|
|
public Generic.IComponentCfg Cfg { get { return flowMeterCfg; } }
|
|
|
|
public string Name { get { return flowMeterCfg.Name; } }
|
|
|
|
public IList<Entities.MeasurementCorrection> Corrections { get { return flowMeterCfg.Corrections; } }
|
|
|
|
public int Idx1 { get { return 0; } }
|
|
|
|
public readonly ControlBoardDev ControlBoard;
|
|
public readonly TBF.BenchControl.Elde.FlowMeter.FlowMeter FlowMeter1;
|
|
public readonly TBF.BenchControl.Elde.FlowMeter.FlowMeter FlowMeter2;
|
|
|
|
public float NominalFlow { get { return nominalFlow; } }
|
|
readonly float nominalFlow;
|
|
|
|
/// The nominal flowed of a pair of flow meters is reached at 4000Hz
|
|
public float LtrPerPulse { get { return nominalFlow / 14400.0f; } }
|
|
|
|
/// Calculates the average of values of two flowmeters. Assumes the flow is divided evenly.
|
|
public float LtrPerPulseCorrected(float flow)
|
|
{
|
|
float flow2 = flow / 2;
|
|
return (FlowMeter1.LtrPerPulseCorrected(flow2) + FlowMeter2.LtrPerPulseCorrected(flow2)) / 2;
|
|
}
|
|
|
|
|
|
public FlowMeter(FlowMeterCfg cfg, IList<Generic.IComponent> components)
|
|
{
|
|
if (cfg == null) throw new ArgumentNullException("cfg");
|
|
this.flowMeterCfg = cfg;
|
|
|
|
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");
|
|
|
|
nominalFlow = cfg.NominalFlow;
|
|
ControlBoard.EtCalib[Idx1] = NominalFlow;
|
|
|
|
/// Prepare data for SendCalibData() control board component method
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|