VirgoSignalTower.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.Device.Bases;
  5. using MECF.Framework.Common.Equipment;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using VirgoRT.Device.YASKAWA;
  12. using VirgoRT.Devices.EFEM;
  13. using VirgoRT.Modules;
  14. namespace VirgoRT.Devices
  15. {
  16. class VirgoSingalLight : SignalLightBase
  17. {
  18. public MECF.Framework.Common.Device.Bases.LightType Type { get; set; }
  19. public Efem EfemController { get; set; }
  20. private F_TRIG _trigError = new F_TRIG();
  21. private bool _isInit;
  22. private TowerLightStatus _preState = TowerLightStatus.Unknown;
  23. public VirgoSingalLight(string module, string name) : base(module, name)
  24. {
  25. _isInit = true;
  26. }
  27. protected override void SetOn()
  28. {
  29. SetLight(TowerLightStatus.On);
  30. }
  31. protected override void SetOff()
  32. {
  33. SetLight(TowerLightStatus.Off);
  34. }
  35. protected override void SetBlinking(bool token)
  36. {
  37. SetLight(TowerLightStatus.Blinking);
  38. }
  39. private bool SetSignalLight(MECF.Framework.Common.Device.Bases.LightType type, TowerLightStatus setpoint)
  40. {
  41. VirgoRT.LightType virgoType;
  42. switch (type)
  43. {
  44. case MECF.Framework.Common.Device.Bases.LightType.Red:
  45. virgoType = LightType.RED;
  46. break;
  47. case MECF.Framework.Common.Device.Bases.LightType.Yellow:
  48. virgoType = LightType.YELLOW;
  49. break;
  50. case MECF.Framework.Common.Device.Bases.LightType.Green:
  51. virgoType = LightType.GREEN;
  52. break;
  53. case MECF.Framework.Common.Device.Bases.LightType.White:
  54. virgoType = LightType.WHITE;
  55. break;
  56. case MECF.Framework.Common.Device.Bases.LightType.Blue:
  57. virgoType = LightType.BLUE;
  58. break;
  59. case MECF.Framework.Common.Device.Bases.LightType.Buzzer:
  60. case MECF.Framework.Common.Device.Bases.LightType.Buzzer1:
  61. virgoType = LightType.BUZZER1;
  62. break;
  63. default:
  64. virgoType = LightType.BUZZER1;
  65. break;
  66. }
  67. VirgoRT.LightStatus virgoSetpoint;
  68. switch (setpoint)
  69. {
  70. case TowerLightStatus.Blinking:
  71. virgoSetpoint = LightStatus.BLINK;
  72. break;
  73. case TowerLightStatus.On:
  74. virgoSetpoint = LightStatus.ON;
  75. break;
  76. case TowerLightStatus.Off:
  77. virgoSetpoint = LightStatus.OFF;
  78. break;
  79. default:
  80. virgoSetpoint = LightStatus.OFF;
  81. break;
  82. }
  83. EfemController.SetLamp(virgoType, virgoSetpoint);
  84. return true;
  85. }
  86. private void SetLight(TowerLightStatus setpoint)
  87. {
  88. try
  89. {
  90. if (setpoint != _preState || _isInit)
  91. {
  92. _trigError.CLK = SetSignalLight(Type, setpoint);
  93. if (_trigError.Q)
  94. {
  95. //EV.PostWarningLog(Module, $"Set {Type} signal light {setpoint} error, {reason}");
  96. }
  97. if (_trigError.M)
  98. {
  99. _isInit = false;
  100. _preState = setpoint;
  101. }
  102. }
  103. }
  104. catch (Exception ex)
  105. {
  106. LOG.Write(ex);
  107. }
  108. }
  109. public void ResetData()
  110. {
  111. _isInit = true;
  112. }
  113. public override void Reset()
  114. {
  115. _trigError.RST = true;
  116. base.Reset();
  117. }
  118. }
  119. public class VirgoSignalTower : SignalTowerBase
  120. {
  121. private Efem _efem;
  122. private List<VirgoSingalLight> _lights = new List<VirgoSingalLight>();
  123. public VirgoSignalTower(string module, string name) : base("", "")
  124. {
  125. base.Module = module;
  126. base.Name = name;
  127. base.Display = name;
  128. base.DeviceID = "";
  129. }
  130. public override bool Initialize()
  131. {
  132. base.Initialize();
  133. if (_efem == null)
  134. {
  135. _efem = Singleton<RouteManager>.Instance.EFEM.EfemDevice;
  136. }
  137. CustomSignalTower();
  138. return true;
  139. }
  140. //重新连接EFEM之后,需要重置灯塔
  141. public void ResetData()
  142. {
  143. foreach (var rorzeSingalLight in _lights)
  144. {
  145. rorzeSingalLight.ResetData();
  146. }
  147. }
  148. public override SignalLightBase CreateLight(MECF.Framework.Common.Device.Bases.LightType type)
  149. {
  150. var light = new VirgoSingalLight(ModuleName.System.ToString(), $"SignalLight{type}")
  151. { Type = type, EfemController = _efem };
  152. _lights.Add(light);
  153. return light;
  154. }
  155. }
  156. }