/// /// Copyright (c) 2017 Sensus Metering Systems /// using System; using System.Collections.Generic; using log4net; using TBF.BenchControl.Generic; using TBF.Boxes; namespace TBF.BenchControl.Modbus.Easytherm { public class Easytherm : ComponentBase, IDevice { private static readonly ILog log = LogManager.GetLogger(typeof(Easytherm)); public override string ToString() { return string.Format("Easytherm({0})", Cfg.ToString(1)); } readonly EasythermCfg easythermCfg; readonly GenericDevices.IModbus modbus; private ushort temperatureSetpoint; public Easytherm() { } public Easytherm(Generic.IComponentCfg cfg, IList components) : base(cfg) { easythermCfg = cfg as EasythermCfg; modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components); if (modbus == null) throw new Exception("Cannot find " + Name + " parent"); log.Debug(this.ToString()); } /// Initialize this device public void Initialize() { } /// Run this device public void RunDeviceBefore() { } /// Run this device public void RunDeviceAfter() { } /// Stop this device public void StopDevice() { } /// /// Set outputs of QuidoRS board /// /// output value public void SetTemperature(ushort temperature) { temperatureSetpoint = temperature; SendTemperature(temperatureSetpoint); } private void SendTemperature(ushort temperatureSetpoint) { byte[] msg = new byte[8]; msg[0] = easythermCfg.ModbusAddress; msg[1] = (byte)Function.PresetSingleRegister; msg[2] = 0; /// Relative address Hi msg[3] = 2; /// Relative address Lo msg[4] = (byte)(temperatureSetpoint >> 8); /// Output data Hi msg[5] = (byte)(temperatureSetpoint & 0xFF); /// Output data Lo modbus.SendMessage(msg); } /// /// Events: SetOpututsDone, Error /// /// Reference to a variable for the pressure in Bar /// SetOutputsOp instance reference casted to IOperaton public IOperation SetTemperatureOp(ushort temperatureSetpoint) { return new SetTemperatureOp(this, temperatureSetpoint); } /// /// Events: pressureDone, Error /// /// Reference to a variable for the pressure in Bar /// Event returned when SetOutput is done /// SetOutputsOp instance reference casted to IOperaton public IOperation ReadTemperatureOp(ushort outValue, Event setOutputsDone) { return new ReadTemperatureOp(this, outValue, setOutputsDone); } } }