IReadWriteNet.cs
15.3 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
using System;
namespace HslCommunication.Core
{
/// <summary>
/// 所有的和设备或是交互类统一读写标准
/// </summary>
/// <remarks>
/// Modbus类,PLC类均实现了本接口,可以基于本接口实现统一所有的不同种类的设备的数据交互
/// </remarks>
/// <example>
/// 此处举例实现modbus,三菱,西门子三种设备的统一的数据交互
/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\IReadWriteNet.cs" region="IReadWriteNetExample" title="IReadWriteNet示例" />
/// </example>
public interface IReadWriteNet
{
#region Read Support
/// <summary>
/// 批量读取底层的数据信息,需要指定地址和长度,具体的结果取决于实现
/// </summary>
/// <param name="address">数据地址</param>
/// <param name="length">数据长度</param>
/// <returns>带有成功标识的byte[]数组</returns>
OperateResult<byte[]> Read(string address, ushort length);
/// <summary>
/// 读取16位的有符号整型
/// </summary>
/// <param name="address">起始地址</param>
/// <returns>带有成功标识的short数据</returns>
OperateResult<short> ReadInt16(string address);
/// <summary>
/// 读取16位的有符号整型数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="length">读取的数组长度</param>
/// <returns>带有成功标识的short数组</returns>
OperateResult<short[]> ReadInt16(string address, ushort length);
/// <summary>
/// 读取16位的无符号整型
/// </summary>
/// <param name="address">起始地址</param>
/// <returns>带有成功标识的ushort数据</returns>
OperateResult<ushort> ReadUInt16(string address);
/// <summary>
/// 读取16位的无符号整型数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="length">读取的数组长度</param>
/// <returns>带有成功标识的ushort数组</returns>
OperateResult<ushort[]> ReadUInt16(string address, ushort length);
/// <summary>
/// 读取32位的有符号整型
/// </summary>
/// <param name="address">起始地址</param>
/// <returns>带有成功标识的int数据</returns>
OperateResult<int> ReadInt32(string address);
/// <summary>
/// 读取32位有符号整型的数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="length">数组长度</param>
/// <returns>带成功标志的结果数据对象</returns>
OperateResult<int[]> ReadInt32(string address, ushort length);
/// <summary>
/// 读取32位的无符号整型
/// </summary>
/// <param name="address">起始地址</param>
/// <returns>带有成功标识的uint数据</returns>
OperateResult<uint> ReadUInt32(string address);
/// <summary>
/// 读取设备的uint类型的数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="length">数组长度</param>
/// <returns>带成功标志的结果数据对象</returns>
OperateResult<uint[]> ReadUInt32(string address, ushort length);
/// <summary>
/// 读取64位的有符号整型
/// </summary>
/// <param name="address">起始地址</param>
/// <returns>带有成功标识的long数据</returns>
OperateResult<long> ReadInt64(string address);
/// <summary>
/// 读取64位的有符号整型数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="length">数组长度</param>
/// <returns>带成功标志的结果数据对象</returns>
OperateResult<long[]> ReadInt64(string address, ushort length);
/// <summary>
/// 读取64位的无符号整型
/// </summary>
/// <param name="address">起始地址</param>
/// <returns>带有成功标识的ulong数据</returns>
OperateResult<ulong> ReadUInt64(string address);
/// <summary>
/// 读取64位的无符号整型的数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="length">数组长度</param>
/// <returns>带成功标志的结果数据对象</returns>
OperateResult<ulong[]> ReadUInt64(string address, ushort length);
/// <summary>
/// 读取单浮点精度的数据
/// </summary>
/// <param name="address">起始地址</param>
/// <returns>带有成功标识的float数据</returns>
OperateResult<float> ReadFloat(string address);
/// <summary>
/// 读取单浮点精度的数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="length">数组长度</param>
/// <returns>带成功标志的结果数据对象</returns>
OperateResult<float[]> ReadFloat(string address, ushort length);
/// <summary>
/// 读取双浮点精度的数据
/// </summary>
/// <param name="address">起始地址</param>
/// <returns>带有成功标识的double数据</returns>
OperateResult<double> ReadDouble(string address);
/// <summary>
/// 读取双浮点精度的数据的数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="length">数组长度</param>
/// <returns>带成功标志的结果数据对象</returns>
OperateResult<double[]> ReadDouble(string address, ushort length);
/// <summary>
/// 读取字符串数据,
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="length">数据长度</param>
/// <returns>带有成功标识的string数据</returns>
OperateResult<string> ReadString(string address, ushort length);
/// <summary>
/// 读取自定义的数据类型,需要继承自IDataTransfer接口
/// </summary>
/// <typeparam name="T">自定义的类型</typeparam>
/// <param name="address">起始地址</param>
/// <returns>带有成功标识的自定义类型数据</returns>
OperateResult<T> ReadCustomer<T>(string address) where T : IDataTransfer, new();
/// <summary>
/// 从设备里读取支持Hsl特性的数据内容,该特性为<see cref="HslDeviceAddressAttribute"/>,详细参考论坛的操作说明。
/// </summary>
/// <typeparam name="T">自定义的数据类型对象</typeparam>
/// <returns>包含是否成功的结果对象</returns>
OperateResult<T> Read<T>() where T : class, new();
#endregion
#region Write Support
/// <summary>
/// 写入byte数组数据
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, byte[] value);
/// <summary>
/// 写入short数据
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, short value);
/// <summary>
/// 写入short数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="values">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, short[] values);
/// <summary>
/// 写入ushort数据
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, ushort value);
/// <summary>
/// 写入ushort数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="values">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, ushort[] values);
/// <summary>
/// 写入int数据
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, int value);
/// <summary>
/// 写入int[]数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="values">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, int[] values);
/// <summary>
/// 写入uint数据
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, uint value);
/// <summary>
/// 写入uint[]数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="values">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, uint[] values);
/// <summary>
/// 写入long数据
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, long value);
/// <summary>
/// 写入long数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="values">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, long[] values);
/// <summary>
/// 写入ulong数据
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, ulong value);
/// <summary>
/// 写入ulong数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="values">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, ulong[] values);
/// <summary>
/// 写入float数据
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, float value);
/// <summary>
/// 写入float数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="values">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, float[] values);
/// <summary>
/// 写入double数据
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, double value);
/// <summary>
/// 写入double数组
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="values">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, double[] values);
/// <summary>
/// 写入字符串信息,编码为ASCII
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, string value);
/// <summary>
/// 写入指定长度的字符串信息,编码为ASCII
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <param name="length">字符串的长度</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, string value, int length);
/// <summary>
/// 写入自定义类型的数据,该类型必须继承自IDataTransfer接口
/// </summary>
/// <typeparam name="T">类型对象</typeparam>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult WriteCustomer<T>(string address, T value) where T : IDataTransfer, new();
/// <summary>
/// 从设备里读取支持Hsl特性的数据内容,该特性为<see cref="HslDeviceAddressAttribute"/>,详细参考论坛的操作说明。
/// </summary>
/// <typeparam name="T">自定义的数据类型对象</typeparam>
/// <returns>包含是否成功的结果对象</returns>
/// <exception cref="ArgumentNullException"></exception>
OperateResult Write<T>(T data) where T : class, new();
#endregion
#region Bool Support
// Bool类型的读写,不一定所有的设备都实现,比如西门子,就没有实现bool[]的读写,Siemens的fetch/write没有实现bool操作
/// <summary>
/// 批量读取底层的数据信息,需要指定地址和长度,具体的结果取决于实现
/// </summary>
/// <param name="address">数据地址</param>
/// <param name="length">数据长度</param>
/// <returns>带有成功标识的byte[]数组</returns>
OperateResult<bool[]> ReadBool(string address, ushort length);
/// <summary>
/// 读取底层的bool数据信息,具体的结果取决于实现
/// </summary>
/// <param name="address">数据地址</param>
/// <returns>带有成功标识的byte[]数组</returns>
OperateResult<bool> ReadBool(string address);
/// <summary>
/// 写入bool数组数据
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, bool[] value);
/// <summary>
/// 写入bool数据
/// </summary>
/// <param name="address">起始地址</param>
/// <param name="value">写入值</param>
/// <returns>带有成功标识的结果类对象</returns>
OperateResult Write(string address, bool value);
#endregion
}
}