TruPlasmaRF.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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. //[Subscription("VPP")]
  371. public ushort VPP { get; set; }
  372. public new AITMatchData DeviceData
  373. {
  374. get
  375. {
  376. return new AITMatchData
  377. {
  378. Module = Module,
  379. DeviceName = Name,
  380. WorkMode = WorkMode.ToString(),
  381. C1 = TunePosition1,
  382. C2 = TunePosition2,
  383. VPP = "",
  384. DCBias = DCBias.ToString()
  385. };
  386. }
  387. }
  388. public TruPlasmaMatch(ModuleName mod, VenusDevice device) : base(mod.ToString(), device.ToString())
  389. {
  390. var portNum = SC.GetStringValue($"{mod}.{device}.Port");
  391. _serial = new AsyncSerialPort(portNum, 9600, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "/r", false);
  392. intervalTime = 100;
  393. }
  394. ~TruPlasmaMatch()
  395. {
  396. _serial?.Close();
  397. }
  398. public override bool Initialize()
  399. {
  400. base.Initialize();
  401. preset(50,50);
  402. if (_serial.Open())
  403. {
  404. _serial.OnBinaryDataChanged += SerialBinaryPortDataReceived;
  405. _serial.OnErrorHappened += SerialPortErrorOccurred;
  406. }
  407. else
  408. {
  409. LOG.Write(eEvent.ERR_RF, Module, "Match 串口无法打开");
  410. return false;
  411. }
  412. DATA.Subscribe($"{Module}.{Name}.C1", () => TunePosition1);
  413. DATA.Subscribe($"{Module}.{Name}.C2", () => TunePosition2);
  414. DATA.Subscribe($"{Module}.{Name}.WorkMode", () => WorkMode.ToString());
  415. OP.Subscribe($"{Module}.{Name}.SetC1", (func, args) =>
  416. {
  417. return true;
  418. });
  419. OP.Subscribe($"{Module}.{Name}.SetC2", (func, args) =>
  420. {
  421. return true;
  422. });
  423. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPositionC1}", (out string reason, int time, object[] param) =>
  424. {
  425. SetMatchPositionC1((float)Convert.ToDouble(param[0]), out reason);
  426. return true;
  427. });
  428. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPositionC2}", (out string reason, int time, object[] param) =>
  429. {
  430. SetMatchPositionC2((float)Convert.ToDouble(param[0]), out reason);
  431. return true;
  432. });
  433. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPosition}", (out string reason, int time, object[] param) =>
  434. {
  435. SetMatchPosition((float)Convert.ToDouble(param[0]), (float)Convert.ToDouble(param[1]), out reason);
  436. return true;
  437. });
  438. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchProcessMode}", (out string reason, int time, object[] param) =>
  439. {
  440. SetMatchMode((string)param[0] == "Auto" ? EnumRfMatchTuneMode.Auto : EnumRfMatchTuneMode.Manual, out reason);
  441. return true;
  442. });
  443. return true;
  444. }
  445. public void readc1()
  446. {
  447. byte[] readc1 = new byte[] { 0x0C, 0xF3, 0x00, 0x02, 0x00, 0x01, 0x61, 0x42, 0x79, 0x18, 0x01, 0x37 };
  448. _serial.Write(readc1.ToArray());
  449. }
  450. public void readc2()
  451. {
  452. byte[] readc1 = new byte[] { 0x0C, 0xF3, 0x00, 0x02, 0x00, 0x01, 0x61, 0x42, 0x79, 0x19, 0x01, 0x38 };
  453. _serial.Write(readc1.ToArray());
  454. }
  455. public override void Monitor()
  456. {
  457. //ReadPosition(50,50);//0x10 (present mode)CMD 可实现任意模式下只读不设值,0x08(auto then manual)在auto模式下可实现相同功能
  458. readc1();
  459. readc2();
  460. }
  461. public override void Terminate()
  462. {
  463. }
  464. public override void Reset()
  465. {
  466. preset(50, 50);
  467. }
  468. /// <summary>
  469. ///
  470. /// </summary>
  471. /// <param name="c1,c2">百分比数字</param>
  472. /// <param name="c2"></param>
  473. ///
  474. private void executeMatchPostion(float c1, float c2)
  475. {
  476. SetPositionManualAuto(c1, c2);
  477. }
  478. public override void SetMatchPosition(float c1, float c2, out string reason)
  479. {
  480. executeMatchPostion(c1, c2);
  481. reason = "";
  482. }
  483. public void SetPresetMode(RfMatchPresetMode mode)
  484. {
  485. }
  486. // -----------------------Private Method-------------------------
  487. //
  488. private void SerialBinaryPortDataReceived(byte[] message)
  489. {
  490. if (message.Count() < 18)
  491. {
  492. string hexString = BitConverter.ToString(message.ToArray()).Replace("-", " ");
  493. //LOG.Write(eEvent.ERR_MATCH, Module, hexString);
  494. //LOG.Write(eEvent.ERR_RF, Module, "收到 Match 数据格式不正确");
  495. }
  496. else
  497. {
  498. try
  499. {
  500. buffer.AddRange(message);
  501. while (buffer.Count >= 18) //至少包含帧头(1字节)、长度(1字节)、其余27字节
  502. {
  503. //2.1 查找数据头
  504. if (buffer[0] == 0x1D && buffer[1] == 0xE2) //传输数据有帧头,用于判断
  505. {
  506. //得到完整的数据,复制到ReceiveBytes中进行校验
  507. byte[] ReceiveBytes = new byte[29];
  508. buffer.CopyTo(0, ReceiveBytes, 0, 29);
  509. TunePosition1 = BitConverter.ToSingle(new byte[] { ReceiveBytes[10], ReceiveBytes[11], ReceiveBytes[12], ReceiveBytes[13] }, 0) * 100;
  510. TunePosition2 = BitConverter.ToSingle(new byte[] { ReceiveBytes[14], ReceiveBytes[15], ReceiveBytes[16], ReceiveBytes[17] }, 0) * 100;
  511. buffer.RemoveRange(0, 29);
  512. switch (ReceiveBytes[19])
  513. {
  514. case 0x01:
  515. this.WorkMode = EnumRfMatchTuneMode.Manual;
  516. break;
  517. case 0x02:
  518. this.WorkMode = EnumRfMatchTuneMode.Auto;
  519. break;
  520. case 0x20:
  521. this.WorkMode = EnumRfMatchTuneMode.Undefined;
  522. break;
  523. default:
  524. break;
  525. }
  526. }
  527. else if (buffer[0] == 0x12 && buffer[1] == 0xED)
  528. {
  529. byte[] ReceiveBytes18 = new byte[18];
  530. buffer.CopyTo(0, ReceiveBytes18, 0, 18);
  531. if (ReceiveBytes18[10] == 0x79 && ReceiveBytes18[11] == 0x18)
  532. {
  533. TunePosition1 = BitConverter.ToSingle(new byte[] { ReceiveBytes18[12], ReceiveBytes18[13], ReceiveBytes18[14], ReceiveBytes18[15] }, 0) * 100;
  534. }else if (ReceiveBytes18[10] == 0x79 && ReceiveBytes18[11] == 0x19)
  535. {
  536. TunePosition2 = BitConverter.ToSingle(new byte[] { ReceiveBytes18[12], ReceiveBytes18[13], ReceiveBytes18[14], ReceiveBytes18[15] }, 0) * 100;
  537. }
  538. buffer.RemoveRange(0, 18);
  539. }
  540. else //帧头不正确时,记得清除
  541. {
  542. buffer.Clear();
  543. LOG.Write(eEvent.ERR_MATCH, Module, $"Match通讯错误");
  544. }
  545. }
  546. }
  547. catch (Exception ex)
  548. {
  549. buffer.Clear();
  550. LOG.WriteExeption(ex);
  551. }
  552. }
  553. }
  554. private void SerialPortErrorOccurred(string str)
  555. {
  556. LOG.Write(eEvent.ERR_RF, Module, $"AdTec Match error [{str}]");
  557. }
  558. private void SetPositionManualAuto(float c1val, float c2val)
  559. {
  560. List<byte> Len = new List<byte>() { 0x16, 0xE9 };
  561. List<byte> DstSrc = new List<byte>() { 0x00, 0x02, 0x00, 0x01 };
  562. List<byte> Cmd = new List<byte> { 0x60, 0x40 };
  563. byte[] val1Bytes = BitConverter.GetBytes(c1val / 100);
  564. byte[] val2Bytes = BitConverter.GetBytes(c2val / 100);
  565. List<byte> Act = new List<byte>() { 0x00 };
  566. List<byte> Ctr123 = new List<byte> { 0x08, 0x00, 0x00 };
  567. List<byte> baseBytes = new List<byte>() { };
  568. baseBytes.AddRange(Len);
  569. baseBytes.AddRange(DstSrc);
  570. baseBytes.AddRange(Cmd);
  571. baseBytes.AddRange(val1Bytes);
  572. baseBytes.AddRange(val2Bytes);
  573. baseBytes.AddRange(Act);
  574. baseBytes.AddRange(Ctr123);
  575. int a = 0;
  576. for (int i = 2; i < baseBytes.Count; i++)
  577. {
  578. a += (Int16)baseBytes[i];
  579. }
  580. byte[] ackture = new byte[2];
  581. byte[] ackbyte = BitConverter.GetBytes(a);
  582. ackture[0] = ackbyte[1];
  583. ackture[1] = ackbyte[0];
  584. baseBytes.AddRange(ackture);
  585. _serial.Write(baseBytes.ToArray());
  586. }
  587. private void preset(float c1val, float c2val)
  588. {
  589. List<byte> Len = new List<byte>() { 0x16, 0xE9 };
  590. List<byte> DstSrc = new List<byte>() { 0x00, 0x02, 0x00, 0x01 };
  591. List<byte> Cmd = new List<byte> { 0x60, 0x40 };
  592. byte[] val1Bytes = BitConverter.GetBytes(c1val / 100);
  593. byte[] val2Bytes = BitConverter.GetBytes(c2val / 100);
  594. List<byte> Act = new List<byte>() { 0x00 };
  595. List<byte> Ctr123 = new List<byte> { 0x04, 0x10, 0x80 };
  596. List<byte> baseBytes = new List<byte>() { };
  597. baseBytes.AddRange(Len);
  598. baseBytes.AddRange(DstSrc);
  599. baseBytes.AddRange(Cmd);
  600. baseBytes.AddRange(val1Bytes);
  601. baseBytes.AddRange(val2Bytes);
  602. baseBytes.AddRange(Act);
  603. baseBytes.AddRange(Ctr123);
  604. int a = 0;
  605. for (int i = 2; i < baseBytes.Count; i++)
  606. {
  607. a += (Int16)baseBytes[i];
  608. }
  609. byte[] ackture = new byte[2];
  610. byte[] ackbyte = BitConverter.GetBytes(a);
  611. ackture[0] = ackbyte[1];
  612. ackture[1] = ackbyte[0];
  613. baseBytes.AddRange(ackture);
  614. _serial.Write(baseBytes.ToArray());
  615. }
  616. public override bool SetMatchMode(EnumRfMatchTuneMode enumRfMatchTuneMode, out string reason)
  617. {
  618. reason = string.Empty;
  619. return true;
  620. }
  621. public override bool ReConnect()
  622. {
  623. return _serial.ReConnect();
  624. }
  625. private void SetWorkMode(EnumRfMatchTuneMode mode)
  626. {
  627. }
  628. private void SetPresetMemory(byte gear)
  629. {
  630. }
  631. }
  632. }