DeviceExtension.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using System.Collections.Concurrent;
  2. using WCS.Core;
  3. using WCS.Entity;
  4. using WCS.Entity.Protocol.Station;
  5. namespace WCS.WorkEngineering.Extensions
  6. {
  7. /// <summary>
  8. /// 设备扩展
  9. /// </summary>
  10. public static class DeviceExtension
  11. {
  12. public static bool IsConv(this Device source)
  13. {
  14. return source.HasProtocol(typeof(IStation521)) || source.HasProtocol(typeof(IStation520)) || source.HasProtocol(typeof(IStation522));
  15. }
  16. #region WCS_DEVICE扩展数据
  17. private static ConcurrentDictionary<string, object> DeviceValues = new ConcurrentDictionary<string, object>();
  18. public static void AddFlag(this Device source, DF flag)
  19. {
  20. var df = source.Get<DF>("DeviceFlag");
  21. df = df | flag;
  22. source.Set("DeviceFlag", df);
  23. }
  24. public static bool Is(this Device source, DF flag)
  25. {
  26. var df = source.Get<DF>("DeviceFlag");
  27. return (df & flag) == flag;
  28. }
  29. public static void Set<T>(this Device source, string key, T value)
  30. {
  31. DeviceValues[source.Code + key] = value;
  32. }
  33. public static T Get<T>(this Device source, string key)
  34. {
  35. if (!DeviceValues.ContainsKey(source.Code + key))
  36. return default(T);
  37. return (T)DeviceValues[source.Code + key];
  38. }
  39. public static short Code(this Device source)
  40. {
  41. return short.Parse(source.Code);
  42. }
  43. public static string Tunnel(this Device source)
  44. {
  45. return source.Get<string>("Tunnel");
  46. }
  47. public static int TunnelNum(this Device source)
  48. {
  49. return int.Parse(source.Tunnel().Last().ToString());
  50. }
  51. public static int Floor(this Device source)
  52. {
  53. return source.Get<int>("Floor");
  54. }
  55. public static Device SC(this Device source)
  56. {
  57. return source.Get<Device>("SC");
  58. }
  59. public static Device RGV(this Device source)
  60. {
  61. return source.Get<Device>("RGV");
  62. }
  63. //public static LocInfo LocInfo(this WCS_DEVICEHdr source)
  64. //{
  65. // return source.Get<LocInfo>("LocInfo");
  66. //}
  67. //public static bool WakeupOn(this WCS_DEVICEHdr source, int sec, string key)
  68. //{
  69. // var str = "WakeupOn" + key;
  70. // var last = source.Get<DateTime>(str);
  71. // if ((DateTime.Now - last).TotalMilliseconds > sec)
  72. // {
  73. // source.Set(str, DateTime.Now);
  74. // return true;
  75. // }
  76. // else
  77. // {
  78. // Ltc.Log("OnSleep");
  79. // return false;
  80. // }
  81. //}
  82. //public static bool WakeupOn(this WCS_DEVICEHdr source, int sec)
  83. //{
  84. // return source.WakeupOn(sec, "");
  85. //}
  86. #endregion WCS_DEVICE扩展数据
  87. //#region 静态方法
  88. //public static WCS_DEVICEHdr[] Where(Func<WCS_DEVICEHdr, bool> func)
  89. //{
  90. // var arr = LogicHandler.AllObjects.OfType<WCS_DEVICEHdr>().Where(func).ToArray();
  91. // return arr;
  92. //}
  93. //public static WCS_DEVICEHdr Find(string code)
  94. //{
  95. // return Where(v => v.CODE == code).Single();
  96. //}
  97. //public static WCS_DEVICEHdr[] Find(params string[] codes)
  98. //{
  99. // return Where(v => codes.Contains(v.CODE)).ToArray();
  100. //}
  101. //public static void Set<T>(string key, T value, params string[] devices)
  102. //{
  103. // var arr = LogicHandler.AllObjects.OfType<WCS_DEVICEHdr>().Where(v => devices.Contains(v.CODE)).ToArray();
  104. // Parallel.ForEach(arr, v =>
  105. // {
  106. // v.Set(key, value);
  107. // });
  108. //}
  109. //public static void Set<T>(string key, T value, Func<WCS_DEVICEHdr, bool> func)
  110. //{
  111. // var arr = LogicHandler.AllObjects.OfType<WCS_DEVICEHdr>().Where(func).ToArray();
  112. // Parallel.ForEach(arr, v =>
  113. // {
  114. // v.Set(key, value);
  115. // });
  116. //}
  117. //public static void AddFlag(DF flag, params string[] devices)
  118. //{
  119. // var arr = LogicHandler.AllObjects.OfType<WCS_DEVICEHdr>().Where(v => devices.Contains(v.CODE)).ToArray();
  120. // Parallel.ForEach(arr, v =>
  121. // {
  122. // v.AddFlag(flag);
  123. // });
  124. //}
  125. //public static void AddFlag(DF flag, Action<WCS_DEVICEHdr> callbck, params string[] devices)
  126. //{
  127. // var arr = LogicHandler.AllObjects.OfType<WCS_DEVICEHdr>().Where(v => devices.Contains(v.CODE)).ToArray();
  128. // Parallel.ForEach(arr, v =>
  129. // {
  130. // v.AddFlag(flag);
  131. // callbck?.Invoke(v);
  132. // });
  133. //}
  134. //#endregion 静态方法
  135. }
  136. /// <summary>
  137. /// 设备配置
  138. /// </summary>
  139. [Flags]
  140. public enum DF
  141. {
  142. 无 = 0,
  143. SRM = 1 << 0,
  144. SRM二级品取货 = 1 << 1,
  145. SRM涂布取货 = 1 << 2,
  146. SRM月台放货 = 1 << 3,
  147. 一楼RGV放货 = 1 << 4,
  148. 月台 = 1 << 5,
  149. 涂布RGV = 1 << 6,
  150. BOPPRGV = 1 << 7,
  151. 涂布RGV取货设备组 = 1 << 8,
  152. 涂布RGV放货设备组 = 1 << 9,
  153. 涂布出库RGV取货站台 = 1 << 10,
  154. 涂布入库RGV取货站台 = 1 << 11,
  155. SRM涂布放货 = 1 << 12,
  156. 涂布RGV取货站台 = 1 << 13,
  157. BOPPRGV取货设备组 = 1 << 14,
  158. BOPPRGV放货设备组 = 1 << 15,
  159. SRMBOPP取货 = 1 << 16,
  160. }
  161. }