using Aitex.Common.Util; using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Device; using Aitex.Core.RT.Device.Unit; using Aitex.Core.RT.Event; using Aitex.Core.RT.IOCore; using Aitex.Core.RT.OperationCenter; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using Aitex.Sorter.Common; using athosRT.tool; using MECF.Framework.Common.Equipment; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.CarrierIdReaders.OmronBarcode; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.CarrierIdReaders.OmronRFID; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.FFUs.AAF; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.Fortrend; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Rorze; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Xml; using FortrendSmifPort = athosRT.Devices.LP.FortrendSmifPort; using RorzeRobot751 = athosRT.Modules.Robot.RorzeRobot751; using EV = athosRT.tool.EV; using DATA = Common.DataCenter.DATA; using athosRT.Devices.LP; using athosRT.Devices.PA; using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot; using athosRT.Devices.FLP; using MECF.Framework.Common.SubstrateTrackings; namespace athosRT.Devices { public class DeviceManager : DeviceManagerBase { private static readonly int LoadPortQuantity = Singleton.Instance.GetValue(nameof(LoadPortQuantity)).GetValueOrDefault(); private static readonly int LoadLockQuantity = Singleton.Instance.GetValue(nameof(LoadLockQuantity)).GetValueOrDefault(); private static readonly int LoadLockSlot = Singleton.Instance.GetValue(nameof(LoadLockSlot)).GetValueOrDefault(); private static readonly bool LoadLockDoorControlByStation = Singleton.Instance.GetValue("LLDoorControlByStation").GetValueOrDefault(); private static readonly bool DmcCardUsed = Singleton.Instance.GetValue("DmcCardInstalled").GetValueOrDefault(); private static readonly bool DisableSignalTower = Singleton.Instance.GetValue(nameof(DisableSignalTower)).GetValueOrDefault(); private readonly string[] _carrierIdReader = new string[10] { nameof (CarrierIdReader), nameof (CarrierIdReader), nameof (CarrierIdReader), nameof (CarrierIdReader), nameof (CarrierIdReader), nameof (CarrierIdReader), nameof (CarrierIdReader), nameof (CarrierIdReader), nameof (CarrierIdReader), nameof (CarrierIdReader) }; private readonly string[] _carrierRfidReader = new string[10] { "RFID", "RFID", "RFID", "RFID", "RFID", "RFID", "RFID", "RFID", "RFID", "RFID" }; private readonly ModuleName[] _lpNames = new ModuleName[10] { ModuleName.LP1, ModuleName.LP2, ModuleName.LP3, ModuleName.LP4, ModuleName.LP5, ModuleName.LP6, ModuleName.LP7, ModuleName.LP8, ModuleName.LP9, ModuleName.LP10 }; private readonly string[] _carrierIdReaderPortScName = new string[10] { "LoadPort.LoadPort1CarrierIdReaderPortName", "LoadPort.LoadPort2CarrierIdReaderPortName", "LoadPort.LoadPort3CarrierIdReaderPortName", "LoadPort.LoadPort4CarrierIdReaderPortName", "LoadPort.LoadPort5CarrierIdReaderPortName", "LoadPort.LoadPort6CarrierIdReaderPortName", "LoadPort.LoadPort7CarrierIdReaderPortName", "LoadPort.LoadPort8CarrierIdReaderPortName", "LoadPort.LoadPort9CarrierIdReaderPortName", "LoadPort.LoadPort10CarrierIdReaderPortName" }; private readonly string[] _rfidReaderAddress = new string[10] { "LoadPort.LoadPort1CarrierIdReaderAddress", "LoadPort.LoadPort2CarrierIdReaderAddress", "LoadPort.LoadPort3CarrierIdReaderAddress", "LoadPort.LoadPort4CarrierIdReaderAddress", "LoadPort.LoadPort5CarrierIdReaderAddress", "LoadPort.LoadPort6CarrierIdReaderAddress", "LoadPort.LoadPort7CarrierIdReaderAddress", "LoadPort.LoadPort8CarrierIdReaderAddress", "LoadPort.LoadPort9CarrierIdReaderAddress", "LoadPort.LoadPort10CarrierIdReaderAddress" }; private readonly string[] _rfidReaderPages = new string[10] { "LoadPort.LoadPort1CarrierIdReaderPage", "LoadPort.LoadPort2CarrierIdReaderPage", "LoadPort.LoadPort3CarrierIdReaderPage", "LoadPort.LoadPort4CarrierIdReaderPage", "LoadPort.LoadPort5CarrierIdReaderPage", "LoadPort.LoadPort6CarrierIdReaderPage", "LoadPort.LoadPort7CarrierIdReaderPage", "LoadPort.LoadPort8CarrierIdReaderPage", "LoadPort.LoadPort9CarrierIdReaderPage", "LoadPort.LoadPort10CarrierIdReaderPage" }; private readonly string[] _rfidNames = new string[10] { "RFIDReaderA", "RFIDReaderB", "RFIDReaderC", "RFIDReaderD", "RFIDReaderE", "RFIDReaderF", "RFIDReaderG", "RFIDReaderH", "RFIDReaderI", "RFIDReaderJ" }; private readonly string[] _lpPortNameSc = new string[10] { "LoadPort.LoadPort1PortName", "LoadPort.LoadPort2PortName", "LoadPort.LoadPort3PortName", "LoadPort.LoadPort4PortName", "LoadPort.LoadPort5PortName", "LoadPort.LoadPort6PortName", "LoadPort.LoadPort7PortName", "LoadPort.LoadPort8PortName", "LoadPort.LoadPort9PortName", "LoadPort.LoadPort10PortName" }; private readonly string[] _llNames = new string[8] { "LL1", "LL2", "LL3", "LL4", "LL5", "LL6", "LL7", "LL8" }; private char[] rfidInstallment; private char[] carrierIdInstallment; private char[] e84Support; public string[] CarrierIdReader => ((IEnumerable)_carrierIdReader).Take(DeviceManager.LoadPortQuantity).ToArray(); public string[] CarrierRfidReader => ((IEnumerable)_carrierRfidReader).Take(DeviceManager.LoadPortQuantity).ToArray(); public IEnumerable LpNames => ((IEnumerable)_lpNames).Take(DeviceManager.LoadPortQuantity); private string[] CarrierIdReaderPortScName => ((IEnumerable)_carrierIdReaderPortScName).Take(DeviceManager.LoadPortQuantity).ToArray(); public string[] LpPortNameSc => ((IEnumerable)_lpPortNameSc).Take(DeviceManager.LoadPortQuantity).ToArray(); public string[] LLNames => ((IEnumerable)_llNames).Take(DeviceManager.LoadLockQuantity).ToArray(); public bool IsAnyLPIdle() => LpNames.Any((Func)(moduleName => DEVICE.GetDevice(moduleName.ToString()).IsIdle)); public ModuleName[] GetAllLoadPortName() => LpNames as ModuleName[]; public LoadPortBaseDevice[] GetAllLoadPorts() => LpNames.Select((Func)(lpName => DEVICE.GetDevice(lpName.ToString()))).ToList().ToArray(); private OmronBarcodeReader GetBarcodeReader(string lp) { int index = Array.IndexOf((Array)LpNames.ToArray(), (object)lp); return DEVICE.GetDevice(lp + "." + _carrierIdReader[index]); } public OmronRfidReader GetRfidReader(string lp) { int num = int.Parse(new Regex("[1-9]\\d*").Match(lp).ToString()); return num <= LoadPortQuantity ? DEVICE.GetDevice(_rfidNames[num - 1]) : (OmronRfidReader)null; } public override bool Initialize() { foreach (FieldInfo field in typeof(DeviceModel).GetFields()) field.SetValue(null, GetDevice(field.Name)); DeviceModel.TrigSafetytoSMIF2.SetTrigger(true,out _); IoSensor[] ioSensorArray1 = new IoSensor[2] { DeviceModel.SensorPMASystemInterlock, DeviceModel.SensorPMBSystemInterlock }; IoSensor[] ioSensorArray2 = new IoSensor[2] { DeviceModel.SensorRBNotExtendPMA, DeviceModel.SensorRBNotExtendPMB }; IoTrigger[] ioTriggerArray1 = new IoTrigger[2] { DeviceModel.TrigSafetytoPMA, DeviceModel.TrigSafetytoPMB }; IoTrigger[] ioTriggerArray2 = new IoTrigger[2] { DeviceModel.TrigRBNotExtendPMA, DeviceModel.TrigRBNotExtendPMB }; IoSensor[] ioSensorArray3 = new IoSensor[2] { DeviceModel.SensorSMIF1PODOPEN, DeviceModel.SensorSMIF1PODOPEN }; IoTrigger[] ioTriggerArray3 = new IoTrigger[2] { DeviceModel.TrigSafetytoPMA, DeviceModel.TrigSafetytoPMB }; IoTrigger[] ioTriggerLP = new IoTrigger[2] { DeviceModel.TrigSafetytoSMIF1, DeviceModel.TrigSafetytoSMIF2 }; RorzeRobot751 RR751 = new RorzeRobot751(ModuleName.System.ToString(), "Robot", "Robot", null, null); RR751.InitializeRobot(); for (int index = 0; index < LoadPortQuantity; ++index) { this.AddCustomDevice((IDevice)new HirataLoadPort(ModuleName.System.ToString(), this._lpNames[index].ToString(), "LoadPort", (RobotBaseDevice)null, ioTriggerLP), "LoadPort", typeof(LoadPortBaseDevice)); } AddCustomDevice(RR751, "Robot", typeof(RobotBaseDevice)); //添加PA 用于新的设备逻辑 if (SC.GetValue("Aligner1.IsEnable")) { Singleton.Instance.SubscribeLocation(ModuleName.Aligner1, 1); //AddCustomDevice(new RorzePreAligner(ModuleName.System.ToString(), "Aligner1", "Aligner1", "", ""), "Aligner1", typeof(PreAligner)); } if (SC.GetValue("Aligner2.IsEnable")) { Singleton.Instance.SubscribeLocation(ModuleName.Aligner1, 1); //AddCustomDevice(new RorzePreAligner(ModuleName.System.ToString(), "Aligner2", "Aligner2", "", ""), "Aligner2", typeof(PreAligner)); } if (Singleton.Instance.GetValue("FfuMemoBusControl").GetValueOrDefault()) { AddCustomDevice(new Ffu("", "FFU", "01", SC.GetStringValue("System.FFUComPortName")), "FFU", typeof(Ffu)); } for (int index = 0; index < LoadLockQuantity; ++index) { LoadLockDevice loadLockDevice = new LoadLockDevice("System", _llNames[index], DeviceManager.LoadLockSlot, ioSensorArray1[index], ioSensorArray2[index], ioTriggerArray1[index], ioTriggerArray2[index]); AddCustomDevice((IDevice)loadLockDevice, "LoadLockDevice", loadLockDevice.GetType()); } if (DisableSignalTower) DeviceModel.SignalTower.CustomSignalTower(PathManager.GetCfgDir() + "SignalTower.xml"); //DeviceModel.TurnOverStation; AddCustomDevice((IDevice)new EquipmentMonitor(), "EquipmentMonitor", typeof(EquipmentMonitor));//这里涉及RT状态的修改 file报错 foreach (object childNode in DeviceModelNodes.ChildNodes) { XmlElement xmlElement = childNode as XmlElement; } AddCustomDevice(new SimpleBuffer("Buffer"), "Buffer", typeof(SimpleBuffer)); OP.Subscribe(OperationName.ResetDevice, new Func(InvokeResetDevice)); OP.Subscribe("DeviceOperation", new Func(InvokeDeviceOperation)); OP.Subscribe("SetManualScanCode", new Func(InvokeSetManualScanCode)); OP.Subscribe("Scan", new Func(InvokeScan)); OP.Subscribe("Write", new Func(InvokeWrite)); OP.Subscribe("ReadCarrierId", new Func(InvokeScan)); OP.Subscribe("ReadFoupRFID", new Func(InvokeReadRfid)); OP.Subscribe("WriteFoupRFID", new Func(InvokeWriteRfid)); RR751.OnSlotMapRead += new Action(Robot_OnSlotMapRead); return true; } private bool InvokeWrite(string arg1, object[] args) { string reason; if (GetRfidReader(args[0].ToString()).Write(args[1].ToString(), out reason)) return true; EV.PostWarningLog(args[0].ToString(), "fail to write RFID, " + reason); return false; } private bool InvokeWriteRfid(string arg1, object[] arg2) { string reason; if (GetRfidReader(arg2[0].ToString()).Write(arg2[1].ToString(), out reason)) return true; EV.PostWarningLog(arg1, "fail to write RFID, " + reason); return false; } private bool InvokeReadRfid(string arg1, object[] arg2) { string reason; if (GetRfidReader(arg2[0].ToString()).Read(out reason)) return true; EV.PostWarningLog(arg1, "fail to read RFID, " + reason); return false; } private bool InvokeScan(string arg1, object[] args) => DEVICE.GetDevice(args[0].ToString()).ReadCarrierID(); private bool InvokeSetManualScanCode(string arg1, object[] args) { DEVICE.GetDevice(args[0].ToString()).OnCarrierIdRead(args[1].ToString()); return true; } private bool InvokeOffline(string arg1, object[] arg2) => true; private void Robot_OnSlotMapRead(ModuleName module, string slotMap) => DEVICE.GetDevice(module.ToString())?.OnSlotMapRead(slotMap); private bool InvokeDeviceOperation(string arg1, object[] args) { string str = ""; string cmd = ""; try { str = (string)args[0]; cmd = (string)args[1]; if ((bool)DATA.Poll(ModuleName.System.ToString(), "IsMaintenanceMode")) { EV.PostMessage("System", EventEnum.DefaultWarning, (object)string.Format("System in maintenance, can not execute {0}{1}", (object)str, (object)cmd)); return false; } object[] objArray = new object[args.Length - 2]; for (int index = 2; index < args.Length; ++index) objArray[index - 2] = (object)args[index].ToString(); if (str == "SignalTower") { OP.DoOperation("System.SignalTower." + cmd); return true; } if (ModuleHelper.IsLoadPort(ModuleHelper.Converter(str))) OP.DoOperation(str + "." + cmd, objArray); else DeviceCmd(str, cmd, objArray); } catch (Exception ex) { LogObject.Error("DeviceManager",ex); EV.PostMessage("System", EventEnum.DefaultWarning, (object)string.Format("Invalid parameters, can not execute {0}{1}", (object)str, (object)cmd)); return false; } return true; } private bool InvokeResetDevice(string arg1, object[] arg2) { Singleton.Instance.PostMsg.MSG>(DeviceEntityT.MSG.RESET); return true; } private void DeviceCmd(string name, string cmd, params object[] args) => DEVICE.Do(string.Format("{0}.{1}", (object)name, (object)cmd), 0, true, args); } }