EfemMessage.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Reflection;
  5. using System.Runtime.Serialization;
  6. using System.Runtime.Serialization.Formatters.Binary;
  7. using System.Text.RegularExpressions;
  8. using Aitex.Core.RT.Event;
  9. using Aitex.Sorter.Common;
  10. using MECF.Framework.Common.Equipment;
  11. using VirgoCommon;
  12. namespace VirgoRT.Device.YASKAWA
  13. {
  14. [Serializable]
  15. public sealed class EfemMessage : IEfemMessage, ICloneable
  16. {
  17. public enum MsgHead
  18. {
  19. MOV, GET, ACK, INF, SET, CAN, ABS, EVT, NAK
  20. }
  21. public const char EOF = ';';
  22. public EfemOperation Operation { get; set; }
  23. public MsgHead Head { get; set; }
  24. public ModuleName Port { get; set; }
  25. public IList<string> Data { get; set; }
  26. public MsgDirection Direct { get; set; } = MsgDirection.To;
  27. public IList<string> Parameters { get; set; }
  28. public string RawString { get; set; }
  29. public string Factor { get; set; } // NAK, CAN
  30. public override string ToString()
  31. {
  32. string sPara = ToParamString();
  33. string sOP = EfemConstant.OperationString[Operation];
  34. string context = $"{Head}:{sOP}{sPara}";
  35. context += EOF;
  36. return context;
  37. }
  38. public string ToParamString()
  39. {
  40. string res = string.Empty;
  41. if (Parameters == null || Parameters.Count <= 0)
  42. return res;
  43. foreach (var para in Parameters)
  44. {
  45. res += '/' + para;
  46. }
  47. return res;
  48. }
  49. public object Clone()
  50. {
  51. using (Stream objStream = new MemoryStream())
  52. {
  53. IFormatter formatter = new BinaryFormatter();
  54. formatter.Serialize(objStream, this);
  55. objStream.Seek(0, SeekOrigin.Begin);
  56. return formatter.Deserialize(objStream) as EfemMessage ?? throw new InvalidOperationException();
  57. }
  58. }
  59. }
  60. [AttributeUsage(AttributeTargets.Enum | AttributeTargets.Field)]
  61. public class HardwareCmdAttribute : Attribute
  62. {
  63. public string Member { get; set; }
  64. public HardwareCmdAttribute(string str) { this.Member = str; }
  65. }
  66. [AttributeUsage(AttributeTargets.Enum | AttributeTargets.Field)]
  67. public class InterpretationAttribute : Attribute
  68. {
  69. public string Comment { get; set; }
  70. public InterpretationAttribute(string str) { this.Comment = str; }
  71. }
  72. public static class Extension
  73. {
  74. private const string ERROR_MSG = "hardware message invalid";
  75. /// <summary>
  76. /// NAK:FACTOR|Message*;
  77. /// ACK:Message*;
  78. /// CAN:Message*|Factor/Place;
  79. /// ABS:Message*|Error/Parameter1/Parameter2;
  80. /// EVT:Message*;
  81. /// </summary>
  82. public static EfemMessage ToMessage(this string context)
  83. {
  84. if (string.IsNullOrEmpty(context) || context.Length < 3)
  85. throw new ArgumentNullException(ERROR_MSG);
  86. EfemMessage msg = new EfemMessage { RawString = context, Direct = MsgDirection.From, Data = new List<string>() };
  87. // remove EOT
  88. string messageBody = context.Substring(0, context.IndexOf(EfemMessage.EOF) + 1);
  89. try
  90. {
  91. // split up the string
  92. string[] sBodies = messageBody.Split(Constant.delimiters);
  93. string sHead = sBodies[0];
  94. string sBasic = sBodies[1];
  95. string sPort = sBodies[2];
  96. // Head
  97. if (Enum.TryParse(sHead, true, out EfemMessage.MsgHead msgHead))
  98. {
  99. msg.Head = msgHead;
  100. }
  101. switch (msg.Head)
  102. {
  103. case EfemMessage.MsgHead.ACK:
  104. case EfemMessage.MsgHead.MOV:
  105. case EfemMessage.MsgHead.INF:
  106. case EfemMessage.MsgHead.EVT:
  107. // Basic
  108. msg.Operation = EfemConstant.ToOperation(sBasic);
  109. // Port
  110. if (Regex.IsMatch(sPort, @"P[123]$"))
  111. {
  112. msg.Port = sPort.ToModule();
  113. }
  114. else if (Regex.IsMatch(sPort, @"ALIGN\d?", RegexOptions.IgnoreCase))
  115. {
  116. msg.Port = sPort.ToModule();
  117. }
  118. else
  119. {
  120. msg.Port = ModuleName.EFEM;
  121. }
  122. // Data
  123. switch (msg.Operation)
  124. {
  125. case EfemOperation.StateTrack:
  126. case EfemOperation.GetWaferInfo:
  127. msg.Data.Add(sBodies[3]);
  128. break;
  129. case EfemOperation.CarrierId:
  130. msg.Data.Add(msg.RawString.Substring("INF:CSTID/P1/".Length));
  131. break;
  132. case EfemOperation.SigStatus:
  133. if(msg.Head != EfemMessage.MsgHead.ACK)
  134. {
  135. msg.Data.Add(sBodies[2]);
  136. msg.Data.Add(sBodies[3]);
  137. msg.Data.Add(sBodies[4]);
  138. }
  139. break;
  140. case EfemOperation.Ready:
  141. msg.Data.Add(sBodies[2]);
  142. break;
  143. default:
  144. break;
  145. }
  146. break;
  147. case EfemMessage.MsgHead.NAK:
  148. msg.Operation = EfemConstant.ToOperation(sBasic);
  149. // Port
  150. if (Regex.IsMatch(sPort, @"P[123]$"))
  151. {
  152. msg.Port = sPort.ToModule();
  153. }
  154. else if (Regex.IsMatch(sPort, @"ALIGN\d?", RegexOptions.IgnoreCase))
  155. {
  156. msg.Port = sPort.ToModule();
  157. }
  158. else
  159. {
  160. msg.Port = ModuleName.EFEM;
  161. }
  162. msg.Factor = sBodies[1];
  163. msg.Data.Add(sBodies[2]);
  164. msg.Operation = EfemConstant.ToOperation(sBasic);
  165. break;
  166. case EfemMessage.MsgHead.CAN:
  167. msg.Operation = EfemConstant.ToOperation(sBasic);
  168. // Port
  169. if (Regex.IsMatch(sPort, @"P[123]$"))
  170. {
  171. msg.Port = sPort.ToModule();
  172. }
  173. else if (Regex.IsMatch(sPort, @"ALIGN\d?", RegexOptions.IgnoreCase))
  174. {
  175. msg.Port = sPort.ToModule();
  176. }
  177. else
  178. {
  179. msg.Port = ModuleName.EFEM;
  180. }
  181. // CAN:ERROR/CLEAR;
  182. int a1 = messageBody.IndexOf(':');
  183. int a3 = messageBody.IndexOf(';');
  184. int a2 = messageBody.IndexOf('|');
  185. if (a2 > 0)
  186. {
  187. msg.Data.Add(messageBody.Substring(a1 + 1, a2 - a1 - 1));
  188. msg.Factor = messageBody.Substring(a2 + 1, a3 - a2 - 1);
  189. }
  190. else
  191. {
  192. int a8 = messageBody.IndexOf('/');
  193. msg.Factor = sBodies[2];
  194. }
  195. break;
  196. case EfemMessage.MsgHead.ABS:
  197. msg.Operation = EfemConstant.ToOperation(sBasic);
  198. // Port
  199. if (Regex.IsMatch(sPort, @"P[123]$"))
  200. {
  201. msg.Port = sPort.ToModule();
  202. }
  203. else if (Regex.IsMatch(sPort, @"ALIGN\d?", RegexOptions.IgnoreCase))
  204. {
  205. msg.Port = sPort.ToModule();
  206. }
  207. else
  208. {
  209. msg.Port = ModuleName.EFEM;
  210. }
  211. // ABS:INIT/ALL|ERROR/SYSTEM_FF10/UNDEFINITION;
  212. int a4 = messageBody.IndexOf('|');
  213. int a5 = messageBody.IndexOf(';');
  214. string errStr = messageBody.Substring(a4 + 1, a5 - a4 - 1);
  215. string[] a6 = errStr.Split('/');
  216. if (a6.Length < 3)
  217. {
  218. throw new ApplicationException($"ABS 格式错误 {errStr}");
  219. }
  220. msg.Factor = a6[0];
  221. msg.Data.Add(a6[1]);
  222. msg.Data.Add(a6[2]);
  223. break;
  224. }
  225. }
  226. catch (Exception ex)
  227. {
  228. EV.PostAlarmLog(ModuleName.EFEM.ToString(), $"Receive [{context}],Analysis error [{ex.Message}]");
  229. }
  230. return msg;
  231. }
  232. public static string ToHWString(this Position pos)
  233. {
  234. string res = string.Empty;
  235. if (ModuleHelper.IsAligner(pos.Module) || ModuleHelper.IsCooling(pos.Module) || ModuleHelper.IsFlipper(pos.Module))
  236. {
  237. res = Constant.ModuleString[pos.Module];
  238. }
  239. else
  240. {
  241. string sMod = Constant.ModuleString[pos.Module];
  242. int num = pos.Slot + 1;
  243. string sSlot = num.ToString("D2");
  244. res = $"{sMod}{sSlot}";
  245. }
  246. return res;
  247. }
  248. public static string ToHWString(this ModuleName mod)
  249. {
  250. return Constant.ModuleString[mod];
  251. }
  252. public static ModuleName ToModule(this string str)
  253. {
  254. if (Constant.StringModule.ContainsKey(str))
  255. return Constant.StringModule[str];
  256. throw new ApplicationException($"Cannot translate {str}");
  257. }
  258. public static string HardwareCmd(this Enum val)
  259. {
  260. FieldInfo fi = val.GetType().GetField(val.ToString());
  261. return fi.GetCustomAttributes(typeof(HardwareCmdAttribute), false) is HardwareCmdAttribute[] attrs
  262. && attrs.Length > 0 ? attrs[0].Member : val.ToString();
  263. }
  264. public static string Interpretation(this Enum val)
  265. {
  266. FieldInfo fi = val.GetType().GetField(val.ToString());
  267. return fi.GetCustomAttributes(typeof(InterpretationAttribute), false) is InterpretationAttribute[] attrs
  268. && attrs.Length > 0 ? attrs[0].Comment : val.ToString();
  269. }
  270. }
  271. /// <summary>
  272. /// constant define
  273. /// </summary>
  274. public class Constant
  275. {
  276. public static readonly char[] delimiters = { ':', '/', '>', '|', ';' };
  277. public const string ALL = "ALL";
  278. public const string MAP = "MAPDT";
  279. public const string SYS = "SYSTEM";
  280. public const string STOWER = "STOWER";
  281. public static readonly Dictionary<ModuleName, string> ModuleString = new Dictionary<ModuleName, string>
  282. {
  283. [ModuleName.EFEM] = "ALL",
  284. [ModuleName.EfemRobot]= "ROB",
  285. [ModuleName.LP1] = "P1",
  286. [ModuleName.LP2] = "P2",
  287. [ModuleName.PMA] = "LLA",
  288. [ModuleName.PMB] = "LLB",
  289. [ModuleName.Aligner1] = "ALIGN3",
  290. [ModuleName.Aligner2] = "ALIGN4",
  291. [ModuleName.Cooling1] = "ALIGN",
  292. [ModuleName.Cooling2] = "ALIGN2",
  293. [ModuleName.Flipper] = "FLIPPER",
  294. [ModuleName.Buffer] = "BUFFER"
  295. };
  296. public static readonly Dictionary<string, ModuleName> StringModule = new Dictionary<string, ModuleName>
  297. {
  298. ["ALL"] = ModuleName.EFEM,
  299. ["System"] = ModuleName.EFEM,
  300. ["P1"] = ModuleName.LP1,
  301. ["P2"] = ModuleName.LP2,
  302. ["LLA"] = ModuleName.PMA,
  303. ["LLB"] = ModuleName.PMB,
  304. ["ALIGN"] = ModuleName.Cooling1,
  305. ["ALIGN2"] = ModuleName.Cooling2,
  306. ["ALIGN3"] = ModuleName.Aligner1,
  307. ["ALIGN4"] = ModuleName.Aligner2,
  308. ["FLIPPER"] = ModuleName.Flipper,
  309. ["BUFFER"] = ModuleName.Buffer,
  310. };
  311. public static readonly Dictionary<Hand, string> ArmString = new Dictionary<Hand, string>
  312. {
  313. [Hand.Blade1] = "ARM2",
  314. [Hand.Blade2] = "ARM1",
  315. [Hand.Both] = "ARM3"
  316. };
  317. public static readonly Dictionary<ExtendPos, string> ExtendPosString = new Dictionary<ExtendPos, string>
  318. {
  319. //[ExtendPos.GetReady] = "G1",
  320. //[ExtendPos.GetTarget] = "GB",
  321. //[ExtendPos.GetBack] = "G4",
  322. //[ExtendPos.PutReady] = "P1",
  323. //[ExtendPos.PutTarget] = "PB",
  324. //[ExtendPos.PutBack] = "P4"
  325. };
  326. public static readonly Dictionary<string, string> FactorString = new Dictionary<string, string>
  327. {
  328. { "MSG", "Message error" },
  329. { "NOREAD", "Communication not established" },
  330. { "NOINITCMPL", "Initialization not completed" },
  331. { "NOORGCMPL", "Not org finished" },
  332. { "VAC", "Vac error" },
  333. { "AIR", "Air error" },
  334. { "EMS", "EMS pushed" },
  335. { "ERROR", "Has Error" },
  336. { "BUSY", "Busy (Module in use)" },
  337. { "CMPL", "Already Completed" },
  338. { "NOMAPCMPL", "Not Mapped" },
  339. { "NONWAF", "NO wafer on the position" },
  340. { "WAFER", "Wafer already existed" },
  341. { "NONPOD", "No Pod" },
  342. { "POD", "Pod Exist" },
  343. { "NOTINMOTION","Not in Motion" },
  344. { "HOLD", "Holded" },
  345. { "NOHOLD", "Not hold" },
  346. { "LLCLOSE", "LL door closed state" },
  347. { "LLNOEXTEND", "LL not extended" },
  348. { "REMOVE", "remove" },
  349. { "MAINTENANCE","In maintain mode or EFEM offline" },
  350. { "NOLINK", "not config" },
  351. { "ARMEXTEND", "arm extended" },
  352. { "POWER", "power off" },
  353. { "PRTWAF", "TODO" },
  354. { "NOPOS", "Not at valid position" },
  355. { "NOFUNC", "not support" },
  356. { "PARAM_NG", "Invalid parameters are included" }
  357. };
  358. public static readonly Dictionary<string, string> ABS_PARA1 = new Dictionary<string, string>
  359. {
  360. { "SYSTEM_FF01", "No specific route data or malfunction" },
  361. { "SYSTEM_FF10", "Operation time out" },
  362. { "SYSTEM_FF11", "Communication time out between PC for robot control and controller" },
  363. { "SYSTEM_FF12", "Encoder battery error" },
  364. { "SYSTEM_FF13", "Loss of encoder information" },
  365. { "SYSTEM_FF20", "No data file of route" },
  366. { "SYSTEM_FF21", "Serial number in route data is wrong" },
  367. { "SYSTEM_FF22", "No line for serial number in route data" },
  368. { "SYSTEM_FF23", "Discrepancy in serial number between route data and teaching data" },
  369. { "SYSTEM_FF30", "Failure of pre-operation movement at the wrist in the robot" },
  370. { "SYSTEM_FF83", "Inability of the robot to return origin" },
  371. { "SYSTEM_FFB0", "Operation malfunction at fan in robot" },
  372. { "SYSTEM_FFF0", "Alarm at Z-axis driver in the robot" },
  373. { "SYSTEM_FFFF", "Robot control program malfunction" }
  374. };
  375. }
  376. }