DeviceManager.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. using Aitex.Common.Util;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Device.Unit;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.Util;
  10. using Aitex.Sorter.Common;
  11. using athosRT.tool;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.CarrierIdReaders.OmronBarcode;
  14. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.CarrierIdReaders.OmronRFID;
  15. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.FFUs.AAF;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.Fortrend;
  17. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  18. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  19. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Rorze;
  20. using System;
  21. using System.Collections.Generic;
  22. using System.Diagnostics;
  23. using System.Linq;
  24. using System.Reflection;
  25. using System.Text;
  26. using System.Text.RegularExpressions;
  27. using System.Threading.Tasks;
  28. using System.Xml;
  29. using FortrendSmifPort = athosRT.Devices.LP.FortrendSmifPort;
  30. using RorzeRobot751 = athosRT.Modules.Robot.RorzeRobot751;
  31. using EV = athosRT.tool.EV;
  32. using DATA = Common.DataCenter.DATA;
  33. using athosRT.Devices.LP;
  34. using athosRT.Devices.PA;
  35. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  36. using athosRT.Devices.FLP;
  37. using MECF.Framework.Common.SubstrateTrackings;
  38. namespace athosRT.Devices
  39. {
  40. public class DeviceManager : DeviceManagerBase
  41. {
  42. private static readonly int LoadPortQuantity = Singleton<DeviceDefineManager>.Instance.GetValue<int>(nameof(LoadPortQuantity)).GetValueOrDefault();
  43. private static readonly int LoadLockQuantity = Singleton<DeviceDefineManager>.Instance.GetValue<int>(nameof(LoadLockQuantity)).GetValueOrDefault();
  44. private static readonly int LoadLockSlot = Singleton<DeviceDefineManager>.Instance.GetValue<int>(nameof(LoadLockSlot)).GetValueOrDefault();
  45. private static readonly bool LoadLockDoorControlByStation = Singleton<DeviceDefineManager>.Instance.GetValue<bool>("LLDoorControlByStation").GetValueOrDefault();
  46. private static readonly bool DmcCardUsed = Singleton<DeviceDefineManager>.Instance.GetValue<bool>("DmcCardInstalled").GetValueOrDefault();
  47. private static readonly bool DisableSignalTower = Singleton<DeviceDefineManager>.Instance.GetValue<bool>(nameof(DisableSignalTower)).GetValueOrDefault();
  48. private readonly string[] _carrierIdReader = new string[10]
  49. {
  50. nameof (CarrierIdReader),
  51. nameof (CarrierIdReader),
  52. nameof (CarrierIdReader),
  53. nameof (CarrierIdReader),
  54. nameof (CarrierIdReader),
  55. nameof (CarrierIdReader),
  56. nameof (CarrierIdReader),
  57. nameof (CarrierIdReader),
  58. nameof (CarrierIdReader),
  59. nameof (CarrierIdReader)
  60. };
  61. private readonly string[] _carrierRfidReader = new string[10]
  62. {
  63. "RFID",
  64. "RFID",
  65. "RFID",
  66. "RFID",
  67. "RFID",
  68. "RFID",
  69. "RFID",
  70. "RFID",
  71. "RFID",
  72. "RFID"
  73. };
  74. private readonly ModuleName[] _lpNames = new ModuleName[10]
  75. {
  76. ModuleName.LP1,
  77. ModuleName.LP2,
  78. ModuleName.LP3,
  79. ModuleName.LP4,
  80. ModuleName.LP5,
  81. ModuleName.LP6,
  82. ModuleName.LP7,
  83. ModuleName.LP8,
  84. ModuleName.LP9,
  85. ModuleName.LP10
  86. };
  87. private readonly string[] _carrierIdReaderPortScName = new string[10]
  88. {
  89. "LoadPort.LoadPort1CarrierIdReaderPortName",
  90. "LoadPort.LoadPort2CarrierIdReaderPortName",
  91. "LoadPort.LoadPort3CarrierIdReaderPortName",
  92. "LoadPort.LoadPort4CarrierIdReaderPortName",
  93. "LoadPort.LoadPort5CarrierIdReaderPortName",
  94. "LoadPort.LoadPort6CarrierIdReaderPortName",
  95. "LoadPort.LoadPort7CarrierIdReaderPortName",
  96. "LoadPort.LoadPort8CarrierIdReaderPortName",
  97. "LoadPort.LoadPort9CarrierIdReaderPortName",
  98. "LoadPort.LoadPort10CarrierIdReaderPortName"
  99. };
  100. private readonly string[] _rfidReaderAddress = new string[10]
  101. {
  102. "LoadPort.LoadPort1CarrierIdReaderAddress",
  103. "LoadPort.LoadPort2CarrierIdReaderAddress",
  104. "LoadPort.LoadPort3CarrierIdReaderAddress",
  105. "LoadPort.LoadPort4CarrierIdReaderAddress",
  106. "LoadPort.LoadPort5CarrierIdReaderAddress",
  107. "LoadPort.LoadPort6CarrierIdReaderAddress",
  108. "LoadPort.LoadPort7CarrierIdReaderAddress",
  109. "LoadPort.LoadPort8CarrierIdReaderAddress",
  110. "LoadPort.LoadPort9CarrierIdReaderAddress",
  111. "LoadPort.LoadPort10CarrierIdReaderAddress"
  112. };
  113. private readonly string[] _rfidReaderPages = new string[10]
  114. {
  115. "LoadPort.LoadPort1CarrierIdReaderPage",
  116. "LoadPort.LoadPort2CarrierIdReaderPage",
  117. "LoadPort.LoadPort3CarrierIdReaderPage",
  118. "LoadPort.LoadPort4CarrierIdReaderPage",
  119. "LoadPort.LoadPort5CarrierIdReaderPage",
  120. "LoadPort.LoadPort6CarrierIdReaderPage",
  121. "LoadPort.LoadPort7CarrierIdReaderPage",
  122. "LoadPort.LoadPort8CarrierIdReaderPage",
  123. "LoadPort.LoadPort9CarrierIdReaderPage",
  124. "LoadPort.LoadPort10CarrierIdReaderPage"
  125. };
  126. private readonly string[] _rfidNames = new string[10]
  127. {
  128. "RFIDReaderA",
  129. "RFIDReaderB",
  130. "RFIDReaderC",
  131. "RFIDReaderD",
  132. "RFIDReaderE",
  133. "RFIDReaderF",
  134. "RFIDReaderG",
  135. "RFIDReaderH",
  136. "RFIDReaderI",
  137. "RFIDReaderJ"
  138. };
  139. private readonly string[] _lpPortNameSc = new string[10]
  140. {
  141. "LoadPort.LoadPort1PortName",
  142. "LoadPort.LoadPort2PortName",
  143. "LoadPort.LoadPort3PortName",
  144. "LoadPort.LoadPort4PortName",
  145. "LoadPort.LoadPort5PortName",
  146. "LoadPort.LoadPort6PortName",
  147. "LoadPort.LoadPort7PortName",
  148. "LoadPort.LoadPort8PortName",
  149. "LoadPort.LoadPort9PortName",
  150. "LoadPort.LoadPort10PortName"
  151. };
  152. private readonly string[] _llNames = new string[8]
  153. {
  154. "LL1",
  155. "LL2",
  156. "LL3",
  157. "LL4",
  158. "LL5",
  159. "LL6",
  160. "LL7",
  161. "LL8"
  162. };
  163. private char[] rfidInstallment;
  164. private char[] carrierIdInstallment;
  165. private char[] e84Support;
  166. public string[] CarrierIdReader => ((IEnumerable<string>)_carrierIdReader).Take<string>(DeviceManager.LoadPortQuantity).ToArray<string>();
  167. public string[] CarrierRfidReader => ((IEnumerable<string>)_carrierRfidReader).Take<string>(DeviceManager.LoadPortQuantity).ToArray<string>();
  168. public IEnumerable<ModuleName> LpNames => ((IEnumerable<ModuleName>)_lpNames).Take<ModuleName>(DeviceManager.LoadPortQuantity);
  169. private string[] CarrierIdReaderPortScName => ((IEnumerable<string>)_carrierIdReaderPortScName).Take<string>(DeviceManager.LoadPortQuantity).ToArray<string>();
  170. public string[] LpPortNameSc => ((IEnumerable<string>)_lpPortNameSc).Take<string>(DeviceManager.LoadPortQuantity).ToArray<string>();
  171. public string[] LLNames => ((IEnumerable<string>)_llNames).Take<string>(DeviceManager.LoadLockQuantity).ToArray<string>();
  172. public bool IsAnyLPIdle() => LpNames.Any<ModuleName>((Func<ModuleName, bool>)(moduleName => DEVICE.GetDevice<LoadPortBaseDevice>(moduleName.ToString()).IsIdle));
  173. public ModuleName[] GetAllLoadPortName() => LpNames as ModuleName[];
  174. public LoadPortBaseDevice[] GetAllLoadPorts() => LpNames.Select<ModuleName, LoadPortBaseDevice>((Func<ModuleName, LoadPortBaseDevice>)(lpName => DEVICE.GetDevice<LoadPortBaseDevice>(lpName.ToString()))).ToList<LoadPortBaseDevice>().ToArray();
  175. private OmronBarcodeReader GetBarcodeReader(string lp)
  176. {
  177. int index = Array.IndexOf((Array)LpNames.ToArray<ModuleName>(), (object)lp);
  178. return DEVICE.GetDevice<OmronBarcodeReader>(lp + "." + _carrierIdReader[index]);
  179. }
  180. public OmronRfidReader GetRfidReader(string lp)
  181. {
  182. int num = int.Parse(new Regex("[1-9]\\d*").Match(lp).ToString());
  183. return num <= LoadPortQuantity ? DEVICE.GetDevice<OmronRfidReader>(_rfidNames[num - 1]) : (OmronRfidReader)null;
  184. }
  185. public override bool Initialize()
  186. {
  187. foreach (FieldInfo field in typeof(DeviceModel).GetFields())
  188. field.SetValue(null, GetDevice(field.Name));
  189. DeviceModel.TrigSafetytoSMIF2.SetTrigger(true,out _);
  190. IoSensor[] ioSensorArray1 = new IoSensor[2]
  191. {
  192. DeviceModel.SensorPMASystemInterlock,
  193. DeviceModel.SensorPMBSystemInterlock
  194. };
  195. IoSensor[] ioSensorArray2 = new IoSensor[2]
  196. {
  197. DeviceModel.SensorRBNotExtendPMA,
  198. DeviceModel.SensorRBNotExtendPMB
  199. };
  200. IoTrigger[] ioTriggerArray1 = new IoTrigger[2]
  201. {
  202. DeviceModel.TrigSafetytoPMA,
  203. DeviceModel.TrigSafetytoPMB
  204. };
  205. IoTrigger[] ioTriggerArray2 = new IoTrigger[2]
  206. {
  207. DeviceModel.TrigRBNotExtendPMA,
  208. DeviceModel.TrigRBNotExtendPMB
  209. };
  210. IoSensor[] ioSensorArray3 = new IoSensor[2]
  211. {
  212. DeviceModel.SensorSMIF1PODOPEN,
  213. DeviceModel.SensorSMIF1PODOPEN
  214. };
  215. IoTrigger[] ioTriggerArray3 = new IoTrigger[2]
  216. {
  217. DeviceModel.TrigSafetytoPMA,
  218. DeviceModel.TrigSafetytoPMB
  219. };
  220. IoTrigger[] ioTriggerLP = new IoTrigger[2]
  221. {
  222. DeviceModel.TrigSafetytoSMIF1,
  223. DeviceModel.TrigSafetytoSMIF2
  224. };
  225. RorzeRobot751 RR751 = new RorzeRobot751(ModuleName.System.ToString(), "Robot", "Robot", null, null);
  226. RR751.InitializeRobot();
  227. for (int index = 0; index < LoadPortQuantity; ++index)
  228. {
  229. this.AddCustomDevice((IDevice)new HirataLoadPort(ModuleName.System.ToString(), this._lpNames[index].ToString(), "LoadPort", (RobotBaseDevice)null, ioTriggerLP), "LoadPort", typeof(LoadPortBaseDevice));
  230. }
  231. AddCustomDevice(RR751, "Robot", typeof(RobotBaseDevice));
  232. //添加PA 用于新的设备逻辑
  233. if (SC.GetValue<bool>("Aligner1.IsEnable"))
  234. {
  235. Singleton<WaferManager>.Instance.SubscribeLocation(ModuleName.Aligner1, 1);
  236. //AddCustomDevice(new RorzePreAligner(ModuleName.System.ToString(), "Aligner1", "Aligner1", "", ""), "Aligner1", typeof(PreAligner));
  237. }
  238. if (SC.GetValue<bool>("Aligner2.IsEnable"))
  239. {
  240. Singleton<WaferManager>.Instance.SubscribeLocation(ModuleName.Aligner1, 1);
  241. //AddCustomDevice(new RorzePreAligner(ModuleName.System.ToString(), "Aligner2", "Aligner2", "", ""), "Aligner2", typeof(PreAligner));
  242. }
  243. if (Singleton<DeviceDefineManager>.Instance.GetValue<bool>("FfuMemoBusControl").GetValueOrDefault())
  244. {
  245. AddCustomDevice(new Ffu("", "FFU", "01", SC.GetStringValue("System.FFUComPortName")), "FFU", typeof(Ffu));
  246. }
  247. for (int index = 0; index < LoadLockQuantity; ++index)
  248. {
  249. LoadLockDevice loadLockDevice = new LoadLockDevice("System", _llNames[index], DeviceManager.LoadLockSlot, ioSensorArray1[index], ioSensorArray2[index], ioTriggerArray1[index], ioTriggerArray2[index]);
  250. AddCustomDevice((IDevice)loadLockDevice, "LoadLockDevice", loadLockDevice.GetType());
  251. }
  252. if (DisableSignalTower)
  253. DeviceModel.SignalTower.CustomSignalTower(PathManager.GetCfgDir() + "SignalTower.xml");
  254. //DeviceModel.TurnOverStation;
  255. AddCustomDevice((IDevice)new EquipmentMonitor(), "EquipmentMonitor", typeof(EquipmentMonitor));//这里涉及RT状态的修改 file报错
  256. foreach (object childNode in DeviceModelNodes.ChildNodes)
  257. {
  258. XmlElement xmlElement = childNode as XmlElement;
  259. }
  260. AddCustomDevice(new SimpleBuffer("Buffer"), "Buffer", typeof(SimpleBuffer));
  261. OP.Subscribe(OperationName.ResetDevice, new Func<string, object[], bool>(InvokeResetDevice));
  262. OP.Subscribe("DeviceOperation", new Func<string, object[], bool>(InvokeDeviceOperation));
  263. OP.Subscribe("SetManualScanCode", new Func<string, object[], bool>(InvokeSetManualScanCode));
  264. OP.Subscribe("Scan", new Func<string, object[], bool>(InvokeScan));
  265. OP.Subscribe("Write", new Func<string, object[], bool>(InvokeWrite));
  266. OP.Subscribe("ReadCarrierId", new Func<string, object[], bool>(InvokeScan));
  267. OP.Subscribe("ReadFoupRFID", new Func<string, object[], bool>(InvokeReadRfid));
  268. OP.Subscribe("WriteFoupRFID", new Func<string, object[], bool>(InvokeWriteRfid));
  269. RR751.OnSlotMapRead += new Action<ModuleName, string>(Robot_OnSlotMapRead);
  270. return true;
  271. }
  272. private bool InvokeWrite(string arg1, object[] args)
  273. {
  274. string reason;
  275. if (GetRfidReader(args[0].ToString()).Write(args[1].ToString(), out reason))
  276. return true;
  277. EV.PostWarningLog(args[0].ToString(), "fail to write RFID, " + reason);
  278. return false;
  279. }
  280. private bool InvokeWriteRfid(string arg1, object[] arg2)
  281. {
  282. string reason;
  283. if (GetRfidReader(arg2[0].ToString()).Write(arg2[1].ToString(), out reason))
  284. return true;
  285. EV.PostWarningLog(arg1, "fail to write RFID, " + reason);
  286. return false;
  287. }
  288. private bool InvokeReadRfid(string arg1, object[] arg2)
  289. {
  290. string reason;
  291. if (GetRfidReader(arg2[0].ToString()).Read(out reason))
  292. return true;
  293. EV.PostWarningLog(arg1, "fail to read RFID, " + reason);
  294. return false;
  295. }
  296. private bool InvokeScan(string arg1, object[] args) => DEVICE.GetDevice<LoadPortBaseDevice>(args[0].ToString()).ReadCarrierID();
  297. private bool InvokeSetManualScanCode(string arg1, object[] args)
  298. {
  299. DEVICE.GetDevice<LoadPortBaseDevice>(args[0].ToString()).OnCarrierIdRead(args[1].ToString());
  300. return true;
  301. }
  302. private bool InvokeOffline(string arg1, object[] arg2) => true;
  303. private void Robot_OnSlotMapRead(ModuleName module, string slotMap) => DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString())?.OnSlotMapRead(slotMap);
  304. private bool InvokeDeviceOperation(string arg1, object[] args)
  305. {
  306. string str = "";
  307. string cmd = "";
  308. try
  309. {
  310. str = (string)args[0];
  311. cmd = (string)args[1];
  312. if ((bool)DATA.Poll(ModuleName.System.ToString(), "IsMaintenanceMode"))
  313. {
  314. EV.PostMessage<EventEnum>("System", EventEnum.DefaultWarning, (object)string.Format("System in maintenance, can not execute {0}{1}", (object)str, (object)cmd));
  315. return false;
  316. }
  317. object[] objArray = new object[args.Length - 2];
  318. for (int index = 2; index < args.Length; ++index)
  319. objArray[index - 2] = (object)args[index].ToString();
  320. if (str == "SignalTower")
  321. {
  322. OP.DoOperation("System.SignalTower." + cmd);
  323. return true;
  324. }
  325. if (ModuleHelper.IsLoadPort(ModuleHelper.Converter(str)))
  326. OP.DoOperation(str + "." + cmd, objArray);
  327. else
  328. DeviceCmd(str, cmd, objArray);
  329. }
  330. catch (Exception ex)
  331. {
  332. LogObject.Error("DeviceManager",ex);
  333. EV.PostMessage<EventEnum>("System", EventEnum.DefaultWarning, (object)string.Format("Invalid parameters, can not execute {0}{1}", (object)str, (object)cmd));
  334. return false;
  335. }
  336. return true;
  337. }
  338. private bool InvokeResetDevice(string arg1, object[] arg2)
  339. {
  340. Singleton<DeviceEntity>.Instance.PostMsg<DeviceEntityT<DeviceManager>.MSG>(DeviceEntityT<DeviceManager>.MSG.RESET);
  341. return true;
  342. }
  343. private void DeviceCmd(string name, string cmd, params object[] args) => DEVICE.Do(string.Format("{0}.{1}", (object)name, (object)cmd), 0, true, args);
  344. }
  345. }