Methods CreateDbEntity and CreateFromDbEntity moved from XyzCfg to ComponentCfgBase, factories modified accordingly.
This commit is contained in:
@@ -7,9 +7,6 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
{
|
||||
public class RegulValveCfg : ComponentCfgBase, IChildComponentCfg
|
||||
{
|
||||
///
|
||||
/// Stored parameters
|
||||
///
|
||||
public int Idx1; /// 1..7
|
||||
public int DacValueClosed; /// 0..1023
|
||||
public int DacValueOpen; /// 0..1023
|
||||
@@ -26,63 +23,35 @@ namespace TBF.BenchControl.Elde.RegulValve
|
||||
/// Parameterless constructor
|
||||
public RegulValveCfg()
|
||||
{
|
||||
Name = "RegulationValve";
|
||||
ParentName = "CB";
|
||||
Idx1 = 1;
|
||||
DacValueClosed = 100;
|
||||
DacValueOpen = 500;
|
||||
PidCoef = 20;
|
||||
StableTimeMs = 500;
|
||||
StoredPositionReuse = false;
|
||||
FlowStableSec = 5;
|
||||
}
|
||||
/// <summary>
|
||||
/// Regulation valve configuration parameters
|
||||
/// </summary>
|
||||
/// <param name="name">Regulation valve name</param>
|
||||
/// <param name="idx1">Position on the control board 0..7</param>
|
||||
/// <param name="dacValueClosed">0..1023</param>
|
||||
/// <param name="dacValueOpen">0..1023</param>
|
||||
/// <param name="pidCoef">1..100</param>
|
||||
public RegulValveCfg(IComponentFactory factory, string name, string parentName, int idx1, int dacValueClosed, int dacValueOpen, int pidCoef, int stableTimeMs, bool storedPositionReuse, int flowStableSec)
|
||||
: base(factory, name, parentName)
|
||||
}
|
||||
|
||||
public RegulValveCfg(IComponentFactory factory)
|
||||
: this()
|
||||
{
|
||||
if (idx1 < 1 || idx1 > 7) throw new ArgumentOutOfRangeException("position");
|
||||
if (dacValueClosed < 0 || dacValueClosed > 1023) throw new ArgumentOutOfRangeException("dacValueOpen");
|
||||
if (dacValueOpen < 0 || dacValueOpen > 1023) throw new ArgumentOutOfRangeException("dacValueOpen");
|
||||
if (pidCoef < 1 || pidCoef > 100) throw new ArgumentOutOfRangeException("pidCoef");
|
||||
|
||||
this.Idx1 = idx1;
|
||||
this.DacValueClosed = dacValueClosed;
|
||||
this.DacValueOpen = dacValueOpen;
|
||||
this.PidCoef = pidCoef;
|
||||
this.StableTimeMs = stableTimeMs;
|
||||
this.StoredPositionReuse = storedPositionReuse;
|
||||
this.FlowStableSec = flowStableSec;
|
||||
}
|
||||
|
||||
public IComponentCfg Clone()
|
||||
{
|
||||
return new RegulValveCfg(Factory, Name, ParentName, Idx1, DacValueClosed, DacValueOpen, PidCoef, StableTimeMs, StoredPositionReuse, FlowStableSec);
|
||||
}
|
||||
this.Factory = factory;
|
||||
}
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("idx1={0}, DA-closed={1}, DA-open={2}, PID={3}, stabT={4}ms, posReuse={5}, flowStable={6}s",
|
||||
Idx1, DacValueClosed, DacValueOpen, PidCoef, StableTimeMs, StoredPositionReuse, FlowStableSec);
|
||||
}
|
||||
|
||||
public TBF.Entities.Component CreateDbEntity()
|
||||
{
|
||||
using (var writer = new StringWriter())
|
||||
{
|
||||
(new XmlSerializer(GetType())).Serialize(writer, this);
|
||||
return Entities.Component.CreateFromCfg(Name, Factory.ClassName, ParentName, ItemNr, DebugLevel, LogLevel, writer.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public static IComponentCfg CreateFromDbEntity(Entities.Component component, IComponentFactory factory)
|
||||
{
|
||||
using (var reader = new StringReader(component.Parameters))
|
||||
{
|
||||
RegulValveCfg config = (RegulValveCfg)(new XmlSerializer(typeof(RegulValveCfg))).Deserialize(reader);
|
||||
config.InitCfgBaseFromEntity(component, factory);
|
||||
return config;
|
||||
}
|
||||
return string.Format("Name={0}, Parent={1}, Idx1={2}, ADC-Closed={3}, ADC-Open={4}, PID={5}, StabTm={6}ms, PosReuse={7}, FlowStable={8}s",
|
||||
Name,
|
||||
(string.IsNullOrEmpty(ParentName) ? "-" : ParentName),
|
||||
Idx1,
|
||||
DacValueClosed,
|
||||
DacValueOpen,
|
||||
PidCoef,
|
||||
StableTimeMs,
|
||||
StoredPositionReuse,
|
||||
FlowStableSec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user