90 lines
2.7 KiB
C#
90 lines
2.7 KiB
C#
///
|
|
/// Copyright (c) 2016 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using log4net;
|
|
|
|
namespace TBF.Rig.Operations
|
|
{
|
|
/// <summary>
|
|
/// Implements Eoperation to calculate (accumulate) enthalpies of heat meters
|
|
///
|
|
/// Events: Event.None (always)
|
|
/// </summary>
|
|
public class EnthalpyCalculationOp : IOperation
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(EnthalpyCalculationOp));
|
|
public override string ToString() { return string.Format("EnthalpyCalculationOp(.,{0})", path.Name); }
|
|
|
|
///
|
|
/// Private fields
|
|
///
|
|
HeatMetersPath path;
|
|
double[] enthalpy;
|
|
|
|
int lastRefPulses;
|
|
|
|
|
|
public static EnthalpyCalculationOp GetOp(double[] enthalpy, HeatMetersPath path)
|
|
{
|
|
try
|
|
{
|
|
EnthalpyCalculationOp op = new EnthalpyCalculationOp(enthalpy, path);
|
|
return op;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
log.ErrorFormat("Failed to create 'EnthalpyCalculationOp' operation: {0}", exc.Message);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Constructors, optional argument is a timer name (you can create more then one timer)
|
|
/// </summary>
|
|
public EnthalpyCalculationOp(double[] enthalpy, HeatMetersPath path)
|
|
{
|
|
if (enthalpy == null) throw new Exception("enthalpy[] array missing");
|
|
this.enthalpy = enthalpy;
|
|
|
|
if (path == null) throw new Exception("path argument in EnthalpyCalculationOp constructor");
|
|
this.path = path;
|
|
}
|
|
|
|
/// <param name="obj">Time period (TimeSpan)</param>
|
|
public void Start()
|
|
{
|
|
lastRefPulses = Rig.Sequences.ProcessData.RefPulses;
|
|
for (int i = 0; i < enthalpy.Length; i++) enthalpy[i] = 0;
|
|
}
|
|
|
|
public Event Run()
|
|
{
|
|
AccumulateEnthalpy();
|
|
return Event.None;
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
AccumulateEnthalpy();
|
|
}
|
|
|
|
private void AccumulateEnthalpy()
|
|
{
|
|
/// Calculate # of reference pulses
|
|
int newRefPulses = Rig.Sequences.ProcessData.RefPulses;
|
|
int deltaPulses = newRefPulses - lastRefPulses;
|
|
lastRefPulses = newRefPulses;
|
|
|
|
/// Calculate volume [l]
|
|
double deltaVolume = deltaPulses * Rig.Sequences.ProcessData.LtrPerRefPulse;
|
|
|
|
for (int i = 0; i < enthalpy.Length; i++)
|
|
{
|
|
//enthalpy[i] += deltaVolume * (path.TempMetersWarm[i].ReadTemperature() - path.TempMetersCold[i].ReadTemperature());
|
|
}
|
|
}
|
|
}
|
|
}
|