TruPlasmaRF.cs 25 KB

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