BoatModuleDevice.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Device.Unit;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.Utilities;
  5. using FurnaceRT.Devices;
  6. using MECF.Framework.Common.Event;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Reflection;
  11. using static Aitex.Core.RT.Device.Unit.IoBoat;
  12. namespace FurnaceRT.Equipments.Boats
  13. {
  14. public partial class BoatModule
  15. {
  16. [Tag("AlarmSignalStepperMotorAlarm")]
  17. public IoAlarmSignal SensorStepperMotorAlarm { get; set; }
  18. private List<AlarmEventItem> _triggeredAlarmList = new List<AlarmEventItem>();
  19. private int _alarmNumber;
  20. public IoShutter ShutterDevice { get; set; }
  21. public IoAPC APCDevice { get; set; }
  22. public IoFurnaceMotor ZAxisDevice { get; set; }
  23. public IoFurnaceMotor RAxisDevice { get; set; }
  24. [Tag("SensorVAC1")]
  25. public IoSensor SensorVAC1 { get; set; }
  26. [Tag("SensorVAC2")]
  27. public IoSensor SensorVAC2 { get; set; }
  28. [Tag("SensorVAC3")]
  29. public IoSensor SensorVAC3 { get; set; }
  30. [Tag("SensorVAC4")]
  31. public IoSensor SensorVAC4 { get; set; }
  32. [Tag("SensorVAC5")]
  33. public IoSensor SensorVAC5 { get; set; }
  34. [Tag("SensorVAC6")]
  35. public IoSensor SensorVAC6 { get; set; }
  36. [Tag("SensorWaferRobotEX1AxisHomePosition")]
  37. public IoSensor SensorWaferRobotEX1AxisHomePosition { get; set; }
  38. [Tag("SensorWaferRobotEX2AxisHomePosition")]
  39. public IoSensor SensorWaferRobotEX2AxisHomePosition { get; set; }
  40. [Tag("SensorPS13LStatus")]
  41. public IoSensor SensorPS13LStatus { get; set; }
  42. [Tag("SensorBoatUnloadInterlock")]
  43. public IoSensor SensorBoatUnloadInterlock { get; set; }
  44. public void InitDevice()
  45. {
  46. Func<object, bool> _isTagAttribute = attribute => attribute is TagAttribute;
  47. Func<MemberInfo, bool> _hasTagAttribute = mi => mi.GetCustomAttributes(false).Any(_isTagAttribute);
  48. var properties = this.GetType().GetProperties().Where(_hasTagAttribute);
  49. foreach (var field in properties)
  50. {
  51. TagAttribute tag = field.GetCustomAttributes(false).First(_isTagAttribute) as TagAttribute;
  52. IDevice device = DEVICE.GetDevice<IDevice>($"{Module}.{tag.Tag}");
  53. if (device == null)
  54. device = DEVICE.GetDevice<IDevice>($"PM1.{tag.Tag}");
  55. if (device != null)
  56. {
  57. device.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged;
  58. PropertyInfo pi = (PropertyInfo)field;
  59. var convertedValue = Convert.ChangeType(device, pi.PropertyType);
  60. System.Diagnostics.Debug.Assert(convertedValue != null);
  61. pi.SetValue(this, convertedValue);
  62. }
  63. }
  64. ShutterDevice = DEVICE.GetDevice<IoShutter>($"PM1.Shutter");
  65. this.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged;
  66. if (ShutterDevice != null)
  67. ShutterDevice.OnDeviceAlarmStateChanged += OnModuleDeviceAlarmStateChanged;
  68. APCDevice = DEVICE.GetDevice<IoAPC>($"PM1.APC");
  69. ZAxisDevice = DEVICE.GetDevice<IoFurnaceMotor>($"PM1.BoatElevatorServo");
  70. RAxisDevice = DEVICE.GetDevice<IoFurnaceMotor>($"PM1.BoatRotationServo");
  71. System.Diagnostics.Debug.Assert(ZAxisDevice != null);
  72. System.Diagnostics.Debug.Assert(RAxisDevice != null);
  73. System.Diagnostics.Debug.Assert(ShutterDevice != null);
  74. System.Diagnostics.Debug.Assert(SensorVAC1 != null);
  75. System.Diagnostics.Debug.Assert(SensorVAC2 != null);
  76. System.Diagnostics.Debug.Assert(SensorVAC3 != null);
  77. System.Diagnostics.Debug.Assert(SensorPS13LStatus != null);
  78. System.Diagnostics.Debug.Assert(SensorBoatUnloadInterlock != null);
  79. }
  80. public void OnModuleDeviceAlarmStateChanged(string deviceId, AlarmEventItem alarmItem)
  81. {
  82. if (alarmItem.IsTriggered)
  83. {
  84. EventLevel level = alarmItem.Level;
  85. _triggeredAlarmList.Add(alarmItem);
  86. if (level == EventLevel.Alarm)
  87. {
  88. try
  89. {
  90. EV.PostAlarmLog(Module, alarmItem);
  91. }
  92. catch (Exception ex)
  93. {
  94. EV.WriteEvent(ex.Message.ToString());
  95. }
  96. }
  97. else
  98. {
  99. EV.PostWarningLog(Module, alarmItem);
  100. }
  101. }
  102. else
  103. {
  104. }
  105. }
  106. public void SetZAxisSpeed(float speed)
  107. {
  108. //BoatDevice.SetZAxisSpeed(speed);
  109. }
  110. public void SetRAxisSpeed(float speed)
  111. {
  112. //BoatDevice.SetRAxisSpeed(speed);
  113. }
  114. public void SetRAxisIntervalPosition(float position)
  115. {
  116. //BoatDevice.SetRAxisIntervalPosition(position);
  117. }
  118. public void BoatZAxisStop()
  119. {
  120. ZAxisDevice.ServoStop();
  121. }
  122. public void BoatRAxisStop()
  123. {
  124. RAxisDevice.ServoStop();
  125. }
  126. private bool SetBoatZAxisSpeed(out string reason, int time, object[] param)
  127. {
  128. reason = string.Empty;
  129. SetZAxisSpeed(Convert.ToSingle(param[0].ToString()));
  130. return true;
  131. }
  132. private bool SetBoatRAxisSpeed(out string reason, int time, object[] param)
  133. {
  134. reason = string.Empty;
  135. SetRAxisSpeed(Convert.ToSingle(param[0].ToString()));
  136. return true;
  137. }
  138. private bool SetBoatRAxisAngle(out string reason, int time, object[] param)
  139. {
  140. reason = string.Empty;
  141. SetRAxisIntervalPosition(Convert.ToSingle(param[0].ToString()));
  142. return true;
  143. }
  144. private bool SetBoatZAxisStop(out string reason, int time, object[] param)
  145. {
  146. reason = string.Empty;
  147. BoatZAxisStop();
  148. return true;
  149. }
  150. private bool SetBoatRAxisStop(out string reason, int time, object[] param)
  151. {
  152. reason = string.Empty;
  153. BoatRAxisStop();
  154. return true;
  155. }
  156. }
  157. }