RejeSMIF.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. using Aitex.Core.RT.Event;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using MECF.Framework.Common.Communications;
  6. using MECF.Framework.Common.Device.Bases;
  7. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Common;
  8. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.SMIFs.Reje
  15. {
  16. public class RejeSMIF : SMIFBase, IConnection
  17. {
  18. private string _address = "";
  19. public string Address { get { return _address; } }
  20. public override bool IsConnected { get; set; }
  21. //public bool
  22. public bool Connect()
  23. {
  24. return true;
  25. }
  26. public bool Disconnect()
  27. {
  28. return true;
  29. }
  30. public string PortStatus { get; set; } = "Closed";
  31. private RejeSMIFConnection _connection;
  32. public RejeSMIFConnection Connection
  33. {
  34. get { return _connection; }
  35. }
  36. public List<IOResponse> IOResponseList { get; set; } = new List<IOResponse>();
  37. public int Axis { get; private set; }
  38. public override bool IsIdle { get; set; }
  39. public override bool IsHomed { get; set; }
  40. public override bool IsPodPresent { get; set; }
  41. public override bool IsArmRetract { get; set; }
  42. public override bool IsAlarm { get; set; }
  43. private R_TRIG _trigError = new R_TRIG();
  44. private R_TRIG _trigCommunicationError = new R_TRIG();
  45. private R_TRIG _trigRetryConnect = new R_TRIG();
  46. private PeriodicJob _thread;
  47. private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
  48. private LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
  49. private object _locker = new object();
  50. //private bool _enableLog;
  51. private string _errorCode = "";
  52. private DeviceTimer _QueryTimer = new DeviceTimer();
  53. private int _QueryInterval = 1000;
  54. private string _scRoot;
  55. public RejeSMIF(string Module, string Name, string scRoot)
  56. {
  57. //_enableLog = SC.GetValue<bool>($"SMIF.{Name}.EnableLogMessage");
  58. _scRoot = scRoot;
  59. _connection = new RejeSMIFConnection(this, _scRoot);
  60. //_connection.EnableLog(_enableLog);
  61. base.Module = Module;
  62. base.Name = Name;
  63. //_lstMonitorHandler.AddLast(new RejeSMIFLoadCassetteHeandler(this));
  64. //_lstMonitorHandler.AddLast(new RejeSMIFUnLoadCassetteHeandler(this));
  65. //_lstMonitorHandler.AddLast(new RejeSMIFORGSHHeandler(this));
  66. //_lstMonitorHandler.AddLast(new RejeSMIFResetHeandler(this));
  67. //_lstMonitorHandler.AddLast(new RejeSMIFSetHomePositionHeandler(this,1000));
  68. _lstMonitorHandler.AddLast(new RejeSMIFGetStatusHandler(this));
  69. if (_connection.Connect())
  70. {
  71. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  72. }
  73. else
  74. {
  75. EV.PostInfoLog(Module, $"{Module}.{Name} connect failed");
  76. }
  77. _QueryTimer.Start(_QueryInterval);
  78. _thread = new PeriodicJob(1000, OnTimer, $"{Name} MonitorHandler", true);
  79. }
  80. private bool OnTimer()
  81. {
  82. try
  83. {
  84. //return true;
  85. _connection.MonitorTimeout();
  86. if (!_connection.IsConnected || _connection.IsCommunicationError)
  87. {
  88. lock (_locker)
  89. {
  90. _lstHandler.Clear();
  91. }
  92. _trigRetryConnect.CLK = !_connection.IsConnected;
  93. if (_trigRetryConnect.Q)
  94. {
  95. if (string.IsNullOrEmpty(_scRoot))
  96. {
  97. _connection.SetPortAddress(SC.GetStringValue($"{Module}.DeviceAddress"));
  98. }
  99. else
  100. {
  101. _connection.SetPortAddress(SC.GetStringValue($"{_scRoot}.{Module}.{Name}.DeviceAddress"));
  102. }
  103. if (!_connection.Connect())
  104. {
  105. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}");
  106. }
  107. else
  108. {
  109. //_lstHandler.AddLast(new BrooksSMIFQueryPinHandler(this, _deviceAddress));
  110. //_lstHandler.AddLast(new BrooksSMIFSetCommModeHandler(this, _deviceAddress, EnumRfPowerCommunicationMode.Host));
  111. }
  112. }
  113. return true;
  114. }
  115. HandlerBase handler = null;
  116. if (!_connection.IsBusy)
  117. {
  118. lock (_locker)
  119. {
  120. if (_lstHandler.Count == 0)
  121. {
  122. foreach (var monitorHandler in _lstMonitorHandler)
  123. {
  124. _lstHandler.AddLast(monitorHandler);
  125. }
  126. }
  127. if (_lstHandler.Count > 0)
  128. {
  129. handler = _lstHandler.First.Value;
  130. _lstHandler.RemoveFirst();
  131. }
  132. }
  133. if (handler != null)
  134. {
  135. _connection.Execute(handler);
  136. }
  137. }
  138. }
  139. catch (Exception ex)
  140. {
  141. LOG.Write(ex);
  142. }
  143. return true;
  144. }
  145. public override bool HomeSmif(out string reason)
  146. {
  147. reason = string.Empty;
  148. lock (_locker)
  149. {
  150. _lstHandler.AddLast(new RejeSMIFHomeHeandler(this));
  151. }
  152. return true;
  153. }
  154. public bool Stop(out string reason)
  155. {
  156. reason = string.Empty;
  157. lock (_locker)
  158. {
  159. _lstHandler.AddLast(new RejeSMIFStopHeandler(this));
  160. _lstHandler.AddLast(new RejeSMIFORGSHHeandler(this));
  161. }
  162. return true;
  163. }
  164. public override bool LoadCassette(out string reason)
  165. {
  166. reason = string.Empty;
  167. lock (_locker)
  168. {
  169. _lstHandler.AddLast(new RejeSMIFLoadCassetteHeandler(this));
  170. }
  171. return true;
  172. }
  173. public override bool UnloadCassette(out string reason)
  174. {
  175. reason = string.Empty;
  176. lock (_locker)
  177. {
  178. _lstHandler.AddLast(new RejeSMIFUnLoadCassetteHeandler(this));
  179. }
  180. return true;
  181. }
  182. public void OnAbs(string absMsg)
  183. {
  184. try
  185. {
  186. string absContext = absMsg.Split('/')[1].Replace(";", "").Replace("\r", "");
  187. NoteError(absContext, 1);
  188. }
  189. catch (Exception ex)
  190. {
  191. LOG.Write(ex);
  192. }
  193. }
  194. public void OnNak(string absMsg)
  195. {
  196. try
  197. {
  198. string absContext = absMsg.Split('/')[1].Replace(";", "").Replace("\r", "");
  199. NoteError(absContext, 2);
  200. //EV.Notify($"{Name}{absContext}");
  201. }
  202. catch (Exception ex)
  203. {
  204. LOG.Write(ex);
  205. }
  206. }
  207. internal void OnEventArrived(string eventData)
  208. {
  209. if (eventData == "ONMGV")
  210. {
  211. ONMGVComplete = true;
  212. }
  213. if (eventData == "MENTE")
  214. {
  215. MENTEComlete = true;
  216. }
  217. if (eventData == "TEACH")
  218. {
  219. TEACHComlete = true;
  220. }
  221. if (eventData == "STOP_")
  222. {
  223. STOPComlete = true;
  224. }
  225. if (eventData == "ORGJZ")
  226. {
  227. ORGJZComlete = true;
  228. }
  229. if (eventData == "ORGJL")
  230. {
  231. ORGJLComlete = true;
  232. }
  233. if (eventData == "DOROP")
  234. {
  235. DOROPComlete = true;
  236. }
  237. if (eventData == "DORCL")
  238. {
  239. DORCLComlete = true;
  240. }
  241. if (eventData == "HOME_")
  242. {
  243. HOMEComlete = true;
  244. }
  245. if (eventData == "STAGE")
  246. {
  247. STAGEComlete = true;
  248. }
  249. if (eventData == "TEACH")
  250. {
  251. TEACHComlete = true;
  252. }
  253. if (eventData == "MAPDO")
  254. {
  255. MAPDOComlete = true;
  256. }
  257. if (eventData == "ORGSH")
  258. {
  259. ORGSHComlete = true;
  260. }
  261. if (eventData == "CLDMP")
  262. {
  263. CLDMPComlete = true;
  264. }
  265. if (eventData == "RESET")
  266. {
  267. RESETComlete = true;
  268. }
  269. }
  270. #region Properties
  271. /// <summary>
  272. /// 设置 onLine模式完成
  273. /// </summary>
  274. public bool ONMGVComplete { get; private set; }
  275. /// <summary>
  276. /// 设置维护模式完成
  277. /// </summary>
  278. public bool MENTEComlete { get; private set; }
  279. /// <summary>
  280. /// 设置示教模式完成
  281. /// </summary>
  282. public bool TEACHComlete { get; private set; }
  283. /// <summary>
  284. /// 执行紧急停止完成
  285. /// </summary>
  286. public bool STOPComlete { get; private set; }
  287. /// <summary>
  288. /// 移动到Stage位置完成
  289. /// </summary>
  290. public bool ORGJZComlete { get; private set; }
  291. /// <summary>
  292. /// 执行SMIFPod Base打开完成
  293. /// </summary>
  294. public bool ORGJLComlete { get; private set; }
  295. /// <summary>
  296. /// 执行SMIFPod Base关闭完成
  297. /// </summary>
  298. public bool DOROPComlete { get; private set; }
  299. /// <summary>
  300. ///执行SMIFPod Base打开完成
  301. /// </summary>
  302. public bool DORCLComlete { get; private set; }
  303. /// <summary>
  304. /// 上移到HOME位置
  305. /// </summary>
  306. public bool HOMEComlete { get; private set; }
  307. /// <summary>
  308. /// 执行 Z 轴下移到 stage 位置
  309. /// </summary>
  310. public bool STAGEComlete { get; private set; }
  311. /// <summary>
  312. /// 执行 Mapping 动作完成
  313. /// </summary>
  314. public bool MAPDOComlete { get; private set; }
  315. /// <summary>
  316. /// 系统搜索原点.系统重新上电时先进行搜索原点动作完成
  317. /// </summary>
  318. public bool ORGSHComlete { get; private set; }
  319. /// <summary>
  320. /// 打开 SMIFPod 并 MAP 扫描晶圆状态完成
  321. /// </summary>
  322. public bool CLDMPComlete { get; private set; }
  323. /// <summary>
  324. /// 重置完成
  325. /// </summary>
  326. public bool RESETComlete { get; private set; }
  327. #endregion
  328. #region Note Functions
  329. private R_TRIG _trigWarningMessage = new R_TRIG();
  330. public void NoteError(string errorData, int MsgType)
  331. {
  332. if (errorData != null)
  333. {
  334. _trigWarningMessage.CLK = true;
  335. if (_trigWarningMessage.Q)
  336. {
  337. if (MsgType == 1)
  338. {
  339. EV.PostWarningLog(Module, $"{Module} error, {(_ASBMessageDict.ContainsKey(errorData) ? _ASBMessageDict[errorData] : errorData)}");
  340. }
  341. else if (MsgType == 2)
  342. {
  343. EV.PostWarningLog(Module, $"{Module} error, {(_NAKMessageDict.ContainsKey(errorData) ? _NAKMessageDict[errorData] : errorData)}");
  344. }
  345. else
  346. {
  347. EV.PostWarningLog(Module, $"{Module} error, {(_ErrorMessageDict.ContainsKey(errorData) ? _ErrorMessageDict[errorData] : errorData)}");
  348. }
  349. }
  350. }
  351. }
  352. private static Dictionary<string, string> _ASBMessageDict = new Dictionary<string, string>()
  353. {
  354. {"COMER","Instruction content is incorrect" },
  355. {"ZDALM","Z axis alram" },
  356. {"LDALM","L axis alram" },
  357. {"ZCRLER","Z axis control system. alram" },
  358. {"LCRLER","L axis control system. alram" },
  359. {"LPOSI","SMIF pod bottom switch not change" },
  360. {"PROTS","Wafer out" },
  361. {"PODNG","SMIF pod current status not change" },
  362. {"TIMOT","Action timeout alarm" },
  363. {"WFCNG","Place more than 2 wafers" },
  364. {"PITNG","Pitch value Settings do not match" },
  365. };
  366. private static Dictionary<string, string> _NAKMessageDict = new Dictionary<string, string>()
  367. {
  368. {"CMDCOMERER","Serial port error" },
  369. {"CBUSY","Opeation is busy" },
  370. {"ORGYT","Origin not searched" },
  371. {"ZDALM","Z axis alram" },
  372. {"LDALM","L axis alram" },
  373. {"ZCRLER","Z axis control system. alram" },
  374. {"LCRLER","L axis control system. alram" },
  375. {"LPOSI","SMIF pod bottom switch status error " },
  376. {"PROTS","Wafer out" },
  377. {"SMILG","SMIF pod position error" },
  378. {"MODNG","System mode does not match" },
  379. {"MAPNE","Map class number does not exist" },
  380. {"MAPUD","No MAP scan was" },
  381. {"ZPOSI","Z axis Out of place" },
  382. {"NOPAR","Wafer parameters are not set" },
  383. };
  384. private static Dictionary<string, string> _ErrorMessageDict = new Dictionary<string, string>()
  385. {
  386. {"10","Z axis control system error" },
  387. {"70","L axis control system error" },
  388. {"11","Z axis speed setting abnormal" },
  389. {"71","L axis speed setting abnormal" },
  390. {"12","Z axis specified number is out of range" },
  391. {"72","L axis specified number is out of range" },
  392. {"13","Z axis reach the limit" },
  393. {"73","L axis reach the limit" },
  394. {"14","Z axis forced to stop" },
  395. {"74","L axis forced to stop" },
  396. {"18","Z axis Number does not exist " },
  397. {"78","L axis Number does not exist " },
  398. {"19","Z axis system error" },
  399. {"79","L axis system error" },
  400. {"1E","Z axis other axis alram" },
  401. {"7E","L axis axis alram" },
  402. {"22","L axis motor error" },
  403. {"032","Wafer out" },
  404. {"33","L axis position error" },
  405. {"34","SMIF pod position error" },
  406. {"42","Z axis motor error" },
  407. {"43","Action timeout alarm" },
  408. {"62","Instruction content is incorrect" },
  409. {"63","Abnormal communication" },
  410. };
  411. #endregion
  412. }
  413. }