Commit 92ca049e authored by 潘栩锋's avatar 潘栩锋 🚴

PLC 写入调试

parent e8649d39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Misc
{
/// <summary>
/// PLC 寄存器用于报警
/// </summary>
public class IsErrorAttribute : Attribute
{
/// <summary>
/// 这个属性用于报警
/// </summary>
/// <param name="offIsError"></param>
public IsErrorAttribute(bool offIsError = false)
{
OffIsError = offIsError;
}
/// <summary>
/// 属性的值为false, 为报警状态
/// </summary>
public bool OffIsError { get; private set; }
}
}
......@@ -82,6 +82,7 @@
<Compile Include="DATARANGE.cs" />
<Compile Include="Enumerable.cs" />
<Compile Include="IgnoreAttribute.cs" />
<Compile Include="IsErrorAttribute.cs" />
<Compile Include="PropertiesManager.cs" />
<Compile Include="PropertyBinding.cs" />
<Compile Include="Range.cs" />
......
......@@ -112,6 +112,9 @@
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="NLog">
<Version>4.6.8</Version>
</PackageReference>
<PackageReference Include="PropertyChanged.Fody">
<Version>2.6.1</Version>
</PackageReference>
......
......@@ -14,6 +14,8 @@ namespace FLY.OBJComponents.Server
/// </summary>
public class PLCProxySystem : IPLCProxySystemService, IPropertyOpt
{
NLog.ILogger logger = NLog.LogManager.GetCurrentClassLogger();
class Plan
{
/// <summary>
......@@ -86,11 +88,40 @@ namespace FLY.OBJComponents.Server
if (dr == null)
return;//不会刷新PLC
if (logger.IsInfoEnabled)
{
//注解
var property = sender.GetType().GetProperty(e.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, e.PropertyName);
//PLC地址
string plcAddr = $"{(dr.dataArea == PLCAddressArea.Coil ? "M" : "D")}{dr.addr}";
logger.Info($"{e.PropertyName} [{desp}] [{plcAddr}] ({old_value})->({new_value})");
}
//向PLC写入数据,mRegs每次只能写入一个,它有列表保存功能。
//SetNameData可以执行很多次,不过它只能一个个发。
dr.mapper.SetNameData(dr, Misc.PropertiesManager.GetValue(sender, e.PropertyName));
}
/// <summary>
/// 屏蔽 "属性变化 写入PLC"
/// </summary>
bool isShield = false;
......
......@@ -578,7 +578,7 @@
<Version>2.0.0-alpha0316</Version>
</PackageReference>
<PackageReference Include="MahApps.Metro.IconPacks">
<Version>3.0.0-alpha0213</Version>
<Version>3.0.0-alpha0270</Version>
</PackageReference>
<PackageReference Include="MvvmLight">
<Version>5.4.1.1</Version>
......
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