/// /// Copyright (c) 2016 Sensus Metering Systems /// using System; using System.Collections.Generic; using log4net; using TBF.Boxes; using TBF.BenchControl.Keithley.Multimeter_2010_RS232; 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 public int Channel { get { return tempMtrCfg.Channel; } } /// 1..5 Dictionary operations; Dictionary operations2; public TempMeter() { } public TempMeter(Generic.IComponentCfg cfg, IList components) : base(cfg) { tempMtrCfg = cfg as TempMeterCfg; Multimeter = (Multimeter)TbfComponents.FindComponent(cfg.ParentName, components); if (Multimeter == null) throw new Exception("Cannot find " + Name + " parent"); operations = new Dictionary(); operations2 = new Dictionary(); log.Debug(this.ToString()); } public float ReadTemperature() { double resistance = Multimeter.ReadResistance(Channel); return Resistance2Temperature(resistance); } private float Resistance2Temperature(double resistance) { return 30.0F + (float)tempMtrCfg.Channel; /// TODO: implement } /// /// Events: TempDone, Error /// /// Reference to a variable for the temperature in Celsius /// ReadTempOp instance reference casted to IOperaton public IOperation ReadTempOp(ref FloatBox temp) { IOperation operation; if (operations.TryGetValue(temp, out operation)) { return operation; } else { operation = new ReadTempOp(this, ref temp); operations.Add(temp, operation); return operation; } } /// /// Events: tempDone, Error /// /// Reference to a variable for the temperature in Celsius /// Event returned when measurement done /// ReadTempOp instance reference casted to IOperaton public IOperation ReadTempOp(ref FloatBox temp, Event tempDone) { IOperation operation; if (operations2.TryGetValue(temp, out operation)) { return operation; } else { operation = new ReadTempOp(this, ref temp, tempDone); operations2.Add(temp, operation); return operation; } } } }