HongHuVce.cs 32 KB

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