TruPlasmaRF.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 Aitex.Core.RT.SCCore;
  7. using Aitex.Core.RT.Tolerance;
  8. using MECF.Framework.Common.Communications;
  9. using MECF.Framework.Common.DataCenter;
  10. using MECF.Framework.Common.Device.Bases;
  11. using MECF.Framework.Common.Equipment;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Text.RegularExpressions;
  17. using System.Threading.Tasks;
  18. using Venus_Core;
  19. namespace Venus_RT.Devices
  20. {
  21. public class TruPlasmaRF : RfPowerBase
  22. {
  23. private readonly AsyncSerialPort _serial;
  24. public TruPlasmaRF(ModuleName mod, VenusDevice device) : base(mod.ToString(), device.ToString())
  25. {
  26. var portNum = SC.GetStringValue(device == VenusDevice.Rf ? $"{mod}.Rf.Port" : $"{mod}.BiasRf.Port");
  27. _serial = new AsyncSerialPort(portNum, 9600, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "\r\r");
  28. }
  29. public override bool Initialize()
  30. {
  31. base.Initialize();
  32. if (_serial.Open())
  33. {
  34. _serial.OnDataChanged += SerialPortDataReceived;
  35. _serial.OnErrorHappened += SerialPortErrorOccurred;
  36. }
  37. else
  38. {
  39. LOG.Write(eEvent.ERR_RF, Module, "Tru 射频发生器串口无法打开");
  40. return false;
  41. }
  42. return true;
  43. }
  44. private void SerialPortDataReceived(string str)
  45. {
  46. }
  47. private void SerialPortErrorOccurred(string obj)
  48. {
  49. LOG.Write(eEvent.ERR_RF, Module, $"Tru 射频串口出错, [{obj}]");
  50. }
  51. public override void SetPower(float val)
  52. {
  53. var power = !_scEnableCalibration.BoolValue ? val : CalibrationData(val, true);
  54. List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x06, 0x00, 0x01, 0x00, 0x04 };
  55. byte[] valueBytes = BitConverter.GetBytes((int)val);
  56. baseBytes.AddRange(valueBytes);
  57. baseBytes = CRC16(baseBytes.ToArray());
  58. baseBytes.Add(0x55);
  59. _serial.Write(baseBytes.ToArray());
  60. }
  61. public override bool SetPowerOnOff(bool on, out string str)
  62. {
  63. str = "";
  64. var _chamber = DEVICE.GetDevice<JetPMBase>(Module);
  65. if (on && !_chamber.CheckGeneratorAndHVInterlock(VenusDevice.Rf))
  66. {
  67. return false;
  68. }
  69. List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6F, 0x00, 0x01, 0x00, 0x07 };
  70. if (on == true)
  71. {
  72. baseBytes.AddRange(new List<byte> { 0x01, 0x00, 0x00, 0x00 });
  73. }
  74. else
  75. {
  76. baseBytes.AddRange(new List<byte> { 0x00, 0x00, 0x00, 0x00 });
  77. }
  78. baseBytes = CRC16(baseBytes.ToArray());
  79. baseBytes.Add(0x55);
  80. _serial.Write(baseBytes.ToArray());
  81. return true;
  82. }
  83. public override void SetPulseMode(bool on)
  84. {
  85. List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6A, 0x01, 0x01, 0x00, 0x04 };
  86. if (on == true)
  87. {
  88. baseBytes.AddRange(new List<byte> { 0x01, 0x00, 0x00, 0x00 });
  89. }
  90. else
  91. {
  92. baseBytes.AddRange(new List<byte> { 0x00, 0x00, 0x00, 0x00 });
  93. }
  94. baseBytes = CRC16(baseBytes.ToArray());
  95. baseBytes.Add(0x55);
  96. _serial.Write(baseBytes.ToArray());
  97. }
  98. public override void SetPulseRateFreq(int nFreq)
  99. {
  100. if (nFreq > 0)
  101. {
  102. List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6C, 0x01, 0x01, 0x00, 0x04 };
  103. byte[] valueBytes = BitConverter.GetBytes(nFreq);
  104. baseBytes.AddRange(valueBytes);
  105. baseBytes = CRC16(baseBytes.ToArray());
  106. baseBytes.Add(0x55);
  107. _serial.Write(baseBytes.ToArray());
  108. }
  109. else
  110. {
  111. LOG.Write(eEvent.ERR_RF, Module, $"{Name},SetPulseRateFreq() parameter error: {nFreq}");
  112. }
  113. }
  114. public override void SetPulseDutyCycle(int percentage)
  115. {
  116. if (percentage >= 10 && percentage <= 90)
  117. {
  118. List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6D, 0x01, 0x01, 0x00, 0x04 };
  119. byte[] valueBytes = BitConverter.GetBytes(percentage);
  120. baseBytes.AddRange(valueBytes);
  121. baseBytes = CRC16(baseBytes.ToArray());
  122. baseBytes.Add(0x55);
  123. _serial.Write(baseBytes.ToArray());
  124. }
  125. else
  126. {
  127. LOG.Write(eEvent.ERR_RF, Module, $"{Name},SetPulseDutyCycle() parameter error: {percentage}");
  128. }
  129. }
  130. #region 霍廷格RF协议crc-16/CCITT-FALSE校验
  131. private bool CRC16(byte[] buffer, ref byte[] ResCRC16) // crc-16/CCITT-FALSE,判断校验
  132. {
  133. bool status = false;
  134. ushort crc = 0xFFFF;
  135. int size = buffer.Length; //计算待计算的数据长度
  136. int i = 0;
  137. if (size > 0)
  138. {
  139. while (size-- > 0)
  140. {
  141. crc = (ushort)((crc >> 8) | (crc << 8));
  142. crc ^= buffer[i++];
  143. crc ^= (ushort)(((byte)crc) >> 4);
  144. crc ^= (ushort)(crc << 12);
  145. crc ^= (ushort)((crc & 0xff) << 5);
  146. }
  147. }
  148. //判断输入的ResCRC16与计算出来的是否一致
  149. if (ResCRC16[0] == (byte)((crc >> 8) & 0xff) && ResCRC16[1] == (byte)(crc & 0xff))
  150. {
  151. status = true;
  152. }
  153. return status;
  154. }
  155. private List<byte> CRC16(byte[] buffer) // crc-16/CCITT-FALSE,补全两个字节
  156. {
  157. ushort crc = 0xFFFF;
  158. int size = buffer.Length; //计算待计算的数据长度
  159. int i = 0;
  160. if (size > 0)
  161. {
  162. while (size-- > 0)
  163. {
  164. crc = (ushort)((crc >> 8) | (crc << 8));
  165. crc ^= buffer[i++];
  166. crc ^= (ushort)(((byte)crc) >> 4);
  167. crc ^= (ushort)(crc << 12);
  168. crc ^= (ushort)((crc & 0xff) << 5);
  169. }
  170. }
  171. var byteList = buffer.ToList();
  172. byteList.Add((byte)(crc & 0xff));
  173. byteList.Add((byte)((crc >> 8) & 0xff));
  174. return byteList;
  175. }
  176. #endregion
  177. }
  178. }