DeviceExtension.cs 4.6 KB

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