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