Commit 58dba8c6 authored by 潘栩锋's avatar 潘栩锋 🚴
parents 65e4bb49 698dda0b
......@@ -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,21 +81,12 @@ namespace FLY.OBJComponents.Server
//PLCs[0].Start();
}
private void Obj_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (isShield)
return;
List<DataToRegs> drs = DRMap;
DataToRegs dr = drs.Find((_dr) => { return (_dr.propertyName == e.PropertyName) && (_dr.owner == sender); });
if (dr == null)
return;//不会刷新PLC
if (logger.IsInfoEnabled)
void LogProperty(object sender, string propertyName, DataToRegs dr)
{
//注解
var property = sender.GetType().GetProperty(e.PropertyName);
var property = sender.GetType().GetProperty(propertyName);
var attrs = property.GetCustomAttributes(typeof(DescriptionAttribute), false);
string desp = "";
if (attrs.Count() > 0)
......@@ -104,25 +98,41 @@ namespace FLY.OBJComponents.Server
var new_value = property.GetValue(sender, null);
//旧值
var old_value = dr.mapper.GetNameData(sender, e.PropertyName);
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)
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})");
logger.Info($"{objName}.{propertyName} [{desp}] [{plcAddr}] ({old_value})->({new_value})");
}
private void Obj_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (isShield)
return;
List<DataToRegs> drs = DRMap;
DataToRegs dr = drs.Find((_dr) => { return (_dr.propertyName == e.PropertyName) && (_dr.owner == sender); });
if (dr == null)
return;//不会刷新PLC
if (logger.IsInfoEnabled)
{
if (!IgnoreLogProperties.Exists(sp => sp.sender == sender && sp.propertyName == e.PropertyName))
{
LogProperty(sender, e.PropertyName, dr);
}
}
//向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