187 lines
6.4 KiB
C#
187 lines
6.4 KiB
C#
using Common;
|
|
using Config.Entities;
|
|
using log4net;
|
|
using System;
|
|
|
|
///
|
|
/// Copyright (c) 2022 Sensus Slovensko a.s.
|
|
///
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using TBF.Resources;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Rig.Sequences;
|
|
|
|
namespace TBF.Rig.Modbus.TempControl.Novus
|
|
{
|
|
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(ProcParams));
|
|
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
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()
|
|
{
|
|
Temp_A = 10.0;
|
|
Temp_B = 20.0;
|
|
Temp_C = 30.0;
|
|
Temp_D = 40.0;
|
|
Temp_E = 50.0;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
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 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 str)
|
|
{
|
|
bool isDash = (str == "-" || str == "--" || str == "---");
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
Temp_A = isDash ? 0 : Units.ConvertFrom(ProcessData.TempUnit, Utils.ParseUDouble(str));
|
|
return CfgUpdateFlags.None;
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifiy the string representation of the parameter
|
|
/// </summary>
|
|
/// <param name="i">Parameter ID</param>
|
|
/// <param name="str">String representation of the parameter</param>
|
|
/// <param name="message">In case false is returned this is the error messsage to be displayed</param>
|
|
/// <returns>true = parameter OK, false = parameter NOK</returns>
|
|
public bool ValidateParam(int i, string str, out string message)
|
|
{
|
|
message = string.Empty;
|
|
|
|
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;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
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 override bool UpdateFromDbEntity(ComponentProcedure dbEntity)
|
|
{
|
|
if (dbEntity == null) return false;
|
|
try
|
|
{
|
|
ProcParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as ProcParams;
|
|
|
|
procedureParamsEntity = dbEntity;
|
|
componentName = dbEntity.CmpntName;
|
|
procedure = dbEntity.Procedure;
|
|
|
|
if (tmp != null)
|
|
{
|
|
tmp.CopyContentTo(this);
|
|
return true;
|
|
}
|
|
else return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.DebugFormat(
|
|
"Error during Procedure parameters deserialization. CmpntName='{0}', Procedure='{1}', Parameters='{2}', Exception: {3}",
|
|
dbEntity?.CmpntName,
|
|
dbEntity?.Procedure,
|
|
dbEntity?.Parameters,
|
|
ex
|
|
);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parameterless constructor initializes the parameters
|
|
/// </summary>
|
|
public ProcParams()
|
|
{
|
|
}
|
|
|
|
public ProcParams(bool initialize)
|
|
{
|
|
if (initialize) InitializeAll();
|
|
}
|
|
|
|
public ProcParams(ComponentProcedure procParamsEntity, string componentName, Procedure procedure)
|
|
{
|
|
this.procedureParamsEntity = procParamsEntity;
|
|
this.componentName = componentName;
|
|
this.procedure = procedure;
|
|
}
|
|
}
|
|
}
|