2016-06-23 14:39:56 +00:00
|
|
|
|
///
|
2023-04-18 12:01:23 +00:00
|
|
|
|
/// Copyright (c) 2016-2023 Sensus Slovensko a.s.
|
2016-06-23 14:39:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2018-04-10 14:10:44 +00:00
|
|
|
|
using Config;
|
2016-06-23 14:39:56 +00:00
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.Boxes;
|
2021-10-26 09:23:57 +00:00
|
|
|
|
using TBF.Rig.Keithley.Multimeter_2010_RS232;
|
2020-05-06 07:45:23 +00:00
|
|
|
|
using TBF.Resources;
|
2023-04-18 12:01:23 +00:00
|
|
|
|
using TBF.UI.Calendar;
|
2016-06-23 14:39:56 +00:00
|
|
|
|
|
2021-10-26 09:23:57 +00:00
|
|
|
|
namespace TBF.Rig.Keithley.TempMeter
|
2016-06-23 14:39:56 +00:00
|
|
|
|
{
|
2020-05-06 07:45:23 +00:00
|
|
|
|
public class TempMeter : ComponentBase, GenericDevices.ITempMeter, GenericDevices.IHasCalendarEvents
|
2016-06-23 14:39:56 +00:00
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(TempMeter));
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
2016-06-23 14:39:56 +00:00
|
|
|
|
|
|
|
|
|
|
readonly TempMeterCfg tempMtrCfg; /// configuration
|
|
|
|
|
|
|
|
|
|
|
|
public readonly Multimeter Multimeter; /// parent component
|
|
|
|
|
|
|
2016-08-22 14:14:59 +00:00
|
|
|
|
public int Channel { get { return tempMtrCfg.Channel; } } /// 1..5
|
|
|
|
|
|
|
2016-08-24 08:49:06 +00:00
|
|
|
|
|
|
|
|
|
|
/// Dictionaries to maintain separate operations for each FloatBox argument
|
2016-10-07 13:33:56 +00:00
|
|
|
|
Dictionary<DoubleBox, IOperation> operations;
|
|
|
|
|
|
Dictionary<DoubleBox, IOperation> operations2;
|
2016-08-22 14:14:59 +00:00
|
|
|
|
|
2016-06-23 14:39:56 +00:00
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public TempMeter() { }
|
2016-06-23 14:39:56 +00:00
|
|
|
|
|
2016-08-05 12:32:36 +00:00
|
|
|
|
public TempMeter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
2016-06-23 14:39:56 +00:00
|
|
|
|
: base(cfg)
|
|
|
|
|
|
{
|
2016-08-05 12:32:36 +00:00
|
|
|
|
tempMtrCfg = cfg as TempMeterCfg;
|
2016-06-23 14:39:56 +00:00
|
|
|
|
|
|
|
|
|
|
Multimeter = (Multimeter)TbfComponents.FindComponent(cfg.ParentName, components);
|
|
|
|
|
|
if (Multimeter == null) throw new Exception("Cannot find " + Name + " parent");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
operations = new Dictionary<DoubleBox, IOperation>();
|
|
|
|
|
|
operations2 = new Dictionary<DoubleBox, IOperation>();
|
|
|
|
|
|
log.FatalFormat("{0} initialized: {1}", Name, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-06 07:45:23 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Calendar support
|
|
|
|
|
|
///
|
2023-04-18 12:01:23 +00:00
|
|
|
|
public List<Config.CalendarEvent.ICalendarEvent> GetCalendarEvents()
|
2020-05-06 07:45:23 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
var calEvents = new List<Config.CalendarEvent.ICalendarEvent>();
|
2020-05-06 07:45:23 +00:00
|
|
|
|
|
2023-04-18 12:01:23 +00:00
|
|
|
|
DateTime calibDue = tempMtrCfg.CalibValidDate;
|
|
|
|
|
|
if (calibDue > TBF.UI.Constants.MinDate)
|
2020-05-06 07:45:23 +00:00
|
|
|
|
{
|
2023-04-18 12:01:23 +00:00
|
|
|
|
/// Five weekly notifications
|
|
|
|
|
|
foreach (var days in new int[] { -35, -28, -21, -14 })
|
2020-05-06 07:45:23 +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-05-06 07:45:23 +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-05-06 07:45:23 +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-05-06 07:45:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-04-18 12:01:23 +00:00
|
|
|
|
|
|
|
|
|
|
return calEvents;
|
2020-05-06 07:45:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-07 13:33:56 +00:00
|
|
|
|
public double ReadTemperature()
|
2016-07-07 09:02:35 +00:00
|
|
|
|
{
|
2016-08-24 08:49:06 +00:00
|
|
|
|
double resistance = Multimeter.ReadResistance(tempMtrCfg.Channel);
|
2016-08-22 14:14:59 +00:00
|
|
|
|
|
2016-08-24 08:49:06 +00:00
|
|
|
|
double temperature = 0;
|
2016-08-26 09:36:09 +00:00
|
|
|
|
if (resistance > 0 && resistance < 2000)
|
2016-08-24 08:49:06 +00:00
|
|
|
|
{
|
2016-08-25 15:36:27 +00:00
|
|
|
|
if (tempMtrCfg.UseITS90)
|
|
|
|
|
|
{
|
|
|
|
|
|
temperature = Formulas.PlatinumResistanceTM_ITS90_R2T(resistance,
|
|
|
|
|
|
tempMtrCfg.R001C,
|
|
|
|
|
|
tempMtrCfg.a7,
|
|
|
|
|
|
tempMtrCfg.b7,
|
|
|
|
|
|
tempMtrCfg.c7);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
temperature = Formulas.PlatinumResistanceTM_ITS27_R2T(resistance,
|
|
|
|
|
|
tempMtrCfg.R0,
|
2016-10-07 13:33:56 +00:00
|
|
|
|
tempMtrCfg.A,
|
|
|
|
|
|
tempMtrCfg.B);
|
2016-08-25 15:36:27 +00:00
|
|
|
|
}
|
2016-07-07 09:02:35 +00:00
|
|
|
|
|
2016-08-24 08:49:06 +00:00
|
|
|
|
log.DebugFormat("Ch = {0}, R = {1} Ohm, T = {2} °C", Channel, resistance.ToString("F3"), temperature.ToString("F3"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-07 13:33:56 +00:00
|
|
|
|
return temperature;
|
2016-08-24 08:49:06 +00:00
|
|
|
|
}
|
2016-08-22 14:14:59 +00:00
|
|
|
|
|
2016-06-23 14:39:56 +00:00
|
|
|
|
/// <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>
|
2016-10-07 13:33:56 +00:00
|
|
|
|
public IOperation ReadTempOp(ref DoubleBox temp)
|
2016-06-23 14:39:56 +00:00
|
|
|
|
{
|
2016-08-22 14:14:59 +00:00
|
|
|
|
IOperation operation;
|
|
|
|
|
|
if (operations.TryGetValue(temp, out operation))
|
|
|
|
|
|
{
|
2016-08-24 08:49:06 +00:00
|
|
|
|
return operation; /// Operation already available
|
2016-08-22 14:14:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-08-24 08:49:06 +00:00
|
|
|
|
/// Create a new operation and store it in the dictionary
|
2016-08-22 14:14:59 +00:00
|
|
|
|
operation = new ReadTempOp(this, ref temp);
|
|
|
|
|
|
operations.Add(temp, operation);
|
|
|
|
|
|
return operation;
|
|
|
|
|
|
}
|
2016-06-23 14:39:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2016-10-07 13:33:56 +00:00
|
|
|
|
public IOperation ReadTempOp(ref DoubleBox temp, Event tempDone)
|
2016-06-23 14:39:56 +00:00
|
|
|
|
{
|
2016-08-22 14:14:59 +00:00
|
|
|
|
IOperation operation;
|
|
|
|
|
|
if (operations2.TryGetValue(temp, out operation))
|
|
|
|
|
|
{
|
2016-08-24 08:49:06 +00:00
|
|
|
|
return operation; /// Operation already available
|
2016-08-22 14:14:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-08-24 08:49:06 +00:00
|
|
|
|
/// Create a new operation and store it in the dictionary
|
2016-08-22 14:14:59 +00:00
|
|
|
|
operation = new ReadTempOp(this, ref temp, tempDone);
|
|
|
|
|
|
operations2.Add(temp, operation);
|
|
|
|
|
|
return operation;
|
|
|
|
|
|
}
|
2016-06-23 14:39:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|