TruPlasmaRF.cs 25 KB

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