///
/// Copyright (c) 2016 Sensus Metering Systems
///
using System;
using log4net;
namespace TBF.BenchControl.Operations
{
///
/// Implements Eoperation to calculate (accumulate) enthalpies of heat meters
///
/// Events: Event.None (always)
///
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;
}
}
///
/// Constructors, optional argument is a timer name (you can create more then one timer)
///
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");
}
/// Time period (TimeSpan)
public void Start()
{
lastRefPulses = BenchControl.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 = BenchControl.Sequences.ProcessData.RefPulses;
int deltaPulses = newRefPulses - lastRefPulses;
lastRefPulses = newRefPulses;
/// Calculate volume [l]
float deltaVolume = (float)deltaPulses * BenchControl.Sequences.ProcessData.LtrPerRefPulse;
for (int i = 0; i < enthalpy.Length; i++)
{
//enthalpy[i] += deltaVolume * (path.TempMetersWarm[i].ReadTemperature() - path.TempMetersCold[i].ReadTemperature());
}
}
}
}