diff --git a/DeviceTest/DeviceTestDlg.cs b/DeviceTest/DeviceTestDlg.cs index 977cd2c0a..3e71e95bd 100644 --- a/DeviceTest/DeviceTestDlg.cs +++ b/DeviceTest/DeviceTestDlg.cs @@ -680,13 +680,13 @@ namespace DeviceTest } else if (tbfComponent1forOp is TBF.Rig.Modbus.TempControl.Easytherm.TControl) { - operation1 = (tbfComponent1forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureOp(10); - operation2 = (tbfComponent1forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureOp(20); + operation1 = (tbfComponent1forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureSetpointOp(10); + operation2 = (tbfComponent1forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureSetpointOp(20); } else if (tbfComponent1forOp is TBF.Rig.Modbus.TempControl.Novus.TControl) { - operation1 = (tbfComponent1forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureOp(10); - operation2 = (tbfComponent1forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureOp(20); + operation1 = (tbfComponent1forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureSetpointOp(10); + operation2 = (tbfComponent1forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureSetpointOp(20); } else if (tbfComponent1forOp is TBF.Rig.Modbus.UltrasoundLevelMeter.LevelMeter) { @@ -724,13 +724,13 @@ namespace DeviceTest } else if (tbfComponent2forOp is TBF.Rig.Modbus.TempControl.Easytherm.TControl) { - operation21 = (tbfComponent2forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureOp(10); - operation22 = (tbfComponent2forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureOp(20); + operation21 = (tbfComponent2forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureSetpointOp(10); + operation22 = (tbfComponent2forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureSetpointOp(20); } else if (tbfComponent2forOp is TBF.Rig.Modbus.TempControl.Novus.TControl) { - operation21 = (tbfComponent2forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureOp(10); - operation22 = (tbfComponent2forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureOp(20); + operation21 = (tbfComponent2forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureSetpointOp(10); + operation22 = (tbfComponent2forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureSetpointOp(20); } else if (tbfComponent2forOp is TBF.Rig.Modbus.UltrasoundLevelMeter.LevelMeter) { @@ -768,13 +768,13 @@ namespace DeviceTest } else if (tbfComponent3forOp is TBF.Rig.Modbus.TempControl.Easytherm.TControl) { - operation31 = (tbfComponent3forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureOp(10); - operation32 = (tbfComponent3forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureOp(20); + operation31 = (tbfComponent3forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureSetpointOp(10); + operation32 = (tbfComponent3forOp as TBF.Rig.Modbus.TempControl.Easytherm.TControl).SetTemperatureSetpointOp(20); } else if (tbfComponent3forOp is TBF.Rig.Modbus.TempControl.Novus.TControl) { - operation31 = (tbfComponent3forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureOp(10); - operation32 = (tbfComponent3forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureOp(20); + operation31 = (tbfComponent3forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureSetpointOp(10); + operation32 = (tbfComponent3forOp as TBF.Rig.Modbus.TempControl.Novus.TControl).SetTemperatureSetpointOp(20); } else if (tbfComponent3forOp is TBF.Rig.Modbus.UltrasoundLevelMeter.LevelMeter) { diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 84886a980..960dd2707 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("3.2.1910.0")] -[assembly: AssemblyFileVersion("3.2.1910.0")] +[assembly: AssemblyVersion("3.2.1911.0")] +[assembly: AssemblyFileVersion("3.2.1911.0")] diff --git a/TBF/Rig/Dummy/TempControl/Component.cs b/TBF/Rig/Dummy/TempControl/Component.cs index 48896d951..133c6b4ef 100644 --- a/TBF/Rig/Dummy/TempControl/Component.cs +++ b/TBF/Rig/Dummy/TempControl/Component.cs @@ -32,6 +32,6 @@ namespace TBF.Rig.Dummy.TempControl public IOperation ReadTempOp(ref DoubleBox temp) { return null; } public IOperation ReadTempOp(ref DoubleBox temp, Event tempDone) { return null; } - public IOperation SetRequiredTemperatureOp() { return null; } + public IOperation SetTemperatureSetpointOp(double temperature) { return null; } } } diff --git a/TBF/Rig/GenericDevices/ITempControl.cs b/TBF/Rig/GenericDevices/ITempControl.cs index ba80339cf..238cc6e00 100644 --- a/TBF/Rig/GenericDevices/ITempControl.cs +++ b/TBF/Rig/GenericDevices/ITempControl.cs @@ -12,8 +12,8 @@ namespace TBF.Rig.GenericDevices /// /// Temperature in °C /// true = OK, false = any error - bool SetTemperatureSetpoint(double reqTempC); + bool SetTemperatureSetpoint(double temperatureC); - IOperation SetRequiredTemperatureOp(); + IOperation SetTemperatureSetpointOp(double temperatureC); } } diff --git a/TBF/Rig/Modbus/TankSelector/TankSelector.cs b/TBF/Rig/Modbus/TankSelector/TankSelector.cs index 117d55a38..6c54c42f2 100644 --- a/TBF/Rig/Modbus/TankSelector/TankSelector.cs +++ b/TBF/Rig/Modbus/TankSelector/TankSelector.cs @@ -334,11 +334,11 @@ namespace TBF.Rig.Modbus.TankSelector AddCondition(Strings.Select_WARM_tank, createOps, new SelectTankOp(this, TankId.Warm)); AddCondition(Strings.Select_HOT_tank, createOps, new SelectTankOp(this, TankId.Hot)); AddCondition(Strings.Unselect_current_tank, createOps, new UnselectTankOp(this)); - AddCondition(Strings.Set_hot_water_heating_temperature, createOps, hotHeating.SetRequiredTemperatureOp()); - AddCondition(Strings.Set_hot_water_cooling_temperature, createOps, hotCooling.SetRequiredTemperatureOp()); - AddCondition(Strings.Set_warm_water_heating_temperature, createOps, warmHeating.SetRequiredTemperatureOp()); - AddCondition(Strings.Set_warm_water_cooling_temperature, createOps, warmCooling.SetRequiredTemperatureOp()); - AddCondition(Strings.Set_cold_water_cooling_temperature, createOps, coldCooling.SetRequiredTemperatureOp()); + //AddCondition(Strings.Set_hot_water_heating_temperature, createOps, hotHeating.SetRequiredTemperatureOp()); + //AddCondition(Strings.Set_hot_water_cooling_temperature, createOps, hotCooling.SetRequiredTemperatureOp()); + //AddCondition(Strings.Set_warm_water_heating_temperature, createOps, warmHeating.SetRequiredTemperatureOp()); + //AddCondition(Strings.Set_warm_water_cooling_temperature, createOps, warmCooling.SetRequiredTemperatureOp()); + //AddCondition(Strings.Set_cold_water_cooling_temperature, createOps, coldCooling.SetRequiredTemperatureOp()); AddCondition("Start heating hot water", createOps, new SetQuidoBitOp(quidoRS, QuidoOutputs.HeatingHotTank, true)); AddCondition("Stop heating hot water", createOps, new SetQuidoBitOp(quidoRS, QuidoOutputs.HeatingHotTank, false)); AddCondition("Start cooling hot water", createOps, new SetQuidoBitOp(quidoRS, QuidoOutputs.CoolingHotTank, true)); diff --git a/TBF/Rig/Modbus/TempControl/Easytherm/ProcParams.cs b/TBF/Rig/Modbus/TempControl/Easytherm/ProcParams.cs index a8d77bfaf..05be1b3b9 100644 --- a/TBF/Rig/Modbus/TempControl/Easytherm/ProcParams.cs +++ b/TBF/Rig/Modbus/TempControl/Easytherm/ProcParams.cs @@ -5,136 +5,163 @@ using System.IO; using System.Xml.Serialization; using Common; using Config.Entities; -using TBF.Rig.Generic; using TBF.Resources; +using TBF.Rig.Generic; +using TBF.Rig.Sequences; namespace TBF.Rig.Modbus.TempControl.Easytherm { - public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams - { - public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0]; - public override XmlSerializer GetSerializer() { return Serializer; } + public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams + { + public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0]; + public override XmlSerializer GetSerializer() { return Serializer; } - public double RequiredTemp; /// [°C] target temperature for a temperature controller or 0=not communicated to the controller + public double Temp_A; /// [°C] Target temperature for a tempe. controller or 0=not communicated to the controller + public double Temp_B; /// [°C] Target temperature for a tempe. controller or 0=not communicated to the controller + public double Temp_C; /// [°C] Target temperature for a tempe. controller or 0=not communicated to the controller + public double Temp_D; /// [°C] Target temperature for a tempe. controller or 0=not communicated to the controller + public double Temp_E; /// [°C] Target temperature for a tempe. controller or 0=not communicated to the controller - public override void InitializeAll() + public override void InitializeAll() + { + Temp_A = 10.0; + Temp_B = 20.0; + Temp_C = 30.0; + Temp_D = 40.0; + Temp_E = 50.0; + } + + string[] paramNames = new string[] { - RequiredTemp = 0; - } - - string[] paramNames = new string[] - { - Strings.Required_temperature_C, + string.Format("{0} A [{1}]", Strings.Temperature, ProcessData.TempUnit.ToDescription()), + string.Format("{0} B [{1}]", Strings.Temperature, ProcessData.TempUnit.ToDescription()), + string.Format("{0} C [{1}]", Strings.Temperature, ProcessData.TempUnit.ToDescription()), + string.Format("{0} D [{1}]", Strings.Temperature, ProcessData.TempUnit.ToDescription()), + string.Format("{0} E [{1}]", Strings.Temperature, ProcessData.TempUnit.ToDescription()), }; - public override string ParamName(int i) { return paramNames[i]; } - public override int ParamsCount() { return paramNames.Length; } + public override string ParamName(int i) { return paramNames[i]; } + public override int ParamsCount() { return paramNames.Length; } - public override string ToString(int i) - { - switch (i) - { - case 0: return (RequiredTemp == 0) ? "---" : RequiredTemp.ToString(); - default: return string.Empty; - } - } + public override string ToString(int i) + { + switch (i) + { + case 0: return (Temp_A == 0) ? "---" : Units.ConvertTo(ProcessData.TempUnit, Temp_A).ToString(); + case 1: return (Temp_B == 0) ? "---" : Units.ConvertTo(ProcessData.TempUnit, Temp_B).ToString(); + case 2: return (Temp_C == 0) ? "---" : Units.ConvertTo(ProcessData.TempUnit, Temp_C).ToString(); + case 3: return (Temp_D == 0) ? "---" : Units.ConvertTo(ProcessData.TempUnit, Temp_D).ToString(); + case 4: return (Temp_E == 0) ? "---" : Units.ConvertTo(ProcessData.TempUnit, Temp_E).ToString(); + default: return string.Empty; + } + } - public CfgUpdateFlags UpdateParam(int i, string strValue) - { - switch (i) - { + public CfgUpdateFlags UpdateParam(int i, string str) + { + bool isDash = (str == "-" || str == "--" || str == "---"); + switch (i) + { case 0: - if (strValue == "-" || strValue == "--" || strValue == "---") - { - RequiredTemp = 0; - } - else - { - RequiredTemp = Utils.ParseUDouble(strValue); - } + Temp_A = isDash ? 0 : Units.ConvertFrom(ProcessData.TempUnit, Utils.ParseUDouble(str)); return CfgUpdateFlags.None; - default: + case 1: + Temp_B = isDash ? 0 : Units.ConvertFrom(ProcessData.TempUnit, Utils.ParseUDouble(str)); return CfgUpdateFlags.None; - } - } + case 2: + Temp_C = isDash ? 0 : Units.ConvertFrom(ProcessData.TempUnit, Utils.ParseUDouble(str)); + return CfgUpdateFlags.None; + case 3: + Temp_D = isDash ? 0 : Units.ConvertFrom(ProcessData.TempUnit, Utils.ParseUDouble(str)); + return CfgUpdateFlags.None; + case 4: + Temp_E = isDash ? 0 : Units.ConvertFrom(ProcessData.TempUnit, Utils.ParseUDouble(str)); + return CfgUpdateFlags.None; + default: + return CfgUpdateFlags.None; + } + } - /// - /// Verifiy the string representation of the parameter - /// - /// Parameter ID - /// String representation of the parameter - /// In case false is returned this is the error messsage to be displayed - /// true = parameter OK, false = parameter NOK - public bool ValidateParam(int i, string strValue, out string message) - { - message = string.Empty; + /// + /// Verifiy the string representation of the parameter + /// + /// Parameter ID + /// String representation of the parameter + /// In case false is returned this is the error messsage to be displayed + /// true = parameter OK, false = parameter NOK + public bool ValidateParam(int i, string str, out string message) + { + message = string.Empty; - double temp; - switch (i) - { - case 0: /// T_hot_heating - if (strValue == "-" || strValue == "--" || strValue == "---" || - (Utils.TryParseUDouble(strValue, out temp) && (temp == 0 || (temp >= 5 && temp <= 95.0f)))) - { - return true; - } + double ddummy; + switch (i) + { + case 0: /// T_hot_heating + if (str == "-" || str == "--" || str == "---" || + (Utils.TryParseUDouble(str, out ddummy) && (ddummy == 0 || (ddummy >= 5 && ddummy <= 95.0)))) + { + return true; + } break; - default: - message = "Invalid index"; - return false; - } + default: + message = "Invalid index"; + return false; + } - message = ParamName(i) + " is invalid"; - return false; - } + message = ParamName(i) + " is invalid"; + return false; + } - void CopyContentTo(ProcParams prms) - { - prms.RequiredTemp = this.RequiredTemp; - } + void CopyContentTo(ProcParams prms) + { + prms.Temp_A = Temp_A; + prms.Temp_B = Temp_B; + prms.Temp_C = Temp_C; + prms.Temp_D = Temp_D; + prms.Temp_E = Temp_E; + } - public IParamsProvider Clone() - { - ProcParams pars = new ProcParams(); - CopyContentTo(pars); - return pars; - } + public IParamsProvider Clone() + { + ProcParams pars = new ProcParams(); + CopyContentTo(pars); + return pars; + } - public override void UpdateFromDbEntity(ComponentProcedure dbEntity) - { - if (dbEntity == null) return; - try - { - ProcParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as ProcParams; + public override void UpdateFromDbEntity(ComponentProcedure dbEntity) + { + if (dbEntity == null) return; + try + { + ProcParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as ProcParams; - procedureParamsEntity = dbEntity; - componentName = dbEntity.CmpntName; - procedure = dbEntity.Procedure; + procedureParamsEntity = dbEntity; + componentName = dbEntity.CmpntName; + procedure = dbEntity.Procedure; - if (tmp != null) tmp.CopyContentTo(this); - } - catch - { - } - } + if (tmp != null) tmp.CopyContentTo(this); + } + catch + { + } + } - /// - /// Parameterless constructor initializes the parameters - /// - public ProcParams() - { - } + /// + /// Parameterless constructor initializes the parameters + /// + public ProcParams() + { + } - public ProcParams(bool initialize) - { - if (initialize) InitializeAll(); - } + public ProcParams(bool initialize) + { + if (initialize) InitializeAll(); + } - public ProcParams(ComponentProcedure procParamsEntity, string componentName, Procedure procedure) - { - this.procedureParamsEntity = procParamsEntity; - this.componentName = componentName; - this.procedure = procedure; - } - } + public ProcParams(ComponentProcedure procParamsEntity, string componentName, Procedure procedure) + { + this.procedureParamsEntity = procParamsEntity; + this.componentName = componentName; + this.procedure = procedure; + } + } } diff --git a/TBF/Rig/Modbus/TempControl/Easytherm/SetRequiredTemperatureOp.cs b/TBF/Rig/Modbus/TempControl/Easytherm/SetTemperatureSetpointOp.cs similarity index 64% rename from TBF/Rig/Modbus/TempControl/Easytherm/SetRequiredTemperatureOp.cs rename to TBF/Rig/Modbus/TempControl/Easytherm/SetTemperatureSetpointOp.cs index 82cdd5908..6fa99e37a 100644 --- a/TBF/Rig/Modbus/TempControl/Easytherm/SetRequiredTemperatureOp.cs +++ b/TBF/Rig/Modbus/TempControl/Easytherm/SetTemperatureSetpointOp.cs @@ -7,14 +7,15 @@ using TBF.Boxes; namespace TBF.Rig.Modbus.TempControl.Easytherm { - public class SetRequiredTemperatureOp : IOperation + public class SetTemperatureSetpointOp : IOperation { - private static readonly ILog log = LogManager.GetLogger(typeof(SetRequiredTemperatureOp)); - public override string ToString() { return string.Format("SetRequiredTemperatureOp({0})", eventDone); } + private static readonly ILog log = LogManager.GetLogger(typeof(SetTemperatureSetpointOp)); + public override string ToString() { return string.Format("SetTemperatureSetpointOp({0})", eventDone); } /// Set by the constructor readonly TControl easytherm; - readonly Event eventDone; + readonly double temperature; + readonly Event eventDone; /// /// Events: PressureInDone, PressureOutDone or Error @@ -22,23 +23,24 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm /// Pressure meter reference /// Reference to the measured pressure variable, value is in bar /// Event to be returned by Run() when completed OK - public SetRequiredTemperatureOp(TControl easytherm, Event eventDone) + public SetTemperatureSetpointOp(TControl easytherm, double temperature, Event eventDone) { if (easytherm == null) throw new ArgumentNullException("easytherm"); this.easytherm = easytherm; + this.temperature = temperature; this.eventDone = eventDone; log.Debug(this.ToString()); } - public SetRequiredTemperatureOp(TControl easytherm) - : this(easytherm, Event.ConditionMet) + public SetTemperatureSetpointOp(TControl easytherm, double temperature) + : this(easytherm, temperature, Event.ConditionMet) { } /// Start this operation public void Start() { - easytherm.SetTemperatureSetpoint(); + easytherm.SetTemperatureSetpoint(temperature); } /// Run this operation diff --git a/TBF/Rig/Modbus/TempControl/Easytherm/TControl.cs b/TBF/Rig/Modbus/TempControl/Easytherm/TControl.cs index 04defe9fa..d5c525214 100644 --- a/TBF/Rig/Modbus/TempControl/Easytherm/TControl.cs +++ b/TBF/Rig/Modbus/TempControl/Easytherm/TControl.cs @@ -6,17 +6,20 @@ using System.Collections.Generic; using log4net; using Common; using Config.Entities; +using SchematicDrawing; using TBF.Rig.GenericDevices; using TBF.Boxes; namespace TBF.Rig.Modbus.TempControl.Easytherm { - public class TControl : ComponentBase, Generic.IDevice, ITempControl - { + public class TControl : ComponentBase, Generic.IDevice, ITempControl, ISequenceCondition, + IDrawingItCmpntWithSetpoint, IDrawingItCmpntWithMeasuredVal, IDrawingItCmpntWithCustomBmp + { private static readonly ILog log = LogManager.GetLogger(typeof(TControl)); public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); } readonly TControlCfg easythermCfg; + public IDrawingItem DrawingItem { get { return easythermCfg as IDrawingItem; } } Common.Modbus modbus; int ticketNumber; /// 0 .. number of devices registered for regular polling - 1 @@ -29,11 +32,76 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm public string MsrdFormat { get { return easythermCfg.MsrdFormat; } } public string AltString { get { return string.Empty; } } + public double SetpointVal + { + get { return temperatureSetPoint; } + set { SetTemperatureSetpoint(value); } + } + /// + public void IncreaseSetpoint() + { + double tempStepC = isFahrenheit ? Units.ConvertFrom(Unit.F, easythermCfg.SetpStep) : easythermCfg.SetpStep; + + double newSetpoint; + if (easythermCfg.RoundToSetpStep) + { + double roundedSetpoint = tempStepC * Math.Round(temperatureSetPoint / tempStepC); + newSetpoint = (roundedSetpoint <= temperatureSetPoint) ? (roundedSetpoint + tempStepC) : roundedSetpoint; + } + else + { + newSetpoint = temperatureSetPoint + tempStepC; + } + + SetTemperatureSetpoint(Math.Min(newSetpoint, 95.0)); + } + /// + public void DecreaseSetpoint() + { + double tempStepC = isFahrenheit ? Units.ConvertFrom(Unit.F, easythermCfg.SetpStep) : easythermCfg.SetpStep; + + double newSetpoint; + if (easythermCfg.RoundToSetpStep) + { + double roundedSetpoint = tempStepC * Math.Round(temperatureSetPoint / tempStepC); + newSetpoint = (roundedSetpoint >= temperatureSetPoint) ? (roundedSetpoint - tempStepC) : roundedSetpoint; + } + else + { + newSetpoint = temperatureSetPoint - tempStepC; + } + + SetTemperatureSetpoint(Math.Max(newSetpoint, 5.0)); + } + + public DrawingShape GetCustomBitmap() + { + switch (easythermCfg.Sz) + { + case Sz.S: + return isHeating ? (isCooling ? TControlCfg.DSBothS : TControlCfg.DSHeatingS) + : (isCooling ? TControlCfg.DSCoolingS : TControlCfg.DSIdleS); + case Sz.M: + return isHeating ? (isCooling ? TControlCfg.DSBothM : TControlCfg.DSHeatingM) + : (isCooling ? TControlCfg.DSCoolingM : TControlCfg.DSIdleM); + default: + case Sz.L: + return isHeating ? (isCooling ? TControlCfg.DSBothL : TControlCfg.DSHeatingL) + : (isCooling ? TControlCfg.DSCoolingL : TControlCfg.DSIdleL); + case Sz.XL: + return isHeating ? (isCooling ? TControlCfg.DSBothXL : TControlCfg.DSHeatingXL) + : (isCooling ? TControlCfg.DSCoolingXL : TControlCfg.DSIdleXL); + } + } + private double temperatureSetPoint; private bool temperatureSetPointValid; private bool temperatureSetPointRequested; + double actualTemperature; - public double requiredTemp { get { return easythermCfg.ProcParams.RequiredTemp; } } + bool isHeating { get { return false; } } /// TODO: ??? Output x: Heating + bool isCooling { get { return false; } } /// TODO: ??? Output y: Cooling + bool isFahrenheit { get { return false; } } public TControl() { } @@ -42,7 +110,9 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm : base(cfg) { easythermCfg = cfg as TControlCfg; - } + + CreateConditions(true); + } /// Initialize this device public override void Initialize() @@ -83,22 +153,24 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm public void RunDeviceAfter() { - if (modbus.IsMyTurn(ticketNumber)) + if (DebugLevel != DebugMode.Simulate && DebugLevel != DebugMode.FailureDuringOperation && + modbus.IsMyTurn(ticketNumber)) { if (!temperatureSetPointValid && !temperatureSetPointRequested) { - RequestTemperatureSetpoint(); + //RequestTemperatureSetpoint(); temperatureSetPointRequested = true; } - else if (temperatureSetPointValid && requiredTemp != temperatureSetPoint) - { - SetTemperatureSetpoint(requiredTemp); - log.InfoFormat("{0} - Set new temperature setpoint = {1}", Name, requiredTemp); - } - else if (modbus.IsMyTurn(ticketNumber)) - { - RequestActualTemperature(); - } + /// TODO: ??? + //else if (temperatureSetPointValid && requiredTemp != temperatureSetPoint) + //{ + // SetTemperatureSetpoint(requiredTemp); + // log.InfoFormat("{0} - Set new temperature setpoint = {1}", Name, requiredTemp); + //} + //else if (modbus.IsMyTurn(ticketNumber)) + //{ + // RequestActualTemperature(); + //} } } @@ -106,52 +178,38 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm public void StopDevice2() { } - /// - /// Set Easytherm controller to required temperature procedure parameter - /// - /// true = OK, false = any error - public bool SetTemperatureSetpoint() - { - return SetTemperatureSetpoint(requiredTemp); - } - /// /// Set Easytherm controller to specified temperature /// - /// Temperature in °C + /// Temperature in °C /// true = OK, false = any error - public bool SetTemperatureSetpoint(double temperature) + public bool SetTemperatureSetpoint(double temperatureC) { - if (temperature != 0 && (temperature < 5.0 || temperature > 95.0)) + if (temperatureC != 0 && (temperatureC < 5.0 || temperatureC > 95.0)) { return false; /// required temperature out of range } - if (temperatureSetPointValid && (temperature == temperatureSetPoint)) + if (temperatureSetPointValid && (temperatureC == temperatureSetPoint)) { return true; /// already set to the required temperature } - if (temperature != 0) /// temperature==0 disables sending the setpoint + if (temperatureC != 0) /// temperature==0 disables sending the setpoint { //ushort temperatureSetpoint = (ushort)temperature; // in °C //ushort destAddress = (ushort)1002; - ushort usTempSetpoint = (ushort)((10000.0f / 400.0f) * temperature); // in 0.01% of range (400 °C) + ushort usTempSetpoint = (ushort)((10000.0f / 400.0f) * temperatureC); // in 0.01% of range (400 °C) ushort destAddress = (ushort)2; /// SendValueToEasytherm(Function.PresetSingleRegister, destAddress, usTempSetpoint); } - temperatureSetPoint = temperature; + temperatureSetPoint = temperatureC; temperatureSetPointValid = true; return true; } - public void RequestTemperatureSetpoint() - { - SendValueToEasytherm(Function.ReadHoldingRegisters, (ushort)2, (ushort)1); // rel.address=2, 1 word - } - public void RequestActualTemperature() { SendValueToEasytherm(Function.ReadInputRegister, (ushort)0, (ushort)1); // rel.address=x, 1 word @@ -176,9 +234,6 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm /// /// Operations, etc. /// - - double actualTemperature; - public double ReadTemperature() { return actualTemperature; @@ -189,19 +244,9 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm /// Events: SetOpututsDone, Error /// /// SetOutputsOp instance reference casted to IOperaton - public IOperation SetRequiredTemperatureOp() + public IOperation SetTemperatureSetpointOp(double temperature) { - return new SetRequiredTemperatureOp(this); - } - - /// - /// Events: SetOpututsDone, Error - /// - /// Reference to a variable for the pressure in Bar - /// SetOutputsOp instance reference casted to IOperaton - public IOperation SetTemperatureOp(float temperature) - { - return new SetTemperatureOp(this, temperature); + return new SetTemperatureSetpointOp(this, temperature); } public IOperation ReadTempOp(ref DoubleBox temp) @@ -213,5 +258,59 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm { return new ReadTempOp(this, ref temp, eventDone); } - } + + + + /// + /// ISequenceCondition interface implementation (conditions in transition sequences) + /// + IList sequenceConditionNames; + IList sequenceConditions; + + public int ConditionsCount { get { return sequenceConditions != null ? sequenceConditions.Count : 0; } } + + /// Strings are added to the combo-box for transition sequence condition selection + public string ConditionName(int i) + { + if (sequenceConditionNames != null && i < sequenceConditionNames.Count && i >= 0) + return sequenceConditionNames[i]; + else + return string.Empty; + } + + /// Operations are executed as a part of a transition sequence + public IOperation ConditionOp(int i) + { + if (sequenceConditions != null && i < sequenceConditions.Count && i >= 0) + return sequenceConditions[i]; + else + return null; + } + + void ClearConditions() + { + sequenceConditionNames = new List(); + sequenceConditions = new List(); + } + + void AddCondition(string conditionName, bool createOperation, IOperation conditionOperation) + { + sequenceConditionNames.Add(conditionName); + if (createOperation) sequenceConditions.Add(conditionOperation); + } + + /// + /// Create a list of conditions + /// + /// true = create names and condition operations, false = create names only + void CreateConditions(bool createOps) + { + ClearConditions(); + AddCondition("Set temperature setpoint A", createOps, SetTemperatureSetpointOp(easythermCfg.ProcParams.Temp_A)); + AddCondition("Set temperature setpoint B", createOps, SetTemperatureSetpointOp(easythermCfg.ProcParams.Temp_B)); + AddCondition("Set temperature setpoint C", createOps, SetTemperatureSetpointOp(easythermCfg.ProcParams.Temp_C)); + AddCondition("Set temperature setpoint D", createOps, SetTemperatureSetpointOp(easythermCfg.ProcParams.Temp_D)); + AddCondition("Set temperature setpoint E", createOps, SetTemperatureSetpointOp(easythermCfg.ProcParams.Temp_E)); + } + } } diff --git a/TBF/Rig/Modbus/TempControl/Easytherm/TControlCfg.cs b/TBF/Rig/Modbus/TempControl/Easytherm/TControlCfg.cs index aa80e5e22..915fe6847 100644 --- a/TBF/Rig/Modbus/TempControl/Easytherm/TControlCfg.cs +++ b/TBF/Rig/Modbus/TempControl/Easytherm/TControlCfg.cs @@ -8,12 +8,13 @@ using System.Xml.Serialization; using Common; using Config.Entities; using SchematicDrawing; +using TBF.Resources; using TBF.Rig.Generic; namespace TBF.Rig.Modbus.TempControl.Easytherm { public class TControlCfg : ComponentCfgBase, IChildComponentCfg, IParamsProvider, - IDrawingItemWithSetpoint, IDrawingItemWithMeasuredVal + IDrawingItemWithSetpoint, IDrawingItemWithMeasuredVal, IDrawingItemWithCustomBmp { public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TControlCfg) })[0]; public override XmlSerializer GetSerializer() { return Serializer; } @@ -52,6 +53,9 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm public string SetpFormat { get; set; } /// 3 public Unit SetpUnit { get; set; } /// 4 + public double SetpStep { get; set; } /// 5 + public bool RoundToSetpStep { get; set; } /// 6 + [XmlIgnore] public IList GNodes { get; set; } @@ -65,6 +69,7 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm /// Private parameterless constructor invoked by all other (public) constructors TControlCfg() { + ProcParams = new ProcParams(true); GNodes = new List(); } @@ -72,7 +77,6 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm : this() { this.Factory = factory; - ProcParams = CreateProcParamsProvider() as ProcParams; Name = "Novus"; ParentName = "Modbus"; @@ -94,6 +98,8 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm MsrdUnit = Unit.C; SetpFormat = "{0:F1} °C"; SetpUnit = Unit.C; + SetpStep = 1.0; + RoundToSetpStep = true; } string[] paramNames = new string[] @@ -103,6 +109,8 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm "Unit of measured temperature", /// 2 "Setpoint format", /// 3 "Unit of temperature setpoint", /// 4 + "Setpoint step", /// 5 + "Round to setpoint step", /// 6 }; public string ParamName(int i) { return paramNames[i]; } public int ParamsCount() { return paramNames.Length; } @@ -114,6 +122,8 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm case 2: case 4: return new string[] { "°C", "°F", "K" }; + case 6: + return new string[] { Strings.yes, Strings.no }; default: return null; } @@ -129,6 +139,8 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm case 2: return (MsrdUnit == Unit.K) ? "K" : (MsrdUnit == Unit.F) ? "°F" : "°C"; case 3: return SetpFormat; case 4: return (SetpUnit == Unit.K) ? "K" : (SetpUnit == Unit.F) ? "°F" : "°C"; + case 5: return SetpStep.ToString(); + case 6: return RoundToSetpStep ? Strings.yes : Strings.no; default: return string.Format("{0}({1}) address={2}", Name, string.IsNullOrEmpty(ParentName) ? "-" : ParentName, ModbusAddress); } @@ -142,11 +154,15 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm case 1: MsrdFormat = str; return CfgUpdateFlags.RestartRqrd; case 2: MsrdUnit = (str == "°K" || str == "K") ? Unit.K : (str == "°F" || str == "F") ? Unit.F - : Unit.C; return CfgUpdateFlags.RestartRqrd; + : Unit.C; + return CfgUpdateFlags.RestartRqrd; case 3: SetpFormat = str; return CfgUpdateFlags.RestartRqrd; case 4: SetpUnit = (str == "°K" || str == "K") ? Unit.K : (str == "°F" || str == "F") ? Unit.F - : Unit.C; return CfgUpdateFlags.RestartRqrd; + : Unit.C; + return CfgUpdateFlags.RestartRqrd; + case 5: SetpStep = Utils.ParseUDouble(str); return CfgUpdateFlags.RestartRqrd; + case 6: RoundToSetpStep = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd; default: return CfgUpdateFlags.None; } } @@ -155,6 +171,7 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm { message = string.Empty; int idummy; + double ddummy; switch (i) { @@ -168,6 +185,12 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm case 4: if (str == "°K" || str == "K" || str == "°F" || str == "F" || str == "°C" || str == "C") return true; break; + case 5: + if (Utils.TryParseUDouble(str, out ddummy)) return true; + break; + case 6: + if (str == Strings.yes || str == Strings.no) return true; + break; default: message = "Invalid index"; return false; @@ -200,6 +223,8 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm prms.MsrdUnit = MsrdUnit; prms.MsrdValLimLo = MsrdValLimLo; prms.MsrdValLimHi = MsrdValLimHi; + prms.SetpStep = SetpStep; + prms.RoundToSetpStep = RoundToSetpStep; } public IParamsProvider Clone() @@ -213,5 +238,41 @@ namespace TBF.Rig.Modbus.TempControl.Easytherm { return true; /// =OK, do nothing } - } + + /// + /// SchematicDrawing support + /// + public DrawingShape GetSampleBitmap() + { + return (Sz == Sz.S) ? DSCoolingS : (Sz == Sz.M) ? DSCoolingM : (Sz == Sz.XL) ? DSCoolingXL : DSCoolingL; + } + + /// + /// Static part, DrawingShape constructor arguments depend on bitmap properties + /// + public static DrawingShape DSIdleS, DSHeatingS, DSCoolingS, DSBothS; + public static DrawingShape DSIdleM, DSHeatingM, DSCoolingM, DSBothM; + public static DrawingShape DSIdleL, DSHeatingL, DSCoolingL, DSBothL; + public static DrawingShape DSIdleXL, DSHeatingXL, DSCoolingXL, DSBothXL; + /// + static TControlCfg() + { + DSIdleS = new DrawingShape(Shape.Custom, Sz.S, 2, 2, null, null, 0, 0, 20, 20, Properties.Resources.TControl_S_idle); + DSHeatingS = new DrawingShape(Shape.Custom, Sz.S, 2, 2, null, null, 0, 0, 20, 20, Properties.Resources.TControl_S_heating); + DSCoolingS = new DrawingShape(Shape.Custom, Sz.S, 2, 2, null, null, 0, 0, 20, 20, Properties.Resources.TControl_S_cooling); + DSBothS = new DrawingShape(Shape.Custom, Sz.S, 2, 2, null, null, 0, 0, 20, 20, Properties.Resources.TControl_S_both); + DSIdleM = new DrawingShape(Shape.Custom, Sz.S, 3, 4, null, null, 0, 5, 30, 30, Properties.Resources.TControl_M_idle); + DSHeatingM = new DrawingShape(Shape.Custom, Sz.S, 3, 4, null, null, 0, 5, 30, 30, Properties.Resources.TControl_M_heating); + DSCoolingM = new DrawingShape(Shape.Custom, Sz.S, 3, 4, null, null, 0, 5, 30, 30, Properties.Resources.TControl_M_cooling); + DSBothM = new DrawingShape(Shape.Custom, Sz.S, 3, 4, null, null, 0, 5, 30, 30, Properties.Resources.TControl_M_both); + DSIdleL = new DrawingShape(Shape.Custom, Sz.S, 4, 4, null, null, 0, 0, 40, 40, Properties.Resources.TControl_L_idle); + DSHeatingL = new DrawingShape(Shape.Custom, Sz.S, 4, 4, null, null, 0, 0, 40, 40, Properties.Resources.TControl_L_heating); + DSCoolingL = new DrawingShape(Shape.Custom, Sz.S, 4, 4, null, null, 0, 0, 40, 40, Properties.Resources.TControl_L_cooling); + DSBothL = new DrawingShape(Shape.Custom, Sz.S, 4, 4, null, null, 0, 0, 40, 40, Properties.Resources.TControl_L_both); + DSIdleXL = new DrawingShape(Shape.Custom, Sz.S, 5, 6, null, null, 0, 5, 50, 50, Properties.Resources.TControl_XL_idle); + DSHeatingXL = new DrawingShape(Shape.Custom, Sz.S, 5, 6, null, null, 0, 5, 50, 50, Properties.Resources.TControl_XL_heating); + DSCoolingXL = new DrawingShape(Shape.Custom, Sz.S, 5, 6, null, null, 0, 5, 50, 50, Properties.Resources.TControl_XL_cooling); + DSBothXL = new DrawingShape(Shape.Custom, Sz.S, 5, 6, null, null, 0, 5, 50, 50, Properties.Resources.TControl_XL_both); + } + } } diff --git a/TBF/Rig/Modbus/TempControl/Novus/ProcParams.cs b/TBF/Rig/Modbus/TempControl/Novus/ProcParams.cs index 736b7151b..e6682742a 100644 --- a/TBF/Rig/Modbus/TempControl/Novus/ProcParams.cs +++ b/TBF/Rig/Modbus/TempControl/Novus/ProcParams.cs @@ -5,8 +5,9 @@ using System.IO; using System.Xml.Serialization; using Common; using Config.Entities; -using TBF.Rig.Generic; using TBF.Resources; +using TBF.Rig.Generic; +using TBF.Rig.Sequences; namespace TBF.Rig.Modbus.TempControl.Novus { @@ -15,17 +16,29 @@ namespace TBF.Rig.Modbus.TempControl.Novus public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0]; public override XmlSerializer GetSerializer() { return Serializer; } - public float RequiredTemp; /// [°C] target temperature for a temperature controller or 0=not communicated to the controller + public double Temp_A; /// [°C] Target temperature for a tempe. controller or 0=not communicated to the controller + public double Temp_B; /// [°C] Target temperature for a tempe. controller or 0=not communicated to the controller + public double Temp_C; /// [°C] Target temperature for a tempe. controller or 0=not communicated to the controller + public double Temp_D; /// [°C] Target temperature for a tempe. controller or 0=not communicated to the controller + public double Temp_E; /// [°C] Target temperature for a tempe. controller or 0=not communicated to the controller public override void InitializeAll() { - RequiredTemp = 0.0f; - } + Temp_A = 10.0; + Temp_B = 20.0; + Temp_C = 30.0; + Temp_D = 40.0; + Temp_E = 50.0; + } string[] paramNames = new string[] { - Strings.Required_temperature_C, + string.Format("{0} A [{1}]", Strings.Temperature, ProcessData.TempUnit.ToDescription()), + string.Format("{0} B [{1}]", Strings.Temperature, ProcessData.TempUnit.ToDescription()), + string.Format("{0} C [{1}]", Strings.Temperature, ProcessData.TempUnit.ToDescription()), + string.Format("{0} D [{1}]", Strings.Temperature, ProcessData.TempUnit.ToDescription()), + string.Format("{0} E [{1}]", Strings.Temperature, ProcessData.TempUnit.ToDescription()), }; public override string ParamName(int i) { return paramNames[i]; } public override int ParamsCount() { return paramNames.Length; } @@ -34,26 +47,36 @@ namespace TBF.Rig.Modbus.TempControl.Novus { switch (i) { - case 0: return (RequiredTemp == 0) ? "---" : RequiredTemp.ToString(); - default: return string.Empty; + case 0: return (Temp_A == 0) ? "---" : Units.ConvertTo(ProcessData.TempUnit, Temp_A).ToString(); + case 1: return (Temp_B == 0) ? "---" : Units.ConvertTo(ProcessData.TempUnit, Temp_B).ToString(); + case 2: return (Temp_C == 0) ? "---" : Units.ConvertTo(ProcessData.TempUnit, Temp_C).ToString(); + case 3: return (Temp_D == 0) ? "---" : Units.ConvertTo(ProcessData.TempUnit, Temp_D).ToString(); + case 4: return (Temp_E == 0) ? "---" : Units.ConvertTo(ProcessData.TempUnit, Temp_E).ToString(); + default: return string.Empty; } } - public CfgUpdateFlags UpdateParam(int i, string strValue) + public CfgUpdateFlags UpdateParam(int i, string str) { + bool isDash = (str == "-" || str == "--" || str == "---"); switch (i) { case 0: - if (strValue == "-" || strValue == "--" || strValue == "---") - { - RequiredTemp = 0; - } - else - { - RequiredTemp = Utils.ParseUFloat(strValue); - } + Temp_A = isDash ? 0 : Units.ConvertFrom(ProcessData.TempUnit, Utils.ParseUDouble(str)); return CfgUpdateFlags.None; - default: + case 1: + Temp_B = isDash ? 0 : Units.ConvertFrom(ProcessData.TempUnit, Utils.ParseUDouble(str)); + return CfgUpdateFlags.None; + case 2: + Temp_C = isDash ? 0 : Units.ConvertFrom(ProcessData.TempUnit, Utils.ParseUDouble(str)); + return CfgUpdateFlags.None; + case 3: + Temp_D = isDash ? 0 : Units.ConvertFrom(ProcessData.TempUnit, Utils.ParseUDouble(str)); + return CfgUpdateFlags.None; + case 4: + Temp_E = isDash ? 0 : Units.ConvertFrom(ProcessData.TempUnit, Utils.ParseUDouble(str)); + return CfgUpdateFlags.None; + default: return CfgUpdateFlags.None; } } @@ -62,19 +85,19 @@ namespace TBF.Rig.Modbus.TempControl.Novus /// Verifiy the string representation of the parameter /// /// Parameter ID - /// String representation of the parameter + /// String representation of the parameter /// In case false is returned this is the error messsage to be displayed /// true = parameter OK, false = parameter NOK - public bool ValidateParam(int i, string strValue, out string message) + public bool ValidateParam(int i, string str, out string message) { message = string.Empty; - float temp; + double ddummy; switch (i) { case 0: /// T_hot_heating - if (strValue == "-" || strValue == "--" || strValue == "---" || - (Utils.TryParseUFloat(strValue, out temp) && (temp == 0 || (temp >= 5 && temp <= 95.0f)))) + if (str == "-" || str == "--" || str == "---" || + (Utils.TryParseUDouble(str, out ddummy) && (ddummy == 0 || (ddummy >= 5 && ddummy <= 95.0)))) { return true; } @@ -90,8 +113,12 @@ namespace TBF.Rig.Modbus.TempControl.Novus void CopyContentTo(ProcParams prms) { - prms.RequiredTemp = this.RequiredTemp; - } + prms.Temp_A = Temp_A; + prms.Temp_B = Temp_B; + prms.Temp_C = Temp_C; + prms.Temp_D = Temp_D; + prms.Temp_E = Temp_E; + } public IParamsProvider Clone() { diff --git a/TBF/Rig/Modbus/TempControl/Novus/SetRequiredTemperatureOp.cs b/TBF/Rig/Modbus/TempControl/Novus/SetTemperatureSetpointOp.cs similarity index 64% rename from TBF/Rig/Modbus/TempControl/Novus/SetRequiredTemperatureOp.cs rename to TBF/Rig/Modbus/TempControl/Novus/SetTemperatureSetpointOp.cs index 2ab41876a..a1459d9f2 100644 --- a/TBF/Rig/Modbus/TempControl/Novus/SetRequiredTemperatureOp.cs +++ b/TBF/Rig/Modbus/TempControl/Novus/SetTemperatureSetpointOp.cs @@ -7,13 +7,14 @@ using TBF.Boxes; namespace TBF.Rig.Modbus.TempControl.Novus { - public class SetRequiredTemperatureOp : IOperation + public class SetTemperatureSetpointOp : IOperation { - private static readonly ILog log = LogManager.GetLogger(typeof(SetRequiredTemperatureOp)); - public override string ToString() { return string.Format("SetRequiredTemperatureOp({0})", eventDone); } + private static readonly ILog log = LogManager.GetLogger(typeof(SetTemperatureSetpointOp)); + public override string ToString() { return string.Format("SetTemperatureSetpointOp({0})", eventDone); } /// Set by the constructor readonly TControl tempControl; + readonly double temperature; readonly Event eventDone; /// @@ -21,23 +22,24 @@ namespace TBF.Rig.Modbus.TempControl.Novus /// /// Temp. controller reference /// Event to be returned by Run() when completed OK - public SetRequiredTemperatureOp(TControl tempControl, Event eventDone) + public SetTemperatureSetpointOp(TControl tempControl, double temperature, Event eventDone) { if (tempControl == null) throw new ArgumentNullException("tempControl"); this.tempControl = tempControl; + this.temperature = temperature; this.eventDone = eventDone; log.Debug(this.ToString()); } - public SetRequiredTemperatureOp(TControl tempControl) - : this(tempControl, Event.ConditionMet) + public SetTemperatureSetpointOp(TControl tempControl, double temperature) + : this(tempControl, temperature, Event.ConditionMet) { } /// Start this operation public void Start() { - tempControl.SetTemperatureSetpoint(); + tempControl.SetTemperatureSetpoint(temperature); } /// Run this operation diff --git a/TBF/Rig/Modbus/TempControl/Novus/TControl.cs b/TBF/Rig/Modbus/TempControl/Novus/TControl.cs index 6cfc21d7a..606af0ddb 100644 --- a/TBF/Rig/Modbus/TempControl/Novus/TControl.cs +++ b/TBF/Rig/Modbus/TempControl/Novus/TControl.cs @@ -83,7 +83,6 @@ namespace TBF.Rig.Modbus.TempControl.Novus SetTemperatureSetpoint(Math.Max(newSetpoint, 5.0)); } - public DrawingShape GetCustomBitmap() { switch (novusCfg.Sz) @@ -121,22 +120,14 @@ namespace TBF.Rig.Modbus.TempControl.Novus bool isFahrenheit { get { return (status2 & (1 << 9)) != 0; } } - public float requiredTemp - { - get - { - return novusCfg.ProcParams != null ? novusCfg.ProcParams.RequiredTemp : 0; - } - } - - - public TControl() { } public TControl(Generic.IComponentCfg cfg, IList components) : base(cfg) { novusCfg = cfg as TControlCfg; + + CreateConditions(true); } /// Initialize this device @@ -245,43 +236,33 @@ namespace TBF.Rig.Modbus.TempControl.Novus public void StopDevice2() { } - /// - /// Set temperature controller setpoint to required temperature, - /// where temperature is a procedure parameter - /// - /// true = OK, false = any error - public bool SetTemperatureSetpoint() - { - return SetTemperatureSetpoint(requiredTemp); - } - /// /// Set temperature controller setpoint to specified value /// - /// Temperature in °C + /// Temperature in °C /// true = OK, false = any error - public bool SetTemperatureSetpoint(double reqTempC) + public bool SetTemperatureSetpoint(double temperatureC) { - if (reqTempC != 0 && (reqTempC < 5.0 || reqTempC > 95.0)) + if (temperatureC != 0 && (temperatureC < 5.0 || temperatureC > 95.0)) { return false; /// required temperature out of range } - if (novusDataValid && (reqTempC == temperatureSetPoint)) + if (novusDataValid && (temperatureC == temperatureSetPoint)) { return true; /// already set to the required temperature } - if (reqTempC != 0) /// temperature==0 disables sending the setpoint + if (temperatureC != 0) /// temperature==0 disables sending the setpoint { - double reqTemp = isFahrenheit ? Units.ConvertTo(Unit.F, reqTempC) : reqTempC; + double reqTemp = isFahrenheit ? Units.ConvertTo(Unit.F, temperatureC) : temperatureC; Int16 tempSetpointInt16 = Convert.ToInt16(Math.Round(10 * reqTemp)); /// setpoint in 0.1 °C or °F ushort destAddress = SetpointAddress; /// SendValueToNovus(Function.PresetSingleRegister, destAddress, tempSetpointInt16); } - temperatureSetPoint = reqTempC; + temperatureSetPoint = temperatureC; return true; } @@ -313,19 +294,9 @@ namespace TBF.Rig.Modbus.TempControl.Novus /// Events: SetOpututsDone, Error /// /// SetOutputsOp instance reference casted to IOperaton - public IOperation SetRequiredTemperatureOp() + public IOperation SetTemperatureSetpointOp(double temperature) { - return new SetRequiredTemperatureOp(this); - } - - /// - /// Events: SetOpututsDone, Error - /// - /// Reference to a variable for the pressure in Bar - /// SetOutputsOp instance reference casted to IOperaton - public IOperation SetTemperatureOp(float temperature) - { - return new SetTemperatureOp(this, temperature); + return new SetTemperatureSetpointOp(this, temperature); } public IOperation ReadTempOp(ref DoubleBox temp) @@ -339,33 +310,57 @@ namespace TBF.Rig.Modbus.TempControl.Novus } - public int ConditionsCount - { - get { return 3; } - } + + /// + /// ISequenceCondition interface implementation (conditions in transition sequences) + /// + IList sequenceConditionNames; + IList sequenceConditions; + + public int ConditionsCount { get { return sequenceConditions != null ? sequenceConditions.Count : 0; } } /// Strings are added to the combo-box for transition sequence condition selection public string ConditionName(int i) { - switch (i) - { - case 0: return string.Format("{0} open_the_drain_valve", Name); - case 1: return string.Format("{0} close_the_drain_valve", Name); - case 2: return string.Format("{0} wait_until_the_tank_is_empty", Name); - default: return string.Empty; - } + if (sequenceConditionNames != null && i < sequenceConditionNames.Count && i >= 0) + return sequenceConditionNames[i]; + else + return string.Empty; } - /// Operation to be executed as a part of a transition sequence + /// Operations are executed as a part of a transition sequence public IOperation ConditionOp(int i) { - switch (i) - { - case 0: return null; - case 1: return null; - case 2: return null; - default: return null; - } + if (sequenceConditions != null && i < sequenceConditions.Count && i >= 0) + return sequenceConditions[i]; + else + return null; + } + + void ClearConditions() + { + sequenceConditionNames = new List(); + sequenceConditions = new List(); + } + + void AddCondition(string conditionName, bool createOperation, IOperation conditionOperation) + { + sequenceConditionNames.Add(conditionName); + if (createOperation) sequenceConditions.Add(conditionOperation); + } + + /// + /// Create a list of conditions + /// + /// true = create names and condition operations, false = create names only + void CreateConditions(bool createOps) + { + ClearConditions(); + AddCondition("Set temperature setpoint A", createOps, SetTemperatureSetpointOp(novusCfg.ProcParams.Temp_A)); + AddCondition("Set temperature setpoint B", createOps, SetTemperatureSetpointOp(novusCfg.ProcParams.Temp_B)); + AddCondition("Set temperature setpoint C", createOps, SetTemperatureSetpointOp(novusCfg.ProcParams.Temp_C)); + AddCondition("Set temperature setpoint D", createOps, SetTemperatureSetpointOp(novusCfg.ProcParams.Temp_D)); + AddCondition("Set temperature setpoint E", createOps, SetTemperatureSetpointOp(novusCfg.ProcParams.Temp_E)); } } } diff --git a/TBF/Rig/Modbus/TempControl/Novus/TControlCfg.cs b/TBF/Rig/Modbus/TempControl/Novus/TControlCfg.cs index d36a76ccd..44bab72d8 100644 --- a/TBF/Rig/Modbus/TempControl/Novus/TControlCfg.cs +++ b/TBF/Rig/Modbus/TempControl/Novus/TControlCfg.cs @@ -8,8 +8,8 @@ using System.Xml.Serialization; using Common; using Config.Entities; using SchematicDrawing; -using TBF.Rig.Generic; using TBF.Resources; +using TBF.Rig.Generic; namespace TBF.Rig.Modbus.TempControl.Novus { @@ -70,6 +70,7 @@ namespace TBF.Rig.Modbus.TempControl.Novus /// Private parameterless constructor invoked by all other (public) constructors TControlCfg() { + ProcParams = new ProcParams(true); GNodes = new List(); } @@ -77,7 +78,6 @@ namespace TBF.Rig.Modbus.TempControl.Novus : this() { this.Factory = factory; - ProcParams = CreateProcParamsProvider() as ProcParams; Name = "Novus"; ParentName = "Modbus"; diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 3df59cebb..edcffb0d2 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -746,14 +746,14 @@ - + - +