BrooksSmifNcdSmec.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using Aitex.Core.RT.Device.Unit;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.SCCore;
  4. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  5. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.SMIFs.Brooks;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.SMIF
  15. {
  16. public class BrooksSmifNcdSmec:BrooksSmifPort
  17. {
  18. public BrooksSmifNcdSmec(string module, string name, string scRoot, RobotBaseDevice robot, IoSensor[] dis,IoTrigger[] dos, bool mapbyLp = true)
  19. : base(module, name, scRoot, robot, mapbyLp)
  20. {
  21. _diCameraBusy = dis[0];
  22. _diCamera25Slot = dis[1];
  23. _diCamera13Slot = dis[2];
  24. _doCameraStart = dos[0];
  25. _doCameraReset = dos[1];
  26. }
  27. private IoSensor _diCameraBusy;
  28. private IoSensor _diCamera25Slot;
  29. private IoSensor _diCamera13Slot;
  30. private IoTrigger _doCameraStart;
  31. private IoTrigger _doCameraReset;
  32. private int _slotNumberParseFromCarrierId;
  33. private bool _isEnableCassetteCheckOnCamera => SC.GetValue<bool>($"LoadPort.{LPModuleName}.EnableCassetteCheckOnCamera");
  34. public override void OnCarrierIdRead(string carrierId, int readerIndex = 1, int startPage = 1, int length = 16, bool updateCarrierID = true)
  35. {
  36. base.OnCarrierIdRead(carrierId);
  37. string startstr = "TYPE:";
  38. string endstr = "LOT:";
  39. Regex rg = new Regex("(?<=(" + startstr + "))[.\\s\\S]*?(?=(" + endstr + "))", RegexOptions.Multiline | RegexOptions.Singleline);
  40. string tempStr = rg.Match(carrierId).Value.Replace(":", "").Trim();
  41. if(!int.TryParse(tempStr.Replace("BOX", "").Replace("CST", "").Substring(0, 2), out _slotNumberParseFromCarrierId))
  42. {
  43. OnError("Parse slot number error");
  44. }
  45. if(SC.GetValue<int>($"CarrierInfo.Carrier{InfoPadCarrierIndex}.CarrierSlotsNumber") != _slotNumberParseFromCarrierId)
  46. {
  47. for (int i = 0; i < 8; i++)
  48. {
  49. if (SC.ContainsItem($"CarrierInfo.Carrier{i}.EnableCarrier")
  50. && !SC.GetValue<bool>($"CarrierInfo.Carrier{i}.EnableCarrier"))
  51. continue;
  52. if (!SC.ContainsItem($"CarrierInfo.Carrier{i}.CarrierName"))
  53. continue;
  54. if (SC.GetValue<int>($"CarrierInfo.Carrier{i}.CarrierSlotsNumber") == _slotNumberParseFromCarrierId)
  55. {
  56. InfoPadCarrierIndex = i;
  57. break;
  58. }
  59. }
  60. }
  61. }
  62. protected override bool fMonitorLoad(object[] param)
  63. {
  64. IsBusy = false;
  65. LoadCassette((int)LpStepEnum.Step1, TimelimitAction, OnError);
  66. if (ExecuteResult.Item1)
  67. {
  68. return false;
  69. }
  70. if (_isEnableCassetteCheckOnCamera)
  71. {
  72. _doCameraStart.SetTrigger(true, out _);
  73. Stopwatch _timerAction = new Stopwatch();
  74. _timerAction.Start();
  75. while (!(_diCamera13Slot.Value ^ _diCamera25Slot.Value))
  76. {
  77. Thread.Sleep(10);
  78. if (_timerAction.ElapsedMilliseconds > 10000)
  79. {
  80. OnError("CameraTimeout");
  81. _doCameraStart.SetTrigger(false, out _);
  82. return true;
  83. }
  84. }
  85. _doCameraStart.SetTrigger(false, out _);
  86. if (string.IsNullOrEmpty(_carrierId))
  87. {
  88. if (!_diCamera25Slot.Value)
  89. {
  90. _slotNumberParseFromCarrierId = 25;
  91. EV.PostInfoLog("LoadPort", $"{LPModuleName} identify carrier to 25 slot");
  92. return true;
  93. }
  94. if (!_diCamera13Slot.Value)
  95. {
  96. _slotNumberParseFromCarrierId = 13;
  97. EV.PostInfoLog("LoadPort", $"{LPModuleName} identify carrier to 13 slot");
  98. return true;
  99. }
  100. }
  101. if (_slotNumberParseFromCarrierId == 25 && !_diCamera25Slot.Value)
  102. {
  103. EV.PostInfoLog("LoadPort", $"{LPModuleName} identify carrier to 25 slot");
  104. return true;
  105. }
  106. if (_slotNumberParseFromCarrierId == 13 && !_diCamera13Slot.Value)
  107. {
  108. EV.PostInfoLog("LoadPort", $"{LPModuleName} identify carrier to 13 slot");
  109. return true;
  110. }
  111. EV.PostAlarmLog("LoadPort", $"CarrierId identify slotnumer:{_slotNumberParseFromCarrierId} but camera identify:{(!_diCamera25Slot.Value ? "25" : "13")}");
  112. OnError("SlotNumberNotMatched");
  113. }
  114. return true;
  115. }
  116. public override bool SetCarrierIndex(int indexValue, out string reason)
  117. {
  118. reason = "";
  119. InfoPadCarrierIndex = indexValue;
  120. EV.PostInfoLog(Module, $"{Name} set carrier type index to {InfoPadCarrierIndex}");
  121. return true;
  122. }
  123. public override Tuple<int, string>[] ValidCarrierTypeList
  124. {
  125. get
  126. {
  127. List<Tuple<int, string>> ret = new List<Tuple<int, string>>();
  128. for (int i = 0; i < 8; i++)
  129. {
  130. if (!SC.ContainsItem($"CarrierInfo.Carrier{i}.CarrierName"))
  131. continue;
  132. if (SC.ContainsItem($"CarrierInfo.Carrier{i}.EnableCarrier")
  133. && !SC.GetValue<bool>($"CarrierInfo.Carrier{i}.EnableCarrier"))
  134. continue;
  135. if (!SC.ContainsItem($"CarrierInfo.Carrier{i}.CarrierName"))
  136. continue;
  137. if (SC.GetValue<int>($"CarrierInfo.Carrier{i}.CarrierSlotsNumber") != _slotNumberParseFromCarrierId)
  138. continue;
  139. string carriertype = "Carrier Type: " + SC.GetStringValue($"CarrierInfo.Carrier{i}.CarrierName");
  140. ret.Add(new Tuple<int, string>(i, carriertype));
  141. }
  142. return ret.ToArray();
  143. }
  144. }
  145. protected override bool fStartReset(object[] param)
  146. {
  147. _doCameraStart.SetTrigger(false, out _);
  148. _doCameraReset.SetTrigger(true, out _);
  149. Thread.Sleep(1000);
  150. _doCameraReset.SetTrigger(false, out _);
  151. lock (_locker)
  152. {
  153. SECSTransactionBuilder.BuildS2F41((int)BrooksSMIFRCMDEnum.Reset).Send(wshost);
  154. SECSTransactionBuilder.BuildS1F5(0).Send(wshost);
  155. }
  156. return true;
  157. }
  158. }
  159. }