101 lines
4.3 KiB
C#
101 lines
4.3 KiB
C#
///
|
|
/// Copyright (c) 2018 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using TBF.Boxes;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.Rig.Elde.TempMeterMeret
|
|
{
|
|
public class TempMeter : ComponentBase, GenericDevices.ITempMeter, GenericDevices.IHasCalendarEvents
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(TempMeter));
|
|
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
|
|
|
readonly TempMeterCfg tempMtrCfg;
|
|
|
|
public readonly ControlBoardDev ControlBoard;
|
|
|
|
|
|
public TempMeter() { }
|
|
|
|
public TempMeter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
|
: base(cfg)
|
|
{
|
|
tempMtrCfg = cfg as TempMeterCfg;
|
|
|
|
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
|
|
ControlBoard.MeretRS485Address[tempMtrCfg.MeretIdx0] = tempMtrCfg.ModbusAddress;
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
log.FatalFormat("{0} initialized: {1}", Name, this);
|
|
}
|
|
|
|
|
|
public IList<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
|
|
{
|
|
DateTime calibrationDue = tempMtrCfg.CalibValidDate;
|
|
IList<Config.CalendarEvent.ICalendarEvent> calendarEvents = new List<Config.CalendarEvent.ICalendarEvent>();
|
|
|
|
if (calibrationDue > TBF.UI.Constants.MinDate)
|
|
{
|
|
/// Calibration due date calendar event
|
|
calendarEvents.Add(new TBF.UI.Calendar.CalibrationDueDateEvent(calibrationDue.Date, Name,
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat))));
|
|
if (DateTime.Now.Date <= calibrationDue.AddDays(-7))
|
|
{
|
|
/// Weekly reminders (last 5 weeks)
|
|
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.Date.AddDays(-35), Name,
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
|
|
false));
|
|
}
|
|
if (DateTime.Now.Date <= calibrationDue.Date)
|
|
{
|
|
/// Daily reminders (last 5 days)
|
|
calendarEvents.Add(new TBF.UI.Calendar.CalibrationReminderEvent(calibrationDue.AddDays(-5), Name,
|
|
string.Format(Strings.Calibration_due_date_is_0,
|
|
calibrationDue.Date.ToString(TBF.UI.Constants.DateFormat)),
|
|
true));
|
|
}
|
|
}
|
|
return calendarEvents;
|
|
}
|
|
|
|
|
|
public double ReadTemperature()
|
|
{
|
|
return Config.Entities.MeasurementCorrection.CorrectedValue((double)ControlBoard.Temperature(tempMtrCfg.TempIdx0), Corrections);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Events: TempDone, Error
|
|
/// </summary>
|
|
/// <param name="temp">Reference to a variable for the temperature in Celsius</param>
|
|
/// <returns>ReadTempOp instance reference casted to IOperaton</returns>
|
|
public IOperation ReadTempOp(ref DoubleBox temp)
|
|
{
|
|
return new ReadTempOp(this, ref temp);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Events: tempDone, Error
|
|
/// </summary>
|
|
/// <param name="temp">Reference to a variable for the temperature in Celsius</param>
|
|
/// <param name="tempDone">Event returned when measurement done</param>
|
|
/// <returns>ReadTempOp instance reference casted to IOperaton</returns>
|
|
public IOperation ReadTempOp(ref DoubleBox temp, Event tempDone)
|
|
{
|
|
return new ReadTempOp(this, ref temp, tempDone);
|
|
}
|
|
}
|
|
}
|