tbf/TestBenchFramework/BenchControl/Elde/RegulValve/RegulValveCfg.cs
2014-07-28 09:56:40 +02:00

74 lines
2.8 KiB
C#

using System;
using System.IO;
using System.Xml.Serialization;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Elde.RegulValve
{
public class RegulValveCfg : ComponentCfgBase, IChildComponentCfg
{
public int Position; /// 0..7
public int DacValueClosed; /// 0..1023
public int DacValueOpen; /// 0..1023
public int PidCoef; /// 1..100
public bool StoredPositionReuse; /// true = store and re-use previous regulation valve positions
/// Parameterless constructor
public RegulValveCfg()
{
}
/// <summary>
/// Regulation valve configuration parameters
/// </summary>
/// <param name="name">Regulation valve name</param>
/// <param name="position">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 position, int dacValueClosed, int dacValueOpen, int pidCoef, bool storedPositionReuse)
: base(factory, name, parentName)
{
if (position < 0 || position > 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.Position = position;
this.DacValueClosed = dacValueClosed;
this.DacValueOpen = dacValueOpen;
this.PidCoef = pidCoef;
this.StoredPositionReuse = storedPositionReuse;
}
public IComponentCfg Clone()
{
return new RegulValveCfg(Factory, Name, ParentName, Position, DacValueClosed, DacValueOpen, PidCoef, StoredPositionReuse);
}
public string ToString(int i)
{
return string.Format("position={0}, DAC-closed={1}, DAC-open={2}, PID={3}, posReuse={4}",
Position, DacValueClosed, DacValueOpen, PidCoef, StoredPositionReuse);
}
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;
}
}
}
}