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
+9 -14
View File
@@ -17,8 +17,9 @@ namespace TBF.Rig.Modbus.TempMeter.Meret
readonly TempMeterCfg tempMtrCfg;
public IDrawingItem DrawingItem { get { return tempMtrCfg as IDrawingItem; } }
readonly GenericDevices.IModbus modbus;
Common.Modbus modbus;
double receivedTemp;
public bool MsrmntAvailable { get { return true; } }
@@ -34,16 +35,16 @@ namespace TBF.Rig.Modbus.TempMeter.Meret
: base(cfg)
{
tempMtrCfg = cfg as TempMeterCfg;
modbus = TbfComponents.FindComponent(cfg.ParentName, components) as GenericDevices.IModbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
log.Warn(this.ToString());
}
public override void Initialize()
{
modbus = TbfComponents.FindComponent(tempMtrCfg.ParentName) as Common.Modbus;
if (modbus == null) throw new Exception("Cannot find " + Name + " parent");
modbus.ComponentNames[tempMtrCfg.ModbusAddress] = Name;
ticketNumber = modbus.RegisterForPolling();
log.FatalFormat("{0} initialized: {1}", Name, this);
}
///
@@ -52,12 +53,6 @@ namespace TBF.Rig.Modbus.TempMeter.Meret
/// <summary>Run this device</summary>
public void RunDeviceBefore()
{
if (tempMtrCfg.DebugLevel == Config.Entities.DebugMode.Simulate ||
tempMtrCfg.DebugLevel == Config.Entities.DebugMode.FailureDuringOperation)
{
return;
}
if (modbus.ReceivedTelegrams[tempMtrCfg.ModbusAddress].Count > 0)
{
byte[] telegram = modbus.ReceivedTelegrams[tempMtrCfg.ModbusAddress].Dequeue();
@@ -87,7 +82,7 @@ namespace TBF.Rig.Modbus.TempMeter.Meret
{
const byte Function = 4; /// Read input registers
const ushort Address = 0; /// Temperature
modbus.SendMessage((byte)tempMtrCfg.ModbusAddress, Function, Address, 2);
modbus.SendMessage((byte)tempMtrCfg.ModbusAddress, Function, Address, 2, Name);
}
}