HongHuVce.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using MECF.Framework.Common.Communications;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.SubstrateTrackings;
  11. using MECF.Framework.RT.ModuleLibrary.VceModules;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.IO.Ports;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Text.RegularExpressions;
  18. using System.Threading.Tasks;
  19. using Venus_Core;
  20. using Venus_RT.Devices.EFEM;
  21. using Venus_RT.Devices.TM;
  22. using Venus_RT.Modules;
  23. namespace Venus_RT.Devices.VCE
  24. {
  25. //定义Vce动作
  26. public enum VceCommand
  27. {
  28. Home,
  29. DoorClose,
  30. DoorOpen,
  31. CheckGoto,
  32. Goto,
  33. GotoLP,
  34. CheckStatus,
  35. Load,
  36. UnLoad,
  37. Map,
  38. ReadMap,
  39. ClearError,
  40. }
  41. public enum VceMessageHead
  42. {
  43. Action,
  44. Read,
  45. Set,
  46. Petrify
  47. }
  48. public sealed class VceMessage
  49. {
  50. private Dictionary<VceCommand, string> _Command2Msg = new Dictionary<VceCommand, string>()
  51. {
  52. //Action
  53. {VceCommand.Home, "HM" },
  54. {VceCommand.Load, "LOAD" },
  55. {VceCommand.UnLoad, "UNLOAD"},
  56. {VceCommand.Map, "MP" },
  57. {VceCommand.CheckGoto, "GC" },
  58. {VceCommand.Goto, "GO" },
  59. {VceCommand.GotoLP, "LP" },
  60. {VceCommand.DoorOpen, "DO" },
  61. {VceCommand.DoorClose, "DC" },
  62. {VceCommand.CheckStatus,"OS" },
  63. //Read
  64. {VceCommand.ReadMap, "MI" },
  65. //Set
  66. {VceCommand.ClearError, "ER" },
  67. };
  68. private Dictionary<VceMessageHead, string> _Type2Head = new Dictionary<VceMessageHead, string>()
  69. {
  70. {VceMessageHead.Action, "A"},
  71. {VceMessageHead.Read, "R"},
  72. {VceMessageHead.Set, "S"},
  73. {VceMessageHead.Petrify, "P"},
  74. };
  75. public VceMessageHead Head { get; set; }
  76. public VceCommand Command { get; set; }
  77. public string Param { get; set; }
  78. public string toString()
  79. {
  80. if (string.IsNullOrEmpty(Param))//含尾参
  81. return $"00,{_Type2Head[Head]},{_Command2Msg[Command]}";
  82. else//不含尾参 目前只允许一个
  83. return $"00,{_Type2Head[Head]},{_Command2Msg[Command]},{Param}";
  84. }
  85. }
  86. /// <summary>
  87. /// 泓浒Vce驱动 下发指令等
  88. /// </summary>
  89. public class HongHuVce : VCEModuleBase
  90. {
  91. #region 私有变量
  92. private AsyncSerialPort _serialport;
  93. private string _portname;
  94. private string _newline = "\r";//终止符 0D
  95. private object _locker = new object();
  96. private bool _IsAsciiMode;
  97. private LinkedList<string> _lstAsciiMsgs = new LinkedList<string>();
  98. private PeriodicJob _thread;
  99. private Regex _match_ReadMsg = new Regex(@"\d\d,X,.*");
  100. private Regex _matchErrorCode = new Regex(@"(?<=_BKGERR )(.*)");
  101. private ModuleName _moduleName;
  102. private RState _status;
  103. private string _currentMsg;
  104. private VceMessage _currentVceMessage;
  105. private bool _HasReceiveMsg;
  106. private bool _IsDashWaferError;
  107. private int _currentSlot = 0;
  108. public override int CurrentSlot => _currentSlot;
  109. private ModuleName _baseLPIndex
  110. {
  111. get
  112. {
  113. switch (RtInstance.ConfigType)
  114. {
  115. case ConfigType.VenusSE:
  116. return ModuleName.LP1;
  117. case ConfigType.VenusDE:
  118. return _moduleName == ModuleName.VCEA ? ModuleName.LP1 : ModuleName.LP2;
  119. default:
  120. return ModuleName.System;
  121. }
  122. }
  123. }
  124. private Loadport[] _LPMs = new Loadport[1];
  125. public override ILoadport this[ModuleName mod]
  126. {
  127. get
  128. {
  129. if (!ModuleHelper.IsLoadPort(mod))
  130. throw new ApplicationException($"{mod} is NOT Loadport");
  131. return _LPMs[mod - _baseLPIndex];
  132. }
  133. }
  134. //待补充
  135. private Dictionary<string, string> _ErrorCode2Reason = new Dictionary<string, string>()
  136. {
  137. {"A1","Action Timeout" },
  138. {"A3","Hardware (CAN or VCN) or configuration failed" },
  139. {"A4","Open Door Prevented Motion" },
  140. {"A5","Platform Action Time-out" },
  141. {"A6","Door Action Timeout" },
  142. {"A7","由于动作连锁导致的异常" },
  143. {"A8","Wafer Slideout" },
  144. {"A9","Door safety LED is blocked" },
  145. {"A11","载台上没有料盒,看一下载台上是否有料盒" },
  146. {"A12","Cassette present prior PICK" },
  147. {"A13","Cassette NOT present during PICK" },
  148. {"A14","Cassette NOT present prior PLACE" },
  149. {"A15","Cassette present after PLACE" },
  150. {"A16","Cassette Present on VCE platform (Servo Arm)" },
  151. {"A17","No new cassette at station after Load" },
  152. {"A18","Proximity sensor blocked but Cassette A not present" },
  153. {"A19","载台上料盒没有取走,请把料盒取走" },
  154. {"A20","Proximity sensor A is blocked (Fixed Buffer)" },
  155. {"A21","Cassette NOT at station A" },
  156. {"A34","Door Clamped sensor is not ON after clamp (only VCE4!)" },
  157. {"A36","Door Not Covered (sensor)" },
  158. {"C0","Illegal Slot Number" },
  159. {"C1","设备收到非法的操作指令" },
  160. {"C2","Illegal pitch value (too big)" },
  161. {"C3","Illegal Cassette type offset" },
  162. {"C4","Illegal number of Slots" },
  163. {"C5","Illegal Partial step size" },
  164. {"C7","Illegal Find Bias" },
  165. {"C8","Unknown Configuration" },
  166. {"C9","Bad command: command cannot be executed with current HW configuration" },
  167. {"C10","VCE is busy" },
  168. {"C12","Bad Fixture Thickness" },
  169. {"C13","Command is NOT executable (file's operation exception)" },
  170. {"C19","VCEConfig.xml is corrupted" },
  171. {"C20","VCEDefaultSettting.xml is corrupted" },
  172. {"CAN1","CAN Error,Replace the board (MCC2B or MCC-GEN5 or MCC-GEN5 EN)" },
  173. {"CAN2","CAN Abort,Replace the board (MCC2B or MCC-GEN5 or MCC-GEN5 EN)" },
  174. {"CAN3","CAN Timeout,Replace the board (MCC2B or MCC-GEN5 or MCC-GEN5 EN)" },
  175. {"H1","Two hand safety switch are not OFF before R-axis motion" },
  176. {"H2","Two hands safety switch timeout" },
  177. {"H3","One or both safety switches are release before R-axis motion is complete" },
  178. {"M0","VCE is NOT Referenced" },
  179. {"M1","Motion Timeout" },
  180. {"M4","Door over speed" },
  181. {"M10","设备中断,设备被外部停止" },
  182. {"M11","FET over Temperature" },
  183. {"M12","FET over Current" },
  184. {"M13","Torque Limit" },
  185. {"M14","Hard Track Error Codes" },
  186. {"M16","Hardware (servo) Motion Error Codes" },
  187. {"M17","Safety Motion Button was Pushed" },
  188. {"M20","Z-brake request before ENABLE_Z_MOVE" },
  189. {"M21","CPLD Detected a difference from the Dual Up Sensors" },
  190. {"M22","Door Closed Error" },
  191. {"M23","Z-brake chip U8 has an output fault" },
  192. {"M24","Unsafe to move: See a safety node (ENABLE_Z_MOVE) or servo following error" },
  193. {"M25","Servo Following Error" },
  194. {"NO_ACT","No actions" },
  195. {"P2","Map NOT Available" },
  196. {"P3","SPS Excessive Offset" },
  197. {"P4","SPS Excessive Thickness" },
  198. {"P12","FB is too large to map" },
  199. {"P13","FB is too small to map" },
  200. {"R1","R-axis is not referenced" },
  201. {"R2","Extended position is NOT defined" },
  202. {"R3","Door NOT Opened" },
  203. {"R4","Wrong Z-axis position: platform must be between UP and DOWN position" },
  204. {"R5","R-axis Limit is exceeded" },
  205. {"R6","R-axis is NOT Homed (it is not IN)" },
  206. {"R7","R-axis Orientation is NOT set" },
  207. {"R9","R-axis is NOT Extended" },
  208. {"S0","Cannot configure Main VCN" },
  209. {"S1","Cannot configure R-axis VCN" },
  210. {"S4","Command String Error: Bad command or parameter, invalid value, etc." },
  211. {"S5","Illegal data entry" },
  212. {"S10","VCEDefaultSetting.XML file is corrupted. Configuration stop" },
  213. {"S11","Not valid for current configuration" },
  214. {"S20","MiscOutput is already in use" },
  215. {"S21","MiscOutput is used by current configuration" },
  216. {"S22","MiscOutput was deleted: it is used by current configuration" },
  217. {"T5","VCN timeout" },
  218. {"U1","USB not found or ‘Upgrade’ directory doesn’t exist" },
  219. {"U2","Script file couldn't be opened" },
  220. {"U3","Script file not found" },
  221. {"U4","File from the list is not found" },
  222. {"U5","Couldn’t create ‘Upgrade’ directory" },
  223. {"U6","Couldn’t copy files" },
  224. {"U10"," upgrade.txt file is missing" },
  225. {"V2","Cannot disable VCN" },
  226. {"230","Robot Extended" },
  227. {"231","Front buffer extended" },
  228. {"232","Valve drive fault" },
  229. {"236","Door Safety LED is broken" },
  230. {"250","FET Q10 is open circuit" },
  231. {"251","FET Q10 is shorted" },
  232. {"260","Atmospheric Robot is Extended" },
  233. {"261","ERGO Obstructs the Door" },
  234. {"262","Door drive fault" },
  235. {"263","Vacuum Robot is Extended" },
  236. {"264","User Misc Output Drive Fault" },
  237. {"265","Safety Hub Output Fault" },
  238. {"306","Illegal command ID number" },
  239. {"309","Command ID is not supported in thatCOMM FLOW" },
  240. {"390","Invalid Checksum" },
  241. {"414","Command ID in use" },
  242. {"673","GEN5 EN: inputs are in ERROR state" },
  243. {"674","GEN5 EN: inputs are in HALT state" },
  244. {"675","GEN5 EN: inputs are in illegal transition" },
  245. {"L13","由于检测到突片,动作被禁止" },
  246. {"L14","防夹光栅报警,检查舱门关闭路径上是否存在遮挡" },
  247. {"K114","防夹光栅报警" },
  248. {"K115","舱门上限报警" },
  249. {"K116","舱门下限报警 " },
  250. {"K117","急停报警 " },
  251. {"K118","位置未被引用,对设备进行初始化" },
  252. {"K119","Z 轴报警" },
  253. {"K120","R 轴报警 " },
  254. {"K121","Z 轴超限位报警" },
  255. {"K122","机械手不在安全位" },
  256. {"K123","Z 轴未使能" },
  257. {"K124","R 轴未使能" },
  258. {"K125","盒子状态互锁报警" },
  259. {"K158","左凸片" },
  260. {"K159","右凸片" },
  261. {"K160","门没有关好" },
  262. {"K161","盖板缺失" },
  263. {"K162","R轴不在原位" },
  264. {"K163","Z轴不在上下料位" },
  265. {"K164","门未打开" },
  266. };
  267. //
  268. #endregion
  269. #region 暴露变量
  270. public override bool IsConnected => _serialport.IsOpen();
  271. public override RState Status => _status;
  272. public override bool IsReady => _status == RState.Init || _status == RState.End;
  273. public override bool IsError => _status == RState.Failed || _status == RState.Timeout;
  274. public override bool IsInit => _status == RState.Init;
  275. public override bool IsDashWaferError => _IsDashWaferError;
  276. private string[] _slotMap = new string[25];
  277. public string SlotMap
  278. {
  279. get
  280. {
  281. WaferInfo[] wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(Name));
  282. string slot = "";
  283. for (int i = 0; i < 25; i++)
  284. {
  285. slot += wafers[i].IsEmpty ? "0" : "1";
  286. }
  287. return slot;
  288. }
  289. }
  290. private bool _OutDoorIsOpen
  291. {
  292. get
  293. {
  294. switch (_moduleName)
  295. {
  296. case ModuleName.VCE1:
  297. //2024-05-20 16:35:34 泓浒四边形硬件还未实现
  298. //DEVICE.GetDevice<HongHuTM>("SETM").VCEACassPresent
  299. return true;
  300. case ModuleName.VCEA:
  301. if (DEVICE.GetDevice<HongHuDETM>("TM").VCEACassPresent)
  302. {
  303. _LPMs[0].HasCassette = true;
  304. }
  305. else
  306. {
  307. _LPMs[0].HasCassette = false;
  308. WaferManager.Instance.DeleteWafer(_LPMs[0].Module, 0, 25);
  309. }
  310. return !DEVICE.GetDevice<HongHuDETM>("TM").VCEALOCKED;
  311. case ModuleName.VCEB:
  312. if (DEVICE.GetDevice<HongHuDETM>("TM").VCEBCassPresent)
  313. {
  314. _LPMs[0].HasCassette = true;
  315. }
  316. else
  317. {
  318. _LPMs[0].HasCassette = false;
  319. WaferManager.Instance.DeleteWafer(_LPMs[0].Module, 0, 25);
  320. }
  321. return !DEVICE.GetDevice<HongHuDETM>("TM").VCEBLOCKED;
  322. default:
  323. return false;
  324. }
  325. }
  326. }
  327. public override bool OutDoorIsOpen => _OutDoorIsOpen;
  328. private bool _hasProtrusion
  329. {
  330. get
  331. {
  332. switch (_moduleName)
  333. {
  334. case ModuleName.VCE1:
  335. //2024-05-20 16:35:34 泓浒四边形硬件还未实现
  336. //DEVICE.GetDevice<HongHuTM>("SETM").VCEProtrusion
  337. return true;
  338. case ModuleName.VCEA:
  339. if (DEVICE.GetDevice<HongHuDETM>("TM").VCEAProtrusion)
  340. {
  341. _LPMs[0].Protrusion = true;
  342. return true;
  343. }
  344. else
  345. {
  346. _LPMs[0].Protrusion = false;
  347. return false;
  348. }
  349. case ModuleName.VCEB:
  350. if (DEVICE.GetDevice<HongHuDETM>("TM").VCEBProtrusion)
  351. {
  352. _LPMs[0].Protrusion = true;
  353. return true;
  354. }
  355. else
  356. {
  357. _LPMs[0].Protrusion = false;
  358. return false;
  359. }
  360. default:
  361. return false;
  362. }
  363. }
  364. }
  365. #endregion
  366. //传入slot数量
  367. public HongHuVce(int slot, ModuleName moduleName) : base(slot, moduleName)
  368. {
  369. _moduleName = moduleName;
  370. _IsAsciiMode = true;
  371. _portname = SC.GetStringValue($"{moduleName}.Port");
  372. _serialport = new AsyncSerialPort(_portname, 9600, 8, Parity.None, StopBits.One, _newline, _IsAsciiMode);
  373. _serialport.Open();
  374. _status = RState.Init;
  375. _serialport.OnDataChanged += onDataChange;
  376. _thread = new PeriodicJob(50, fnTimer, _moduleName.ToString(), true);
  377. if(moduleName == ModuleName.VCE1)
  378. _LPMs[0] = new Loadport(ModuleName.LP1);
  379. else
  380. _LPMs[0] = new Loadport((moduleName - ModuleName.VCEA) + ModuleName.LP1);
  381. CarrierManager.Instance.DeleteCarrier(_LPMs[0].Module.ToString());
  382. WaferManager.Instance.DeleteWafer(_LPMs[0].Module, 0, 25);
  383. CarrierManager.Instance.SubscribeLocation(_LPMs[0].Module.ToString(), 1);
  384. Action<ModuleName, int> _subscribeLoc = (ModuleName module, int waferCount) => {
  385. if (ModuleHelper.IsInstalled(module))
  386. {
  387. WaferManager.Instance.SubscribeLocation(module, waferCount);
  388. }
  389. };
  390. _subscribeLoc(_LPMs[0].Module, slot);
  391. }
  392. /// <summary>
  393. /// 对处理过的数据list进行处理
  394. /// 将每条数据进行解析
  395. /// </summary>
  396. /// <returns></returns>
  397. private bool fnTimer()
  398. {
  399. lock (_locker)
  400. {
  401. //采用ascii传输
  402. if (_IsAsciiMode)
  403. {
  404. //有数据尚未处理
  405. while (_lstAsciiMsgs.Count > 0)
  406. {
  407. string _needHandle = _lstAsciiMsgs.First.Value;
  408. HandleSingleMsg(_needHandle);
  409. _lstAsciiMsgs.RemoveFirst();
  410. }
  411. }
  412. //采用binary
  413. else
  414. {
  415. }
  416. }
  417. return true;
  418. }
  419. /// <summary>
  420. /// 处理单条信息的函数
  421. /// 1、判断结束 2、判断错误
  422. /// </summary>
  423. /// <param name="msg">需要处理的单条回复</param>
  424. private void HandleSingleMsg(string rawmsgs)
  425. {
  426. string[] msgs = rawmsgs.Split('\r');
  427. foreach (var Msg in msgs)
  428. {
  429. string msg = Msg.Trim();
  430. LOG.Write(eEvent.EV_VCE_COMMON_INFO, _moduleName, $"{_moduleName} Receive msg=>{msg}");
  431. if (!string.IsNullOrEmpty(msg))
  432. {
  433. //action set petrify _BKGRDY结束
  434. switch (_currentVceMessage.Head)
  435. {
  436. case VceMessageHead.Action:
  437. case VceMessageHead.Set:
  438. case VceMessageHead.Petrify:
  439. switch (msg)
  440. {
  441. //设备收到 开始运行 目前状态在下发
  442. case "_RDY":
  443. LOG.Write(eEvent.EV_VCE_COMMON_INFO, _moduleName, $"vce start {_currentVceMessage.Head}");
  444. break;
  445. //设备执行完毕
  446. case "_BKGRDY":
  447. LOG.Write(eEvent.EV_VCE_COMMON_INFO, _moduleName, $"vce {_currentVceMessage.Head} over");
  448. switch (_currentVceMessage.Command)
  449. {
  450. case VceCommand.Home:
  451. case VceCommand.Map:
  452. case VceCommand.GotoLP:
  453. _currentSlot = 0;
  454. break;
  455. }
  456. _status = RState.End;
  457. break;
  458. //异常处理
  459. default:
  460. _status = RState.Failed;
  461. string reason;
  462. Errorhandle(msg, out reason);
  463. LOG.Write(eEvent.ERR_VCE_COMMON_Failed, _moduleName, reason);
  464. break;
  465. }
  466. break;
  467. case VceMessageHead.Read:
  468. //如果收到的信息符合
  469. if (_match_ReadMsg.IsMatch(msg))
  470. {
  471. //收到消息 用于结束
  472. _HasReceiveMsg = true;
  473. switch (_currentVceMessage.Command)
  474. {
  475. //处理wafer 信息为map数据
  476. case VceCommand.ReadMap:
  477. ReadMapData(msg);
  478. break;
  479. case VceCommand.CheckStatus:
  480. ReadStatus(msg);
  481. break;
  482. }
  483. }
  484. //_RDY查询结束
  485. else
  486. {
  487. if (msg == "_RDY")
  488. {
  489. if (_HasReceiveMsg)
  490. {
  491. _status = RState.End;
  492. }
  493. else
  494. {
  495. LOG.Write(eEvent.ERR_VCE_COMMON_Failed, _moduleName, $"Read Message is over but not receive msg! raw message:{_currentMsg}");
  496. _status = RState.Failed;
  497. }
  498. }
  499. else
  500. {
  501. _status = RState.Failed;
  502. LOG.Write(eEvent.ERR_VCE_COMMON_Failed, _moduleName, $"Read Message is invalid: receive message {msg} and send message {_currentMsg}");
  503. }
  504. }
  505. break;
  506. }
  507. }
  508. }
  509. }
  510. private void ReadStatus(string msg)
  511. {
  512. try
  513. {
  514. //BRa,SLbb,CPc,WPd,ERe
  515. string[] status = msg.Split(',');
  516. _currentSlot = Convert.ToInt32(status[4].Substring(2, 2));
  517. }
  518. catch (Exception ex)
  519. {
  520. LOG.Write(eEvent.ERR_VCE_COMMON_Failed,_moduleName, $"illegal msg:{msg}, {ex.Message}");
  521. }
  522. }
  523. private void ReadMapData(string msg)
  524. {
  525. string waferinfo = "";
  526. string[] waferitems = msg.Split(',');
  527. //智能模式 可以识别叠片
  528. for (int i = 3; i < waferitems.Length - 1; ++i)
  529. {
  530. //如果包含只需要逐个检查
  531. if (waferitems[i].Contains('?'))
  532. {
  533. foreach (char j in waferitems[i])
  534. {
  535. if (waferinfo.Length >= 25)
  536. break;
  537. else
  538. waferinfo += j;
  539. }
  540. }
  541. else
  542. waferinfo += waferitems[i];
  543. }
  544. for (int i = 0; i < waferinfo.Length; ++i)
  545. {
  546. int slotnum = i;
  547. if (slotnum < 25)
  548. {
  549. switch (waferinfo[i])
  550. {
  551. case '0':
  552. WaferManager.Instance.DeleteWafer(_LPMs[0].Module, slotnum);
  553. break;
  554. case 'X':
  555. WaferManager.Instance.CreateWafer(_LPMs[0].Module, slotnum, WaferStatus.Normal);
  556. break;
  557. case 'C':
  558. LOG.Write(eEvent.ERR_VCE_COMMON_Failed, _moduleName, $"Slot {i+1}:double or dummy wafer.");
  559. WaferManager.Instance.CreateWafer(_LPMs[0].Module, slotnum, WaferStatus.Double);
  560. break;
  561. case '?':
  562. LOG.Write(eEvent.ERR_VCE_COMMON_Failed, _moduleName, $"Slot {i + 1}:Crossed wafer.");
  563. WaferManager.Instance.CreateWafer(_LPMs[0].Module, slotnum, WaferStatus.Crossed);
  564. break;
  565. }
  566. }
  567. }
  568. _LPMs[0].IsMapped = true;
  569. }
  570. private void Errorhandle(string msg,out string reason)
  571. {
  572. if (_matchErrorCode.IsMatch(msg))
  573. {
  574. //若是匹配
  575. //包含原因
  576. string errorcode = _matchErrorCode.Match(msg).Value;
  577. if (_ErrorCode2Reason.ContainsKey(errorcode))
  578. {
  579. if(errorcode == "L13")
  580. _IsDashWaferError = true;
  581. reason = _ErrorCode2Reason[errorcode];
  582. }
  583. else
  584. {
  585. reason = "未找到相关Error Code";
  586. }
  587. }
  588. else
  589. {
  590. //若不匹配
  591. reason = "回复消息不符合标准格式";
  592. }
  593. }
  594. /// <summary>
  595. /// 处理新到的数据
  596. /// 利用linkedlist处理拆包 粘包情况
  597. /// </summary>
  598. /// <param name="newline">新到数据</param>
  599. private void onDataChange(string oneLineMessage)
  600. {
  601. lock (_locker)
  602. {
  603. if (string.IsNullOrEmpty(_newline))//没有CR
  604. {
  605. _lstAsciiMsgs.AddLast(oneLineMessage);//将消息添加到最后
  606. return;
  607. }
  608. string[] array = oneLineMessage.Split(_newline.ToCharArray());//按照cr分开通讯数据
  609. foreach (string text in array)
  610. {
  611. if (!string.IsNullOrEmpty(text))
  612. {
  613. _lstAsciiMsgs.AddLast(text + _newline);//存进list中等待处理
  614. }
  615. }
  616. }
  617. }
  618. public override bool HomeALL()
  619. {
  620. _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.Home ,Param = "ALL" };
  621. _currentMsg = _currentVceMessage.toString() + _newline ;
  622. _status = RState.Running;
  623. return _serialport.Write(_currentMsg);
  624. }
  625. public override bool Home(string axis)
  626. {
  627. _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.Home, Param = axis };
  628. _currentMsg = _currentVceMessage.toString() + _newline;
  629. _status = RState.Running;
  630. return _serialport.Write(_currentMsg);
  631. }
  632. public override bool CheckStatus()
  633. {
  634. if (!CheckVceStatus())
  635. return false;
  636. _currentVceMessage = new VceMessage { Head = VceMessageHead.Read, Command = VceCommand.CheckStatus };
  637. _currentMsg = _currentVceMessage.toString() + _newline;
  638. _status = RState.Running;
  639. return _serialport.Write(_currentMsg);
  640. }
  641. public override bool CloseDoor()
  642. {
  643. if (!CheckVceStatus())
  644. return false;
  645. _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.DoorClose };
  646. _currentMsg = _currentVceMessage.toString() + _newline;
  647. _status = RState.Running;
  648. return _serialport.Write(_currentMsg);
  649. }
  650. /// <summary>
  651. /// 开门提示
  652. /// 在honghuVCE中没有ATM信号的内部卡控 可能会导致开门的压差
  653. /// 因此每一次都要增加判断,只要引用此处功能的,前面都需要有判断
  654. ///
  655. /// </summary>
  656. /// <returns></returns>
  657. public override bool OpenDoor()
  658. {
  659. //如果其他指令正在执行 且
  660. //if (!CheckVceStatus())
  661. // return false;
  662. if (_IsDashWaferError)
  663. _IsDashWaferError = false;
  664. _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.DoorOpen };
  665. _currentMsg = _currentVceMessage.toString() + _newline;
  666. _status = RState.Running;
  667. return _serialport.Write(_currentMsg);
  668. }
  669. public override bool Load()
  670. {
  671. if (!CheckVceStatus())
  672. return false;
  673. _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.Load };
  674. _currentMsg = _currentVceMessage.toString() + _newline;
  675. _status = RState.Running;
  676. return _serialport.Write(_currentMsg);
  677. }
  678. public override bool UnLoad()
  679. {
  680. if (!CheckVceStatus())
  681. return false;
  682. _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.UnLoad };
  683. _currentMsg = _currentVceMessage.toString() + _newline;
  684. _status = RState.Running;
  685. return _serialport.Write(_currentMsg);
  686. }
  687. public override bool Map()
  688. {
  689. if (!CheckVceStatus())
  690. return false;
  691. _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.Map };
  692. _currentMsg = _currentVceMessage.toString() + _newline;
  693. _status = RState.Running;
  694. return _serialport.Write(_currentMsg);
  695. }
  696. public override bool ReadMap()
  697. {
  698. if (!CheckVceStatus())
  699. return false;
  700. _currentVceMessage = new VceMessage { Head = VceMessageHead.Read, Command = VceCommand.ReadMap, Param = "S" };
  701. _currentMsg = _currentVceMessage.toString() + _newline;
  702. _status = RState.Running;
  703. _HasReceiveMsg = false;
  704. return _serialport.Write(_currentMsg);
  705. }
  706. public override bool Goto(int Targetslot)
  707. {
  708. if (!CheckVceStatus())
  709. return false;
  710. LOG.Write(eEvent.EV_VCE_COMMON_INFO,_moduleName, $"SlotNum:{Targetslot}");
  711. _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.Goto, Param = (Targetslot+1).ToString().PadLeft(2,'0') };
  712. _currentMsg = _currentVceMessage.toString() + _newline;
  713. _status = RState.Running;
  714. return _serialport.Write(_currentMsg);
  715. }
  716. public override bool GotoLP()
  717. {
  718. if (!CheckVceStatus())
  719. return false;
  720. _currentVceMessage = new VceMessage { Head = VceMessageHead.Action, Command = VceCommand.GotoLP };
  721. _currentMsg = _currentVceMessage.toString() + _newline;
  722. _status = RState.Running;
  723. return _serialport.Write(_currentMsg);
  724. }
  725. public override bool ClearError()
  726. {
  727. _currentVceMessage = new VceMessage { Head = VceMessageHead.Set, Command = VceCommand.ClearError };
  728. _currentMsg = _currentVceMessage.toString() + _newline;
  729. _status = RState.Running;
  730. return _serialport.Write(_currentMsg);
  731. }
  732. }
  733. }