HslSiemensDataEntity.cs
3.92 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
namespace HHECS.Model.PLCHelper.PLCComponent.HslComponent
{
/// <summary>
/// 适配HSL西门子通信的数据实体
/// </summary>
public class HslSiemensDataEntity
{
/// <summary>
/// 被解析的OPC地址ID
/// </summary>
public int OPCAddressId { get; set; }
private string address;
/// <summary>
/// 对应HSL的数据地址格式
/// 定位到字节偏移量:"M100", "I100", "Q100", "DB20.100"
/// </summary>
public string Address
{
get
{
switch (Area)
{
case SiemensArea.I:
case SiemensArea.Q:
case SiemensArea.M:
case SiemensArea.D:
case SiemensArea.T:
case SiemensArea.C:
case SiemensArea.V:
return Area.ToString() + DataOffset;
case SiemensArea.DB:
return Area.ToString() + BlockIndex + "." + DataOffset;
default:
return null;
}
}
}
private string addressX;
/// <summary>
/// 对应HSL的数据地址格式
/// 定位到位:"M100.6", "I100.7", "Q100.0", "DB20.100.0"
/// </summary>
public string AddressX
{
get
{
switch (Area)
{
case SiemensArea.I:
case SiemensArea.Q:
case SiemensArea.M:
case SiemensArea.D:
case SiemensArea.T:
case SiemensArea.C:
case SiemensArea.V:
if (DataType == PLCDataType.BOOL)
{
return Area.ToString() + DataOffset + "." + BitOffset;
}
else
{
return Area.ToString() + DataOffset;
}
case SiemensArea.DB:
if (DataType == PLCDataType.BOOL)
{
return Area.ToString() + BlockIndex + "." + DataOffset + "." + BitOffset;
}
else
{
return Area.ToString() + BlockIndex + "." + DataOffset;
}
default:
return null;
}
}
}
/// <summary>
/// DB,M,I...
/// </summary>
public SiemensArea Area { get; set; }
/// <summary>
/// 数据类型,word,int...
/// </summary>
public PLCDataType DataType { get; set; }
/// <summary>
/// 块索引
/// 比如DB100,这个值为100;M区,这个值为0
/// </summary>
public int BlockIndex { get; set; }
/// <summary>
/// 起始量
/// 比如DB100X20.3,则此值为20;
/// MW100,此值为100;
/// </summary>
public int DataOffset { get; set; }
/// <summary>
/// 位偏移,相对于读取bit而言,取值为0到7,其他类型为0
/// </summary>
public int BitOffset { get; set; }
/// <summary>
/// 定义为此数据类型的个数,在现行项目下,一般为1,char一般为20;
/// </summary>
public int DataAmount { get; set; } = 1;
/// <summary>
/// 缓存buffer
/// </summary>
public byte[] Buffer { get; set; }
private ushort byteSize;
public ushort ByteSize
{
get
{
return (ushort)(SiemensHelper.GetByteSize(DataType) * DataAmount);
}
}
}
}