HirataLoadPort.cs 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using Aitex.Core.RT.Device.Unit;
  8. using Aitex.Core.RT.Event;
  9. using Aitex.Core.RT.Log;
  10. using Aitex.Core.RT.SCCore;
  11. using Aitex.Sorter.Common;
  12. using MECF.Framework.Common.Communications;
  13. using TSC = Aitex.Sorter.Common;
  14. using Aitex.Core.Common;
  15. using MECF.Framework.Common.SubstrateTrackings;
  16. using Aitex.Core.Util;
  17. using System.IO.Ports;
  18. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDK;
  19. using Aitex.Core.RT.OperationCenter;
  20. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.Hirata
  21. {
  22. public enum HirataSystemStatus
  23. {
  24. Normal =0x30,
  25. RecoverableError = 0x41,
  26. UnrecoverableError = 0x45,
  27. }
  28. public enum HirataMode
  29. {
  30. Online=0x30,
  31. Teaching=0x31,
  32. Maintenance =0x32,
  33. }
  34. public enum HirataInitPosMovement
  35. {
  36. OperationStatus=0x30,
  37. HomePosStatus=0x31,
  38. LoadStatus=0x32,
  39. }
  40. public enum HirataOperationStatus
  41. {
  42. DuringStop=0x30,
  43. DuringOperation=0x31,
  44. }
  45. public enum HirataContainerStatus
  46. {
  47. Absence=0x30,
  48. NormalMount=0x31,
  49. MountError=0x32,
  50. }
  51. public enum HirataPosition
  52. {
  53. Open=0x30,
  54. Close=0x31,
  55. TBD =0x3F
  56. }
  57. public enum HirataVacummStatus
  58. {
  59. OFF=0x30,
  60. ON=0x31,
  61. }
  62. public enum HirataWaferProtrusion
  63. {
  64. ShadingStatus=0x30,
  65. LightIncidentStatus=0x31,
  66. }
  67. public enum HirataElevatorAxisPosition
  68. {
  69. UP=0x30,
  70. Down=0x31,
  71. MappingStartPos=0x32,
  72. MappingEndPos=0x33,
  73. TBD = 0x3F,
  74. }
  75. public enum HirataDockPosition
  76. {
  77. Undock=0x30,
  78. Dock=0x31,
  79. TBD = 0x3F,
  80. }
  81. public enum HirataMapPosition
  82. {
  83. MeasurementPos=0x30,
  84. WaitingPost=0x31,
  85. TBD = 0x3F,
  86. }
  87. public enum HirataMappingStatus
  88. {
  89. NotPerformed=0x30,
  90. NormalEnd=0x31,
  91. ErrorStop=0x32,
  92. }
  93. public enum HirataModel
  94. {
  95. Type1=0x30,
  96. Type2=0x31,
  97. Type3=0x32,
  98. Type4=0x33,
  99. Type5=0x34,
  100. }
  101. public class HirataLoadPort : LoadPort
  102. {
  103. private bool _isTcpConnection;
  104. public HirataLoadPort(string module, string name,bool IsTCPconnection = false) : base(module, name)
  105. {
  106. _isTcpConnection = IsTCPconnection;
  107. }
  108. private HirataLoadPortConnection _connection;
  109. public HirataLoadPortConnection Connection
  110. {
  111. get => _connection;
  112. }
  113. private HirataLoadPortTcpConnection _tcpconnection;
  114. public HirataLoadPortTcpConnection TCPconnection => _tcpconnection;
  115. public HirataSystemStatus SystemStatus { get; set; }
  116. public HirataMode Mode { get; set; }
  117. public HirataInitPosMovement InitPosMovement { get; set; }
  118. public HirataOperationStatus OperationStatus { get; set; }
  119. public byte HostErrorCode { get; set; }
  120. public byte LoadPortErrorCode { get; set; }
  121. public HirataContainerStatus ContainerStatus { get; set; }
  122. public HirataPosition ClampPosition { get; set; }
  123. public HirataPosition DoorLatchPosition { get; set; }
  124. public HirataVacummStatus VacuumStatus { get; set; }
  125. public HirataPosition DoorPosition { get; set;}
  126. public HirataWaferProtrusion WaferProtrusion { get; set; }
  127. public HirataElevatorAxisPosition ElevatorAxisPosition { get; set; }
  128. public HirataDockPosition DockPosition { get; set; }
  129. public HirataMapPosition MapperPostion { get; set; }
  130. public HirataMappingStatus MappingStatus { get; set; }
  131. public HirataModel Model { get; set; }
  132. private PeriodicJob _thread;
  133. private static Object _locker = new Object();
  134. private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
  135. private bool _enableLog = true;
  136. //private bool _commErr = false;
  137. private R_TRIG _trigError = new R_TRIG();
  138. private R_TRIG _trigWarningMessage = new R_TRIG();
  139. private R_TRIG _trigCommunicationError = new R_TRIG();
  140. private R_TRIG _trigRetryConnect = new R_TRIG();
  141. public override bool IsBusy
  142. {
  143. get
  144. {
  145. if (_isTcpConnection)
  146. return (_lstHandler.Count > 0 || _tcpconnection.IsBusy);
  147. return _lstHandler.Count > 0 || _connection.IsBusy;
  148. }
  149. }
  150. public override bool Initialize()
  151. {
  152. base.Initialize();
  153. IsMapWaferByLoadPort = true;
  154. if (_isTcpConnection)
  155. {
  156. string ipaddress = SC.GetStringValue($"LoadPort.{Name}.Address");
  157. _enableLog = SC.GetValue<bool>($"LoadPort.{Name}.EnableLogMessage");
  158. _tcpconnection = new HirataLoadPortTcpConnection(this, ipaddress);
  159. _tcpconnection.EnableLog(_enableLog);
  160. }
  161. else
  162. {
  163. string portName = SC.GetStringValue($"LoadPort.{Name}.PortName");
  164. int bautRate = SC.GetValue<int>($"LoadPort.{Name}.BaudRate");
  165. int dataBits = SC.GetValue<int>($"LoadPort.{Name}.DataBits");
  166. Enum.TryParse(SC.GetStringValue($"LoadPort.{Name}.Parity"), out Parity parity);
  167. Enum.TryParse(SC.GetStringValue($"LoadPort.{Name}.StopBits"), out StopBits stopBits);
  168. //_deviceAddress = SC.GetValue<int>($"{Name}.DeviceAddress");
  169. _enableLog = SC.GetValue<bool>($"LoadPort.{Name}.EnableLogMessage");
  170. _connection = new HirataLoadPortConnection(this, portName, bautRate, dataBits, parity, stopBits);
  171. _connection.EnableLog(_enableLog);
  172. }
  173. int count = SC.ContainsItem("System.ComPortRetryCount") ? SC.GetValue<int>("System.ComPortRetryCount") : 5;
  174. int sleep = SC.ContainsItem("System.ComPortRetryDelayTime") ? SC.GetValue<int>("System.ComPortRetryDelayTime") : 2;
  175. if (sleep <= 0 || sleep > 10)
  176. sleep = 2;
  177. int retry = 0;
  178. do
  179. {
  180. _connection.Disconnect();
  181. Thread.Sleep(sleep * 1000);
  182. if (_connection.Connect())
  183. {
  184. //LOG.Write($"Connected with {Module}.{Name} .");
  185. EV.PostInfoLog(Module, $"Connected with {Module}.{Name} .");
  186. break;
  187. }
  188. if (count > 0 && retry++ > count)
  189. {
  190. LOG.Write($"Retry connect {Module}.{Name} stop retry.");
  191. EV.PostAlarmLog(Module, $"Can't connect to {Module}.{Name}.");
  192. break;
  193. }
  194. } while (true);
  195. _thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  196. return true;
  197. }
  198. private bool OnTimer()
  199. {
  200. try
  201. {
  202. if (_isTcpConnection)
  203. {
  204. _tcpconnection.MonitorTimeout();
  205. if (!_tcpconnection.IsConnected || _tcpconnection.IsCommunicationError)
  206. {
  207. lock (_locker)
  208. {
  209. _lstHandler.Clear();
  210. }
  211. _trigRetryConnect.CLK = !_tcpconnection.IsConnected;
  212. if (_trigRetryConnect.Q)
  213. {
  214. if (!_tcpconnection.Connect())
  215. {
  216. EV.PostAlarmLog(Module, $"Can not connect with {_tcpconnection.Address}, {Module}.{Name}");
  217. }
  218. }
  219. return true;
  220. }
  221. HandlerBase handler = null;
  222. if (!_tcpconnection.IsBusy)
  223. {
  224. lock (_locker)
  225. {
  226. if (_lstHandler.Count == 0)
  227. {
  228. //_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
  229. //_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
  230. }
  231. if (_lstHandler.Count > 0)
  232. {
  233. handler = _lstHandler.First.Value;
  234. if (handler != null) _tcpconnection.Execute(handler);
  235. _lstHandler.RemoveFirst();
  236. }
  237. }
  238. }
  239. }
  240. else
  241. {
  242. _connection.MonitorTimeout();
  243. if (!_connection.IsConnected || _connection.IsCommunicationError)
  244. {
  245. lock (_locker)
  246. {
  247. _lstHandler.Clear();
  248. }
  249. _trigRetryConnect.CLK = !_connection.IsConnected;
  250. if (_trigRetryConnect.Q)
  251. {
  252. _connection.SetPortAddress(SC.GetStringValue($"{Name}.Address"));
  253. if (!_connection.Connect())
  254. {
  255. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
  256. }
  257. }
  258. return true;
  259. }
  260. HandlerBase handler = null;
  261. if (!_connection.IsBusy)
  262. {
  263. lock (_locker)
  264. {
  265. if (_lstHandler.Count == 0)
  266. {
  267. //_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.RequeststatusStatus, null));
  268. //_lstHandler.AddLast(new SingleTransactionHandler(this, TazmoCommand.Requeststatus2Status, null));
  269. }
  270. if (_lstHandler.Count > 0)
  271. {
  272. handler = _lstHandler.First.Value;
  273. if (handler != null) _connection.Execute(handler);
  274. _lstHandler.RemoveFirst();
  275. }
  276. }
  277. }
  278. }
  279. }
  280. catch (Exception ex)
  281. {
  282. LOG.Write(ex);
  283. }
  284. return true;
  285. }
  286. private LoadportCassetteState _cassetteState = LoadportCassetteState.None;
  287. public override LoadportCassetteState CassetteState
  288. {
  289. get { return _cassetteState; }
  290. set
  291. {
  292. _cassetteState = value;
  293. }
  294. }
  295. public void SetCassetteState(LoadportCassetteState state)
  296. {
  297. _cassetteState = state;
  298. if (state == LoadportCassetteState.Normal)
  299. {
  300. if (!_isPlaced)
  301. {
  302. OnCarrierPlaced();
  303. }
  304. if (!_isPresent)
  305. {
  306. OnCarrierPresent();
  307. }
  308. }
  309. }
  310. public override void Terminate()
  311. {
  312. if (_isTcpConnection)
  313. _tcpconnection.Disconnect();
  314. else
  315. _connection.Disconnect();
  316. }
  317. public override void Monitor()
  318. {
  319. base.Monitor();
  320. try
  321. {
  322. if (_isTcpConnection)
  323. {
  324. _tcpconnection.EnableLog(_enableLog);
  325. _trigCommunicationError.CLK = _tcpconnection.IsCommunicationError;
  326. if (_trigCommunicationError.Q)
  327. {
  328. EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_tcpconnection.LastCommunicationError}");
  329. }
  330. }
  331. else
  332. {
  333. _connection.EnableLog(_enableLog);
  334. _trigCommunicationError.CLK = _connection.IsCommunicationError;
  335. if (_trigCommunicationError.Q)
  336. {
  337. EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  338. }
  339. }
  340. }
  341. catch (Exception ex)
  342. {
  343. LOG.Write(ex);
  344. }
  345. }
  346. public override void Reset()
  347. {
  348. base.Reset();
  349. _trigError.RST = true;
  350. _trigWarningMessage.RST = true;
  351. if (_isTcpConnection)
  352. _tcpconnection.SetCommunicationError(false, "");
  353. else
  354. _connection.SetCommunicationError(false, "");
  355. _trigCommunicationError.RST = true;
  356. lock (_locker)
  357. {
  358. _lstHandler.Clear();
  359. }
  360. _enableLog = SC.GetValue<bool>($"LoadPort.{Name}.EnableLogMessage");
  361. _trigRetryConnect.RST = true;
  362. }
  363. public override bool IsEnableMapWafer()
  364. {
  365. if (IsIdle
  366. && _isPresent
  367. && _isPlaced
  368. && DoorState == FoupDoorState.Open
  369. && CassetteState == LoadportCassetteState.Normal
  370. )
  371. return true;
  372. return false;
  373. }
  374. public override bool IsEnableTransferWafer()
  375. {
  376. if (IsIdle
  377. && _isPresent
  378. && _isPlaced
  379. && DoorState == FoupDoorState.Open
  380. && CassetteState == LoadportCassetteState.Normal
  381. )
  382. return true;
  383. return false;
  384. }
  385. public override bool IsEnableTransferWafer(out string reason)
  386. {
  387. reason = "";
  388. if (IsIdle
  389. && _isPresent
  390. && _isPlaced
  391. && DoorState == FoupDoorState.Open
  392. && CassetteState == LoadportCassetteState.Normal
  393. )
  394. return true;
  395. return false;
  396. }
  397. public override bool ClearError(out string reason)
  398. {
  399. reason = string.Empty;
  400. lock (_locker)
  401. {
  402. _lstHandler.Clear();
  403. _lstHandler.AddLast(new SetHandler(this, "RESET", null));
  404. }
  405. return true;
  406. }
  407. public override bool Init(out string reason)
  408. {
  409. reason = string.Empty;
  410. lock (_locker)
  411. {
  412. _lstHandler.Clear();
  413. _lstHandler.AddLast(new SetHandler(this, "INITL", null));
  414. }
  415. return true;
  416. }
  417. public override bool Home(out string reason)
  418. {
  419. reason = string.Empty;
  420. lock (_locker)
  421. {
  422. _lstHandler.Clear();
  423. _lstHandler.AddLast(new MoveHandler(this, "ORGSH", null));
  424. _lstHandler.AddLast(new GetHandler(this, "STATE", null));
  425. _lstHandler.AddLast(new ModHandler(this, "ONMGV", null));
  426. }
  427. return true;
  428. }
  429. public override bool ForceHome(out string reason)
  430. {
  431. reason = string.Empty;
  432. lock (_locker)
  433. {
  434. _lstHandler.Clear();
  435. _lstHandler.AddLast(new MoveHandler(this, "ABORG", null));
  436. }
  437. return true;
  438. }
  439. public override bool LoadWithoutMap(out string reason)
  440. {
  441. reason = string.Empty;
  442. lock (_locker)
  443. {
  444. _lstHandler.AddLast(new MoveHandler(this, "CLOAD", null));
  445. }
  446. return true;
  447. }
  448. public override bool Load(out string reason) //map and loads
  449. {
  450. reason = string.Empty;
  451. lock (_locker)
  452. {
  453. _lstHandler.AddLast(new MoveHandler(this, "CLDMP", null));
  454. }
  455. return true;
  456. }
  457. public override bool Unload(out string reason)
  458. {
  459. reason = string.Empty;
  460. lock (_locker)
  461. {
  462. _lstHandler.AddLast(new MoveHandler(this, "CULOD", null));
  463. }
  464. return true;
  465. }
  466. public override bool Clamp(out string reason)
  467. {
  468. reason = string.Empty;
  469. lock (_locker)
  470. {
  471. _lstHandler.AddLast(new MoveHandler(this, "PODCL", null));
  472. }
  473. return true;
  474. }
  475. public override bool Unclamp(out string reason)
  476. {
  477. reason = string.Empty;
  478. lock (_locker)
  479. {
  480. _lstHandler.AddLast(new MoveHandler(this, "PODOP", null));
  481. }
  482. return true;
  483. }
  484. public override bool Dock(out string reason)
  485. {
  486. reason = string.Empty;
  487. lock (_locker)
  488. {
  489. _lstHandler.AddLast(new MoveHandler(this, "CLDDK", null));
  490. }
  491. return true;
  492. }
  493. public override bool Undock(out string reason)
  494. {
  495. reason = string.Empty;
  496. lock (_locker)
  497. {
  498. _lstHandler.AddLast(new MoveHandler(this, "CULFC", null));
  499. }
  500. return true;
  501. }
  502. public override bool OpenDoor(out string reason)
  503. {
  504. reason = string.Empty;
  505. lock (_locker)
  506. {
  507. _lstHandler.AddLast(new MoveHandler(this, "CLMPO", null));
  508. }
  509. return true;
  510. }
  511. public override bool OpenDoorNoMap(out string reason)
  512. {
  513. reason = string.Empty;
  514. lock (_locker)
  515. {
  516. _lstHandler.AddLast(new MoveHandler(this, "CLDOP", null));
  517. }
  518. return true;
  519. }
  520. public override bool CloseDoor(out string reason)
  521. {
  522. reason = string.Empty;
  523. lock (_locker)
  524. {
  525. _lstHandler.AddLast(new MoveHandler(this, "CULDK", null));
  526. }
  527. return true;
  528. }
  529. public override bool SetIndicator(Indicator light, IndicatorState op, out string reason)
  530. {
  531. reason = string.Empty;
  532. return true;
  533. }
  534. public bool SetOnlineMode(out string reason)
  535. {
  536. reason = string.Empty;
  537. lock (_locker)
  538. {
  539. _lstHandler.AddLast(new ModHandler(this, "ONMGV", null));
  540. }
  541. return true;
  542. }
  543. public override bool QueryState(out string reason)
  544. {
  545. reason = string.Empty;
  546. lock (_locker)
  547. {
  548. _lstHandler.AddLast(new GetHandler(this, "STATE", null));
  549. }
  550. return true;
  551. }
  552. public override bool QueryIndicator(out string reason)
  553. {
  554. reason = string.Empty;
  555. lock (_locker)
  556. {
  557. _lstHandler.AddLast(new GetHandler(this, "LEDST", null));
  558. }
  559. return true;
  560. }
  561. public override bool QueryWaferMap(out string reason)
  562. {
  563. reason = string.Empty;
  564. lock (_locker)
  565. {
  566. _lstHandler.AddLast(new GetHandler(this, "MAPDT", null));
  567. }
  568. return true;
  569. }
  570. public bool OnEvent(out string reason)
  571. {
  572. reason = string.Empty;
  573. lock (_locker)
  574. {
  575. _lstHandler.AddLast(new GetHandler(this, "STATE", null));
  576. }
  577. return true;
  578. }
  579. public void OnCarrierNotPlaced()
  580. {
  581. _isPlaced = false;
  582. ConfirmRemoveCarrier();
  583. }
  584. public void OnCarrierNotPresent()
  585. {
  586. _isPresent = false;
  587. //ConfirmRemoveCarrier();
  588. }
  589. public void OnCarrierPlaced()
  590. {
  591. _isPlaced = true;
  592. ConfirmAddCarrier();
  593. QueryState(out _);
  594. }
  595. public void OnCarrierPresent()
  596. {
  597. _isPresent = true;
  598. //ConfirmAddCarrier();
  599. }
  600. public void OnSwitchKey1()
  601. {
  602. _isAccessSwPressed = true;
  603. }
  604. public void OnSwitchKey2()
  605. {
  606. }
  607. public void OffSwitchKey1()
  608. {
  609. _isAccessSwPressed = false;
  610. }
  611. public void OffSwitchKey2()
  612. {
  613. }
  614. public override bool ReadRfId(out string reason)
  615. {
  616. OP.DoOperation("ReadCarrierId", Name);
  617. reason = "";
  618. return true;
  619. }
  620. }
  621. }
  622. // public string Address { get; set; }
  623. // public bool IsConnected
  624. // {
  625. // get { return _port.IsOpen(); }
  626. // }
  627. // public bool UnlockKey
  628. // {
  629. // set
  630. // {
  631. // }
  632. // }
  633. // public bool Enable
  634. // {
  635. // set
  636. // {
  637. // if (_enableTrigger != null)
  638. // {
  639. // _enableTrigger.SetTrigger(value, out _);
  640. // }
  641. // }
  642. // }
  643. // public bool FFUIsOK { get; set; }
  644. // private LoadportCassetteState _cassetteState = LoadportCassetteState.None;
  645. // public override LoadportCassetteState CassetteState
  646. // {
  647. // get { return _cassetteState; }
  648. // set
  649. // {
  650. // _cassetteState = value;
  651. // }
  652. // }
  653. // public bool Processed { get; set; }
  654. // public bool Communication
  655. // {
  656. // get
  657. // {
  658. // return _port == null ? !_commErr : !_commErr && _port.IsOpen();
  659. // }
  660. // }
  661. // //
  662. // public override bool IsBusy
  663. // {
  664. // get { return _foregroundHandler != null || _handlers.Count > 0; }
  665. // }
  666. // public override bool IsMoving
  667. // {
  668. // get { return _foregroundHandler != null && _handlers.Count > 0; }
  669. // }
  670. // public const string delimiter = "\r";
  671. // public const int min_len = 3; //S00
  672. // private static Object _locker = new Object();
  673. // private AsyncSerial _port;
  674. // private bool _commErr = false;
  675. // private IHandler _eventHandler = null;
  676. // private IHandler _foregroundHandler = null; //moving
  677. // private Queue<IHandler> _handlers = new Queue<IHandler>();
  678. // private IoSensor _sensorEnable = null;
  679. // private IoTrigger _enableTrigger = null;
  680. // public HirataLoadPort(string module, string name, string port, IoSensor sensorEnable, IoTrigger triggerEnable,
  681. // EnumLoadPortType portType = EnumLoadPortType.LoadPort)
  682. // : base(module, name)
  683. // {
  684. // _port = new AsyncSerial(port, 9600, 8);
  685. // _port.OnDataChanged += (OnDataChanged);
  686. // _port.OnErrorHappened += (OnErrorHandler);
  687. // _eventHandler = new handler<OnEventHandler>(Name);
  688. // _sensorEnable = sensorEnable;
  689. // _enableTrigger = triggerEnable;
  690. // Initalized = false;
  691. // IsMapWaferByLoadPort = portType == EnumLoadPortType.LoadPort;
  692. // PortType = portType;
  693. // IndicatiorLoad = IndicatorState.UNKNOW;
  694. // IndicatiorUnload = IndicatorState.UNKNOW;
  695. // IndicatiorPresence = IndicatorState.UNKNOW;
  696. // IndicatorAlarm = IndicatorState.UNKNOW;
  697. // IndicatiorPlacement = IndicatorState.UNKNOW;
  698. // IndicatiorOpAccess = IndicatorState.UNKNOW;
  699. // IndicatiorStatus1 = IndicatorState.UNKNOW;
  700. // IndicatiorStatus2 = IndicatorState.UNKNOW;
  701. // DoorState = FoupDoorState.Unknown;
  702. // ClampState = FoupClampState.Unknown;
  703. // CassetteState = LoadportCassetteState.Unknown;
  704. // //if (!this.QueryState(out string reason))
  705. // //{
  706. // // EV.PostAlarmLog(module,$"Query state error.{reason}");
  707. // //}
  708. // Enable = true;
  709. // Address = port;
  710. // }
  711. // public void SetCassetteState(LoadportCassetteState state)
  712. // {
  713. // _cassetteState = state;
  714. // if (state == LoadportCassetteState.Normal)
  715. // {
  716. // if (!_isPlaced)
  717. // {
  718. // OnCarrierPlaced();
  719. // }
  720. // if (!_isPresent)
  721. // {
  722. // OnCarrierPresent();
  723. // }
  724. // }
  725. // }
  726. // public override bool Initialize()
  727. // {
  728. // base.Initialize();
  729. // _commErr = true;
  730. // ConnectionManager.Instance.Subscribe($"{Name}", this);
  731. // Connect();
  732. // //if (!RetryInstance.Instance().Execute<bool>(
  733. // // ()=> _port.Open(),
  734. // // SC.GetValue<int>("System.ComPortRetryDelayTime"),
  735. // // SC.GetValue<int>("System.ComPortRetryCount"),
  736. // // true
  737. // //))
  738. // //{
  739. // // return false;
  740. // //}
  741. // return true;
  742. // }
  743. // public override bool Connect()
  744. // {
  745. // _commErr = false;
  746. // Task.Factory.StartNew(() =>
  747. // {
  748. // int count = SC.ContainsItem("System.ComPortRetryCount") ? SC.GetValue<int>("System.ComPortRetryCount") : 5;
  749. // int sleep = SC.ContainsItem("System.ComPortRetryDelayTime") ? SC.GetValue<int>("System.ComPortRetryDelayTime") : 2;
  750. // if (sleep <= 0 || sleep > 10)
  751. // sleep = 2;
  752. // int retry = 0;
  753. // do
  754. // {
  755. // _port.Close();
  756. // Thread.Sleep(sleep * 1000);
  757. // if (_port.Open())
  758. // {
  759. // //LOG.Write($"Connected with {Module}.{Name} .");
  760. // EV.PostInfoLog(Module, $"Connected with {Module}.{Name} .");
  761. // break;
  762. // }
  763. // if (count > 0 && retry++ > count)
  764. // {
  765. // LOG.Write($"Retry connect {Module}.{Name} stop retry.");
  766. // EV.PostAlarmLog(Module, $"Can't connect to {Module}.{Name}.");
  767. // break;
  768. // }
  769. // Thread.Sleep(sleep * 1000);
  770. // LOG.Write($"Retry connect {Module}.{Name} for the {retry + 1} time.");
  771. // } while (true);
  772. // });
  773. // return true;
  774. // }
  775. // public bool Disconnect()
  776. // {
  777. // return true;
  778. // }
  779. // public override bool IsEnableMapWafer()
  780. // {
  781. // if (IsIdle
  782. // && _isPresent
  783. // && _isPlaced
  784. // && DoorState == FoupDoorState.Open
  785. // && CassetteState == LoadportCassetteState.Normal
  786. // )
  787. // return true;
  788. // return false;
  789. // }
  790. // public override bool IsEnableTransferWafer()
  791. // {
  792. // return IsEnableTransferWafer(out _);
  793. // }
  794. // public override bool IsEnableTransferWafer(out string reason)
  795. // {
  796. // reason = "";
  797. // if (_isPlaced
  798. // && _isPresent
  799. // && _isMapped
  800. // && IsIdle
  801. // && DoorState == FoupDoorState.Open
  802. // && CassetteState == LoadportCassetteState.Normal
  803. // && IsWaferEnableTransfer()
  804. // ) return true;
  805. // return false;
  806. // }
  807. // /// <summary>
  808. // ///The Indicator is for EAP/Operator
  809. // /// LOAD READY: LoadPort Ready to receive FOUP
  810. // /// UNLOAD READY: FOUP ready to remove
  811. // ///
  812. // /// </summary>
  813. // public void OnStateUpdated()
  814. // {
  815. // if (!SC.ContainsItem("Process.OptionLoadportMonitor") || !SC.GetValue<bool>("Process.OptionLoadportMonitor"))
  816. // return;
  817. // if (_isPresent && _isPlaced && this.ClampState == FoupClampState.Open && this.DockPOS == TDKY_AxisPos.Undock)
  818. // {
  819. // if (IndicatiorUnload != IndicatorState.ON)
  820. // SetIndicator(Indicator.UNLOAD, IndicatorState.ON);
  821. // if (IndicatiorLoad != IndicatorState.OFF)
  822. // SetIndicator(Indicator.LOAD, IndicatorState.OFF);
  823. // return;
  824. // }
  825. // if (!_isPresent || !_isPlaced)
  826. // {
  827. // if (IndicatiorUnload != IndicatorState.OFF)
  828. // SetIndicator(Indicator.UNLOAD, IndicatorState.OFF);
  829. // if (IndicatiorLoad != IndicatorState.ON)
  830. // SetIndicator(Indicator.LOAD, IndicatorState.ON);
  831. // return;
  832. // }
  833. // if (IndicatiorUnload != IndicatorState.OFF)
  834. // SetIndicator(Indicator.UNLOAD, IndicatorState.OFF);
  835. // if (IndicatiorLoad != IndicatorState.OFF)
  836. // SetIndicator(Indicator.LOAD, IndicatorState.OFF);
  837. // }
  838. // public void OnAccessButtonPushed()
  839. // {
  840. // if (_isPresent && _isPlaced)
  841. // {
  842. // }
  843. // }
  844. // /// <summary>
  845. // ///reset load port error
  846. // ///
  847. // /// </summary>
  848. // public override void Reset()
  849. // {
  850. // lock (_locker)
  851. // {
  852. // _foregroundHandler = null;
  853. // _handlers.Clear();
  854. // }
  855. // FFUIsOK = true;
  856. // _commErr = false;
  857. // Enable = true;
  858. // Error = false;
  859. // base.Reset();
  860. // }
  861. // public override bool Home(out string reason)
  862. // {
  863. // reason = string.Empty;
  864. // lock (_locker)
  865. // {
  866. // _foregroundHandler = null;
  867. // _handlers.Clear();
  868. // }
  869. // return execute(new handler<HomeHandler>(Name), out reason);
  870. // }
  871. // public override bool ForceHome(out string reason)
  872. // {
  873. // reason = string.Empty;
  874. // lock (_locker)
  875. // {
  876. // _foregroundHandler = null;
  877. // _handlers.Clear();
  878. // }
  879. // return execute(new handler<ForceHomeHandler>(Name), out reason);
  880. // }
  881. // public override bool FOSBMode(out string reason)
  882. // {
  883. // reason = string.Empty;
  884. // lock (_locker)
  885. // {
  886. // _foregroundHandler = null;
  887. // _handlers.Clear();
  888. // }
  889. // return execute(new handler<FOSBModeHandler>(Name), out reason);
  890. // }
  891. // public override bool FOUPMode(out string reason)
  892. // {
  893. // reason = string.Empty;
  894. // lock (_locker)
  895. // {
  896. // _foregroundHandler = null;
  897. // _handlers.Clear();
  898. // }
  899. // return execute(new handler<FOUPModeHandler>(Name), out reason);
  900. // }
  901. // public override bool FOSBDock(out string reason)
  902. // {
  903. // reason = string.Empty;
  904. // lock (_locker)
  905. // {
  906. // _foregroundHandler = null;
  907. // _handlers.Clear();
  908. // }
  909. // return execute(new handler<DockPosHandler>(Name), out reason);
  910. // }
  911. // public override bool FOSBUnDock(out string reason)
  912. // {
  913. // reason = string.Empty;
  914. // lock (_locker)
  915. // {
  916. // _foregroundHandler = null;
  917. // _handlers.Clear();
  918. // }
  919. // return execute(new handler<UnDockPosHandler>(Name), out reason);
  920. // }
  921. // public override bool FOSBDoorOpen(out string reason)
  922. // {
  923. // reason = string.Empty;
  924. // lock (_locker)
  925. // {
  926. // _foregroundHandler = null;
  927. // _handlers.Clear();
  928. // }
  929. // return execute(new handler<DoorOpenHandler>(Name), out reason);
  930. // }
  931. // public override bool FOSBDoorClose(out string reason)
  932. // {
  933. // reason = string.Empty;
  934. // lock (_locker)
  935. // {
  936. // _foregroundHandler = null;
  937. // _handlers.Clear();
  938. // }
  939. // return execute(new handler<DoorCloseHandler>(Name), out reason);
  940. // }
  941. // public override bool FOSBDoorUp(out string reason)
  942. // {
  943. // reason = string.Empty;
  944. // lock (_locker)
  945. // {
  946. // _foregroundHandler = null;
  947. // _handlers.Clear();
  948. // }
  949. // return execute(new handler<DoorUpHandler>(Name), out reason);
  950. // }
  951. // public override bool FOSBDoorDown(out string reason)
  952. // {
  953. // reason = string.Empty;
  954. // lock (_locker)
  955. // {
  956. // _foregroundHandler = null;
  957. // _handlers.Clear();
  958. // }
  959. // return execute(new handler<DoorDownHandler>(Name), out reason);
  960. // }
  961. // /// <summary>
  962. // /// Clear LP error
  963. // /// </summary>
  964. // public override bool ClearError(out string reason)
  965. // {
  966. // reason = string.Empty;
  967. // reason = string.Empty;
  968. // lock (_locker)
  969. // {
  970. // _foregroundHandler = null;
  971. // _handlers.Clear();
  972. // }
  973. // return execute(new handler<ResetHandler>(Name), out reason);
  974. // }
  975. // public override bool Stop(out string reason)
  976. // {
  977. // reason = string.Empty;
  978. // lock (_locker)
  979. // {
  980. // _foregroundHandler = null;
  981. // _handlers.Clear();
  982. // }
  983. // return execute(new handler<MovHandler>(Name, MovType.STOP_), out reason);
  984. // }
  985. // public override bool Load(out string reason) //map and loads
  986. // {
  987. // return Move(MovType.CLDMP, out reason);
  988. // }
  989. // public override bool LoadWithoutMap(out string reason)
  990. // {
  991. // return Move(MovType.CLOAD, out reason);
  992. // }
  993. // public override bool Unload(out string reason)
  994. // {
  995. // return Move(MovType.CULOD, out reason);
  996. // }
  997. // public override bool Clamp(out string reason)
  998. // {
  999. // return Move(MovType.PODCL, out reason);
  1000. // }
  1001. // public override bool Unclamp(out string reason)
  1002. // {
  1003. // return Move(MovType.PODOP, out reason);
  1004. // }
  1005. // public override bool Dock(out string reason)
  1006. // {
  1007. // return Move(MovType.CLDDK, out reason);
  1008. // }
  1009. // public override bool Undock(out string reason)
  1010. // {
  1011. // return Move(MovType.CULFC, out reason); //????
  1012. // }
  1013. // public override bool OpenDoor(out string reason)
  1014. // {
  1015. // return Move(MovType.CLMPO, out reason);
  1016. // }
  1017. // public override bool OpenDoorNoMap(out string reason)
  1018. // {
  1019. // return Move(MovType.CLDOP, out reason);
  1020. // }
  1021. // public override bool CloseDoor(out string reason)
  1022. // {
  1023. // return Move(MovType.CULDK, out reason);
  1024. // }
  1025. // public override bool SetIndicator(Indicator light, IndicatorState op, out string reason)
  1026. // {
  1027. // reason = string.Empty;
  1028. // return execute(new handler<IndicatorHandler>(Name, light, op), out reason);
  1029. // }
  1030. // public bool SetOnlineMode(out string reason)
  1031. // {
  1032. // reason = string.Empty;
  1033. // return execute(new handler<ModHandler>(Name, Mode.ONMGV), out reason);
  1034. // }
  1035. // public override bool QueryState(out string reason)
  1036. // {
  1037. // reason = string.Empty;
  1038. // return execute(new handler<QueryStateHandler>(Name), out reason);
  1039. // }
  1040. // public override bool QueryIndicator(out string reason)
  1041. // {
  1042. // reason = string.Empty;
  1043. // return execute(new handler<QueryIndicatorHandler>(Name), out reason);
  1044. // }
  1045. // public override bool QueryWaferMap(out string reason)
  1046. // {
  1047. // reason = string.Empty;
  1048. // return execute(new handler<QueryWaferMappingHandler>(DeviceID), out reason);
  1049. // }
  1050. // public override bool QueryFOSBMode(out string reason)
  1051. // {
  1052. // reason = string.Empty;
  1053. // return execute(new handler<QueryFOSBModeHandler>(DeviceID), out reason);
  1054. // }
  1055. // public bool Move(MovType fun, out string reason)
  1056. // {
  1057. // reason = string.Empty;
  1058. // return execute(new handler<MovHandler>(Name, fun), out reason);
  1059. // }
  1060. // //public bool Query(QueryType type, out string reason)
  1061. // //{
  1062. // // reason = string.Empty;
  1063. // // return execute(new handler<QueryWaferMappingHandler>(Name), out reason);
  1064. // //}
  1065. // public bool SetEvent(EvtType fun, out string reason)
  1066. // {
  1067. // reason = string.Empty;
  1068. // return execute(new handler<SetEventHandler>(Name, fun), out reason);
  1069. // }
  1070. // public bool OnEvent(out string reason)
  1071. // {
  1072. // reason = string.Empty;
  1073. // lock (_locker)
  1074. // {
  1075. // if (!execute(new handler<QueryStateHandler>(Name), out reason))
  1076. // return false;
  1077. // //execute(new handler<QueryIndicatorHandler>(Name), out reason);
  1078. // //LoadLight();
  1079. // //UnloadLight();
  1080. // return execute(new handler<QueryIndicatorHandler>(Name), out reason);
  1081. // }
  1082. // }
  1083. // private bool execute(IHandler handler1, out string reason)
  1084. // {
  1085. // reason = string.Empty;
  1086. // lock (_locker)
  1087. // {
  1088. // if (_foregroundHandler == null)
  1089. // {
  1090. // if (!handler1.Execute(ref _port))
  1091. // {
  1092. // reason = "Communication failed, please recovery it.";
  1093. // return false;
  1094. // }
  1095. // _foregroundHandler = handler1;
  1096. // }
  1097. // else
  1098. // {
  1099. // var type = handler1.GetType();
  1100. // string name = type.Name;
  1101. // if (type.GenericTypeArguments.Length > 0)
  1102. // name = type.GenericTypeArguments[0].Name;
  1103. // LOG.Info(string.Format("Add command {0}", name));
  1104. // _handlers.Enqueue(handler1);
  1105. // }
  1106. // }
  1107. // return true;
  1108. // }
  1109. // private bool execute(out string reason)
  1110. // {
  1111. // reason = string.Empty;
  1112. // lock (_locker)
  1113. // {
  1114. // if (_handlers.Count > 0)
  1115. // {
  1116. // IHandler handler = _handlers.Dequeue();
  1117. // if (!handler.Execute(ref _port))
  1118. // {
  1119. // reason = " communication failed, please recovery it.";
  1120. // LOG.Error(reason);
  1121. // EV.PostMessage(Name, EventEnum.DefaultWarning, "【Reader】" + reason);
  1122. // return false;
  1123. // }
  1124. // _foregroundHandler = handler;
  1125. // }
  1126. // }
  1127. // return true;
  1128. // }
  1129. // private void OnDataChanged(string package)
  1130. // {
  1131. // try
  1132. // {
  1133. // package = package.ToUpper();
  1134. // string[] msgs = Regex.Split(package, delimiter);
  1135. // foreach (string msg in msgs)
  1136. // {
  1137. // if (msg.Length > min_len)
  1138. // {
  1139. // bool completed = false;
  1140. // string resp = msg.Substring(3, msg.Length - min_len);
  1141. // lock (_locker)
  1142. // {
  1143. // if (_foregroundHandler != null && _foregroundHandler.OnMessage(ref _port, resp, out completed))
  1144. // {
  1145. // string reason = string.Empty;
  1146. // if (!_foregroundHandler.IsBackground)
  1147. // {
  1148. // _foregroundHandler = null;
  1149. // execute(out reason);
  1150. // OnActionDone(true);
  1151. // }
  1152. // else
  1153. // {
  1154. // if (completed)
  1155. // {
  1156. // _foregroundHandler = null;
  1157. // QueryState(out reason);
  1158. // if (_foregroundHandler is handler<HomeHandler>)
  1159. // {
  1160. // QueryIndicator(out reason);
  1161. // }
  1162. // }
  1163. // }
  1164. // }
  1165. // else
  1166. // {
  1167. // _eventHandler.OnMessage(ref _port, resp, out completed); //process event
  1168. // }
  1169. // }
  1170. // }
  1171. // }
  1172. // }
  1173. // catch (ExcuteFailedException ex)
  1174. // {
  1175. // EV.PostWarningLog(Module, $"{Name} action failed, " + ex.Message);
  1176. // _foregroundHandler = null;
  1177. // OnError($"{ Name} action failed");
  1178. // }
  1179. // catch (InvalidPackageException ex)
  1180. // {
  1181. // EV.PostWarningLog(Module, $"{Name} received unprocessed message, {ex.Message}");
  1182. // OnError($"{Name} received unprocessed message");
  1183. // }
  1184. // catch (Exception ex)
  1185. // {
  1186. // LOG.Write($" {Name} has exception:" + ex.Message);
  1187. // }
  1188. // }
  1189. // private void OnErrorHandler(ErrorEventArgs args)
  1190. // {
  1191. // _commErr = true;
  1192. // Initalized = false;
  1193. // EV.PostAlarmLog(Module, $"{Display} Communication error, {args.Reason}");
  1194. // OnError($"{Display} Communication error");
  1195. // }
  1196. // public void OnCarrierNotPlaced()
  1197. // {
  1198. // _isPlaced = false;
  1199. // ConfirmRemoveCarrier();
  1200. // }
  1201. // public void OnCarrierNotPresent()
  1202. // {
  1203. // _isPresent = false;
  1204. // //ConfirmRemoveCarrier();
  1205. // }
  1206. // public void OnCarrierPlaced()
  1207. // {
  1208. // _isPlaced = true;
  1209. // ConfirmAddCarrier();
  1210. // QueryState(out _);
  1211. // }
  1212. // public void OnCarrierPresent()
  1213. // {
  1214. // _isPresent = true;
  1215. // //ConfirmAddCarrier();
  1216. // }
  1217. // public void OnSwitchKey1()
  1218. // {
  1219. // _isAccessSwPressed = true;
  1220. // }
  1221. // public void OnSwitchKey2()
  1222. // {
  1223. // }
  1224. // public void OffSwitchKey1()
  1225. // {
  1226. // _isAccessSwPressed = false;
  1227. // }
  1228. // public void OffSwitchKey2()
  1229. // {
  1230. // }
  1231. // public void SetIndicator(Indicator led, IndicatorState state)
  1232. // {
  1233. // SetIndicator(led, state, out string reason);
  1234. // }
  1235. // //impment E84 interface
  1236. // public bool ReadyForLoad()
  1237. // {
  1238. // return CassetteState == LoadportCassetteState.Absent;
  1239. // }
  1240. // public bool ReadyForUnload()
  1241. // {
  1242. // return CassetteState == LoadportCassetteState.Normal;
  1243. // }
  1244. // public bool FoupArrirved()
  1245. // {
  1246. // return CassetteState == LoadportCassetteState.Normal;
  1247. // }
  1248. // public bool FoupRemoved()
  1249. // {
  1250. // return CassetteState == LoadportCassetteState.Absent;
  1251. // }
  1252. // public LPTransferState GetTransferState()
  1253. // {
  1254. // return LPTransferState.IN_SERVICE;
  1255. // }
  1256. // public LPAccessMode GetAccessMode()
  1257. // {
  1258. // return LPAccessMode.AUTO;
  1259. // }
  1260. // public LPReservedState GetReservedState()
  1261. // {
  1262. // return LPReservedState.NOT_RESERVED;
  1263. // }
  1264. // public void LPTSTrans(LPTransferState lpts)
  1265. // {
  1266. // return;
  1267. // }
  1268. // public bool IsSystemAutoMode()
  1269. // {
  1270. // return false;
  1271. // }
  1272. // public void SetAccessMode(bool isauto)
  1273. // {
  1274. // return;
  1275. // }
  1276. // public void E84Retry()
  1277. // {
  1278. // throw new NotImplementedException();
  1279. // }
  1280. // public void SetCompleted()
  1281. // {
  1282. // return;
  1283. // }
  1284. // }
  1285. //}