TruPlasmaRF.cs 26 KB

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