AdTecRF.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. using System;
  2. using System.Collections;
  3. using System.Text.RegularExpressions;
  4. using Aitex.Core.Common.DeviceData;
  5. using Aitex.Core.RT.DataCenter;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.IOCore;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Core.RT.OperationCenter;
  10. using Aitex.Core.RT.SCCore;
  11. using Aitex.Core.RT.Tolerance;
  12. using Aitex.Core.Util;
  13. using MECF.Framework.Common.Communications;
  14. using MECF.Framework.Common.Device.Bases;
  15. using MECF.Framework.Common.Equipment;
  16. using Virgo_DCommon;
  17. using Virgo_DRT.Modules;
  18. namespace Virgo_DRT.Devices
  19. {
  20. #region RFG
  21. static class AdTecRfMessage
  22. {
  23. public static string ANALOG;
  24. public const string EOF = "\r";
  25. public const char DELIMITER = ' ';
  26. public const string MANUAL = "MANUAL";
  27. public const string RS232 = "***";
  28. public const string SET_POWER = " W";
  29. public const string RF_ON = "G";
  30. public const string RF_OFF = "S";
  31. public const string ERR_RES = "N";
  32. public const string QUERY = "Q";
  33. public const string RESET = "RESET";
  34. public const string CHK_COMM = "HS";
  35. }
  36. class AdTecGenerator : RfPowerBase
  37. {
  38. // ----------------------------Fields--------------------------
  39. //
  40. private int QUERY_INTERVAL = 5000;
  41. private const string INFO_PATTERN = @"(\d{7})\s(\d{5})\s(\d{5})\s(\d{5})\s(\d{5})";
  42. private bool _bRfAlarm = false;
  43. private readonly AsyncSerialPort _serial;
  44. private readonly DeviceTimer _timerQueryStatus = new DeviceTimer();
  45. private DateTime _powerOnStartTime;
  46. private TimeSpan _powerOnElapsedTime;
  47. private readonly R_TRIG _rfOnTrigger = new R_TRIG();
  48. private readonly R_TRIG _ErrTrigger = new R_TRIG();
  49. private readonly R_TRIG _ErrTest = new R_TRIG();
  50. private ToleranceChecker _checkerPower;
  51. private ToleranceChecker _checkerReflectPower;
  52. private readonly double _scPowerAlarmTime;
  53. private readonly double _scPowerAlarmRange;
  54. private readonly double _scReflectPowerAlarmTime;
  55. private readonly double _scReflectPowerAlarmRange;
  56. private readonly double _scPowerRange;
  57. private readonly DIAccessor _diIntlk;
  58. // --------------------------Properties------------------------
  59. //
  60. public bool ConnectedStatus { get; set; }
  61. public float ScalePower => (float)_scPowerRange;
  62. public GeneratorStatus Status { get; set; }
  63. public override bool IsPowerOn
  64. {
  65. get => Status == GeneratorStatus.ON;
  66. set { }
  67. }
  68. public override bool IsError
  69. {
  70. get => Status == GeneratorStatus.ERROR;
  71. set { }
  72. }
  73. [Subscription("RfAlarm")]
  74. public bool RfAlarm
  75. {
  76. get
  77. {
  78. return _bRfAlarm;
  79. }
  80. }
  81. [Subscription("PowerOnTime")]
  82. public string PowerOnTime
  83. {
  84. get
  85. {
  86. if (IsPowerOn)
  87. {
  88. _powerOnElapsedTime = DateTime.Now - _powerOnStartTime;
  89. //return $"{(int)_powerOnElapsedTime.TotalHours:00}:{_powerOnElapsedTime.Minutes:00}:{_powerOnElapsedTime.Seconds:00}";
  90. //return $"{(int)_powerOnElapsedTime.TotalHours:00}:{_powerOnElapsedTime.Minutes:00}:{(_powerOnElapsedTime.Seconds > 0 ? (_powerOnElapsedTime.Seconds + 1) : 0):00}";
  91. //return $"{(int)(_powerOnElapsedTime.Hours * 3600 + _powerOnElapsedTime.Minutes * 60 + (_powerOnElapsedTime.Seconds > 0 ? (_powerOnElapsedTime.Seconds + 1) : 0))}";
  92. return $"{(int)(_powerOnElapsedTime.Hours * 3600 + _powerOnElapsedTime.Minutes * 60 + _powerOnElapsedTime.Seconds)}";
  93. }
  94. else
  95. {
  96. return "0";
  97. }
  98. }
  99. }
  100. public bool RFInterlock => _diIntlk == null || _diIntlk.Value;
  101. public new AITRfData DeviceData =>
  102. new AITRfData
  103. {
  104. Module = Module,
  105. DeviceName = Name,
  106. ScalePower = ScalePower,
  107. ForwardPower = ForwardPower,
  108. ReflectPower = ReflectPower,
  109. IsRfOn = IsPowerOn,
  110. PowerSetPoint = PowerSetPoint,
  111. PowerOnElapsedTime = PowerOnTime,
  112. IsInterlockOk = RFInterlock,
  113. };
  114. // --------------------------Constructor-----------------------
  115. //
  116. public AdTecGenerator(ModuleName mod) : base(mod.ToString(), Virgo_DDevice.Rf.ToString())
  117. {
  118. var portNum = SC.GetStringValue($"{mod}.Rf.Port");
  119. this.Status = GeneratorStatus.Unknown;
  120. _serial = new AsyncSerialPort(portNum, 9600, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "\r\r");
  121. _scPowerAlarmTime = SC.GetValue<double>($"{Module}.{Name}.PowerAlarmTime");
  122. _scPowerAlarmRange = SC.GetValue<double>($"{Module}.{Name}.PowerAlarmRange");
  123. _scReflectPowerAlarmTime = SC.GetValue<double>($"{Module}.{Name}.ReflectPowerAlarmTime");
  124. _scReflectPowerAlarmRange = SC.GetValue<double>($"{Module}.{Name}.ReflectPowerAlarmRange");
  125. _scPowerRange = SC.GetValue<double>($"{Module}.{Name}.PowerRange");
  126. _diIntlk = IO.DI[$"{Module}.DI_Generator_Hardware_Interlock"];
  127. }
  128. ~AdTecGenerator()
  129. {
  130. _serial?.Close();
  131. }
  132. public override bool Initialize()
  133. {
  134. base.Initialize();
  135. DATA.Subscribe($"{Module}.{Name}.DeviceData", () => DeviceData);
  136. if (_serial.Open())
  137. {
  138. this.ConnectedStatus = true;
  139. _serial.OnDataChanged += SerialPortDataReceived;
  140. _serial.OnErrorHappened += SerialPortErrorOccurred;
  141. }
  142. else
  143. {
  144. this.ConnectedStatus = false;
  145. EV.PostAlarmLog(this.Module, "AD TEC 射频发生器串口无法打开");
  146. return false;
  147. }
  148. _timerQueryStatus.Start(QUERY_INTERVAL);
  149. _checkerPower = new ToleranceChecker(_scPowerAlarmTime);
  150. _checkerReflectPower = new ToleranceChecker(_scReflectPowerAlarmTime);
  151. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetPowerOnOff}", (out string reason, int time, object[] param) =>
  152. {
  153. SetPowerOnOff(Convert.ToBoolean((string)param[0]), out reason);
  154. return true;
  155. });
  156. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetPower}", (out string reason, int time, object[] param) =>
  157. {
  158. reason = "";
  159. ushort val = Convert.ToUInt16(param[0]);
  160. SetPower(val);
  161. return true;
  162. });
  163. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetContinuousPower}", (out string reason, int time, object[] param) =>
  164. {
  165. reason = "";
  166. ushort val = Convert.ToUInt16(param[0]);
  167. SetPower(val);
  168. return true;
  169. });
  170. SetCommunicationMode(1);
  171. return true;
  172. }
  173. public override void Monitor()
  174. {
  175. // 状态查询
  176. if (_timerQueryStatus.IsTimeout())
  177. {
  178. this.SendCmd(AdTecRfMessage.QUERY);
  179. _timerQueryStatus.Start(QUERY_INTERVAL);
  180. }
  181. // power on triggered
  182. _rfOnTrigger.CLK = IsPowerOn;
  183. if (_rfOnTrigger.Q)
  184. {
  185. _powerOnStartTime = DateTime.Now;
  186. _checkerPower.Reset(_scPowerAlarmTime);
  187. _checkerReflectPower.Reset(_scReflectPowerAlarmTime);
  188. }
  189. if (_rfOnTrigger.M)
  190. {
  191. _checkerPower.Monitor(ForwardPower, PowerSetPoint - _scPowerAlarmRange, PowerSetPoint + _scPowerAlarmRange, _scPowerAlarmTime);
  192. if (_checkerPower.Trig)
  193. {
  194. EV.PostAlarmLog($"{Module} {Display}",
  195. $"Forward power {ForwardPower:0} out of range[{PowerSetPoint - _scPowerAlarmRange:0},{PowerSetPoint + _scPowerAlarmRange:0}] in {_scPowerAlarmTime:0} seconds");
  196. _bRfAlarm = true;
  197. SetPowerOnOff(false, out _);
  198. }
  199. _checkerReflectPower.Monitor(ReflectPower, double.MinValue, _scReflectPowerAlarmRange, _scReflectPowerAlarmTime);
  200. if (_checkerReflectPower.Trig)
  201. {
  202. EV.PostAlarmLog($"{Module} {Display}",
  203. $"Reflect power {ReflectPower:0} out of range[0,{_scReflectPowerAlarmRange:0}] in {_scReflectPowerAlarmTime:0} seconds");
  204. _bRfAlarm = true;
  205. SetPowerOnOff(false, out _);
  206. }
  207. }
  208. if (!_rfOnTrigger.CLK)
  209. {
  210. ForwardPower = 0;
  211. ReflectPower = 0;
  212. }
  213. // 通信 checking, 2 second 一次
  214. //if (_timerComm.IsTimeout() && !_bQueryComm)
  215. //{
  216. // this.SendCmd(AdTecRfMessage.CHK_COMM);
  217. // _bQueryComm = true;
  218. // _timerComm.Start(CHK_COMM_INTERVAL);
  219. //}
  220. }
  221. public override void Terminate()
  222. {
  223. _serial?.Close();
  224. }
  225. public override void Reset()
  226. {
  227. _bRfAlarm = false;
  228. _rfOnTrigger.RST = true;
  229. _ErrTrigger.RST = true;
  230. _ErrTest.RST = true;
  231. this.SendCmd(AdTecRfMessage.RESET);
  232. this.Status = GeneratorStatus.OFF;
  233. }
  234. public void SetRfMode(RfMode mode)
  235. {
  236. throw new NotImplementedException();
  237. }
  238. public override void SetCommunicationMode(int mode)
  239. {
  240. CommunicationType t1 = (CommunicationType)mode;
  241. switch (t1)
  242. {
  243. case CommunicationType.Analogue:
  244. this.SendCmd(AdTecRfMessage.ANALOG);
  245. break;
  246. case CommunicationType.RS232:
  247. this.SendCmd(AdTecRfMessage.RS232);
  248. break;
  249. default:
  250. throw new ArgumentOutOfRangeException("Communication mode error");
  251. }
  252. }
  253. public override void SetPower(float val)
  254. {
  255. if (!(this.ControlMode == EnumRfPowerControlMode.RS232Mode)) SetCommunicationMode(1);
  256. ushort a = (ushort)val;
  257. if (SendCmd($"{a:D4}{AdTecRfMessage.SET_POWER}"))
  258. {
  259. PowerSetPoint = val;
  260. }
  261. }
  262. public override bool SetPowerOnOff(bool on, out string str)
  263. {
  264. if (!(this.ControlMode == EnumRfPowerControlMode.RS232Mode)) SetCommunicationMode(1);
  265. str = "";
  266. if (on)
  267. {
  268. SendCmd(AdTecRfMessage.RF_ON);
  269. Status = GeneratorStatus.ON;
  270. QUERY_INTERVAL = 500;
  271. }
  272. else
  273. {
  274. SendCmd(AdTecRfMessage.RF_OFF);
  275. Status = GeneratorStatus.OFF;
  276. ForwardPower = 0;
  277. ReflectPower = 0;
  278. QUERY_INTERVAL = 5000;
  279. _ErrTrigger.RST = true;
  280. }
  281. _timerQueryStatus.Start(QUERY_INTERVAL);
  282. return true;
  283. }
  284. //----------------------------------Private Method-------------------------------
  285. //
  286. private void SerialPortDataReceived(string str)
  287. {
  288. if (string.IsNullOrEmpty(str))
  289. {
  290. EV.PostAlarmLog(Module, "AdTec RFG 无数据反馈");
  291. return;
  292. }
  293. string str2 = str.Trim('\r');
  294. if (str2 == AdTecRfMessage.ERR_RES)
  295. {
  296. EV.PostWarningLog(this.Module, $"AdTEC 收到 [{str2}]");
  297. return;
  298. }
  299. try
  300. {
  301. LOG.Info($"{Module} Generator rec [{str2}]");
  302. if (string.IsNullOrEmpty(str2))
  303. {
  304. _ErrTest.CLK = true;
  305. if (_ErrTest.Q)
  306. return;
  307. }
  308. Match match1 = Regex.Match(str2, INFO_PATTERN);
  309. if (!match1.Success)
  310. {
  311. EV.PostAlarmLog(Module, "AdTec 数据格式错误");
  312. return;
  313. }
  314. string[] str1 =
  315. {
  316. match1.Groups[1].Value,
  317. match1.Groups[2].Value,
  318. match1.Groups[3].Value,
  319. match1.Groups[4].Value,
  320. match1.Groups[5].Value
  321. };
  322. this.ParseQueryData(str1);
  323. _ErrTest.RST = true;
  324. }
  325. catch (Exception ex)
  326. {
  327. LOG.Write(ex);
  328. }
  329. }
  330. private void ParseQueryData(string[] strInfo)
  331. {
  332. // Control mode
  333. string s2 = strInfo[0].Substring(0, 1);
  334. this.ControlMode = (EnumRfPowerControlMode)Convert.ToUInt16(s2);
  335. // output mode
  336. string s0 = strInfo[0].Substring(1, 1);
  337. this.WorkMode = (EnumRfPowerWorkMode)Convert.ToUInt16(s0);
  338. // ON/OFF
  339. char s1 = strInfo[0][1];
  340. this.IsPowerOn = s1 == '1';
  341. // error code
  342. string alarm = strInfo[0].Substring(5, 2);
  343. byte errCode = Convert.ToByte(alarm);
  344. _ErrTrigger.CLK = errCode > 0;
  345. if (_ErrTrigger.Q)
  346. {
  347. string code = errCode == 1 ? "Ref Over" : errCode == 2 ? "Ref Limit" :
  348. errCode == 3 ? "Cur Over" :
  349. errCode == 4 ? "Cur Limit" :
  350. errCode == 5 ? "Temp Over" :
  351. errCode == 6 ? "Temp Sensor Short" :
  352. errCode == 7 ? "Temp Sensor Open" :
  353. errCode == 8 ? "Sensor Error" :
  354. errCode == 9 ? "Fwd Power Over" :
  355. errCode == 10 ? "RF ON Timer" :
  356. errCode == 11 ? "RS232C error" :
  357. errCode == 12 ? "Amp Unbalance" :
  358. errCode == 14 ? "Fan error" :
  359. errCode == 15 ? "Coolant Error" :
  360. errCode == 16 ? "Voltage Error" :
  361. errCode == 17 ? "Fwd Power Down" :
  362. errCode == 22 ? "PD Over" :
  363. errCode == 23 ? "PD Limit" :
  364. errCode == 26 ? "Dew Condensation" :
  365. errCode == 29 ? "SW Failure" :
  366. errCode == 99 ? "Safety Lock" : string.Empty;
  367. if (!string.IsNullOrEmpty(code))
  368. {
  369. if (errCode == 99)
  370. EV.PostWarningLog(Module, "Generator " + code);
  371. else
  372. EV.PostAlarmLog(Module, "Generator " + code);
  373. }
  374. }
  375. // forward power
  376. this.ForwardPower = Convert.ToUInt16(strInfo[2]);
  377. // reflect power
  378. this.ReflectPower = Convert.ToUInt16(strInfo[3]);
  379. }
  380. private void SerialPortErrorOccurred(string obj)
  381. {
  382. Status = GeneratorStatus.ERROR;
  383. EV.PostAlarmLog(this.Module, $"AdTec RFG 串口出错, [{obj}]");
  384. }
  385. private bool SendCmd(string str)
  386. {
  387. if (str != AdTecRfMessage.QUERY)
  388. {
  389. EV.PostInfoLog(Module, $"Generator send [{str}]");
  390. }
  391. return _serial.Write(str + "\r");
  392. }
  393. }
  394. #endregion RFG
  395. #region match
  396. static class AdTecMatchMessage
  397. {
  398. public const string PRESET = "G";
  399. public const string AUTO = "L";
  400. public const string MANUAL = "M";
  401. public const string PRESET_MEM = "P";
  402. public const string START_QUERY = "S3";
  403. public const string STOP_QUERY = "SP";
  404. public const string WRITE_POS = "$APGR";
  405. public const string READ_POS = "$APRR";
  406. }
  407. class AdTecMatch : RfMatchBase
  408. {
  409. // ----------------------------Fields--------------------------
  410. //
  411. private readonly AsyncSerialPort _serial;
  412. private const ushort S3_HEAD_LENGTH = 2;
  413. private readonly DeviceTimer _timerQueryStatus = new DeviceTimer();
  414. private int QUERY_INTERVAL = 1000;
  415. //private int _scMatchPresetMode;
  416. //private int _scMatchMode;
  417. //private readonly SCConfigItem _scMatchPositionC1;
  418. //private readonly SCConfigItem _scMatchPositionC2;
  419. //private readonly bool _scEnableC1C2Position;
  420. // --------------------------Properties------------------------
  421. //
  422. [Subscription("MatchWorkMode")]
  423. public EnumRfMatchTuneMode WorkMode { get; set; }
  424. public float C1 { get; set; }
  425. public float C2 { get; set; }
  426. [Subscription("VPP")]
  427. public ushort VPP { get; set; }
  428. public override AITRfMatchData DeviceData
  429. {
  430. get
  431. {
  432. return new AITRfMatchData
  433. {
  434. };
  435. }
  436. }
  437. // --------------------------Constructor-----------------------
  438. //
  439. public AdTecMatch(ModuleName mod) : base(mod.ToString(), Virgo_DDevice.Match.ToString())
  440. {
  441. var portNum = SC.GetStringValue($"{mod}.match.Port");
  442. _serial = new AsyncSerialPort(portNum, 9600, 8);
  443. //_scMatchPresetMode = SC.GetValue<int>($"{Module}.Rf.PresetMode");
  444. //_scMatchMode = SC.GetValue<int>($"{Module}.Rf.MatchMode");
  445. //_scMatchPositionC1 = SC.GetConfigItem($"{Module}.Rf.MatchPositionC1");
  446. //_scMatchPositionC2 = SC.GetConfigItem($"{Module}.Rf.MatchPositionC2");
  447. //_scEnableC1C2Position = SC.GetValue<bool>($"{Module}.Rf.EnableC1C2Position");
  448. }
  449. ~AdTecMatch()
  450. {
  451. _serial?.Close();
  452. }
  453. public override bool Initialize()
  454. {
  455. base.Initialize();
  456. if (_serial.Open())
  457. {
  458. _serial.OnDataChanged += SerialPortDataReceived;
  459. _serial.OnErrorHappened += SerialPortErrorOccurred;
  460. }
  461. else
  462. {
  463. EV.PostAlarmLog(Module, "Match 串口无法打开");
  464. return false;
  465. }
  466. DATA.Subscribe($"{Module}.{Name}.C1", () => C1);
  467. DATA.Subscribe($"{Module}.{Name}.C2", () => C2);
  468. OP.Subscribe($"{Module}.{Name}.SetC1", (func, args) =>
  469. {
  470. return true;
  471. });
  472. OP.Subscribe($"{Module}.{Name}.SetC2", (func, args) =>
  473. {
  474. return true;
  475. });
  476. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPositionC1}", (out string reason, int time, object[] param) =>
  477. {
  478. SetMatchPositionC1((float)Convert.ToDouble(param[0]), out reason);
  479. return true;
  480. });
  481. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPositionC2}", (out string reason, int time, object[] param) =>
  482. {
  483. SetMatchPositionC2((float)Convert.ToDouble(param[0]), out reason);
  484. return true;
  485. });
  486. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchPosition}", (out string reason, int time, object[] param) =>
  487. {
  488. SetMatchPosition((float)Convert.ToDouble(param[0]), (float)Convert.ToDouble(param[1]), out reason);
  489. return true;
  490. });
  491. OP.Subscribe($"{Module}.{Name}.{AITRfOperation.SetMatchProcessMode}", (out string reason, int time, object[] param) =>
  492. {
  493. SetMatchMode((string)param[0], out reason);
  494. return true;
  495. });
  496. _timerQueryStatus.Start(QUERY_INTERVAL);
  497. this.SendCmd(AdTecMatchMessage.START_QUERY);
  498. return true;
  499. }
  500. public override void Monitor()
  501. {
  502. try
  503. {
  504. if (_timerQueryStatus.IsTimeout())
  505. {
  506. this.SendCmd(AdTecMatchMessage.READ_POS);
  507. _timerQueryStatus.Start(QUERY_INTERVAL);
  508. }
  509. }
  510. catch (Exception ex)
  511. {
  512. LOG.Write(ex);
  513. }
  514. }
  515. public override void Terminate()
  516. {
  517. this.SendCmd(AdTecMatchMessage.STOP_QUERY);
  518. }
  519. public override void Reset()
  520. {
  521. //SendCmd(AdTecMatchMessage.STOP_QUERY);
  522. }
  523. /// <summary>
  524. ///
  525. /// </summary>
  526. /// <param name="c1,c2">百分比数字</param>
  527. /// <param name="c2"></param>
  528. public override void SetMatchPosition(float c1, float c2, out string reason)
  529. {
  530. //base.SetMatchPosition(c1, c2, out reason);
  531. ////this.SetWorkMode(EnumRfMatchTuneMode.Manual);
  532. //this.SetPosition(c1, c2);
  533. ////this.SetPresetMemory(0);
  534. ////this.SetWorkMode(EnumRfMatchTuneMode.Auto);
  535. //TunePosition1 = c1;
  536. //TunePosition2 = c2;
  537. reason = "";
  538. }
  539. public void SetPresetMode(RfMatchPresetMode mode)
  540. {
  541. }
  542. // -----------------------Private Method-------------------------
  543. //
  544. private void SerialPortDataReceived(string strOrg)
  545. {
  546. if (string.IsNullOrWhiteSpace(strOrg))
  547. {
  548. EV.PostAlarmLog(Module, "收到 Match 数据为空");
  549. return;
  550. }
  551. string[] sContent = strOrg.Split('\r');
  552. foreach (var sItem in sContent)
  553. {
  554. string sItem1 = sItem.TrimStart('\n');
  555. if (sItem1.Contains(AdTecMatchMessage.START_QUERY))
  556. {
  557. // BYTE 3,4; bit 7
  558. string s0 = sItem1.Substring(2 + S3_HEAD_LENGTH, 2);
  559. ushort status0 = Convert.ToUInt16(s0);
  560. byte[] a1 = BitConverter.GetBytes(status0);
  561. BitArray ba1 = new BitArray(a1);
  562. this.WorkMode = ba1[7] ? EnumRfMatchTuneMode.Manual : EnumRfMatchTuneMode.Auto;
  563. TuneMode1 = WorkMode;
  564. TuneMode2 = WorkMode;
  565. string sVpp = sItem1.Substring(42 + S3_HEAD_LENGTH, 3);
  566. this.VPP = Convert.ToUInt16(sVpp, 16);
  567. }
  568. else if (sItem1.Contains(AdTecMatchMessage.READ_POS))
  569. {
  570. string s1 = sItem1.Substring(5);
  571. string sLoad = s1.Substring(0, 3);
  572. string sPhase = s1.Substring(3, 3);
  573. this.TunePosition1 = Convert.ToUInt16(sLoad, 16) * 0.1f;
  574. this.TunePosition2 = Convert.ToUInt16(sPhase, 16) * 0.1f;
  575. }
  576. }
  577. }
  578. private void SerialPortErrorOccurred(string str)
  579. {
  580. EV.PostAlarmLog(Module, $"AdTec Match error [{str}]");
  581. }
  582. private void SendCmd(string str)
  583. {
  584. _serial?.Write(str + "\r");
  585. //EV.PostInfoLog(Module.ToString(), $"Match send [{str}]");
  586. }
  587. private void SetPosition(float c1val, float c2val)
  588. {
  589. ushort val1 = (ushort)(c1val * 10);
  590. ushort val2 = (ushort)(c2val * 10);
  591. string cmd = AdTecMatchMessage.WRITE_POS + val1.ToString("X3") + val2.ToString("X3");
  592. this.SendCmd(cmd);
  593. }
  594. private void SetWorkMode(EnumRfMatchTuneMode mode)
  595. {
  596. this.SendCmd(mode == EnumRfMatchTuneMode.Auto ? AdTecMatchMessage.AUTO :
  597. mode == EnumRfMatchTuneMode.Manual ? AdTecMatchMessage.MANUAL : "");
  598. }
  599. private void SetPresetMemory(byte gear)
  600. {
  601. this.SendCmd(AdTecMatchMessage.PRESET_MEM + gear.ToString());
  602. }
  603. }
  604. #endregion match
  605. }