ModBusMonitorAddress.cs
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
namespace HslCommunication.ModBus
{
/// <summary>
/// 服务器端提供的数据监视服务
/// </summary>
public class ModBusMonitorAddress
{
/// <summary>
/// 本次数据监视的地址
/// </summary>
public ushort Address { get; set; }
/// <summary>
/// 数据写入时触发的事件
/// </summary>
public event Action<ModBusMonitorAddress, short> OnWrite;
/// <summary>
/// 数据改变时触发的事件
/// </summary>
public event Action<ModBusMonitorAddress, short, short> OnChange;
/// <summary>
/// 强制设置触发事件
/// </summary>
/// <param name="value"></param>
public void SetValue(short value)
{
OnWrite?.Invoke(this, value);
}
/// <summary>
/// 强制设置触发值变更事件
/// </summary>
/// <param name="before">变更前的值</param>
/// <param name="after">变更后的值</param>
public void SetChangeValue(short before, short after)
{
if (before != after)
{
OnChange?.Invoke(this, before, after);
}
}
}
}