2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2023-04-18 12:01:23 +00:00
|
|
|
|
/// Copyright (c) 2013-2023 Sensus Slovensko a.s.
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using log4net;
|
2022-01-23 18:56:15 +00:00
|
|
|
|
using Config.Entities;
|
2014-07-31 15:04:09 +00:00
|
|
|
|
using TBF.Boxes;
|
2020-03-05 12:59:43 +00:00
|
|
|
|
using TBF.Resources;
|
2023-04-18 12:01:23 +00:00
|
|
|
|
using TBF.UI.Calendar;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2021-10-26 09:23:57 +00:00
|
|
|
|
namespace TBF.Rig.Elde.FlowMeter
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2020-03-05 12:59:43 +00:00
|
|
|
|
public class FlowMeter : ComponentBase, Generic.IDevice, GenericDevices.IFlowMeter, GenericDevices.IHasCalendarEvents
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(FlowMeter));
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-12-31 12:46:33 +00:00
|
|
|
|
readonly FlowMeterCfg flowMeterCfg;
|
2017-12-14 14:10:17 +00:00
|
|
|
|
readonly ControlBoardDev controlBoard;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2019-03-08 13:52:02 +00:00
|
|
|
|
public int Idx1 { get { return flowMeterCfg.Idx1; } }
|
2019-04-11 11:45:28 +00:00
|
|
|
|
public double NominalFlow { get { return flowMeterCfg.NominalFlow; } }
|
2019-05-10 15:47:11 +00:00
|
|
|
|
public double LtrPerPulse { get { return flowMeterCfg.NominalFlow / 7200.0; } } /// Nominal frequency is 2000 Hz
|
2014-09-10 11:43:33 +00:00
|
|
|
|
|
2019-04-11 11:45:28 +00:00
|
|
|
|
public double LtrPerPulseCorrected(double flow, int rangeIx)
|
2014-09-10 11:43:33 +00:00
|
|
|
|
{
|
2021-08-18 11:06:37 +00:00
|
|
|
|
if (flow == 0) return LtrPerPulse; /// To avoid division by zero
|
|
|
|
|
|
|
2015-08-16 16:05:35 +00:00
|
|
|
|
/// Apply correction
|
2022-01-23 18:56:15 +00:00
|
|
|
|
var rangeCorrections = new List<MeasurementCorrection>();
|
2018-01-24 13:16:38 +00:00
|
|
|
|
foreach (var corr in Corrections)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (corr.RangeIx == rangeIx) rangeCorrections.Add(corr);
|
|
|
|
|
|
}
|
2022-01-23 18:56:15 +00:00
|
|
|
|
double correctedFlow = MeasurementCorrection.CorrectedValue(flow, rangeCorrections);
|
2019-04-11 11:45:28 +00:00
|
|
|
|
return (LtrPerPulse * correctedFlow / flow);
|
2014-09-10 11:43:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-24 13:16:38 +00:00
|
|
|
|
|
|
|
|
|
|
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); }
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public FlowMeter() { }
|
2015-06-29 09:14:33 +00:00
|
|
|
|
|
2016-08-05 12:32:36 +00:00
|
|
|
|
public FlowMeter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
|
|
|
|
|
: base(cfg)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2016-08-05 12:32:36 +00:00
|
|
|
|
flowMeterCfg = cfg as FlowMeterCfg;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-12-14 14:10:17 +00:00
|
|
|
|
controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components);
|
|
|
|
|
|
if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent");
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// Prepare data for SendCalibData() control board component method
|
2019-04-11 11:45:28 +00:00
|
|
|
|
if (Idx1 < controlBoard.EtCalib.Length)
|
|
|
|
|
|
{
|
|
|
|
|
|
controlBoard.EtCalib[Idx1] = (float)flowMeterCfg.NominalFlow;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-05 12:59:43 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// IDevice interface functions
|
|
|
|
|
|
///
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public override void Initialize()
|
2020-03-05 12:59:43 +00:00
|
|
|
|
{
|
2021-02-08 09:06:25 +00:00
|
|
|
|
for (int r = 0; r <= 5; r++)
|
2020-03-05 12:59:43 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
if (RangeEnabled(r) && flowMeterCfg.GetCalibValidDate(r) > DateTime.MinValue
|
2021-02-08 09:06:25 +00:00
|
|
|
|
&& flowMeterCfg.GetCalibValidDate(r).Date < DateTime.Now.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception(string.Format("{0}/r{1}: {2}", Name, r, Strings.Calibration_certificate_validity_expired));
|
|
|
|
|
|
}
|
2020-03-05 12:59:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
log.FatalFormat("{0} initialized: {1}", Name, this);
|
2020-03-05 12:59:43 +00:00
|
|
|
|
}
|
2021-04-07 07:57:42 +00:00
|
|
|
|
|
2020-03-05 12:59:43 +00:00
|
|
|
|
public void RunDeviceBefore() { }
|
|
|
|
|
|
public void RunDeviceAfter() { }
|
|
|
|
|
|
public void StopDevice() { }
|
|
|
|
|
|
public void StopDevice2() { }
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Calendar support
|
|
|
|
|
|
///
|
2023-04-18 12:01:23 +00:00
|
|
|
|
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
|
2020-03-05 12:59:43 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
|
2020-03-05 12:59:43 +00:00
|
|
|
|
|
2023-04-18 12:01:23 +00:00
|
|
|
|
DateTime calibDue = flowMeterCfg.CalibValidDate;
|
|
|
|
|
|
if (calibDue > TBF.UI.Constants.MinDate)
|
2020-03-05 12:59:43 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
/// Five weekly notifications
|
|
|
|
|
|
foreach (var days in new int[] { -35, -28, -21, -14 })
|
2020-04-21 08:59:31 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
if (calibDue.Date.AddDays(days + 6) >= DateTime.Now.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Notification,
|
|
|
|
|
|
calibDue.Date.AddDays(days),
|
|
|
|
|
|
Name,
|
|
|
|
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
|
|
|
|
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
|
|
|
|
|
|
}
|
2020-04-21 08:59:31 +00:00
|
|
|
|
}
|
2023-04-18 12:01:23 +00:00
|
|
|
|
|
|
|
|
|
|
/// Five daily warnings
|
|
|
|
|
|
foreach (var days in new int[] { -7, -6, -5, -4, -3, -2, -1 })
|
2020-04-21 08:59:31 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
if (calibDue.Date.AddDays(days) >= DateTime.Now.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Weekly reminders (last 5 weeks)
|
|
|
|
|
|
calEvents.Add(new CalibrationReminderEvent(Config.CalendarEvent.AutoAction.Warning,
|
|
|
|
|
|
calibDue.Date.AddDays(days),
|
|
|
|
|
|
Name,
|
|
|
|
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
|
|
|
|
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Calibration due date
|
|
|
|
|
|
if (calibDue.Date >= DateTime.Now.Date)
|
|
|
|
|
|
{
|
|
|
|
|
|
calEvents.Add(new CalibrationDueDateEvent(calibDue.Date,
|
|
|
|
|
|
Name,
|
|
|
|
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
|
|
|
|
calibDue.Date.ToString(TBF.UI.Constants.DateFormat))));
|
2020-04-21 08:59:31 +00:00
|
|
|
|
}
|
2020-03-05 12:59:43 +00:00
|
|
|
|
}
|
2023-04-18 12:01:23 +00:00
|
|
|
|
|
|
|
|
|
|
return calEvents;
|
2020-03-05 12:59:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-14 14:10:17 +00:00
|
|
|
|
public double ReadFlow() { return controlBoard.ReferenceFlow; }
|
|
|
|
|
|
public double ReadFrequency() { return controlBoard.ReferenceFreq; }
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <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>
|
2016-10-07 14:22:36 +00:00
|
|
|
|
public IOperation ReadFlowOp(ref DoubleBox flow)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2017-12-14 14:10:17 +00:00
|
|
|
|
return new ReadFlowOp(this, controlBoard, ref flow);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2016-10-07 14:22:36 +00:00
|
|
|
|
public IOperation ReadFlowOp(ref DoubleBox flow, Event flowDone)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2017-12-14 14:10:17 +00:00
|
|
|
|
return new ReadFlowOp(this, controlBoard, ref flow, flowDone);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|