using Aitex.Core.RT.Device; using Aitex.Core.RT.Device.Unit; using Aitex.Core.RT.Event; using Aitex.Core.Utilities; using FurnaceRT.Devices; using MECF.Framework.Common.Event; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using static Aitex.Core.RT.Device.Unit.IoBoat; namespace FurnaceRT.Equipments.Boats { public partial class BoatModule { [Tag("AlarmSignalStepperMotorAlarm")] public IoAlarmSignal SensorStepperMotorAlarm { get; set; } private List _triggeredAlarmList = new List(); private int _alarmNumber; public IoShutter ShutterDevice { get; set; } public IoAPC APCDevice { get; set; } public IoFurnaceMotor ZAxisDevice { get; set; } public IoFurnaceMotor RAxisDevice { get; set; } [Tag("SensorVAC1")] public IoSensor SensorVAC1 { get; set; } [Tag("SensorVAC2")] public IoSensor SensorVAC2 { get; set; } [Tag("SensorVAC3")] public IoSensor SensorVAC3 { get; set; } [Tag("SensorVAC4")] public IoSensor SensorVAC4 { get; set; } [Tag("SensorVAC5")] public IoSensor SensorVAC5 { get; set; } [Tag("SensorVAC6")] public IoSensor SensorVAC6 { get; set; } [Tag("SensorWaferRobotEX1AxisHomePosition")] public IoSensor SensorWaferRobotEX1AxisHomePosition { get; set; } [Tag("SensorWaferRobotEX2AxisHomePosition")] public IoSensor SensorWaferRobotEX2AxisHomePosition { get; set; } [Tag("SensorPS13LStatus")] public IoSensor SensorPS13LStatus { get; set; } [Tag("SensorBoatUnloadInterlock")] public IoSensor SensorBoatUnloadInterlock { get; set; } public void InitDevice() { Func _isTagAttribute = attribute => attribute is TagAttribute; Func _hasTagAttribute = mi => mi.GetCustomAttributes(false).Any(_isTagAttribute); var properties = this.GetType().GetProperties().Where(_hasTagAttribute); foreach (var field in properties) { TagAttribute tag = field.GetCustomAttributes(false).First(_isTagAttribute) as TagAttribute; IDevice device = DEVICE.GetDevice($"{Module}.{tag.Tag}"); if (device == null) device = DEVICE.GetDevice($"PM1.{tag.Tag}"); if (device != null) { device.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged; PropertyInfo pi = (PropertyInfo)field; var convertedValue = Convert.ChangeType(device, pi.PropertyType); System.Diagnostics.Debug.Assert(convertedValue != null); pi.SetValue(this, convertedValue); } } ShutterDevice = DEVICE.GetDevice($"PM1.Shutter"); this.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged; if (ShutterDevice != null) ShutterDevice.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged; APCDevice = DEVICE.GetDevice($"PM1.APC"); ZAxisDevice = DEVICE.GetDevice($"PM1.BoatElevatorServo"); RAxisDevice = DEVICE.GetDevice($"PM1.BoatRotationServo"); System.Diagnostics.Debug.Assert(ZAxisDevice != null); System.Diagnostics.Debug.Assert(RAxisDevice != null); System.Diagnostics.Debug.Assert(ShutterDevice != null); System.Diagnostics.Debug.Assert(SensorVAC1 != null); System.Diagnostics.Debug.Assert(SensorVAC2 != null); System.Diagnostics.Debug.Assert(SensorVAC3 != null); System.Diagnostics.Debug.Assert(SensorPS13LStatus != null); System.Diagnostics.Debug.Assert(SensorBoatUnloadInterlock != null); } public void OnModuleDeviceAlarmStateChanged(string deviceId, AlarmEventItem alarmItem) { if (alarmItem.IsTriggered) { EventLevel level = alarmItem.Level; _triggeredAlarmList.Add(alarmItem); if (level == EventLevel.Alarm) { try { EV.PostAlarmLog(Module, alarmItem); } catch (Exception ex) { EV.WriteEvent(ex.Message.ToString()); } } else { EV.PostWarningLog(Module, alarmItem); } } else { } } public void SetZAxisSpeed(float speed) { //BoatDevice.SetZAxisSpeed(speed); } public void SetRAxisSpeed(float speed) { //BoatDevice.SetRAxisSpeed(speed); } public void SetRAxisIntervalPosition(float position) { //BoatDevice.SetRAxisIntervalPosition(position); } public void BoatZAxisStop() { ZAxisDevice.ServoStop(); } public void BoatRAxisStop() { RAxisDevice.ServoStop(); } private bool SetBoatZAxisSpeed(out string reason, int time, object[] param) { reason = string.Empty; SetZAxisSpeed(Convert.ToSingle(param[0].ToString())); return true; } private bool SetBoatRAxisSpeed(out string reason, int time, object[] param) { reason = string.Empty; SetRAxisSpeed(Convert.ToSingle(param[0].ToString())); return true; } private bool SetBoatRAxisAngle(out string reason, int time, object[] param) { reason = string.Empty; SetRAxisIntervalPosition(Convert.ToSingle(param[0].ToString())); return true; } private bool SetBoatZAxisStop(out string reason, int time, object[] param) { reason = string.Empty; BoatZAxisStop(); return true; } private bool SetBoatRAxisStop(out string reason, int time, object[] param) { reason = string.Empty; BoatRAxisStop(); return true; } } }