2016-06-23 14:39:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2016 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using TBF.Boxes;
|
2016-08-22 14:14:59 +00:00
|
|
|
|
using TBF.BenchControl.Keithley.Multimeter_2010_RS232;
|
2016-06-23 14:39:56 +00:00
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.Keithley.TempMeter
|
|
|
|
|
|
{
|
|
|
|
|
|
public class TempMeter : ComponentBase, GenericDevices.ITempMeter
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(TempMeter));
|
|
|
|
|
|
public override string ToString() { return string.Format("Keithley.TempMeter({0})", Cfg.ToString(1)); }
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<FloatBox, IOperation> operations;
|
|
|
|
|
|
Dictionary<FloatBox, IOperation> operations2;
|
|
|
|
|
|
|
2016-06-23 14:39:56 +00:00
|
|
|
|
|
|
|
|
|
|
public TempMeter()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
2016-08-22 14:14:59 +00:00
|
|
|
|
operations = new Dictionary<FloatBox, IOperation>();
|
|
|
|
|
|
operations2 = new Dictionary<FloatBox, IOperation>();
|
|
|
|
|
|
|
2016-06-23 14:39:56 +00:00
|
|
|
|
log.Debug(this.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-07 09:02:35 +00:00
|
|
|
|
public float ReadTemperature()
|
|
|
|
|
|
{
|
2016-08-22 14:14:59 +00:00
|
|
|
|
double resistance = Multimeter.ReadResistance(Channel);
|
|
|
|
|
|
|
|
|
|
|
|
return Resistance2Temperature(resistance);
|
2016-07-07 09:02:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-22 14:14:59 +00:00
|
|
|
|
private float Resistance2Temperature(double resistance)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 30.0F + (float)tempMtrCfg.Channel; /// TODO: implement
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
public IOperation ReadTempOp(ref FloatBox temp)
|
|
|
|
|
|
{
|
2016-08-22 14:14:59 +00:00
|
|
|
|
IOperation operation;
|
|
|
|
|
|
if (operations.TryGetValue(temp, out operation))
|
|
|
|
|
|
{
|
|
|
|
|
|
return operation;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
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>
|
|
|
|
|
|
public IOperation ReadTempOp(ref FloatBox temp, Event tempDone)
|
|
|
|
|
|
{
|
2016-08-22 14:14:59 +00:00
|
|
|
|
IOperation operation;
|
|
|
|
|
|
if (operations2.TryGetValue(temp, out operation))
|
|
|
|
|
|
{
|
|
|
|
|
|
return operation;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
operation = new ReadTempOp(this, ref temp, tempDone);
|
|
|
|
|
|
operations2.Add(temp, operation);
|
|
|
|
|
|
return operation;
|
|
|
|
|
|
}
|
2016-06-23 14:39:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|