FortrendSmifPort.cs 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.RT.SCCore;
  4. using Aitex.Core.Util;
  5. using Aitex.Sorter.Common;
  6. using athosRT.tool;
  7. using Brooks.WinSECS;
  8. using Common.DataCenter;
  9. using MECF.Framework.Common.Communications;
  10. using MECF.Framework.Common.Equipment;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.Fortrend;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  14. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  15. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Sensors;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.ComponentModel;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using System.Windows.Media.Animation;
  23. using EV = athosRT.tool.EV;
  24. namespace athosRT.Devices.LP
  25. {
  26. public class FortrendSmifPort : LoadPortBaseDevice, IConnection
  27. {
  28. public enum LpStepEnum
  29. {
  30. Step1,
  31. Step2,
  32. Step3,
  33. Step4,
  34. Step5,
  35. Step6,
  36. Step7,
  37. Step8,
  38. Step9,
  39. Step10,
  40. Step11,
  41. Step12
  42. }
  43. private enum STATE
  44. {
  45. IDLE,
  46. WAIT
  47. }
  48. private bool _isLoaded;
  49. private R_TRIG _trigError = new R_TRIG();
  50. private R_TRIG _trigCommunicationError = new R_TRIG();
  51. private R_TRIG _trigRetryConnect = new R_TRIG();
  52. private DeviceTimer _reConnectdTimer = new DeviceTimer();
  53. private PeriodicJob _thread;
  54. private object _locker = new object();
  55. private bool _enableLog;
  56. private string _errorCode = "";
  57. private DeviceTimer _setStatusTimer = new DeviceTimer();
  58. private int SetStatusTime = 800;
  59. private DateTime _dtStartAction;
  60. private string _scRoot;
  61. private static Dictionary<string, string> _ErrorDict = new Dictionary<string, string>
  62. {
  63. { "1", "PLM Error" },
  64. { "2", "Pod not present" },
  65. { "38", "Latch error" },
  66. { "39", "Pod Remove" },
  67. { "40", "Mask Position Incorrect" },
  68. { "41", "Inhibit Detected while Elevator going Down" },
  69. { "43", "Protrusion Detected" },
  70. { "44", "END EFFECTOR PROTRUSION" },
  71. { "45", "PELLICLE ON TOP" },
  72. { "49", "PLM not Ready" }
  73. };
  74. private static Dictionary<string, string> _RealyMessageDict = new Dictionary<string, string>
  75. {
  76. { "OK", "Comment accepted" },
  77. { "BUSY", "Command rejected, LPI is busy" },
  78. { "ALARM", "Command rejected, LPI in alarm state" },
  79. { "NO_POD", "Command rejected, Pod not on LPI" },
  80. { "NOT_READY", "Command rejected, Host interlock not enabled" },
  81. { "INVALID_ARG", "Command rejected, at least one invalid parameter" },
  82. { "CANNOT_PERFORM", "LPI not in the proper state to perform the Host command" },
  83. { "DENIED", "Command rejected for other reason" }
  84. };
  85. private static Dictionary<string, string> _AlarmTimeCodeDict = new Dictionary<string, string>
  86. {
  87. { "00", "No alarm" },
  88. { "41", "Alarm occurred during a fetch or open operation" },
  89. { "42", "Alarm occurred during a cassette placement on the process tool" },
  90. { "43", "Alarm occurred during a returning of the minienvironment to Home" },
  91. { "44", "Alarm occurred during a retrieval of the cassette from the Tool" },
  92. { "45", "Alarm occurred during a placement of the cassette on the Pod door" },
  93. { "46", "Non-recoverable fatal error" }
  94. };
  95. private static Dictionary<string, string> _ErrorCodeDict = new Dictionary<string, string>
  96. {
  97. { "00", "No error" },
  98. { "01", "Position following error" },
  99. { "02", "LPI not Home" },
  100. { "03", "LPI busy" },
  101. { "04", "Pod removed/missing elevator door" },
  102. { "05", "Aborted by user" },
  103. { "07", "Protrusion sensor failure" },
  104. { "08", "Slot sensor failure" },
  105. { "09", "Wafer presence sensor failure" },
  106. { "10", "Flash sensor failure" },
  107. { "11", "Elevator over-travel limit trip" },
  108. { "13", "Excessive wafer protrusion" },
  109. { "14", "System internal time-out" },
  110. { "15", "Servo command error" },
  111. { "16", "Pod door open time-out" },
  112. { "17", "Pod door close time-out" },
  113. { "18", "Pod hold-down open time-out" },
  114. { "19", "Pod hold-down close time-out" },
  115. { "20", "Wafer seater failed to move toward wafer" },
  116. { "21", "Wafer seater failed to return to Home" },
  117. { "22", "Elevator failed to reach target position" },
  118. { "24", "System error" },
  119. { "27", "Loss of configuration data" },
  120. { "28", "Cassette not present" },
  121. { "29", "Loss of air flow" },
  122. { "31", "Gripper open time out" },
  123. { "32", "Gripper close time out" },
  124. { "33", "Interprocessor communication error" },
  125. { "34", "Gripper overtravel" },
  126. { "35", "Cassette found during unload" }
  127. };
  128. protected DeviceTimer counter = new DeviceTimer();
  129. protected DeviceTimer delayTimer = new DeviceTimer();
  130. private int _id;
  131. private int _currentTokenId = -1;
  132. private Stack<int> _steps = new Stack<int>();
  133. private STATE state;
  134. private int loop = 0;
  135. private int loopCount = 0;
  136. private int loopID = 0;
  137. private DeviceTimer timer = new DeviceTimer();
  138. protected RoutineResult RoutineToken = new RoutineResult
  139. {
  140. Result = RoutineState.Running
  141. };
  142. protected Tuple<bool, Result> ExecuteResult;
  143. public WinSECS wshost { get; set; }
  144. public FortrendSMIFHostAgent ha { get; set; }
  145. public bool IsQueryComplete { get; set; }
  146. public override bool IsLoaded => _isLoaded;
  147. public bool IsAutoMode { get; set; }
  148. public override bool IsHomed { get; set; }
  149. public bool IsPodPresent { get; set; }
  150. public bool IsPodLocked { get; set; }
  151. public bool IsArmRetract { get; set; }
  152. public bool IsAlarm { get; set; }
  153. public FunctionEnum FunctionBeingDoneThisTime { get; set; }
  154. public CollisionStatusEnum CurrentCollisonStatus { get; set; }
  155. public PortReadyStatusEnum CurrentPortReadyStatus { get; set; }
  156. public bool IsLiftAtOverTravelLimit { get; set; }
  157. public bool IsLiftAtUpLimit { get; set; }
  158. public bool IsLiftAtStagePosition { get; set; }
  159. public WaferSeaterStateEnum CurrentWaferSeaterStatus { get; set; }
  160. public bool IsConnected { get; set; }
  161. public string Address { get; private set; }
  162. public string AlarmOccurTime { get; private set; }
  163. public string AlarmInfo { get; private set; }
  164. public int TokenId => _id;
  165. public int LoopCounter => loop;
  166. public int LoopTotalTime => loopCount;
  167. public int Elapsed => (int)(timer.GetElapseTime() / 1000.0);
  168. public override WaferSize GetCurrentWaferSize()
  169. {
  170. return WaferSize.WS8;
  171. }
  172. public FortrendSmifPort(string module, string name, string scRoot, RobotBaseDevice robot)
  173. : base(module, name, robot)
  174. {
  175. //IL_010a: Unknown result type (might be due to invalid IL or missing references)
  176. //IL_0114: Expected O, but got Unknown
  177. //IL_025c: Unknown result type (might be due to invalid IL or missing references)
  178. base.Module = module;
  179. base.Name = name;
  180. _scRoot = scRoot;
  181. string stringValue = SC.GetStringValue("LoadPort." + base.Name + ".PortName");
  182. if (!Enum.TryParse<ModuleName>(name, out var result))
  183. {
  184. Enum.TryParse<ModuleName>(module, out result);
  185. }
  186. wshost = new WinSECS();
  187. wshost.PortType = SECS_PORT_TYPE.SECS1_SERIAL;
  188. wshost.AutoDevice = true;
  189. wshost.DefaultDeviceID = 0;
  190. wshost.Secs1.IgnoreSytemBytes = false;
  191. wshost.MultipleOpen = true;
  192. wshost.MonitorEnabled = true;
  193. wshost.Secs1.AcceptDupBlock = false;
  194. wshost.Secs1.Interleave = true;
  195. wshost.Secs1.RetryCount = 10;
  196. wshost.Secs1.SecsHost = true;
  197. wshost.Secs1.T1 = 1f;
  198. wshost.Secs1.T2 = 10f;
  199. wshost.Secs1.T3 = 30u;
  200. wshost.Secs1.T4 = 45u;
  201. wshost.Secs1.AutoBaud = false;
  202. wshost.Secs1.PortName = SC.GetStringValue("LoadPort." + base.Name + ".PortName");
  203. wshost.Secs1.BaudRate = 9600u;
  204. ha = new FortrendSMIFHostAgent(wshost, this);
  205. wshost.OpenPort((INotifyAgent)(object)ha);
  206. if (wshost.PortIsOpen)
  207. {
  208. IsConnected = true;
  209. }
  210. Singleton<ConnectionManager>.Instance.Subscribe(base.Name ?? "", this);
  211. IsMapWaferByLoadPort = true;
  212. }
  213. public void OnErrorArrived(string alarmcode, string alarmdecri, string alarmtext)
  214. {
  215. //EV.PostAlarmLog(base.Name, "AlarmID:(" + alarmdecri + ")" + _ErrorDict[alarmdecri] + ",AlarmText(" + alarmtext + ")");
  216. switch (alarmcode)
  217. {
  218. case "1":
  219. {
  220. string text = alarmtext.Replace("Error Code ", "|").Split(new char[1] { '|' })[1];
  221. string text2 = text;
  222. string text3 = text2;
  223. if (text3 == "52")
  224. {
  225. IsError = true;
  226. EV.PostAlarmLog(base.Name, base.Name + " Has Protrude Error.");
  227. base.IsBusy = false;
  228. CheckToPostMessage(17, null);
  229. }
  230. break;
  231. }
  232. case "2":
  233. case "5":
  234. case "6":
  235. case "43":
  236. if (_ErrorDict.ContainsKey(alarmdecri))
  237. {
  238. //EV.PostAlarmLog(base.Name, "AlarmID:(" + alarmdecri + ")" + _ErrorDict[alarmdecri] + ",AlarmText(" + alarmtext + ")");
  239. }
  240. OnError();
  241. break;
  242. case "38":
  243. case "39":
  244. case "40":
  245. case "41":
  246. case "44":
  247. case "45":
  248. case "49":
  249. if (_ErrorDict.ContainsKey(alarmdecri))
  250. {
  251. //EV.PostWarningLog(base.Name, "AlarmID:(" + alarmdecri + ")" + _ErrorDict[alarmdecri] + ",AlarmText(" + alarmtext + ")");
  252. }
  253. break;
  254. }
  255. }
  256. public void OnStausArrived(bool isplace, bool home, bool alarm, bool isbusy)
  257. {
  258. base.IsBusy = isbusy;
  259. IsPodPresent = isplace;
  260. IsIdle = home;
  261. if (isplace)
  262. {
  263. OnCarrierPresent();
  264. OnCarrierPlaced();
  265. }
  266. }
  267. public void OnEventArrived(string eventID)
  268. {
  269. EV.PostInfoLog(base.Name, "EventId:" + eventID);
  270. if (int.TryParse(eventID, out var result))
  271. {
  272. switch (result)
  273. {
  274. case 1:
  275. OnCarrierNotPresent();
  276. OnCarrierNotPlaced();
  277. break;
  278. case 2:
  279. OnCarrierPresent();
  280. OnCarrierPlaced();
  281. break;
  282. case 3:
  283. IsAutoMode = true;
  284. break;
  285. case 4:
  286. IsAutoMode = false;
  287. break;
  288. case 11:
  289. EV.PostInfoLog("LoadPort", $"{base.LPModuleName} start to load");
  290. break;
  291. case 12:
  292. _isLoaded = true;
  293. DockState = FoupDockState.Docked;
  294. break;
  295. case 13:
  296. OnError("LoadAborted");
  297. break;
  298. case 14:
  299. EV.PostInfoLog("LoadPort", $"{base.LPModuleName} start to unload");
  300. break;
  301. case 15:
  302. DockState = FoupDockState.Undocked;
  303. _isLoaded = false;
  304. IsIdle = true;
  305. break;
  306. case 16:
  307. OnError("UnloadAborted");
  308. break;
  309. case 17:
  310. //EV.PostInfoLog("Loa dPort", $"{base.LPModuleName} start to home");
  311. break;
  312. case 18:
  313. DockState = FoupDockState.Undocked;
  314. IsHomed = true;
  315. IsError = false;
  316. EV.PostInfoLog("LoadPort", $"{base.LPModuleName} Home Complete");
  317. break;
  318. case 19:
  319. OnError("HomeAborted");
  320. break;
  321. case 31:
  322. IsIdle = true;
  323. ClampState = FoupClampState.Close;
  324. //LOG.Write($"{base.LPModuleName} Lock Complete", 2, "D:\\sorter\\trunk\\Framework\\RTEquipmentLibrary\\HardwareUnits\\LoadPorts\\Fortrend\\FortrendSmifPort.cs", "OnEventArrived", 241);
  325. break;
  326. case 32:
  327. IsIdle = true;
  328. ClampState = FoupClampState.Open;
  329. //LOG.Write($"{base.LPModuleName} UnLock Complete", 2, "D:\\sorter\\trunk\\Framework\\RTEquipmentLibrary\\HardwareUnits\\LoadPorts\\Fortrend\\FortrendSmifPort.cs", "OnEventArrived", 246);
  330. break;
  331. }
  332. }
  333. }
  334. internal void ParseStatus3(byte[] statusValue)
  335. {
  336. }
  337. internal void ParseStatus2(byte[] statusValue)
  338. {
  339. CurrentPortReadyStatus = (PortReadyStatusEnum)statusValue[0];
  340. }
  341. public void ParseStatus1(byte[] statusValue)
  342. {
  343. IsAutoMode = statusValue[0] == 1;
  344. IsPodPresent = statusValue[1] == 1;
  345. if (IsPodPresent)
  346. {
  347. OnCarrierPresent();
  348. OnCarrierPlaced();
  349. }
  350. else
  351. {
  352. OnCarrierNotPresent();
  353. OnCarrierNotPlaced();
  354. }
  355. FunctionBeingDoneThisTime = (FunctionEnum)statusValue[3];
  356. CurrentCollisonStatus = (CollisionStatusEnum)statusValue[4];
  357. IsPodLocked = statusValue[5] == 1;
  358. }
  359. internal void OnAlarmArrived(string alarmData)
  360. {
  361. EV.PostAlarmLog(base.Name, "alarmdata:" + alarmData);
  362. if (alarmData.Length == 4)
  363. {
  364. string text = alarmData.Substring(0, 2);
  365. string text2 = alarmData.Substring(2, 2);
  366. AlarmOccurTime = text + "=" + _AlarmTimeCodeDict[text];
  367. AlarmInfo = text2 + "=" + _ErrorCodeDict[text2];
  368. EV.PostAlarmLog(base.Module, base.Module + " " + AlarmOccurTime + ", for " + AlarmInfo);
  369. OnError();
  370. IsAlarm = true;
  371. }
  372. }
  373. public override void Reset()
  374. {
  375. _trigError.RST = true;
  376. _trigCommunicationError.RST = true;
  377. _trigRetryConnect.RST = true;
  378. CheckToPostMessage(5, null);
  379. }
  380. protected override bool fStartReset(object[] param)
  381. {
  382. lock (_locker)
  383. {
  384. SECSTransactionBuilder.BuildS1F5(0).Send(wshost);
  385. }
  386. return true;
  387. }
  388. protected override bool fMonitorReset(object[] param)
  389. {
  390. IsError = false;
  391. base.IsBusy = false;
  392. return true;
  393. }
  394. protected override bool fStartInit(object[] param)
  395. {
  396. //LOG.Write($"{base.LPModuleName} start to home,isHome:{IsHomed}", 2, "D:\\sorter\\trunk\\Framework\\RTEquipmentLibrary\\HardwareUnits\\LoadPorts\\Fortrend\\FortrendSmifPort.cs", "fStartInit", 416);
  397. IsHomed = false;
  398. lock (_locker)
  399. {
  400. SECSTransactionBuilder.BuildS1F5(0).Send(wshost);
  401. SECSTransactionBuilder.BuildS2F21(11).Send(wshost);
  402. }
  403. _dtStartAction = DateTime.Now;
  404. return true;
  405. }
  406. protected override bool fMonitorInit(object[] param)
  407. {
  408. if (DateTime.Now - _dtStartAction > TimeSpan.FromSeconds(TimelimitHome))
  409. {
  410. OnError("InitTimeout");
  411. return true;
  412. }
  413. base.IsBusy = false;
  414. return IsHomed;
  415. }
  416. protected override bool fStartLoad(object[] objs)
  417. {
  418. ResetRoutine();
  419. return true;
  420. }
  421. protected override bool fMonitorLoad(object[] param)
  422. {
  423. base.IsBusy = false;
  424. LoadCassette(0, TimelimitAction, OnError);
  425. if (ExecuteResult.Item1)
  426. {
  427. return false;
  428. }
  429. QueryMap(1, TimelimitAction, OnError);
  430. if (ExecuteResult.Item1)
  431. {
  432. return false;
  433. }
  434. return true;
  435. }
  436. protected override bool fStartExecute(object[] param)
  437. {
  438. try
  439. {
  440. switch (param[0].ToString())
  441. {
  442. case "Unclamp":
  443. IsIdle = false;
  444. lock (_locker)
  445. {
  446. SECSTransactionBuilder.BuildS2F21(13).Send(wshost);
  447. }
  448. break;
  449. case "Clamp":
  450. IsIdle = false;
  451. lock (_locker)
  452. {
  453. SECSTransactionBuilder.BuildS2F21(12).Send(wshost);
  454. }
  455. break;
  456. case "MapWafer":
  457. lock (_locker)
  458. {
  459. if (!IsMapWaferByLoadPort)
  460. {
  461. string reason;
  462. if (base.MapRobot != null)
  463. {
  464. return base.MapRobot.WaferMapping(base.LPModuleName, out reason);
  465. }
  466. return false;
  467. }
  468. }
  469. break;
  470. case "QueryState":
  471. IsQueryComplete = false;
  472. lock (_locker)
  473. {
  474. SECSTransactionBuilder.BuildS1F5(0).Send(wshost);
  475. }
  476. break;
  477. }
  478. _dtStartAction = DateTime.Now;
  479. return true;
  480. }
  481. catch (Exception ex)
  482. {
  483. //LOG.Write(ex, 2, "D:\\sorter\\trunk\\Framework\\RTEquipmentLibrary\\HardwareUnits\\LoadPorts\\Fortrend\\FortrendSmifPort.cs", "fStartExecute", 521);
  484. LogObject.Info(base.Name, "Parameter invalid");
  485. return false;
  486. }
  487. }
  488. protected override bool fMonitorExecuting(object[] param)
  489. {
  490. base.IsBusy = false;
  491. if (DateTime.Now - _dtStartAction > TimeSpan.FromSeconds(TimelimitHome))
  492. {
  493. OnError("InitTimeout");
  494. return true;
  495. }
  496. return IsIdle;
  497. }
  498. public override bool Stop(out string reason)
  499. {
  500. lock (_locker)
  501. {
  502. }
  503. return base.Stop(out reason);
  504. }
  505. public bool QueryMapStatus(out string reason)
  506. {
  507. reason = string.Empty;
  508. lock (_locker)
  509. {
  510. SECSTransactionBuilder.BuildS1F5(2).Send(wshost);
  511. }
  512. IsIdle = false;
  513. if (!_setStatusTimer.IsIdle())
  514. {
  515. _setStatusTimer.Stop();
  516. }
  517. _setStatusTimer.Start(0.0);
  518. return true;
  519. }
  520. public bool QueryPortStatus(out string reason)
  521. {
  522. reason = string.Empty;
  523. lock (_locker)
  524. {
  525. SECSTransactionBuilder.BuildS1F5(0).Send(wshost);
  526. }
  527. if (!_setStatusTimer.IsIdle())
  528. {
  529. _setStatusTimer.Stop();
  530. }
  531. _setStatusTimer.Start(0.0);
  532. return true;
  533. }
  534. protected override bool fStartUnload(object[] param)
  535. {
  536. lock (_locker)
  537. {
  538. SECSTransactionBuilder.BuildS2F21(10).Send(wshost);
  539. }
  540. IsIdle = false;
  541. _dtStartAction = DateTime.Now;
  542. return true;
  543. }
  544. protected override bool fMonitorUnload(object[] param)
  545. {
  546. base.IsBusy = false;
  547. if (DateTime.Now - _dtStartAction > TimeSpan.FromSeconds(TimelimitAction))
  548. {
  549. OnError("UnloadTimeout");
  550. return true;
  551. }
  552. return IsIdle;
  553. }
  554. public void OnCarrierNotPlaced()
  555. {
  556. _isPlaced = false;
  557. ConfirmRemoveCarrier();
  558. }
  559. public void OnCarrierNotPresent()
  560. {
  561. _isPresent = false;
  562. }
  563. public void OnCarrierPlaced()
  564. {
  565. _isPlaced = true;
  566. ConfirmAddCarrier();
  567. }
  568. public void OnCarrierPresent()
  569. {
  570. _isPresent = true;
  571. }
  572. public override void OnSlotMapRead(string slotMap)
  573. {
  574. CurrentSlotMapResult = slotMap.Replace("0", "?").Replace("2", "0");
  575. int num = 0;
  576. for (int i = 0; i < slotMap.Length; i++)
  577. {
  578. WaferInfo waferInfo = null;
  579. switch (slotMap[i])
  580. {
  581. case '2':
  582. Singleton<WaferManager>.Instance.DeleteWafer(base.LPModuleName, i);
  583. Singleton<CarrierManager>.Instance.UnregisterCarrierWafer(base.Name, i);
  584. break;
  585. case '1':
  586. waferInfo = Singleton<WaferManager>.Instance.CreateWafer(base.LPModuleName, i, WaferStatus.Normal, WaferSize.WS8);
  587. Singleton<WaferManager>.Instance.CheckWaferSize(base.LPModuleName, i, GetCurrentWaferSize());
  588. Singleton<CarrierManager>.Instance.RegisterCarrierWafer(base.Name, i, waferInfo);
  589. break;
  590. case '4':
  591. waferInfo = Singleton<WaferManager>.Instance.CreateWafer(base.LPModuleName, i, WaferStatus.Crossed, WaferSize.WS8);
  592. Singleton<WaferManager>.Instance.CheckWaferSize(base.LPModuleName, i, GetCurrentWaferSize());
  593. Singleton<CarrierManager>.Instance.RegisterCarrierWafer(base.Name, i, waferInfo);
  594. EV.PostAlarmLog(base.Name, $"{base.Name} Slot:{i + 1} occur crossed. ");
  595. num++;
  596. break;
  597. case 'W':
  598. waferInfo = Singleton<WaferManager>.Instance.CreateWafer(base.LPModuleName, i, WaferStatus.Double, WaferSize.WS8);
  599. Singleton<WaferManager>.Instance.CheckWaferSize(base.LPModuleName, i, GetCurrentWaferSize());
  600. Singleton<CarrierManager>.Instance.RegisterCarrierWafer(base.Name, i, waferInfo);
  601. break;
  602. case '0':
  603. waferInfo = Singleton<WaferManager>.Instance.CreateWafer(base.LPModuleName, i, WaferStatus.Unknown, WaferSize.WS8);
  604. Singleton<WaferManager>.Instance.CheckWaferSize(base.LPModuleName, i, GetCurrentWaferSize());
  605. Singleton<CarrierManager>.Instance.RegisterCarrierWafer(base.Name, i, waferInfo);
  606. break;
  607. }
  608. }
  609. if (num == 0)
  610. {
  611. base.MapError = false;
  612. }
  613. else
  614. {
  615. base.MapError = true;
  616. }
  617. SerializableDictionary<string, object> serializableDictionary = new SerializableDictionary<string, object>();
  618. serializableDictionary["SlotMap"] = CurrentSlotMapResult;
  619. serializableDictionary["PortID"] = base.PortID;
  620. serializableDictionary["PORT_CTGRY"] = base.SpecPortName;
  621. serializableDictionary["CarrierType"] = SpecCarrierType;
  622. serializableDictionary["CarrierIndex"] = InfoPadCarrierIndex;
  623. serializableDictionary["InfoPadSensorIndex"] = InfoPadSensorIndex;
  624. serializableDictionary["CarrierID"] = base.CarrierId;
  625. EV.Notify(EventSlotMapAvailable, serializableDictionary);
  626. if (CurrentSlotMapResult.Contains("4"))
  627. {
  628. base.MapError = true;
  629. EV.Notify(base.AlarmLoadPortMapCrossedWafer);
  630. EV.Notify(base.AlarmLoadPortMappingError);
  631. OnError("MappingError");
  632. }
  633. if (CurrentSlotMapResult.Contains("3"))
  634. {
  635. base.MapError = true;
  636. EV.Notify(base.AlarmLoadPortMapDoubleWafer);
  637. EV.Notify(base.AlarmLoadPortMappingError);
  638. OnError("MappingError");
  639. }
  640. if (CurrentSlotMapResult.Contains("W"))
  641. {
  642. base.MapError = true;
  643. EV.Notify(base.AlarmLoadPortMapDoubleWafer);
  644. EV.Notify(base.AlarmLoadPortMappingError);
  645. OnError("MappingError");
  646. }
  647. if (CurrentSlotMapResult.Contains("?"))
  648. {
  649. base.MapError = true;
  650. EV.Notify(base.AlarmLoadPortMapUnknownWafer);
  651. EV.Notify(base.AlarmLoadPortMappingError);
  652. OnError("MappingError");
  653. }
  654. if (base.LPCallBack != null)
  655. {
  656. base.LPCallBack.MappingComplete(_carrierId, CurrentSlotMapResult);
  657. }
  658. _isMapped = true;
  659. }
  660. public override void Terminate()
  661. {
  662. }
  663. public override void Monitor()
  664. {
  665. //IL_0045: Unknown result type (might be due to invalid IL or missing references)
  666. //IL_0057: Unknown result type (might be due to invalid IL or missing references)
  667. if (!IsConnected && ha != null && (_reConnectdTimer.IsIdle() || _reConnectdTimer.GetElapseTime() > 10000.0))
  668. {
  669. wshost.ClosePort();
  670. wshost.OpenPort((INotifyAgent)(object)ha);
  671. _reConnectdTimer.Start(0.0);
  672. }
  673. if (IsConnected)
  674. {
  675. _reConnectdTimer.Stop();
  676. }
  677. }
  678. public override bool IsEnableTransferWafer(out string reason)
  679. {
  680. reason = "";
  681. //====为了过检=====
  682. //_isLoaded = true;
  683. //_isMapped = true;
  684. //=================
  685. if (_isPresent && _isPlaced && _isLoaded && IsReady() && _isMapped)
  686. {
  687. return true;
  688. }
  689. return false;
  690. }
  691. public override bool Connect()
  692. {
  693. return true;
  694. }
  695. public bool Disconnect()
  696. {
  697. return true;
  698. }
  699. protected override bool fStartWrite(object[] param)
  700. {
  701. return true;
  702. }
  703. protected override bool fStartRead(object[] param)
  704. {
  705. return true;
  706. }
  707. public override bool ReadCarrierID(int offset = 0, int length = 16)
  708. {
  709. return ReadCarrierIDByIndex();
  710. }
  711. public override bool ReadCarrierIDByIndex(int offset = 0, int length = 16, int index = 0)
  712. {
  713. //IL_000d: Unknown result type (might be due to invalid IL or missing references)
  714. //IL_0013: Expected O, but got Unknown
  715. base.IsBusy = true;
  716. SECSTransaction val = new SECSTransaction(100u, 121u);
  717. val.Primary.Root.Name = "S100F121";
  718. val.Primary.Root.AddNew("Param1", "");
  719. val.Primary.Root.Item("Param1")
  720. .Format = (SECS_FORMAT)44;
  721. val.Primary.Root.Item("Param1").Value = ((object)320724);
  722. val.ReplyExpected = true;
  723. val.Send(wshost);
  724. return true;
  725. }
  726. public override bool WriteCarrierID(string cid, int offset = 0, int length = 16)
  727. {
  728. //IL_000d: Unknown result type (might be due to invalid IL or missing references)
  729. //IL_0013: Expected O, but got Unknown
  730. base.IsBusy = true;
  731. SECSTransaction val = new SECSTransaction(100u, 119u);
  732. val.Primary.Root.Name = "HCS";
  733. val.Primary.Root.AddNew("L4", "");
  734. val.Primary.Root.Item("L4").Format = (SECS_FORMAT)0;
  735. val.Primary.Root.Item("L4")
  736. .AddNew("NAME", "ECID NAME");
  737. val.Primary.Root.Item("L4")
  738. .Item("NAME")
  739. .Format = (SECS_FORMAT)44;
  740. val.Primary.Root.Item("L4")
  741. .Item("NAME")
  742. .Value = ((object)50801);
  743. val.Primary.Root.Item("L4")
  744. .AddNew("VALUE", "ECID VALUE");
  745. val.Primary.Root.Item("L4").Item("VALUE").Format = (SECS_FORMAT)41;
  746. val.Primary.Root.Item("L4").Item("VALUE").Value = ((object)1);
  747. val.Primary.Root.Item("L4")
  748. .AddNew("DateTime", "ECID DateTime");
  749. val.Primary.Root.Item("L4").Item("DateTime").Format = ((SECS_FORMAT)16);
  750. val.Primary.Root.Item("L4").Item("DateTime").Value = ((object)"2002031112121200");
  751. val.Primary.Root.Item("L4")
  752. .AddNew("DataItem", "ECID DataItem");
  753. val.Primary.Root.Item("L4").Item("DataItem").Format = ((SECS_FORMAT)16);
  754. val.Primary.Root.Item("L4").Item("DataItem").Value = ((object)cid);
  755. val.ReplyExpected = true;
  756. val.Send(wshost);
  757. return true;
  758. }
  759. public override bool WriteCarrierIDByIndex(string cid, int offset = 0, int length = 16, int index = 0)
  760. {
  761. //IL_001e: Unknown result type (might be due to invalid IL or missing references)
  762. //IL_0024: Expected O, but got Unknown
  763. base.IsBusy = true;
  764. string value = "CST:C080164 TYPE:CST25_AU LOT:" + cid + " QTY:12 FLOW:033000 STATUS:WAITING PRI:3-1 PD:0418A CSRLOT: CLEAN:2021/11/10 19:22:04 EQPGRP:DUMMY STAGE:CP-TEST1 RECIPE:DUMMY EMP:N ;";
  765. SECSTransaction val = new SECSTransaction(100u, 119u);
  766. val.Primary.Root.Name = "HCS";
  767. val.Primary.Root.AddNew("L4", "");
  768. val.Primary.Root.Item("L4")
  769. .Format = ((SECS_FORMAT)0);
  770. val.Primary.Root.Item("L4")
  771. .AddNew("NAME", "ECID NAME");
  772. val.Primary.Root.Item("L4")
  773. .Item("NAME")
  774. .Format = ((SECS_FORMAT)44);
  775. val.Primary.Root.Item("L4")
  776. .Item("NAME")
  777. .Value = ((object)50801);
  778. val.Primary.Root.Item("L4")
  779. .AddNew("VALUE", "ECID VALUE");
  780. val.Primary.Root.Item("L4").Item("VALUE").Format = ((SECS_FORMAT)41);
  781. val.Primary.Root.Item("L4")
  782. .Item("VALUE")
  783. .Value = ((object)1);
  784. val.Primary.Root.Item("L4")
  785. .AddNew("DateTime", "ECID DateTime");
  786. val.Primary.Root.Item("L4")
  787. .Item("DateTime")
  788. .Format = ((SECS_FORMAT)16);
  789. val.Primary.Root.Item("L4")
  790. .Item("DateTime")
  791. .Value = ((object)"2002031112121200");
  792. val.Primary.Root.Item("L4")
  793. .AddNew("DataItem", "ECID DataItem");
  794. val.Primary.Root.Item("L4").Item("DataItem").Format = ((SECS_FORMAT)16);
  795. val.Primary.Root.Item("L4")
  796. .Item("DataItem")
  797. .Value = (object)value;
  798. val.ReplyExpected = true;
  799. val.Send(wshost);
  800. return true;
  801. }
  802. public void LoadCassette(int id, int time, Action<string> error)
  803. {
  804. Tuple<bool, Result> tuple = ExecuteAndWait(id, delegate
  805. {
  806. EV.PostInfoLog($"{base.LPModuleName}", $"start loading");
  807. string empty = string.Empty;
  808. _isLoaded = false;
  809. lock (_locker)
  810. {
  811. SECSTransactionBuilder.BuildS2F21(9).Send(wshost);
  812. }
  813. return true;
  814. }, () => _isLoaded ? new Result?(Result.DONE) : new Result?(Result.RUN), time * 1000);
  815. if (tuple.Item1)
  816. {
  817. if (tuple.Item2 == Result.FAIL)
  818. {
  819. error("load failed");
  820. }
  821. if (tuple.Item2 == Result.TIMEOUT)
  822. {
  823. error("load timeout");
  824. }
  825. }
  826. }
  827. protected void QueryMap(int id, int time, Action<string> error)
  828. {
  829. Tuple<bool, Result> tuple = ExecuteAndWait(id, delegate
  830. {
  831. EV.PostInfoLog("System", $"{base.LPModuleName} start to query map");
  832. string empty = string.Empty;
  833. _isMapped = false;
  834. lock (_locker)
  835. {
  836. SECSTransactionBuilder.BuildS1F3(new int[2] { 1, 2 }).Send(wshost);
  837. }
  838. return true;
  839. }, () => _isMapped ? new Result?(Result.DONE) : new Result?(Result.RUN), time * 1000);
  840. if (tuple.Item1)
  841. {
  842. if (tuple.Item2 == Result.FAIL)
  843. {
  844. error("map failed");
  845. }
  846. if (tuple.Item2 == Result.TIMEOUT)
  847. {
  848. error("map timeout");
  849. }
  850. }
  851. }
  852. public void ResetRoutine()
  853. {
  854. _id = 0;
  855. _steps.Clear();
  856. loop = 0;
  857. loopCount = 0;
  858. state = STATE.IDLE;
  859. counter.Start(360000.0);
  860. RoutineToken.Result = RoutineState.Running;
  861. _currentTokenId = -1;
  862. ExecuteResult = Tuple.Create(item1: false, Result.DONE);
  863. }
  864. protected void PerformRoutineStep(int id, Func<RoutineState> execution, RoutineResult result)
  865. {
  866. if (Acitve(id))
  867. {
  868. result.Result = execution();
  869. }
  870. }
  871. public void StopLoop()
  872. {
  873. loop = loopCount;
  874. }
  875. public Tuple<bool, Result> Loop<T>(T id, Func<bool> func, int count)
  876. {
  877. int id2 = Convert.ToInt32(id);
  878. bool flag = Acitve(id2);
  879. if (flag)
  880. {
  881. if (!func())
  882. {
  883. return Tuple.Create(flag, Result.FAIL);
  884. }
  885. loopID = id2;
  886. loopCount = count;
  887. next();
  888. return Tuple.Create(item1: true, Result.RUN);
  889. }
  890. return Tuple.Create(item1: false, Result.RUN);
  891. }
  892. public Tuple<bool, Result> EndLoop<T>(T id, Func<bool> func)
  893. {
  894. int id2 = Convert.ToInt32(id);
  895. bool flag = Acitve(id2);
  896. if (flag)
  897. {
  898. if (++loop >= loopCount)
  899. {
  900. if (!func())
  901. {
  902. return Tuple.Create(flag, Result.FAIL);
  903. }
  904. loop = 0;
  905. loopCount = 0;
  906. next();
  907. return Tuple.Create(item1: true, Result.RUN);
  908. }
  909. next(loopID);
  910. return Tuple.Create(item1: true, Result.RUN);
  911. }
  912. return Tuple.Create(item1: false, Result.RUN);
  913. }
  914. public Tuple<bool, Result> ExecuteAndWait<T>(T id, IRoutine routine)
  915. {
  916. int id2 = Convert.ToInt32(id);
  917. if (Acitve(id2))
  918. {
  919. if (state == STATE.IDLE)
  920. {
  921. switch (routine.Start())
  922. {
  923. case Result.FAIL:
  924. return Tuple.Create(item1: true, Result.FAIL);
  925. case Result.DONE:
  926. next();
  927. return Tuple.Create(item1: true, Result.DONE);
  928. }
  929. state = STATE.WAIT;
  930. }
  931. Result result = routine.Monitor();
  932. int num;
  933. switch (result)
  934. {
  935. case Result.DONE:
  936. next();
  937. return Tuple.Create(item1: true, Result.DONE);
  938. default:
  939. num = ((result == Result.TIMEOUT) ? 1 : 0);
  940. break;
  941. case Result.FAIL:
  942. num = 1;
  943. break;
  944. }
  945. if (num != 0)
  946. {
  947. return Tuple.Create(item1: true, Result.FAIL);
  948. }
  949. return Tuple.Create(item1: true, Result.RUN);
  950. }
  951. return Tuple.Create(item1: false, Result.RUN);
  952. }
  953. public Tuple<bool, Result> ExecuteAndWait<T>(T id, List<IRoutine> routines)
  954. {
  955. int id2 = Convert.ToInt32(id);
  956. if (Acitve(id2))
  957. {
  958. if (state == STATE.IDLE)
  959. {
  960. foreach (IRoutine routine in routines)
  961. {
  962. if (routine.Start() == Result.FAIL)
  963. {
  964. return Tuple.Create(item1: true, Result.FAIL);
  965. }
  966. }
  967. state = STATE.WAIT;
  968. }
  969. bool flag = false;
  970. bool flag2 = true;
  971. foreach (IRoutine routine2 in routines)
  972. {
  973. Result result = routine2.Monitor();
  974. flag2 = flag2 && (result == Result.FAIL || result == Result.DONE);
  975. flag = flag || result == Result.FAIL;
  976. }
  977. if (flag2)
  978. {
  979. next();
  980. if (flag)
  981. {
  982. return Tuple.Create(item1: true, Result.FAIL);
  983. }
  984. return Tuple.Create(item1: true, Result.DONE);
  985. }
  986. return Tuple.Create(item1: true, Result.RUN);
  987. }
  988. return Tuple.Create(item1: false, Result.RUN);
  989. }
  990. public Tuple<bool, Result> Check<T>(T id, Func<bool> func)
  991. {
  992. return Check(Check(Convert.ToInt32(id), func));
  993. }
  994. public Tuple<bool, Result> Execute<T>(T id, Func<bool> func)
  995. {
  996. return Check(execute(Convert.ToInt32(id), func));
  997. }
  998. public Tuple<bool, Result> Wait<T>(T id, Func<bool> func, double timeout = 2147483647.0)
  999. {
  1000. return Check(wait(Convert.ToInt32(id), func, timeout));
  1001. }
  1002. public Tuple<bool, Result> Wait<T>(T id, Func<bool?> func, double timeout = 2147483647.0)
  1003. {
  1004. return Check(wait(Convert.ToInt32(id), func, timeout));
  1005. }
  1006. public Tuple<bool, Result> ExecuteAndWait<T>(T id, Func<bool> execute, Func<Result?> check, double timeout = 2147483647.0)
  1007. {
  1008. int num = Convert.ToInt32(id);
  1009. bool flag = Acitve(num);
  1010. Result? result = Result.RUN;
  1011. if (flag)
  1012. {
  1013. if (state == STATE.IDLE)
  1014. {
  1015. if (!execute())
  1016. {
  1017. ExecuteResult = Tuple.Create(flag, Result.FAIL);
  1018. return Tuple.Create(flag, Result.FAIL);
  1019. }
  1020. timer.Start(timeout);
  1021. state = STATE.WAIT;
  1022. _currentTokenId = num;
  1023. }
  1024. result = check();
  1025. if (!result.HasValue)
  1026. {
  1027. ExecuteResult = Tuple.Create(flag, Result.FAIL);
  1028. return Tuple.Create(flag, Result.FAIL);
  1029. }
  1030. if (result == Result.DONE)
  1031. {
  1032. next();
  1033. ExecuteResult = Tuple.Create(item1: true, Result.RUN);
  1034. return Tuple.Create(item1: true, Result.RUN);
  1035. }
  1036. if (result == Result.Succeed)
  1037. {
  1038. next();
  1039. ExecuteResult = Tuple.Create(item1: true, Result.RUN);
  1040. return Tuple.Create(item1: true, Result.RUN);
  1041. }
  1042. if (result == Result.FAIL)
  1043. {
  1044. ExecuteResult = Tuple.Create(item1: true, Result.FAIL);
  1045. return Tuple.Create(item1: true, Result.FAIL);
  1046. }
  1047. if (timer.IsTimeout())
  1048. {
  1049. ExecuteResult = Tuple.Create(item1: true, Result.TIMEOUT);
  1050. return Tuple.Create(item1: true, Result.TIMEOUT);
  1051. }
  1052. ExecuteResult = Tuple.Create(item1: true, Result.RUN);
  1053. return Tuple.Create(item1: true, Result.RUN);
  1054. }
  1055. ExecuteResult = Tuple.Create(item1: false, Result.RUN);
  1056. return Tuple.Create(item1: false, Result.RUN);
  1057. }
  1058. public Tuple<bool, Result> Wait<T>(T id, IRoutine rt)
  1059. {
  1060. int id2 = Convert.ToInt32(id);
  1061. if (Acitve(id2))
  1062. {
  1063. if (state == STATE.IDLE)
  1064. {
  1065. rt.Start();
  1066. state = STATE.WAIT;
  1067. }
  1068. Result item = rt.Monitor();
  1069. return Tuple.Create(item1: true, item);
  1070. }
  1071. return Tuple.Create(item1: false, Result.RUN);
  1072. }
  1073. public Tuple<bool, Result> Monitor<T>(T id, Func<bool> func, Func<bool> check, double time)
  1074. {
  1075. int id2 = Convert.ToInt32(id);
  1076. bool flag = Acitve(id2);
  1077. bool flag2 = false;
  1078. if (flag)
  1079. {
  1080. if (state == STATE.IDLE)
  1081. {
  1082. if (func != null && !func())
  1083. {
  1084. return Tuple.Create(item1: true, Result.FAIL);
  1085. }
  1086. timer.Start(time);
  1087. state = STATE.WAIT;
  1088. }
  1089. if (!check())
  1090. {
  1091. return Tuple.Create(item1: true, Result.FAIL);
  1092. }
  1093. if (timer.IsTimeout())
  1094. {
  1095. next();
  1096. }
  1097. return Tuple.Create(item1: true, Result.RUN);
  1098. }
  1099. return Tuple.Create(item1: false, Result.RUN);
  1100. }
  1101. public Tuple<bool, Result> Delay<T>(T id, Func<bool> func, double time)
  1102. {
  1103. int num = Convert.ToInt32(id);
  1104. if (Acitve(num))
  1105. {
  1106. if (state == STATE.IDLE)
  1107. {
  1108. if (func != null && !func())
  1109. {
  1110. ExecuteResult = Tuple.Create(item1: true, Result.FAIL);
  1111. return Tuple.Create(item1: true, Result.FAIL);
  1112. }
  1113. _currentTokenId = num;
  1114. timer.Start(time);
  1115. state = STATE.WAIT;
  1116. }
  1117. if (timer.IsTimeout())
  1118. {
  1119. next();
  1120. }
  1121. ExecuteResult = Tuple.Create(item1: true, Result.RUN);
  1122. return Tuple.Create(item1: true, Result.RUN);
  1123. }
  1124. ExecuteResult = Tuple.Create(item1: false, Result.RUN);
  1125. return Tuple.Create(item1: false, Result.RUN);
  1126. }
  1127. public Tuple<bool, Result> DelayCheck<T>(T id, Func<bool> func, double time)
  1128. {
  1129. int id2 = Convert.ToInt32(id);
  1130. if (Acitve(id2))
  1131. {
  1132. if (state == STATE.IDLE)
  1133. {
  1134. timer.Start(time);
  1135. state = STATE.WAIT;
  1136. }
  1137. if (timer.IsTimeout())
  1138. {
  1139. if (func != null && !func())
  1140. {
  1141. return Tuple.Create(item1: true, Result.FAIL);
  1142. }
  1143. next();
  1144. }
  1145. return Tuple.Create(item1: true, Result.RUN);
  1146. }
  1147. return Tuple.Create(item1: false, Result.RUN);
  1148. }
  1149. private Tuple<bool, bool> execute(int id, Func<bool> func)
  1150. {
  1151. bool flag = Acitve(id);
  1152. bool flag2 = false;
  1153. if (flag)
  1154. {
  1155. flag2 = func();
  1156. if (flag2)
  1157. {
  1158. next();
  1159. }
  1160. }
  1161. return Tuple.Create(flag, flag2);
  1162. }
  1163. private Tuple<bool, bool> Check(int id, Func<bool> func)
  1164. {
  1165. bool flag = Acitve(id);
  1166. bool item = false;
  1167. if (flag)
  1168. {
  1169. if (ExecuteResult.Item1)
  1170. {
  1171. return Tuple.Create(item1: true, item2: true);
  1172. }
  1173. item = func();
  1174. next();
  1175. }
  1176. return Tuple.Create(flag, item);
  1177. }
  1178. private Tuple<bool, bool, bool> wait(int id, Func<bool> func, double timeout = 2147483647.0)
  1179. {
  1180. bool flag = Acitve(id);
  1181. bool flag2 = false;
  1182. bool item = false;
  1183. if (flag)
  1184. {
  1185. if (state == STATE.IDLE)
  1186. {
  1187. timer.Start(timeout);
  1188. state = STATE.WAIT;
  1189. }
  1190. flag2 = func();
  1191. if (flag2)
  1192. {
  1193. next();
  1194. }
  1195. item = timer.IsTimeout();
  1196. }
  1197. return Tuple.Create(flag, flag2, item);
  1198. }
  1199. private Tuple<bool, bool?, bool> wait(int id, Func<bool?> func, double timeout = 2147483647.0)
  1200. {
  1201. bool flag = Acitve(id);
  1202. bool? item = false;
  1203. bool item2 = false;
  1204. if (flag)
  1205. {
  1206. if (state == STATE.IDLE)
  1207. {
  1208. timer.Start(timeout);
  1209. state = STATE.WAIT;
  1210. }
  1211. item = func();
  1212. if (item.HasValue && item.Value)
  1213. {
  1214. next();
  1215. }
  1216. item2 = timer.IsTimeout();
  1217. }
  1218. return Tuple.Create(flag, item, item2);
  1219. }
  1220. private Tuple<bool, Result> Check(Tuple<bool, bool> value)
  1221. {
  1222. if (value.Item1)
  1223. {
  1224. if (!value.Item2)
  1225. {
  1226. ExecuteResult = Tuple.Create(item1: true, Result.FAIL);
  1227. return Tuple.Create(item1: true, Result.FAIL);
  1228. }
  1229. ExecuteResult = Tuple.Create(item1: true, Result.RUN);
  1230. return Tuple.Create(item1: true, Result.RUN);
  1231. }
  1232. ExecuteResult = Tuple.Create(item1: false, Result.RUN);
  1233. return Tuple.Create(item1: false, Result.RUN);
  1234. }
  1235. private Tuple<bool, Result> Check(Tuple<bool, bool, bool> value)
  1236. {
  1237. if (value.Item1)
  1238. {
  1239. if (CheckTimeout(value))
  1240. {
  1241. return Tuple.Create(item1: true, Result.TIMEOUT);
  1242. }
  1243. return Tuple.Create(item1: true, Result.RUN);
  1244. }
  1245. return Tuple.Create(item1: false, Result.RUN);
  1246. }
  1247. private Tuple<bool, Result> Check(Tuple<bool, bool?, bool> value)
  1248. {
  1249. if (value.Item1)
  1250. {
  1251. if (!value.Item2.HasValue)
  1252. {
  1253. return Tuple.Create(item1: true, Result.FAIL);
  1254. }
  1255. if (value.Item2 == false && value.Item3)
  1256. {
  1257. return Tuple.Create(item1: true, Result.TIMEOUT);
  1258. }
  1259. return Tuple.Create(item1: true, Result.RUN);
  1260. }
  1261. return Tuple.Create(item1: false, Result.RUN);
  1262. }
  1263. private bool CheckTimeout(Tuple<bool, bool, bool> value)
  1264. {
  1265. return value.Item1 && !value.Item2 && value.Item3;
  1266. }
  1267. private bool Acitve(int id)
  1268. {
  1269. if (_steps.Contains(id))
  1270. {
  1271. return false;
  1272. }
  1273. _id = id;
  1274. return true;
  1275. }
  1276. private void next()
  1277. {
  1278. _steps.Push(_id);
  1279. state = STATE.IDLE;
  1280. }
  1281. private void next(int step)
  1282. {
  1283. while (_steps.Pop() != step)
  1284. {
  1285. }
  1286. state = STATE.IDLE;
  1287. }
  1288. public void Delay(int id, double delaySeconds)
  1289. {
  1290. Tuple<bool, Result> tuple = Delay(id, () => true, delaySeconds * 1000.0);
  1291. if (tuple.Item1 && tuple.Item2 != 0)
  1292. {
  1293. }
  1294. }
  1295. public bool IsActived(int id)
  1296. {
  1297. return _steps.Contains(id);
  1298. }
  1299. public override bool Home(out string reason)
  1300. {
  1301. IsHomed = false;
  1302. reason = "";
  1303. bool flag = CheckToPostMessage(0, "Home");
  1304. if (!flag)
  1305. {
  1306. reason = $"Can't execute on {CurrentState}";
  1307. }
  1308. return flag;
  1309. }
  1310. public virtual bool IsCarrierEnabled
  1311. {
  1312. get
  1313. {
  1314. //debug 完全取决于sc的值
  1315. if (SC.ContainsItem($"CarrierInfo.Carrier{InfoPadCarrierIndex}.EnableCarrier"))
  1316. {
  1317. //return SC.GetValue<bool>($"CarrierInfo.Carrier{InfoPadCarrierIndex}.EnableCarrier");
  1318. return true;
  1319. }
  1320. return true;
  1321. }
  1322. }
  1323. public override bool IsEnableLoad(out string reason)
  1324. {
  1325. if (!_isPlaced)
  1326. {
  1327. reason = "No carrier placed";
  1328. return false;
  1329. }
  1330. if (_isDocked)
  1331. {
  1332. reason = "Carrier is docked";
  1333. return false;
  1334. }
  1335. if (!IsReady())
  1336. {
  1337. reason = "Not Ready";
  1338. return false;
  1339. }
  1340. if (!IsCarrierEnabled)
  1341. {
  1342. reason = "CarrierNotEnabled";
  1343. return false;
  1344. }
  1345. reason = "";
  1346. return true;
  1347. }
  1348. public override bool Load(out string reason)
  1349. {
  1350. if (!IsEnableLoad(out reason))
  1351. {
  1352. EV.PostAlarmLog("LoadPort", "Can't execute load command due to " + reason);
  1353. if (reason == "CarrierNotEnabled")
  1354. {
  1355. EV.Notify($"{LPModuleName}CarrierNotEnabled");
  1356. }
  1357. return false;
  1358. }
  1359. reason = "";
  1360. if (!((!IsMapWaferByLoadPort) ? CheckToPostMessage(3, "LoadWithoutMap") : CheckToPostMessage(3, "LoadWithMap")))
  1361. {
  1362. reason = $"Can't execute on {CurrentState}";
  1363. return false;
  1364. }
  1365. return true;
  1366. }
  1367. protected override void SubscribeDataVariable()
  1368. {
  1369. Singleton<WaferManager>.Instance.SubscribeLocation(LPModuleName, 25);
  1370. Singleton<CarrierManager>.Instance.SubscribeLocation(LPModuleName.ToString());
  1371. DATA.Subscribe(Name, "IsPresent" , () => _isPresent);
  1372. DATA.Subscribe(Name, "IsPlaced" , () => _isPlaced);
  1373. DATA.Subscribe(Name, "IsClamped" , () => ClampState == FoupClampState.Close);
  1374. DATA.Subscribe(Name, "IsDocked" , () => DockState == FoupDockState.Docked);
  1375. DATA.Subscribe(Name, "IsDoorOpen" , () => DoorState == FoupDoorState.Open);
  1376. DATA.Subscribe(Name, "IsAccessSwPressed" , () => IsAccessSwPressed);
  1377. DATA.Subscribe(Name, "CarrierId" , () => _carrierId);
  1378. DATA.Subscribe(Name, "LPLotID" , () => _lplotID);
  1379. DATA.Subscribe(Name, "IsMapped" , () => _isMapped);
  1380. DATA.Subscribe(Name, "IsAutoDetectCarrierType" , () => IsAutoDetectCarrierType);
  1381. DATA.Subscribe(Name, "ValidCarrierTypeList" , () => ValidCarrierTypeList);
  1382. DATA.Subscribe(Name + ".LoadportState" , () => CurrentState.ToString());
  1383. //DATA.Subscribe(Name + ".Status" , () => CurrentState.ToString());
  1384. DATA.Subscribe(Name + ".LoadportError" , () => ErrorCode);
  1385. DATA.Subscribe(Name + ".CassetteState" , () => CassetteState);
  1386. DATA.Subscribe(Name + ".FoupClampState" , () => ClampState);
  1387. DATA.Subscribe(Name + ".FoupDockState" , () => DockState);
  1388. DATA.Subscribe(Name + ".FoupDoorState" , () => DoorState);
  1389. DATA.Subscribe(Name + ".FoupDoorPosition" , () => DoorPosition);
  1390. DATA.Subscribe(Name + ".SlotMap" , () => SlotMap);
  1391. DATA.Subscribe(Name + ".WaferMapThickness" , () => WaferMapThickness);
  1392. DATA.Subscribe(Name + ".IndicatiorLoad" , () => IndicatiorLoad );
  1393. DATA.Subscribe(Name + ".IndicatiorUnload" , () => IndicatiorUnload ) ;
  1394. DATA.Subscribe(Name + ".IndicatiorPresence" , () => IndicatiorPresence );
  1395. DATA.Subscribe(Name + ".IndicatiorPlacement" , () => IndicatiorPlacement );
  1396. DATA.Subscribe(Name + ".IndicatiorAlarm" , () => IndicatorAlarm );
  1397. DATA.Subscribe(Name + ".IndicatiorAccessAuto" , () => IndicatiorAccessAuto );
  1398. DATA.Subscribe(Name + ".IndicatiorAccessManual" , () => IndicatiorAccessManual );
  1399. DATA.Subscribe(Name + ".IndicatiorOpAccess" , () => IndicatiorOpAccess );
  1400. DATA.Subscribe(Name + ".IndicatiorStatus1" , () => IndicatiorStatus1 );
  1401. DATA.Subscribe(Name + ".IndicatiorStatus2" , () => IndicatiorStatus2 );
  1402. DATA.Subscribe(Name + ".CasstleType" , () => (int)CasstleType );
  1403. DATA.Subscribe(Name + ".InfoPadCarrierType" , () => SpecCarrierType );
  1404. DATA.Subscribe(Name + ".InfoPadCarrierTypeInformation" , () => SpecCarrierInformation );
  1405. DATA.Subscribe(Name + ".InfoPadCarrierIndex" , () => InfoPadCarrierIndex );
  1406. DATA.Subscribe(Name + ".CarrierWaferSize" , () => GetCurrentWaferSize().ToString());
  1407. DATA.Subscribe(Name + ".IsError" , () => CurrentState == LoadPortStateEnum.Error);
  1408. DATA.Subscribe(Name + ".PreDefineWaferCount" , () => PreDefineWaferCount);
  1409. DATA.Subscribe(Name + ".IsVerifyPreDefineWaferCount" , () => IsVerifyPreDefineWaferCount);
  1410. DATA.Subscribe(Name + ".ValidSlotsNumber" , () => ValidSlotsNumber);
  1411. }
  1412. }
  1413. }