tbf/TestBenchFramework/BenchControl/Elde/Valve/ValveCfg.cs
Milan Hanajik 6933442e76 - possibility to invert valves (UI as well as the functionality)
- UI prepared for the usage of valve delays
2014-09-06 07:37:27 +02:00

85 lines
3.4 KiB
C#

using System.IO;
using System.Xml.Serialization;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Elde.Valve
{
public class ValveCfg : ComponentCfgBase, IChildComponentCfg
{
public int OpenCloseTime; /// Delay for SetValvesOp operations
public int BitPosition; /// Bit-position
public ValveCategory Category; /// None, Feeding, Bench or Output
public bool Inverted; /// The valve is inverted: 0=open, 1=closed
///
public string CoupledToName; /// Name of the coupled valve or null
public bool InvertCouple; /// The coupled valve has inverted position
public int LagOpening; /// Delay (referred to the master valve) when opening this valve in [s]
public int LagClosing; /// Delay (referred to the master valve) when closing this valve in [s]
/// Negative values of delays mean an earlier function of the coupled valve.
/// Parameterless constructor
public ValveCfg()
{
OpenCloseTime = 1; /// Defaut value
}
/// Constructor 1
public ValveCfg(IComponentFactory factory, string name, string parentName, int bitPosition, bool inverted, int openCloseTime,
ValveCategory category, string coupledToName, bool invertCouple, int lagOpening, int lagClosing)
: base(factory, name, parentName)
{
this.OpenCloseTime = openCloseTime;
this.BitPosition = bitPosition;
this.Category = category;
this.Inverted = inverted;
this.CoupledToName = coupledToName;
this.InvertCouple = invertCouple;
this.LagOpening = lagOpening;
this.LagClosing = lagClosing;
}
/// Constructor 2 without CoupledTo valve
public ValveCfg(IComponentFactory factory, string name, string parentName, int bitPosition, bool inverted, int openCloseTime, ValveCategory category)
: this(factory, name, parentName, bitPosition, inverted, openCloseTime, category, null, false, 0, 0)
{
}
public IComponentCfg Clone()
{
return new ValveCfg(Factory, Name, ParentName, BitPosition, Inverted, OpenCloseTime, Category, CoupledToName, InvertCouple, LagOpening, LagClosing);
}
public string ToString(int i)
{
return string.Format("bit={0}, inv.={1}, delay={2}s, cat.={3}, coupledTo={4}, inv.Couple={5}, lagOpen={6}s, lagClose={7}s",
BitPosition,
(Inverted ? "yes" : "no"),
OpenCloseTime,
Category,
(string.IsNullOrEmpty(CoupledToName) ? "---" : CoupledToName),
(InvertCouple ? "yes" : "no"),
LagOpening,
LagClosing);
}
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))
{
ValveCfg config = (ValveCfg)(new XmlSerializer(typeof(ValveCfg))).Deserialize(reader);
config.InitCfgBaseFromEntity(component, factory);
return config;
}
}
}
}