HongHuVce.cs 30 KB

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