Commit 698dda0b authored by 潘栩锋's avatar 潘栩锋 🚴

添加寄存器写入调试忽略

parent 6113b027
......@@ -15,7 +15,10 @@ namespace FLY.OBJComponents.Server
public class PLCProxySystem : IPLCProxySystemService, IPropertyOpt
{
NLog.ILogger logger = NLog.LogManager.GetCurrentClassLogger();
/// <summary>
/// 用于调试, 在这个表内的属性不输出调试
/// </summary>
public List<SenderProperty> IgnoreLogProperties = new List<SenderProperty>();
class Plan
{
/// <summary>
......@@ -78,6 +81,36 @@ namespace FLY.OBJComponents.Server
//PLCs[0].Start();
}
void LogProperty(object sender, string propertyName, DataToRegs dr)
{
//注解
var property = sender.GetType().GetProperty(propertyName);
var attrs = property.GetCustomAttributes(typeof(DescriptionAttribute), false);
string desp = "";
if (attrs.Count() > 0)
{
desp = (attrs.First() as DescriptionAttribute).Description;
}
//新值
var new_value = property.GetValue(sender, null);
//旧值
var old_value = dr.mapper.GetNameData(sender, propertyName);
//PLC地址
string plcAddr = $"{(dr.dataArea == PLCAddressArea.Coil ? "M" : "D")}{dr.addr}";
//对象名称
string objName = "";
var names = from kv in ObjNames where kv.Value == sender select kv.Key;
if (names.Count() > 0)
objName = names.First();
logger.Info($"{objName}.{propertyName} [{desp}] [{plcAddr}] ({old_value})->({new_value})");
}
private void Obj_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (isShield)
......@@ -91,38 +124,15 @@ namespace FLY.OBJComponents.Server
if (logger.IsInfoEnabled)
{
//注解
var property = sender.GetType().GetProperty(e.PropertyName);
var attrs = property.GetCustomAttributes(typeof(DescriptionAttribute), false);
string desp = "";
if (attrs.Count() > 0)
if (!IgnoreLogProperties.Exists(sp => sp.sender == sender && sp.propertyName == e.PropertyName))
{
desp = (attrs.First() as DescriptionAttribute).Description;
LogProperty(sender, e.PropertyName, dr);
}
//新值
var new_value = property.GetValue(sender, null);
//旧值
var old_value = dr.mapper.GetNameData(sender, e.PropertyName);
//PLC地址
string plcAddr = $"{(dr.dataArea == PLCAddressArea.Coil ? "M" : "D")}{dr.addr}";
//对象名称
string objName="";
var names= from kv in ObjNames where kv.Value == sender select kv.Key;
if (names.Count()>0)
objName = names.First();
logger.Info($"{objName}.{e.PropertyName} [{desp}] [{plcAddr}] ({old_value})->({new_value})");
}
//向PLC写入数据,mRegs每次只能写入一个,它有列表保存功能。
//SetNameData可以执行很多次,不过它只能一个个发。
dr.mapper.SetNameData(dr, Misc.PropertiesManager.GetValue(sender, e.PropertyName));
}
/// <summary>
......@@ -303,4 +313,10 @@ namespace FLY.OBJComponents.Server
return null;
}
}
public class SenderProperty
{
public object sender;
public string propertyName;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment