318 lines
12 KiB
C#
318 lines
12 KiB
C#
///
|
|
/// Copyright (c) 2022 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Xml.Serialization;
|
|
using Common;
|
|
using Config.Entities;
|
|
using SchematicDrawing;
|
|
using TBF.Resources;
|
|
using TBF.Rig.Generic;
|
|
|
|
namespace TBF.Rig.Modbus.TempControl.Novus
|
|
{
|
|
public enum Type
|
|
{
|
|
N1200HC,
|
|
N1200,
|
|
N1040,
|
|
Count
|
|
}
|
|
|
|
public class TControlCfg : ComponentCfgBase, IChildComponentCfg, IParamsProvider,
|
|
IDrawingItemWithSetpoint, IDrawingItemWithMeasuredVal, IDrawingItemWithCustomBmp
|
|
{
|
|
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TControlCfg) })[0];
|
|
public override XmlSerializer GetSerializer() { return Serializer; }
|
|
|
|
public IComponentCfgCtrl GetControl(IList<Component> cmpntEntities)
|
|
{
|
|
var parents = cmpntEntities.Where(x => x.ClassName == "Modbus.Common");
|
|
return new Configs.ParamsProvider.ComponentCfgCtrl(this, parents);
|
|
}
|
|
|
|
///
|
|
/// Serialized parameters
|
|
///
|
|
public int ModbusAddress; /// 0: 1..254
|
|
public Type Type; /// 1: N1200HC, N1200 or N1040
|
|
|
|
/// Schematic drawing info
|
|
public Shape Shape { get; set; }
|
|
public int X { get; set; }
|
|
public int Y { get; set; }
|
|
public Sz Sz { get; set; }
|
|
public Orient Orient { get; set; }
|
|
public bool Flip { get; set; }
|
|
public int LblX { get; set; }
|
|
public int LblY { get; set; }
|
|
public Orient LblOrient { get; set; }
|
|
public int MsrdX { get; set; }
|
|
public int MsrdY { get; set; }
|
|
public Orient MsrdOrient { get; set; }
|
|
public string MsrdFormat { get; set; } /// 2
|
|
public Unit MsrdUnit { get; set; } /// 3
|
|
public double MsrdValLimLo { get; set; }
|
|
public double MsrdValLimHi { get; set; }
|
|
public int SetpX { get; set; }
|
|
public int SetpY { get; set; }
|
|
public Orient SetpOrient { get; set; }
|
|
public string SetpFormat { get; set; } /// 4
|
|
public Unit SetpUnit { get; set; } /// 5
|
|
|
|
public double SetpStep { get; set; } /// 6
|
|
public bool RoundToSetpStep { get; set; } /// 7
|
|
|
|
[XmlIgnore]
|
|
public IList<GNode> GNodes { get; set; }
|
|
|
|
[XmlIgnore]
|
|
public bool IsOffline { get; set; }
|
|
|
|
|
|
/// <summary> Procedure parameters </summary>
|
|
[XmlIgnore]
|
|
public ProcParams ProcParams;
|
|
public override IParamsProvider GetRuntimeProcParamsProvider() { return ProcParams; }
|
|
public override IParamsProvider CreateProcParamsProvider() { return new ProcParams(true); }
|
|
|
|
|
|
/// Private parameterless constructor invoked by all other (public) constructors
|
|
TControlCfg()
|
|
{
|
|
ProcParams = new ProcParams(true);
|
|
GNodes = new List<GNode>();
|
|
}
|
|
|
|
public TControlCfg(IComponentFactory factory)
|
|
: this()
|
|
{
|
|
this.Factory = factory;
|
|
|
|
Name = "Novus";
|
|
ParentName = "Modbus";
|
|
Shape = Shape.Custom;
|
|
Sz = Sz.M;
|
|
MsrdValLimLo = 5;
|
|
MsrdValLimHi = 95;
|
|
MsrdY = 22;
|
|
|
|
InitializeAll();
|
|
}
|
|
|
|
public string ComponentName { get { return Name; } }
|
|
|
|
public void InitializeAll()
|
|
{
|
|
ModbusAddress = 49;
|
|
Type = Novus.Type.N1200HC;
|
|
MsrdFormat = "{0:F1} °C";
|
|
MsrdUnit = Unit.C;
|
|
SetpFormat = "{0:F1} °C";
|
|
SetpUnit = Unit.C;
|
|
SetpStep = 1.0;
|
|
RoundToSetpStep = true;
|
|
}
|
|
|
|
string[] paramNames = new string[]
|
|
{
|
|
"Modbus address", /// 0
|
|
"Type", /// 1
|
|
"Measured temperature format", /// 2
|
|
"Unit of measured temperature", /// 3
|
|
"Setpoint format", /// 4
|
|
"Unit of temperature setpoint", /// 5
|
|
"Setpoint step", /// 6
|
|
"Round to setpoint step", /// 7
|
|
};
|
|
public string ParamName(int i) { return paramNames[i]; }
|
|
public int ParamsCount() { return paramNames.Length; }
|
|
|
|
public ICollection<string> ParamValues(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 1:
|
|
var list = new List<string>();
|
|
for (Novus.Type t = 0; t < Novus.Type.Count; t++) list.Add(t.ToString());
|
|
return list;
|
|
case 3:
|
|
case 5:
|
|
return new string[] { "°C", "°F", "K" };
|
|
case 7:
|
|
return new string[] { Strings.yes, Strings.no };
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
public string ToString(int i)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: return ModbusAddress.ToString();
|
|
case 1: return Type.ToString();
|
|
case 2: return MsrdFormat;
|
|
case 3: return (MsrdUnit == Unit.K) ? "K" : (MsrdUnit == Unit.F) ? "°F" : "°C";
|
|
case 4: return SetpFormat;
|
|
case 5: return (SetpUnit == Unit.K) ? "K" : (SetpUnit == Unit.F) ? "°F" : "°C";
|
|
case 6: return SetpStep.ToString();
|
|
case 7: return RoundToSetpStep ? Strings.yes : Strings.no;
|
|
default:
|
|
return string.Format("{0}({1}) address = {2}, type = {3}",
|
|
Name, string.IsNullOrEmpty(ParentName) ? "-" : ParentName, ModbusAddress, Type);
|
|
}
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateParam(int i, string str)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0: ModbusAddress = int.Parse(str); return CfgUpdateFlags.RestartRqrd;
|
|
case 1:
|
|
for (Novus.Type t = 0; t < Novus.Type.Count; t++)
|
|
{
|
|
if (t.ToString() == str)
|
|
{
|
|
Type = t;
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
}
|
|
}
|
|
return CfgUpdateFlags.None;
|
|
case 2: MsrdFormat = str; return CfgUpdateFlags.RestartRqrd;
|
|
case 3: MsrdUnit = (str == "°K" || str == "K") ? Unit.K
|
|
: (str == "°F" || str == "F") ? Unit.F
|
|
: Unit.C;
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
case 4: SetpFormat = str; return CfgUpdateFlags.RestartRqrd;
|
|
case 5: SetpUnit = (str == "°K" || str == "K") ? Unit.K
|
|
: (str == "°F" || str == "F") ? Unit.F
|
|
: Unit.C;
|
|
return CfgUpdateFlags.RestartRqrd;
|
|
case 6: SetpStep = Utils.ParseUDouble(str); return CfgUpdateFlags.RestartRqrd;
|
|
case 7: RoundToSetpStep = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
|
|
|
|
default: return CfgUpdateFlags.None;
|
|
}
|
|
}
|
|
|
|
public bool ValidateParam(int i, string str, out string message)
|
|
{
|
|
message = string.Empty;
|
|
int idummy;
|
|
double ddummy;
|
|
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
/// ModbusAddress
|
|
if (int.TryParse(str, out idummy) && idummy >= 1 && idummy <= 254) return true;
|
|
break;
|
|
case 1:
|
|
case 7:
|
|
/// Type, RoundToSetpStep (yes/no)
|
|
if (ParamValues(i).Contains(str)) return true;
|
|
break;
|
|
case 2:
|
|
case 4:
|
|
/// MsrdFormat, SetpFormat
|
|
return true;
|
|
case 3:
|
|
case 5:
|
|
/// MsrdUnit, SetpUnit
|
|
if (ParamValues(i).Contains(str) || str == "C" || str == "F" || str == "°K") return true;
|
|
break;
|
|
case 6:
|
|
/// SetpStep
|
|
if (Utils.TryParseUDouble(str, out ddummy)) return true;
|
|
break;
|
|
default:
|
|
message = "Invalid index";
|
|
return false;
|
|
}
|
|
|
|
message = ParamName(i) + " is invalid";
|
|
return false;
|
|
}
|
|
|
|
void CopyContentTo(TControlCfg prms)
|
|
{
|
|
prms.ParentName = ParentName;
|
|
prms.ModbusAddress = ModbusAddress;
|
|
prms.Type = Type;
|
|
prms.Shape = Shape;
|
|
prms.Sz = Sz;
|
|
prms.Orient = Orient;
|
|
prms.Flip = Flip;
|
|
prms.LblX = LblX;
|
|
prms.LblY = LblY;
|
|
prms.LblOrient = LblOrient;
|
|
prms.SetpX = SetpX;
|
|
prms.SetpY = SetpY;
|
|
prms.SetpOrient = SetpOrient;
|
|
prms.SetpFormat = SetpFormat;
|
|
prms.SetpUnit = SetpUnit;
|
|
prms.MsrdX = MsrdX;
|
|
prms.MsrdY = MsrdY;
|
|
prms.MsrdOrient = MsrdOrient;
|
|
prms.MsrdFormat = MsrdFormat;
|
|
prms.MsrdUnit = MsrdUnit;
|
|
prms.MsrdValLimLo = MsrdValLimLo;
|
|
prms.MsrdValLimHi = MsrdValLimHi;
|
|
prms.SetpStep = SetpStep;
|
|
prms.RoundToSetpStep = RoundToSetpStep;
|
|
}
|
|
|
|
public IParamsProvider Clone()
|
|
{
|
|
TControlCfg pars = new TControlCfg();
|
|
CopyContentTo(pars);
|
|
return pars;
|
|
}
|
|
|
|
public bool UpdateEmbeddedDbEntity()
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|