TruPlasmaRF.cs 25 KB

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