/// /// Copyright (c) 2017-2019 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using log4net; using Config.Entities; using TBF.Boxes; namespace TBF.Rig.Elde.FlowMeterTriplet { public class FlowMeter : ComponentBase, GenericDevices.IFlowMeter { private static readonly ILog log = LogManager.GetLogger(typeof(FlowMeter)); public override string ToString() { return string.Format("{0}({1})", ClassName, 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 { return flowMeterCfg.NominalFlow / 21600.0; } } /// Nominal frequency is 6000 Hz public double LtrPerPulseCorrected(double flow, int rangeIx) { /// Apply correction double correctedFlow = MeasurementCorrection.CorrectedValue(flow, Corrections); return (LtrPerPulse * correctedFlow / flow); } public FlowMeter() { } public FlowMeter(Generic.IComponentCfg cfg, IList 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) throw new Exception("Flowmeter " + Name + " parameter 'Idx1' is out of range"); controlBoard.EtCalib[Idx1] = (float)flowMeterCfg.NominalFlow; } public override void Initialize() { log.FatalFormat("{0} initialized: {1}", Name, this); } public double ReadFlow() { return controlBoard.ReferenceFlow; } public double ReadFrequency() { return controlBoard.ReferenceFreq; } /// /// Events: FlowDone, Error /// /// Reference to a variable for the flow in Bar /// ReadFlowOp instance reference casted to IOperaton public IOperation ReadFlowOp(ref DoubleBox flow) { return new ReadFlowOp(this, controlBoard, ref flow); } /// /// Events: flowDone, Error /// /// Reference to a variable for the flow in Bar /// Event returned when measurement done /// ReadFlowOp instance reference casted to IOperaton public IOperation ReadFlowOp(ref DoubleBox flow, Event flowDone) { return new ReadFlowOp(this, controlBoard, ref flow, flowDone); } } }