IReadWriteNet.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace MECF.Framework.RT.Core.IoProviders.Common.Net
  6. {
  7. /// <summary>
  8. /// 所有的和设备或是交互类统一读写标准
  9. /// </summary>
  10. /// <remarks>
  11. /// Modbus类,PLC类均实现了本接口,可以基于本接口实现统一所有的不同种类的设备的数据交互
  12. /// </remarks>
  13. /// <example>
  14. /// 此处举例实现modbus,三菱,西门子三种设备的统一的数据交互
  15. /// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Core\IReadWriteNet.cs" region="IReadWriteNetExample" title="IReadWriteNet示例" />
  16. /// </example>
  17. public interface IReadWriteNet
  18. {
  19. #region Read Support
  20. /// <summary>
  21. /// 批量读取底层的数据信息,需要指定地址和长度,具体的结果取决于实现
  22. /// </summary>
  23. /// <param name="address">数据地址</param>
  24. /// <param name="length">数据长度</param>
  25. /// <returns>带有成功标识的byte[]数组</returns>
  26. OperateResult<byte[]> Read( string address, ushort length );
  27. /// <summary>
  28. /// 读取16位的有符号整型
  29. /// </summary>
  30. /// <param name="address">起始地址</param>
  31. /// <returns>带有成功标识的short数据</returns>
  32. OperateResult<short> ReadInt16( string address );
  33. /// <summary>
  34. /// 读取16位的有符号整型数组
  35. /// </summary>
  36. /// <param name="address">起始地址</param>
  37. /// <param name="length">读取的数组长度</param>
  38. /// <returns>带有成功标识的short数组</returns>
  39. OperateResult<short[]> ReadInt16( string address, ushort length );
  40. /// <summary>
  41. /// 读取16位的无符号整型
  42. /// </summary>
  43. /// <param name="address">起始地址</param>
  44. /// <returns>带有成功标识的ushort数据</returns>
  45. OperateResult<ushort> ReadUInt16( string address );
  46. /// <summary>
  47. /// 读取16位的无符号整型数组
  48. /// </summary>
  49. /// <param name="address">起始地址</param>
  50. /// <param name="length">读取的数组长度</param>
  51. /// <returns>带有成功标识的ushort数组</returns>
  52. OperateResult<ushort[]> ReadUInt16( string address, ushort length );
  53. /// <summary>
  54. /// 读取32位的有符号整型
  55. /// </summary>
  56. /// <param name="address">起始地址</param>
  57. /// <returns>带有成功标识的int数据</returns>
  58. OperateResult<int> ReadInt32( string address );
  59. /// <summary>
  60. /// 读取32位有符号整型的数组
  61. /// </summary>
  62. /// <param name="address">起始地址</param>
  63. /// <param name="length">数组长度</param>
  64. /// <returns>带成功标志的结果数据对象</returns>
  65. OperateResult<int[]> ReadInt32( string address, ushort length );
  66. /// <summary>
  67. /// 读取32位的无符号整型
  68. /// </summary>
  69. /// <param name="address">起始地址</param>
  70. /// <returns>带有成功标识的uint数据</returns>
  71. OperateResult<uint> ReadUInt32( string address );
  72. /// <summary>
  73. /// 读取设备的uint类型的数组
  74. /// </summary>
  75. /// <param name="address">起始地址</param>
  76. /// <param name="length">数组长度</param>
  77. /// <returns>带成功标志的结果数据对象</returns>
  78. OperateResult<uint[]> ReadUInt32( string address, ushort length );
  79. /// <summary>
  80. /// 读取64位的有符号整型
  81. /// </summary>
  82. /// <param name="address">起始地址</param>
  83. /// <returns>带有成功标识的long数据</returns>
  84. OperateResult<long> ReadInt64( string address );
  85. /// <summary>
  86. /// 读取64位的有符号整型数组
  87. /// </summary>
  88. /// <param name="address">起始地址</param>
  89. /// <param name="length">数组长度</param>
  90. /// <returns>带成功标志的结果数据对象</returns>
  91. OperateResult<long[]> ReadInt64( string address, ushort length );
  92. /// <summary>
  93. /// 读取64位的无符号整型
  94. /// </summary>
  95. /// <param name="address">起始地址</param>
  96. /// <returns>带有成功标识的ulong数据</returns>
  97. OperateResult<ulong> ReadUInt64( string address );
  98. /// <summary>
  99. /// 读取64位的无符号整型的数组
  100. /// </summary>
  101. /// <param name="address">起始地址</param>
  102. /// <param name="length">数组长度</param>
  103. /// <returns>带成功标志的结果数据对象</returns>
  104. OperateResult<ulong[]> ReadUInt64( string address, ushort length );
  105. /// <summary>
  106. /// 读取单浮点精度的数据
  107. /// </summary>
  108. /// <param name="address">起始地址</param>
  109. /// <returns>带有成功标识的float数据</returns>
  110. OperateResult<float> ReadFloat( string address );
  111. /// <summary>
  112. /// 读取单浮点精度的数组
  113. /// </summary>
  114. /// <param name="address">起始地址</param>
  115. /// <param name="length">数组长度</param>
  116. /// <returns>带成功标志的结果数据对象</returns>
  117. OperateResult<float[]> ReadFloat( string address, ushort length );
  118. /// <summary>
  119. /// 读取双浮点精度的数据
  120. /// </summary>
  121. /// <param name="address">起始地址</param>
  122. /// <returns>带有成功标识的double数据</returns>
  123. OperateResult<double> ReadDouble( string address );
  124. /// <summary>
  125. /// 读取双浮点精度的数据的数组
  126. /// </summary>
  127. /// <param name="address">起始地址</param>
  128. /// <param name="length">数组长度</param>
  129. /// <returns>带成功标志的结果数据对象</returns>
  130. OperateResult<double[]> ReadDouble( string address, ushort length );
  131. /// <summary>
  132. /// 读取字符串数据,
  133. /// </summary>
  134. /// <param name="address">起始地址</param>
  135. /// <param name="length">数据长度</param>
  136. /// <returns>带有成功标识的string数据</returns>
  137. OperateResult<string> ReadString( string address, ushort length );
  138. /// <summary>
  139. /// 读取自定义的数据类型,需要继承自IDataTransfer接口
  140. /// </summary>
  141. /// <typeparam name="T">自定义的类型</typeparam>
  142. /// <param name="address">起始地址</param>
  143. /// <returns>带有成功标识的自定义类型数据</returns>
  144. OperateResult<T> ReadCustomer<T>( string address ) where T : IDataTransfer, new();
  145. #endregion
  146. #region Write Support
  147. /// <summary>
  148. /// 写入byte数组数据
  149. /// </summary>
  150. /// <param name="address">起始地址</param>
  151. /// <param name="value">写入值</param>
  152. /// <returns>带有成功标识的结果类对象</returns>
  153. OperateResult Write( string address, byte[] value );
  154. /// <summary>
  155. /// 写入short数据
  156. /// </summary>
  157. /// <param name="address">起始地址</param>
  158. /// <param name="value">写入值</param>
  159. /// <returns>带有成功标识的结果类对象</returns>
  160. OperateResult Write( string address, short value );
  161. /// <summary>
  162. /// 写入short数据
  163. /// </summary>
  164. /// <param name="address">起始地址</param>
  165. /// <param name="values">写入值</param>
  166. /// <returns>带有成功标识的结果类对象</returns>
  167. OperateResult Write( string address, short[] values );
  168. /// <summary>
  169. /// 写入int数据
  170. /// </summary>
  171. /// <param name="address">起始地址</param>
  172. /// <param name="value">写入值</param>
  173. /// <returns>带有成功标识的结果类对象</returns>
  174. OperateResult Write( string address, int value );
  175. /// <summary>
  176. /// 写入int[]数组
  177. /// </summary>
  178. /// <param name="address">起始地址</param>
  179. /// <param name="values">写入值</param>
  180. /// <returns>带有成功标识的结果类对象</returns>
  181. OperateResult Write( string address, int[] values );
  182. /// <summary>
  183. /// 写入long数据
  184. /// </summary>
  185. /// <param name="address">起始地址</param>
  186. /// <param name="value">写入值</param>
  187. /// <returns>带有成功标识的结果类对象</returns>
  188. OperateResult Write( string address, long value );
  189. /// <summary>
  190. /// 写入long数组
  191. /// </summary>
  192. /// <param name="address">起始地址</param>
  193. /// <param name="values">写入值</param>
  194. /// <returns>带有成功标识的结果类对象</returns>
  195. OperateResult Write( string address, long[] values );
  196. /// <summary>
  197. /// 写入float数据
  198. /// </summary>
  199. /// <param name="address">起始地址</param>
  200. /// <param name="value">写入值</param>
  201. /// <returns>带有成功标识的结果类对象</returns>
  202. OperateResult Write( string address, float value );
  203. /// <summary>
  204. /// 写入float数组
  205. /// </summary>
  206. /// <param name="address">起始地址</param>
  207. /// <param name="values">写入值</param>
  208. /// <returns>带有成功标识的结果类对象</returns>
  209. OperateResult Write( string address, float[] values );
  210. /// <summary>
  211. /// 写入double数据
  212. /// </summary>
  213. /// <param name="address">起始地址</param>
  214. /// <param name="value">写入值</param>
  215. /// <returns>带有成功标识的结果类对象</returns>
  216. OperateResult Write( string address, double value );
  217. /// <summary>
  218. /// 写入double数组
  219. /// </summary>
  220. /// <param name="address">起始地址</param>
  221. /// <param name="values">写入值</param>
  222. /// <returns>带有成功标识的结果类对象</returns>
  223. OperateResult Write( string address, double[] values );
  224. /// <summary>
  225. /// 写入字符串信息,编码为ASCII
  226. /// </summary>
  227. /// <param name="address">起始地址</param>
  228. /// <param name="value">写入值</param>
  229. /// <returns>带有成功标识的结果类对象</returns>
  230. OperateResult Write( string address, string value );
  231. /// <summary>
  232. /// 写入指定长度的字符串信息,编码为ASCII
  233. /// </summary>
  234. /// <param name="address">起始地址</param>
  235. /// <param name="value">写入值</param>
  236. /// <param name="length">字符串的长度</param>
  237. /// <returns>带有成功标识的结果类对象</returns>
  238. OperateResult Write( string address, string value, int length );
  239. /// <summary>
  240. /// 写入自定义类型的数据,该类型必须继承自IDataTransfer接口
  241. /// </summary>
  242. /// <typeparam name="T">类型对象</typeparam>
  243. /// <param name="address">起始地址</param>
  244. /// <param name="value">写入值</param>
  245. /// <returns>带有成功标识的结果类对象</returns>
  246. OperateResult WriteCustomer<T>( string address, T value ) where T : IDataTransfer, new();
  247. #endregion
  248. }
  249. }