Modbus logging with child component names, ver. 3.1.1606

This commit is contained in:
Milan Hanajik
2021-04-09 16:29:24 +02:00
parent f33bc4f167
commit 9724e8779a
16 changed files with 183 additions and 164 deletions
+10 -12
View File
@@ -16,7 +16,8 @@ namespace TBF.Rig.Modbus.Easytherm
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
readonly EasythermCfg easythermCfg;
readonly GenericDevices.IModbus modbus;
Common.Modbus modbus;
private float temperatureSetPoint;
private bool temperatureSetPointValid;
@@ -33,26 +34,24 @@ namespace TBF.Rig.Modbus.Easytherm
: base(cfg)
{
easythermCfg = cfg as EasythermCfg;
modbus = (GenericDevices.IModbus)TbfComponents.FindComponent(cfg.ParentName, components);
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
log.Warn(this.ToString());
}
/// <summary>Initialize this device</summary>
public override void Initialize()
{
temperatureSetPointValid = false;
modbus = TbfComponents.FindComponent(easythermCfg.ParentName) as Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
temperatureSetPointValid = false;
temperatureSetPointRequested = false;
modbus.ComponentNames[easythermCfg.ModbusAddress] = Name;
ticketNumber = modbus.RegisterForPolling();
log.FatalFormat("{0} initialized: {1}", Name, this);
}
/// <summary>Run this device</summary>
public void RunDeviceBefore()
{
if (easythermCfg.DebugLevel == DebugMode.Simulate) return;
if (modbus.ReceivedTelegrams[easythermCfg.ModbusAddress].Count > 0)
{
byte[] telegram = modbus.ReceivedTelegrams[easythermCfg.ModbusAddress].Dequeue();
@@ -83,8 +82,7 @@ namespace TBF.Rig.Modbus.Easytherm
public void RunDeviceAfter()
{
if (easythermCfg.DebugLevel != Config.Entities.DebugMode.Simulate &&
easythermCfg.DebugLevel != Config.Entities.DebugMode.FailureDuringOperation)
if (modbus.IsMyTurn(ticketNumber))
{
if (!temperatureSetPointValid && !temperatureSetPointRequested)
{
@@ -169,7 +167,7 @@ namespace TBF.Rig.Modbus.Easytherm
msg[4] = (byte)(value >> 8); /// Data Hi
msg[5] = (byte)(value & 0xFF); /// Data Lo
modbus.SendMessage(msg);
modbus.SendMessage(msg, Name);
}