HongHuVce.cs 31 KB

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