TruPlasmaRF.cs 25 KB

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