using System; using System.IO; using System.Xml.Serialization; using TBF.BenchControl.Generic; namespace TBF.BenchControl.Elde.PressureMeter { public class PressureMeterCfg : ComponentCfgBase, Generic.IChildComponentCfg { public int Position; /// 0..7 public byte RS485Address; /// 0..255 /// Parameterless constructor public PressureMeterCfg() { } /// /// Regulation valve configuration parameters /// /// Regulation valve name /// Position on the control board 1..5 /// 0..1023 /// 0..1023 public PressureMeterCfg(IComponentFactory factory, string name, string parentName, int index, byte rs485Address) : base(factory, name, parentName) { if (index < 0 || index > 7) throw new ArgumentOutOfRangeException("Position"); this.Position = index; if (rs485Address < 0 || rs485Address > 255) throw new ArgumentOutOfRangeException("RS485Address"); this.RS485Address = rs485Address; } public IComponentCfg Clone() { return new PressureMeterCfg(Factory, Name, ParentName, Position, RS485Address); } public string ToString(int i) { return string.Format("index={0}, RS485 address={1}", Position, RS485Address); } 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)) { PressureMeterCfg config = (PressureMeterCfg)(new XmlSerializer(typeof(PressureMeterCfg))).Deserialize(reader); config.InitCfgBaseFromEntity(component, factory); return config; } } } }