TruPlasmaRF_Ethercat.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using MECF.Framework.Common.Device.Bases;
  7. using MECF.Framework.Common.Equipment;
  8. using System;
  9. using System.Diagnostics;
  10. using Venus_Core;
  11. using Venus_RT.Devices.AdLinkEthercat;
  12. namespace Venus_RT.Devices
  13. {
  14. public class TruPlasmaRF_Ethercat : RfPowerBase
  15. {
  16. //Int32 v_card_name = 0;
  17. Int32 v_board_id = -1;
  18. //Int32 v_StartAxisID = 0;
  19. Int32 BUS_No = 0;
  20. Int32 Mod_ID = 0;
  21. private readonly VenusDevice _device;
  22. private Stopwatch _stopWatch = new Stopwatch();
  23. private JetPMBase _chamber;
  24. public new AITRfData DeviceData =>
  25. new AITRfData
  26. {
  27. Module = Module,
  28. DeviceName = Name,
  29. ScalePower = ScalePower,
  30. ForwardPower = ForwardPower,
  31. ReflectPower = ReflectPower,
  32. IsRfOn = IsPowerOn,
  33. PowerSetPoint = PowerSetPoint,
  34. };
  35. public TruPlasmaRF_Ethercat(ModuleName mod, VenusDevice device, Int32 board_id) : base(mod.ToString(), device.ToString())
  36. {
  37. _device = device;
  38. v_board_id = board_id;
  39. _stopWatch.Start();
  40. _chamber = DEVICE.GetDevice<JetPMBase>(Module);
  41. }
  42. public override bool Initialize()
  43. {
  44. base.Initialize();
  45. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  46. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetPowerOnOff}", (out string reason, int time, object[] param) =>
  47. {
  48. SetPowerOnOff(Convert.ToBoolean((string)param[0]), out reason);
  49. return true;
  50. });
  51. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetPower}", (out string reason, int time, object[] param) =>
  52. {
  53. reason = "";
  54. ushort val = Convert.ToUInt16(param[0]);
  55. SetPower(val);
  56. return true;
  57. });
  58. return true;
  59. }
  60. public override void Monitor()
  61. {
  62. if (_stopWatch.ElapsedMilliseconds > 50)
  63. {
  64. IsPowerOn = GetPowerOnOff();
  65. ForwardPower = GetPower();
  66. ReflectPower=GetReflectPower();
  67. _stopWatch.Restart();
  68. if (IsPowerOn == true && _chamber != null && _chamber.RFInterlock(_device) == false)
  69. {
  70. SetPowerOnOff(false, out _);
  71. }
  72. }
  73. }
  74. public override bool SetPowerOnOff(bool on, out string str)
  75. {
  76. str = "";
  77. Int32 ret;
  78. UInt16 ByteOffset = 0;
  79. UInt16 Size = 1;
  80. uint Value = 0;
  81. string operation;
  82. if (on)
  83. {
  84. operation = "ON";
  85. Value = 1;
  86. ret = APS168.APS_set_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, Value);
  87. }
  88. else
  89. {
  90. operation = "OFF";
  91. ret = APS168.APS_set_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, Value);
  92. }
  93. if (ret != 0)
  94. {
  95. LOG.Write(eEvent.ERR_RF, Module, $"{_device} Set Power {operation} Fail!");
  96. }
  97. else
  98. {
  99. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Set Power {operation} Success!");
  100. }
  101. return true;
  102. }
  103. public bool GetPowerOnOff()
  104. {
  105. Int32 ret;
  106. UInt16 ByteOffset = 0;
  107. UInt16 Size = 1;
  108. uint Value = 0;
  109. ret = APS168.APS_get_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, ref Value);
  110. if (ret != 0)
  111. {
  112. LOG.Write(eEvent.ERR_RF, Module, $"{_device} Get Power ON/OFF Fail!");
  113. }
  114. else
  115. {
  116. //LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Get Power ON/OFF Success!");
  117. if (Value == 3)
  118. {
  119. return true;
  120. }
  121. }
  122. return false;
  123. }
  124. public override void SetPower(float val)
  125. {
  126. Int32 ret;
  127. UInt16 ByteOffset = 2;
  128. UInt16 Size = 4;
  129. uint Value = 0;
  130. byte[] byteArray = BitConverter.GetBytes(val);
  131. Value = BitConverter.ToUInt32(byteArray, 0);
  132. ret = APS168.APS_set_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, Value);
  133. if (ret != 0)
  134. {
  135. LOG.Write(eEvent.ERR_RF, Module, $"{_device} Set Power Setpoint {val} Fail!");
  136. }
  137. else
  138. {
  139. PowerSetPoint = val;
  140. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Set Power Setpoint {val} Success!");
  141. }
  142. }
  143. public float GetPower()
  144. {
  145. Int32 ret;
  146. Int32 BUS_No = 0;
  147. UInt16 ByteOffset = 6;
  148. UInt16 Size = 4;
  149. uint Value = 0;
  150. ret = APS168.APS_get_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, ref Value);
  151. if (ret != 0)
  152. {
  153. LOG.Write(eEvent.ERR_RF, Module, $"{_device} Get Power Setpoint Fail!");
  154. }
  155. else
  156. {
  157. //LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Get Power Setpoint Success!");
  158. }
  159. return BitConverter.ToSingle(BitConverter.GetBytes(Value), 0);
  160. }
  161. public float GetReflectPower()
  162. {
  163. Int32 ret;
  164. Int32 BUS_No = 0;
  165. UInt16 ByteOffset = 10;
  166. UInt16 Size = 4;
  167. uint Value = 0;
  168. ret = APS168.APS_get_field_bus_pdo(v_board_id, BUS_No, ByteOffset, Size, ref Value);
  169. if (ret != 0)
  170. {
  171. //LOG.Write(eEvent.ERR_RF, Module, $"{_device} Get Reflect Power Fail");
  172. }
  173. else
  174. {
  175. return BitConverter.ToSingle(BitConverter.GetBytes(Value), 0); ;
  176. }
  177. return -1;
  178. }
  179. public override void SetPulseMode(bool on)
  180. {
  181. Int32 ret = 0;
  182. Byte[] Data = new Byte[32];
  183. UInt16 OD_index = 0x7001;
  184. UInt16 OD_Subindex = 1;
  185. UInt32 DataLength = 1;
  186. UInt32 TimeOut = 10000;
  187. Int32 Datatemp;
  188. UInt32 Flags = 0;
  189. string operation;
  190. if (on)
  191. {
  192. operation = "Enable";
  193. Datatemp = 1;
  194. }
  195. else
  196. {
  197. operation = "Disable";
  198. Datatemp = 0;
  199. }
  200. for (Int32 i = 0; i < 8; i++)
  201. {
  202. Data[i] = (Byte)((Datatemp >> (i * 8)) & 0xFF);
  203. }
  204. ret = APS168.APS_set_field_bus_sdo(v_board_id, BUS_No, Mod_ID, OD_index, OD_Subindex, Data, DataLength, TimeOut, Flags);
  205. if (ret != 0)
  206. {
  207. LOG.Write(eEvent.ERR_RF, Module, $"{_device} {operation} Pulsing Mode Fail!");
  208. }
  209. else
  210. {
  211. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} {operation} Pulsing Mode Success!");
  212. }
  213. }
  214. public override void SetPulseRateFreq(int nFreq)
  215. {
  216. if (nFreq < 0)
  217. {
  218. return;
  219. }
  220. float f = Convert.ToSingle(nFreq);
  221. Int32 ret = 0;
  222. Byte[] Data = new Byte[32];
  223. UInt16 OD_index = 0x7008;
  224. UInt16 OD_Subindex = 1;
  225. UInt32 DataLength = 32;
  226. UInt32 TimeOut = 10000;
  227. UInt32 Flags = 0;
  228. Data = BitConverter.GetBytes(f);
  229. ret = APS168.APS_set_field_bus_sdo(v_board_id, BUS_No, Mod_ID, OD_index, OD_Subindex, Data, DataLength, TimeOut, Flags);
  230. if (ret != 0)
  231. {
  232. LOG.Write(eEvent.ERR_RF, Module, $"{_device} Set Pulse Rate Freq{nFreq} Fail!");
  233. }
  234. else
  235. {
  236. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Set Pulse Rate Freq{nFreq} Success!");
  237. }
  238. }
  239. public override void SetPulseDutyCycle(int percentage)
  240. {
  241. if (percentage <= 10 && percentage >= 90)
  242. {
  243. return;
  244. }
  245. float f = Convert.ToSingle(percentage);
  246. Int32 ret = 0;
  247. Byte[] Data = new Byte[32];
  248. UInt16 OD_index = 0x7008;
  249. UInt16 OD_Subindex = 2;
  250. UInt32 DataLength = 32;
  251. UInt32 TimeOut = 10000;
  252. UInt32 Flags = 0;
  253. Data = BitConverter.GetBytes(f);
  254. ret = APS168.APS_set_field_bus_sdo(v_board_id, BUS_No, Mod_ID, OD_index, OD_Subindex, Data, DataLength, TimeOut, Flags);
  255. if (ret != 0)
  256. {
  257. LOG.Write(eEvent.ERR_RF, Module, $"{_device} Set Pulse Duty Cycle {percentage} Fail!");
  258. }
  259. else
  260. {
  261. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"{_device} Set Pulse Duty Cycle {percentage} Success!");
  262. }
  263. }
  264. }
  265. }