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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLY.Modbus
{
/// <summary>
/// property 与 PLC继电器 更新操作,与 RegsData 对应
/// </summary>
public class CoilData : AreaManager
{
public CoilData(PLCAddressArea area, int maxOfOneRead) : base(area, maxOfOneRead)
{
}
/// <summary>
/// 根据当前regs的配置指定读寄存器的计划
/// </summary>
public override void MakePlan()
{
//this.maxOfOneRead = maxOfOneRead;
if (regs == null)
{
throw new Exception("还没有执行 BuildArray()");
}
lock (plan_buffer)
{
plan_buffer.Clear();
int addr = -1;
int num = 0;
for (int i = 0; i < regs.Count(); i++)
{
if (!regs[i].isNeedUpdate)
continue;
if (addr == -1)
{
addr = regs[i].addr;
num = 1;
}
else
{
int n = regs[i].addr - addr + 1;
if (n <= maxOfOneRead)
{
num = n;
}
else
{
plan_buffer.Add(new Plan(area, addr, num));
addr = -1;
i--;
}
}
}
if (addr != -1)
{
plan_buffer.Add(new Plan(area, addr, num));
addr = -1;
}
isPlanChanged = true;
}
}
}
}