67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
using System.IO;
|
|
using System.IO.Ports;
|
|
using System.Xml.Serialization;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.MettlerToledo
|
|
{
|
|
public class BalanceCfg : ComponentCfgBase, Generic.IComponentCfg
|
|
{
|
|
public int ComPortNr;
|
|
public int BaudRate;
|
|
public Parity Parity;
|
|
public int DataBits;
|
|
public StopBits StopBits;
|
|
public Handshake Handshake;
|
|
|
|
public float Capacity; /// Balance range in 'kg' or tank volume in 'l'
|
|
|
|
/// Parameterless constructor
|
|
public BalanceCfg()
|
|
{
|
|
}
|
|
|
|
/// Constructor
|
|
public BalanceCfg(IComponentFactory factory, string name, int comPortNr, int baudRate, Parity parity, int dataBits, StopBits stopBits, Handshake handshake, float capacity)
|
|
: base(factory, name)
|
|
{
|
|
this.ComPortNr = comPortNr;
|
|
this.BaudRate = baudRate;
|
|
this.Parity = parity;
|
|
this.DataBits = dataBits;
|
|
this.StopBits = stopBits;
|
|
this.Handshake = handshake;
|
|
this.Capacity = capacity;
|
|
}
|
|
|
|
public IComponentCfg Clone()
|
|
{
|
|
return new BalanceCfg(Factory, Name, ComPortNr, BaudRate, Parity, DataBits, StopBits, Handshake, Capacity);
|
|
}
|
|
|
|
public string ToString(int i)
|
|
{
|
|
return string.Format("COM{0}, {1}Bd, {2}bits, parity={3}, stopBits={4}, {5}, capacity={6}kg", ComPortNr, BaudRate, DataBits, Parity, StopBits, Handshake, Capacity);
|
|
}
|
|
|
|
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))
|
|
{
|
|
BalanceCfg config = (BalanceCfg)(new XmlSerializer(typeof(BalanceCfg))).Deserialize(reader);
|
|
config.InitCfgBaseFromEntity(component, factory);
|
|
return config;
|
|
}
|
|
}
|
|
}
|
|
}
|