TruPlasmaRF.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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 Aitex.Core.UI.Control;
  9. using Aitex.Core.Util;
  10. using CommunityToolkit.HighPerformance.Buffers;
  11. using MECF.Framework.Common.Communications;
  12. using MECF.Framework.Common.DataCenter;
  13. using MECF.Framework.Common.Device.Bases;
  14. using MECF.Framework.Common.Equipment;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.Diagnostics;
  19. using System.Linq;
  20. using System.ServiceModel.Channels;
  21. using Venus_Core;
  22. namespace Venus_RT.Devices
  23. {
  24. public class TruPlasmaRF : RfPowerBase
  25. {
  26. private readonly AsyncSerialPort _serial;
  27. private List<byte> buffer = new List<byte>(4096);
  28. public TruPlasmaRF(ModuleName mod, VenusDevice device) : base(mod.ToString(), device.ToString())
  29. {
  30. this.Status = GeneratorStatus.Unknown;
  31. var portNum = SC.GetStringValue(device == VenusDevice.Rf ? $"{mod}.Rf.Port" : $"{mod}.BiasRf.Port");
  32. _serial = new AsyncSerialPort(portNum, 9600, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "/r", false);
  33. }
  34. public override bool Initialize()
  35. {
  36. base.Initialize();
  37. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  38. if (_serial.Open())
  39. {
  40. _serial.OnBinaryDataChanged += SerialPortDataReceived;
  41. _serial.OnErrorHappened += SerialPortErrorOccurred;
  42. ResetCommand();
  43. getcontrol();
  44. SetPulseMode(false);
  45. }
  46. else
  47. {
  48. LOG.Write(eEvent.ERR_RF, Module, "Tru 射频发生器串口无法打开");
  49. return false;
  50. }
  51. return true;
  52. }
  53. public new AITRfData DeviceData =>
  54. new AITRfData
  55. {
  56. Module = Module,
  57. DeviceName = Name,
  58. ScalePower = ScalePower,
  59. ForwardPower = ForwardPower,
  60. ReflectPower = ReflectPower,
  61. IsRfOn = IsPowerOn,
  62. PowerSetPoint = PowerSetPoint,
  63. };
  64. private void SerialPortDataReceived(byte[] rawMessage)
  65. {
  66. try
  67. {
  68. buffer.AddRange(rawMessage);
  69. while (buffer.Count >= 18) //至少包含ACK帧头(1字节)、长度、校验位(17或12字节)
  70. {
  71. //2.1 查找数据头
  72. if (buffer[0] == 0x06) //传输数据有帧头,用于判断
  73. {
  74. //得到完整的数据,复制到ReceiveBytes中进行校验
  75. byte[] ReceiveBytes = new byte[13];
  76. byte[] ReadReceiveBytes = new byte[18];
  77. buffer.CopyTo(0, ReceiveBytes, 0, 13);
  78. buffer.CopyTo(0, ReadReceiveBytes, 0, 18);
  79. if ((ReceiveBytes[12] == 0x55) && (ReceiveBytes[1] == 0xAA)) //校验,最后一个字节是校验位
  80. {
  81. parsecmd(ReceiveBytes);
  82. buffer.RemoveRange(0, 13);
  83. }
  84. else if ((ReadReceiveBytes[17] == 0x55) && (ReceiveBytes[1] == 0xAA))
  85. {
  86. parsecmd(ReadReceiveBytes);
  87. buffer.RemoveRange(0, 18);
  88. }
  89. else
  90. {
  91. buffer.Clear();
  92. LOG.Write(eEvent.ERR_RF, Module, $"rf通讯错误");
  93. }
  94. }
  95. else //帧头不正确时,记得清除
  96. {
  97. //buffer.RemoveAt(0);
  98. }
  99. }
  100. }
  101. catch (Exception ex)
  102. {
  103. buffer.Clear();
  104. LOG.WriteExeption(ex);
  105. }
  106. }
  107. public GeneratorStatus Status { get; set; }
  108. private float _forwardPower;
  109. public override float ForwardPower
  110. {
  111. get
  112. {
  113. return _forwardPower;
  114. }
  115. set
  116. {
  117. _forwardPower = CalibrationData(value, false);
  118. }
  119. }
  120. private bool GetBitValue(byte value, int bit)
  121. {
  122. return (value & (byte)Math.Pow(2, bit)) > 0 ? true : false;
  123. }
  124. public override bool ReConnect()
  125. {
  126. return _serial.ReConnect();
  127. }
  128. public override bool IsPowerOn
  129. {
  130. get => Status == GeneratorStatus.ON;
  131. set { }
  132. }
  133. public void parsecmd(byte[] message)
  134. {
  135. try
  136. {
  137. IsPowerOn = GetBitValue(message[4], 4);
  138. if (GetBitValue(message[4], 4))
  139. {
  140. Status = GeneratorStatus.ON;
  141. }
  142. else
  143. {
  144. Status = GeneratorStatus.OFF;
  145. }
  146. switch (message[5])
  147. {
  148. case 0x01://ParamRead
  149. if (message.Length == 18 && message[6] == 0x14)
  150. {
  151. int DataValue = BitConverter.ToInt32(new byte[] { message[11], message[12], message[13], message[14] }, 0);
  152. ReflectPower = DataValue;
  153. }
  154. else if (message.Length == 18 && message[6] == 0x12)
  155. {
  156. int DataValue1 = BitConverter.ToInt32(new byte[] { message[11], message[12], message[13], message[14] }, 0);
  157. ForwardPower = DataValue1;
  158. }
  159. break;
  160. case 0x02://ParamWrite
  161. break;
  162. case 0xFE://TelegramError
  163. LOG.Write(eEvent.ERR_RF, Module, "Telegram structure is not correct");
  164. break;
  165. default:
  166. // 默认代码块
  167. break;
  168. }
  169. switch (message[9])
  170. {
  171. case 0x26:
  172. Status = GeneratorStatus.OFF;
  173. IsPowerOn = false;
  174. break;
  175. case 0x24:
  176. LOG.Write(eEvent.ERR_RF, Module, "Telegram structure is not correct");
  177. break;
  178. default:
  179. // 默认代码块
  180. break;
  181. }
  182. }
  183. catch (Exception ex)
  184. {
  185. LOG.WriteExeption(ex);
  186. }
  187. }
  188. private void SerialPortErrorOccurred(string obj)
  189. {
  190. LOG.Write(eEvent.ERR_RF, Module, $"Tru 射频串口出错, [{obj}]");
  191. }
  192. public override void SetPower(float val)
  193. {
  194. List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x06, 0x00, 0x01, 0x00, 0x04 };
  195. byte[] valueBytes = BitConverter.GetBytes((int)val);
  196. baseBytes.AddRange(valueBytes);
  197. baseBytes = CRC16(baseBytes.ToArray());
  198. baseBytes.Add(0x55);
  199. _serial.Write(baseBytes.ToArray());
  200. }
  201. public override void Monitor()
  202. {
  203. readpi();
  204. readpr();
  205. }
  206. public void getcontrol()
  207. {
  208. byte[] getincontrol = new byte[] { 0xAA, 0x02, 0x06, 0x00, 0x05, 0x01, 0x00, 0x00, 0xFF, 0x34, 0x8A, 0x55 };
  209. _serial.Write(getincontrol.ToArray());
  210. }
  211. public void releasecontrol()
  212. {
  213. byte[] getincontrol = new byte[] { 0xAA, 0x02, 0x06, 0x00, 0x05, 0x02, 0x00, 0x00, 0xFF, 0xE8, 0x11, 0x55 };
  214. _serial.Write(getincontrol.ToArray());
  215. }
  216. public void readpr()//reflect
  217. {
  218. byte[] getincontrol = new byte[] { 0xAA, 0x02, 0x06, 0x00, 0x01, 0x14, 0x00, 0x01, 0xFF, 0xE1, 0x97, 0x55 };
  219. _serial.Write(getincontrol.ToArray());
  220. }
  221. public void readpi()//forward
  222. {
  223. byte[] getincontrola = new byte[] { 0xAA, 0x02, 0x06, 0x00, 0x01, 0x12, 0x00, 0x01, 0xFF, 0x78, 0xB0, 0x55 };
  224. _serial.Write(getincontrola.ToArray());
  225. }
  226. public void ResetCommand()
  227. {
  228. LOG.Write(eEvent.ERR_RF, Module, $"Send rest");
  229. byte[] getincontrol = new byte[] { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x4D, 0x00, 0x01, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x30, 0x72, 0x55 };
  230. _serial.Write(getincontrol.ToArray());
  231. }
  232. public override void Reset()
  233. {
  234. byte[] getincontrol = new byte[] { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x4D, 0x00, 0x01, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x30, 0x72, 0x55 };
  235. _serial.Write(getincontrol.ToArray());
  236. }
  237. public override bool SetPowerOnOff(bool on, out string str)
  238. {
  239. str = "";
  240. var _chamber = DEVICE.GetDevice<JetPMBase>(Module);
  241. if (on && !_chamber.CheckGeneratorAndHVInterlock(VenusDevice.Rf))
  242. {
  243. return false;
  244. }
  245. getcontrol();
  246. List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6F, 0x00, 0x01, 0x00, 0x07 };
  247. if (on == true)
  248. {
  249. baseBytes.AddRange(new List<byte> { 0x01, 0x00, 0x00, 0x00 });
  250. }
  251. else
  252. {
  253. baseBytes.AddRange(new List<byte> { 0x00, 0x00, 0x00, 0x00 });
  254. }
  255. baseBytes = CRC16(baseBytes.ToArray());
  256. baseBytes.Add(0x55);
  257. _serial.Write(baseBytes.ToArray());
  258. if (on == false)
  259. {
  260. releasecontrol();
  261. }
  262. return true;
  263. }
  264. public override void SetPulseMode(bool on)
  265. {
  266. List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6A, 0x01, 0x01, 0x00, 0x04 };
  267. if (on == true)
  268. {
  269. baseBytes.AddRange(new List<byte> { 0x01, 0x00, 0x00, 0x00 });
  270. }
  271. else
  272. {
  273. baseBytes.AddRange(new List<byte> { 0x00, 0x00, 0x00, 0x00 });
  274. }
  275. baseBytes = CRC16(baseBytes.ToArray());
  276. baseBytes.Add(0x55);
  277. _serial.Write(baseBytes.ToArray());
  278. }
  279. public override void SetPulseRateFreq(int nFreq)
  280. {
  281. if (nFreq > 0)
  282. {
  283. List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6C, 0x01, 0x01, 0x00, 0x04 };
  284. byte[] valueBytes = BitConverter.GetBytes(nFreq);
  285. baseBytes.AddRange(valueBytes);
  286. baseBytes = CRC16(baseBytes.ToArray());
  287. baseBytes.Add(0x55);
  288. _serial.Write(baseBytes.ToArray());
  289. }
  290. else
  291. {
  292. LOG.Write(eEvent.ERR_RF, Module, $"{Name},SetPulseRateFreq() parameter error: {nFreq}");
  293. }
  294. }
  295. public override void SetPulseDutyCycle(int percentage)
  296. {
  297. if (percentage >= 10 && percentage <= 90)
  298. {
  299. List<byte> baseBytes = new List<byte>() { 0xAA, 0x02, 0x0B, 0x00, 0x02, 0x6D, 0x01, 0x01, 0x00, 0x04 };
  300. byte[] valueBytes = BitConverter.GetBytes(percentage);
  301. baseBytes.AddRange(valueBytes);
  302. baseBytes = CRC16(baseBytes.ToArray());
  303. baseBytes.Add(0x55);
  304. _serial.Write(baseBytes.ToArray());
  305. }
  306. else
  307. {
  308. LOG.Write(eEvent.ERR_RF, Module, $"{Name},SetPulseDutyCycle() parameter error: {percentage}");
  309. }
  310. }
  311. #region 霍廷格RF协议crc-16/CCITT-FALSE校验
  312. private bool CRC16(byte[] buffer, ref byte[] ResCRC16) // crc-16/CCITT-FALSE,判断校验
  313. {
  314. bool status = false;
  315. ushort crc = 0xFFFF;
  316. int size = buffer.Length; //计算待计算的数据长度
  317. int i = 0;
  318. if (size > 0)
  319. {
  320. while (size-- > 0)
  321. {
  322. crc = (ushort)((crc >> 8) | (crc << 8));
  323. crc ^= buffer[i++];
  324. crc ^= (ushort)(((byte)crc) >> 4);
  325. crc ^= (ushort)(crc << 12);
  326. crc ^= (ushort)((crc & 0xff) << 5);
  327. }
  328. }
  329. //判断输入的ResCRC16与计算出来的是否一致
  330. if (ResCRC16[0] == (byte)((crc >> 8) & 0xff) && ResCRC16[1] == (byte)(crc & 0xff))
  331. {
  332. status = true;
  333. }
  334. return status;
  335. }
  336. private List<byte> CRC16(byte[] buffer) // crc-16/CCITT-FALSE,补全两个字节
  337. {
  338. ushort crc = 0xFFFF;
  339. int size = buffer.Length; //计算待计算的数据长度
  340. int i = 0;
  341. if (size > 0)
  342. {
  343. while (size-- > 0)
  344. {
  345. crc = (ushort)((crc >> 8) | (crc << 8));
  346. crc ^= buffer[i++];
  347. crc ^= (ushort)(((byte)crc) >> 4);
  348. crc ^= (ushort)(crc << 12);
  349. crc ^= (ushort)((crc & 0xff) << 5);
  350. }
  351. }
  352. var byteList = buffer.ToList();
  353. byteList.Add((byte)(crc & 0xff));
  354. byteList.Add((byte)((crc >> 8) & 0xff));
  355. return byteList;
  356. }
  357. #endregion
  358. }
  359. class TruPlasmaMatch : RfMatchBase
  360. {
  361. private readonly AsyncSerialPort _serial;
  362. private const ushort S3_HEAD_LENGTH = 2;
  363. private readonly DeviceTimer _timerQueryStatus = new DeviceTimer();
  364. private int QUERY_INTERVAL = 1000;
  365. private List<byte> buffer = new List<byte>(4096);
  366. [Subscription("MatchWorkMode")]
  367. public EnumRfMatchTuneMode WorkMode { get; set; }
  368. public float C1 { get; set; }
  369. public float C2 { get; set; }
  370. public float _C1setpoint { get; set; }
  371. public float _C2setpoint { get; set; }
  372. //[Subscription("VPP")]
  373. public ushort VPP { get; set; }
  374. public float VDC { get; set; }
  375. public new AITMatchData DeviceData
  376. {
  377. get
  378. {
  379. return new AITMatchData
  380. {
  381. Module = Module,
  382. DeviceName = Name,
  383. WorkMode = WorkMode.ToString(),
  384. C1 = TunePosition1,
  385. C2 = TunePosition2,
  386. VPP = "",
  387. DCBias = DCBias.ToString(),
  388. C1SetPoint= _C1setpoint,
  389. C2SetPoint = _C2setpoint,
  390. };
  391. }
  392. }
  393. public TruPlasmaMatch(ModuleName mod, VenusDevice device) : base(mod.ToString(), device.ToString())
  394. {
  395. var portNum = SC.GetStringValue($"{mod}.{device}.Port");
  396. _serial = new AsyncSerialPort(portNum, 9600, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "/r", false);
  397. intervalTime = 100;
  398. }
  399. ~TruPlasmaMatch()
  400. {
  401. _serial?.Close();
  402. }
  403. public override bool Initialize()
  404. {
  405. base.Initialize();
  406. preset(50,50);
  407. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  408. if (_serial.Open())
  409. {
  410. _serial.OnBinaryDataChanged += SerialBinaryPortDataReceived;
  411. _serial.OnErrorHappened += SerialPortErrorOccurred;
  412. }
  413. else
  414. {
  415. LOG.Write(eEvent.ERR_RF, Module, "Match 串口无法打开");
  416. return false;
  417. }
  418. DATA.Subscribe($"{Module}.{Name}.C1", () => TunePosition1);
  419. DATA.Subscribe($"{Module}.{Name}.C2", () => TunePosition2);
  420. DATA.Subscribe($"{Module}.{Name}.VDC", () => VDC);
  421. DATA.Subscribe($"{Module}.{Name}.WorkMode", () => WorkMode.ToString());
  422. OP.Subscribe($"{Module}.{Name}.SetC1", (func, args) =>
  423. {
  424. return true;
  425. });
  426. OP.Subscribe($"{Module}.{Name}.SetC2", (func, args) =>
  427. {
  428. return true;
  429. });
  430. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPositionC1}", (out string reason, int time, object[] param) =>
  431. {
  432. SetMatchPositionC1((float)Convert.ToDouble(param[0]), out reason);
  433. return true;
  434. });
  435. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPositionC2}", (out string reason, int time, object[] param) =>
  436. {
  437. SetMatchPositionC2((float)Convert.ToDouble(param[0]), out reason);
  438. return true;
  439. });
  440. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPosition}", (out string reason, int time, object[] param) =>
  441. {
  442. SetMatchPosition((float)Convert.ToDouble(param[0]), (float)Convert.ToDouble(param[1]), out reason);
  443. return true;
  444. });
  445. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchProcessMode}", (out string reason, int time, object[] param) =>
  446. {
  447. SetMatchMode((string)param[0] == "Auto" ? EnumRfMatchTuneMode.Auto : EnumRfMatchTuneMode.Manual, out reason);
  448. return true;
  449. });
  450. return true;
  451. }
  452. public void readc1()
  453. {
  454. byte[] readc1 = new byte[] { 0x0C, 0xF3, 0x00, 0x02, 0x00, 0x01, 0x61, 0x42, 0x79, 0x18, 0x01, 0x37 };
  455. _serial.Write(readc1.ToArray());
  456. }
  457. public void readc2()
  458. {
  459. byte[] readc1 = new byte[] { 0x0C, 0xF3, 0x00, 0x02, 0x00, 0x01, 0x61, 0x42, 0x79, 0x19, 0x01, 0x38 };
  460. _serial.Write(readc1.ToArray());
  461. }
  462. public void readVDC()
  463. {
  464. byte[] readvdc = new byte[] { 0x0C, 0xF3, 0x00, 0x02, 0x00, 0x00, 0x61, 0x42, 0x79, 0x1E, 0x01, 0x3C };
  465. _serial.Write(readvdc.ToArray());
  466. }
  467. public override void Monitor()
  468. {
  469. //ReadPosition(50,50);//0x10 (present mode)CMD 可实现任意模式下只读不设值,0x08(auto then manual)在auto模式下可实现相同功能
  470. readc1();
  471. readc2();
  472. //readVDC();
  473. }
  474. public override void Terminate()
  475. {
  476. }
  477. public override void Reset()
  478. {
  479. preset(50, 50);
  480. }
  481. /// <summary>
  482. ///
  483. /// </summary>
  484. /// <param name="c1,c2">百分比数字</param>
  485. /// <param name="c2"></param>
  486. ///
  487. private void executeMatchPostion(float c1, float c2)
  488. {
  489. SetPositionManualAuto(c1, c2);
  490. }
  491. public override void SetMatchPosition(float c1, float c2, out string reason)
  492. {
  493. //preset(c1, c2);
  494. executeMatchPostion(c1, c2);
  495. reason = "";
  496. }
  497. public void SetPresetMode(RfMatchPresetMode mode)
  498. {
  499. }
  500. // -----------------------Private Method-------------------------
  501. //
  502. private void SerialBinaryPortDataReceived(byte[] message)
  503. {
  504. if (message.Count() < 18)
  505. {
  506. string hexString = BitConverter.ToString(message.ToArray()).Replace("-", " ");
  507. //LOG.Write(eEvent.ERR_MATCH, Module, hexString);
  508. //LOG.Write(eEvent.ERR_RF, Module, "收到 Match 数据格式不正确");
  509. }
  510. else
  511. {
  512. try
  513. {
  514. buffer.AddRange(message);
  515. while (buffer.Count >= 18) //至少包含帧头(1字节)、长度(1字节)、其余27字节
  516. {
  517. //2.1 查找数据头
  518. if (buffer[0] == 0x1D && buffer[1] == 0xE2) //传输数据有帧头,用于判断
  519. {
  520. //得到完整的数据,复制到ReceiveBytes中进行校验
  521. byte[] ReceiveBytes = new byte[29];
  522. buffer.CopyTo(0, ReceiveBytes, 0, 29);
  523. TunePosition1 = BitConverter.ToSingle(new byte[] { ReceiveBytes[10], ReceiveBytes[11], ReceiveBytes[12], ReceiveBytes[13] }, 0) * 100;
  524. TunePosition2 = BitConverter.ToSingle(new byte[] { ReceiveBytes[14], ReceiveBytes[15], ReceiveBytes[16], ReceiveBytes[17] }, 0) * 100;
  525. buffer.RemoveRange(0, 29);
  526. switch (ReceiveBytes[19])
  527. {
  528. case 0x01:
  529. this.WorkMode = EnumRfMatchTuneMode.Manual;
  530. break;
  531. case 0x02:
  532. this.WorkMode = EnumRfMatchTuneMode.Auto;
  533. break;
  534. case 0x20:
  535. this.WorkMode = EnumRfMatchTuneMode.Undefined;
  536. break;
  537. default:
  538. break;
  539. }
  540. }
  541. else if (buffer[0] == 0x12 && buffer[1] == 0xED)
  542. {
  543. byte[] ReceiveBytes18 = new byte[18];
  544. buffer.CopyTo(0, ReceiveBytes18, 0, 18);
  545. if (ReceiveBytes18[10] == 0x79 && ReceiveBytes18[11] == 0x18)
  546. {
  547. TunePosition1 = BitConverter.ToSingle(new byte[] { ReceiveBytes18[12], ReceiveBytes18[13], ReceiveBytes18[14], ReceiveBytes18[15] }, 0) * 100;
  548. } else if (ReceiveBytes18[10] == 0x79 && ReceiveBytes18[11] == 0x19)
  549. {
  550. TunePosition2 = BitConverter.ToSingle(new byte[] { ReceiveBytes18[12], ReceiveBytes18[13], ReceiveBytes18[14], ReceiveBytes18[15] }, 0) * 100;
  551. }
  552. else if (ReceiveBytes18[10] == 0x79 && ReceiveBytes18[11] == 0x1E)
  553. {
  554. VDC = BitConverter.ToSingle(new byte[] { ReceiveBytes18[12], ReceiveBytes18[13], ReceiveBytes18[14], ReceiveBytes18[15] }, 0);
  555. }
  556. buffer.RemoveRange(0, 18);
  557. }
  558. else //帧头不正确时,记得清除
  559. {
  560. buffer.Clear();
  561. //LOG.Write(eEvent.ERR_MATCH, Module, $"Match通讯错误");
  562. }
  563. }
  564. }
  565. catch (Exception ex)
  566. {
  567. buffer.Clear();
  568. LOG.WriteExeption(ex);
  569. }
  570. }
  571. }
  572. private void SerialPortErrorOccurred(string str)
  573. {
  574. LOG.Write(eEvent.ERR_RF, Module, $"TruPlasma Match error [{str}]");
  575. }
  576. private void SetPositionManualAuto(float c1val, float c2val)
  577. {
  578. _C1setpoint = c1val;
  579. _C2setpoint = c2val;
  580. List<byte> Len = new List<byte>() { 0x16, 0xE9 };
  581. List<byte> DstSrc = new List<byte>() { 0x00, 0x02, 0x00, 0x01 };
  582. List<byte> Cmd = new List<byte> { 0x60, 0x40 };
  583. byte[] val1Bytes = BitConverter.GetBytes(c1val / 100);
  584. byte[] val2Bytes = BitConverter.GetBytes(c2val / 100);
  585. List<byte> Act = new List<byte>() { 0x00 };
  586. List<byte> Ctr123 = new List<byte> { 0x08, 0x00, 0x00 };
  587. List<byte> baseBytes = new List<byte>() { };
  588. baseBytes.AddRange(Len);
  589. baseBytes.AddRange(DstSrc);
  590. baseBytes.AddRange(Cmd);
  591. baseBytes.AddRange(val1Bytes);
  592. baseBytes.AddRange(val2Bytes);
  593. baseBytes.AddRange(Act);
  594. baseBytes.AddRange(Ctr123);
  595. int a = 0;
  596. for (int i = 2; i < baseBytes.Count; i++)
  597. {
  598. a += (Int16)baseBytes[i];
  599. }
  600. byte[] ackture = new byte[2];
  601. byte[] ackbyte = BitConverter.GetBytes(a);
  602. ackture[0] = ackbyte[1];
  603. ackture[1] = ackbyte[0];
  604. baseBytes.AddRange(ackture);
  605. _serial.Write(baseBytes.ToArray());
  606. }
  607. private void preset(float c1val, float c2val)
  608. {
  609. _C1setpoint = c1val;
  610. _C2setpoint = c2val;
  611. List<byte> Len = new List<byte>() { 0x16, 0xE9 };
  612. List<byte> DstSrc = new List<byte>() { 0x00, 0x02, 0x00, 0x01 };
  613. List<byte> Cmd = new List<byte> { 0x60, 0x40 };
  614. byte[] val1Bytes = BitConverter.GetBytes(c1val / 100);
  615. byte[] val2Bytes = BitConverter.GetBytes(c2val / 100);
  616. List<byte> Act = new List<byte>() { 0x00 };
  617. List<byte> Ctr123 = new List<byte> { 0x04, 0x10, 0x80 };
  618. List<byte> baseBytes = new List<byte>() { };
  619. baseBytes.AddRange(Len);
  620. baseBytes.AddRange(DstSrc);
  621. baseBytes.AddRange(Cmd);
  622. baseBytes.AddRange(val1Bytes);
  623. baseBytes.AddRange(val2Bytes);
  624. baseBytes.AddRange(Act);
  625. baseBytes.AddRange(Ctr123);
  626. int a = 0;
  627. for (int i = 2; i < baseBytes.Count; i++)
  628. {
  629. a += (Int16)baseBytes[i];
  630. }
  631. byte[] ackture = new byte[2];
  632. byte[] ackbyte = BitConverter.GetBytes(a);
  633. ackture[0] = ackbyte[1];
  634. ackture[1] = ackbyte[0];
  635. baseBytes.AddRange(ackture);
  636. _serial.Write(baseBytes.ToArray());
  637. }
  638. public override bool SetMatchMode(EnumRfMatchTuneMode enumRfMatchTuneMode, out string reason)
  639. {
  640. reason = string.Empty;
  641. return true;
  642. }
  643. public override bool ReConnect()
  644. {
  645. return _serial.ReConnect();
  646. }
  647. private void SetWorkMode(EnumRfMatchTuneMode mode)
  648. {
  649. }
  650. private void SetPresetMemory(byte gear)
  651. {
  652. }
  653. }
  654. }