Components Initialize() rewritten, double StartChangeHandler() calls avoided, ToString() methods are equl, use ClassName.

This commit is contained in:
Milan Hanajik
2021-04-08 12:03:18 +02:00
parent 331803e51d
commit 1d50b7206d
178 changed files with 2003 additions and 2151 deletions
@@ -22,7 +22,7 @@ namespace TBF.BenchControl.RegisterReaders.KPackE.Radio
public class Radio : ComponentBase, IDevice
{
private static readonly ILog log = LogManager.GetLogger(typeof(Radio));
public override string ToString() { return string.Format("Radio({0})", Cfg.ToString(1)); }
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
enum KPackE_Type
{
@@ -71,9 +71,7 @@ namespace TBF.BenchControl.RegisterReaders.KPackE.Radio
public IReceivesDataFromRadio EntryForm;
public Radio()
{
}
public Radio() { }
/// <summary>
/// Ambient temperature / humidity / pressure meter 'Greco' connected via serial interface (RS232)
@@ -82,41 +80,28 @@ namespace TBF.BenchControl.RegisterReaders.KPackE.Radio
public Radio(Generic.IComponentCfg cfg)
: base(cfg)
{
RegReaders = new List<RegisterReader.RegisterReader>();
serialPort = null;
radioCfg = cfg as RadioCfg;
}
public override void Initialize()
{
RegReaders = new List<RegisterReader.RegisterReader>();
data = new List<byte>();
log.Warn(this.ToString());
}
~Radio()
{
}
public void Initialize()
{
if (radioCfg.DebugLevel == DebugMode.Simulate)
{
serialPort = null;
log.FatalFormat("{0} - Device simulated", Name);
return;
}
lastTelegramReceived = DateTime.MinValue;
string comPortName = "COM" + radioCfg.ComPortNr.ToString();
serialPort = new SerialPort(comPortName, radioCfg.BaudRate, radioCfg.Parity, radioCfg.DataBits, radioCfg.StopBits);
serialPort.Handshake = radioCfg.Handshake;
serialPort.Open();
//stopWorkerThread = false;
//workerThread = new Thread(Worker);
//workerThread.Start();
log.FatalFormat("{0} - Device successfully initialized", Name);
if (radioCfg.DebugLevel == DebugMode.Normal)
{
string portName = "COM" + radioCfg.ComPortNr.ToString();
serialPort = new SerialPort(portName, radioCfg.BaudRate, radioCfg.Parity, radioCfg.DataBits, radioCfg.StopBits);
serialPort.Handshake = radioCfg.Handshake;
serialPort.Open();
log.FatalFormat("{0} initialized: {1}", Name, this);
}
else
{
serialPort = null;
log.FatalFormat("{0} simulated: {1}", Name, this);
}
}