DeviceExtension.cs 4.9 KB

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