DeviceExtension.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using WCS.Core;
  2. using PLCType = WCS.Core.PLCType;
  3. namespace WCS.WorkEngineering.Extensions
  4. {
  5. /// <summary>
  6. /// 设备扩展
  7. /// </summary>
  8. public static class DeviceExtension
  9. {
  10. #region 设备类型
  11. /// <summary>
  12. /// 是否是巷道
  13. /// </summary>
  14. /// <param name="source">设备信息</param>
  15. /// <returns></returns>
  16. public static bool IsTunnel(this Device source)
  17. {
  18. return source.HasFlag(DeviceFlags.巷道);
  19. }
  20. #endregion 设备类型
  21. #region 协议操作扩展
  22. public static void AddProtocol<T>(this Device device, int position, ushort db, string ip)
  23. {
  24. var info = new ProtocolInfo
  25. {
  26. Position = position,
  27. DBInfo = new DBInfo
  28. {
  29. No = db,
  30. PLCInfo = new PLCInfo
  31. {
  32. IP = ip,
  33. Port = 102,
  34. Rack = 0,
  35. Slot = 1,
  36. Type = PLCType.Siemens
  37. }
  38. }
  39. };
  40. device.AddProtocol<T>(info);
  41. }
  42. #endregion 协议操作扩展
  43. }
  44. /// <summary>
  45. /// 设备标签
  46. /// </summary>
  47. [Flags]
  48. public enum DeviceFlags
  49. {
  50. 扫码 = 1 << 0,
  51. 称重 = 1 << 1,
  52. 外检 = 1 << 2,
  53. 顶升 = 1 << 3,
  54. 移栽 = 1 << 4,
  55. 旋转 = 1 << 5,
  56. 入库 = 1 << 6,
  57. 出库 = 1 << 7,
  58. 巷道口 = 1 << 8,
  59. RGV口 = 1 << 9,
  60. AGV口 = 1 << 10,
  61. 直轨 = 1 << 11,
  62. 弯轨 = 1 << 12,
  63. 环轨 = 1 << 13,
  64. 巷道 = 1 << 14,
  65. 堆垛机 = 1 << 15,
  66. 输送机 = 1 << 16,
  67. }
  68. /// <summary>
  69. /// 输送机段信息
  70. /// </summary>
  71. public class StationSegmentInfo
  72. {
  73. /// <summary>
  74. /// 构造函数
  75. /// </summary>
  76. /// <param name="start">起始设备号</param>
  77. /// <param name="end">结束设备号</param>
  78. /// <param name="ip">ip</param>
  79. public StationSegmentInfo(int start, int end, string ip)
  80. {
  81. Start = start;
  82. End = end;
  83. IP = ip;
  84. }
  85. /// <summary>
  86. /// 起始设备编号
  87. /// </summary>
  88. public int Start { get; set; }
  89. /// <summary>
  90. ///结束设备编号
  91. /// </summary>
  92. public int End { get; set; }
  93. /// <summary>
  94. /// 输送机段所属IP
  95. /// </summary>
  96. public string IP { get; set; }
  97. }
  98. /// <summary>
  99. /// 扫码器信息
  100. /// </summary>
  101. public class BcrInfo
  102. {
  103. /// <summary>
  104. /// 构造函数
  105. /// </summary>
  106. /// <param name="deviceNo">设备编号</param>
  107. /// <param name="ip">ip</param>
  108. public BcrInfo(int[] deviceNo, string ip)
  109. {
  110. DeviceNo = deviceNo;
  111. IP = ip;
  112. }
  113. /// <summary>
  114. /// 设备编号
  115. /// </summary>
  116. public int[] DeviceNo { get; set; }
  117. /// <summary>
  118. /// ip
  119. /// </summary>
  120. public string IP { get; set; }
  121. }
  122. /// <summary>
  123. /// 外形信息
  124. /// </summary>
  125. public class ShapeInfo
  126. {
  127. /// <summary>
  128. /// 构造函数
  129. /// </summary>
  130. /// <param name="deviceNo">设备编号</param>
  131. /// <param name="ip">ip</param>
  132. public ShapeInfo(int[] deviceNo, string ip)
  133. {
  134. DeviceNo = deviceNo;
  135. IP = ip;
  136. }
  137. /// <summary>
  138. /// 设备编号
  139. /// </summary>
  140. public int[] DeviceNo { get; set; }
  141. /// <summary>
  142. /// ip
  143. /// </summary>
  144. public string IP { get; set; }
  145. }
  146. /// <summary>
  147. /// 路径信息
  148. /// </summary>
  149. public class RouteInfo
  150. {
  151. /// <summary>
  152. /// 构造函数
  153. /// </summary>
  154. /// <param name="deviceCode">起始点设备号</param>
  155. /// <param name="nextList">下一个设备集合</param>
  156. public RouteInfo(string deviceCode, string[] nextList)
  157. {
  158. DeviceCode = deviceCode;
  159. NextList = nextList;
  160. }
  161. /// <summary>
  162. /// 设备号
  163. /// </summary>
  164. public string DeviceCode { get; set; }
  165. /// <summary>
  166. /// 下一个设备
  167. /// </summary>
  168. public string[] NextList { get; set; }
  169. }
  170. }