using IoTClient.Enums;
using Net462DllTest.Enums;
using Serein.Library.Attributes;
using System;
using static Net462DllTest.Signal.PlcVarInfoAttribute;
using static Net462DllTest.Signal.PlcVarInfo;
namespace Net462DllTest.Signal
{
[AttributeUsage(AttributeTargets.Field)]
public class PlcVarInfoAttribute : Attribute
{
public PlcVarInfo Info { get; }
///
///
///
/// 数据类型
/// 变量地址
/// 通知行为类型
/// 是否只读
/// 是否定时刷新
/// 刷新间隔(ms)
public PlcVarInfoAttribute(DataTypeEnum dateType,
string address,
OnNotificationType notificationType,
bool isReadOnly = false,
bool isTimingRead = true,
int interval = 1000
)
{
Info = new PlcVarInfo()
{
DataType = dateType,
IsReadOnly = isReadOnly,
Address = address,
Interval = interval,
IsTimingRead= isTimingRead,
NotificationType = notificationType,
};
}
}
public class PlcVarInfo
{
public enum OnNotificationType
{
///
/// 刷新时通知(每次写入Model后都会触发相应的触发器)
///
OnRefresh,
///
/// 改变时才通知(与Model对应数据不一致时才会触发相应的触发器)
///
OnChanged,
}
///
/// 变量类型
///
public PlcVarName Name { get; set; }
///
/// 数据类型
///
public DataTypeEnum DataType { get; set; }
///
/// 变量地址
///
public string Address { get; set; }
///
/// 变量是否只读
///
public bool IsReadOnly { get; set; }
///
/// 是否定时刷新
///
public bool IsTimingRead { get; set; }
///
/// 刷新间隔(ms)
///
public int Interval { get; set; } = 100; // 100ms
public OnNotificationType NotificationType { get; set; } = OnNotificationType.OnChanged;
public override string ToString()
{
if (IsTimingRead)
{
return $"数据:{Name},类型:{DataType},地址:{Address},只读:{IsReadOnly},自动刷新:{IsTimingRead},刷新间隔:{Interval}";
}
else
{
return $"数据:{Name},类型:{DataType},地址:{Address},只读:{IsReadOnly}";
}
}
}
}