IoRf.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. using System;
  2. using System.Xml;
  3. using Aitex.Core.Common.DeviceData;
  4. using Aitex.Core.RT.DataCenter;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.RT.Tolerance;
  10. using Aitex.Core.Util;
  11. using Aitex.Platform;
  12. namespace Aitex.Core.RT.Device.Unit
  13. {
  14. public class IoRf : BaseDevice, IDevice
  15. {
  16. //IO
  17. public bool IsOffline
  18. {
  19. get
  20. {
  21. return _diOffline != null && _diOffline.RawData;
  22. }
  23. }
  24. public float ScalePower
  25. {
  26. get
  27. {
  28. return _scPowerRange == null ? 99999 : (float)_scPowerRange.Value;
  29. }
  30. }
  31. public float ScaleFrequency
  32. {
  33. get
  34. {
  35. return 1000;
  36. }
  37. }
  38. public float ScaleDuty
  39. {
  40. get
  41. {
  42. return 100;
  43. }
  44. }
  45. public string UnitPower
  46. {
  47. get
  48. {
  49. return "w";
  50. }
  51. }
  52. public string UnitFrequency
  53. {
  54. get
  55. {
  56. return "Hz";
  57. }
  58. }
  59. public string UnitDuty
  60. {
  61. get
  62. {
  63. return "%";
  64. }
  65. }
  66. [Subscription(AITRfProperty.IsOverTemp)]
  67. public bool IsOverTemp
  68. {
  69. get
  70. {
  71. return _diOverTemp != null && _diOverTemp.Value;
  72. }
  73. }
  74. [Subscription(AITRfProperty.RFEnable)]
  75. public bool IsRfOn //True:on
  76. {
  77. get
  78. {
  79. if (_diStatus != null)
  80. return _diStatus.Value;
  81. return _doPowerOn.Value;
  82. }
  83. }
  84. [Subscription(AITRfProperty.RFSetPoint)]
  85. public float PowerSetPoint
  86. {
  87. get
  88. {
  89. return _aoPower.Value;
  90. }
  91. set
  92. {
  93. _aoPower.Value = value;
  94. }
  95. }
  96. [Subscription(AITRfProperty.RFDuty)]
  97. public float DutySetPoint
  98. {
  99. get
  100. {
  101. return _aoPulsingDutyCycle == null ? 0 : _aoPulsingDutyCycle.Value;
  102. }
  103. }
  104. [Subscription(AITRfProperty.RFFrequency)]
  105. public float FrequencySetPoint
  106. {
  107. get
  108. {
  109. return _aoPulsingFrency == null ? 0 : _aoPulsingFrency.Value;
  110. }
  111. }
  112. [Subscription(AITRfProperty.RFForwardPower)]
  113. public float RFForwardPower
  114. {
  115. get
  116. {
  117. if (_aiForwardPower == null)
  118. return 0;
  119. return (_scRegulationFactor != null && _scRegulationFactor.Value > 0) ? (float)(_aiForwardPower.Value / _scRegulationFactor.Value) : _aiForwardPower.Value;
  120. }
  121. }
  122. [Subscription(AITRfProperty.RFReflectPower)]
  123. public float RFReflectPower
  124. {
  125. get
  126. {
  127. return _aiReflectedPower == null ? 0 : _aiReflectedPower.Value;
  128. }
  129. }
  130. [Subscription(AITRfProperty.RFInterlock)]
  131. public bool RFInterlock
  132. {
  133. get
  134. {
  135. return _diIntlk == null || _diIntlk.Value;
  136. }
  137. }
  138. [Subscription(AITRfProperty.RFMode)]
  139. public RfMode WorkMode
  140. {
  141. get
  142. {
  143. if (_aoWorkMode == null)
  144. return RfMode.ContinuousWaveMode;
  145. return Math.Abs(_aoWorkMode.Value - (int)RfMode.PulsingMode) < 0.1 ? RfMode.PulsingMode : RfMode.ContinuousWaveMode;
  146. }
  147. }
  148. public float MatchMode
  149. {
  150. get
  151. {
  152. if (_aiMatchMode != null)
  153. return _aiMatchMode.Value;
  154. return _aoMatchMode == null ? 0 : _aoMatchMode.Value;
  155. }
  156. }
  157. public int MatchProcessMode
  158. {
  159. get
  160. {
  161. return null == _aiMatchPresetMode ? 0 : (int)_aiMatchPresetMode.Value;
  162. }
  163. }
  164. [Subscription(AITRfProperty.RFMatchPositionC1Feedback)]
  165. public float MatchPositionC1
  166. {
  167. get
  168. {
  169. if (_aiMatchPositionC1 != null)
  170. return _aiMatchPositionC1.Value;
  171. return 0;
  172. }
  173. }
  174. [Subscription(AITRfProperty.RFMatchPositionC2Feedback)]
  175. public float MatchPositionC2
  176. {
  177. get
  178. {
  179. if (_aiMatchPositionC2 != null)
  180. return _aiMatchPositionC2.Value;
  181. return 0;
  182. }
  183. }
  184. [Subscription(AITRfProperty.RFMatchPositionC1SetPoint)]
  185. public float MatchPositionC1SetPoint
  186. {
  187. get
  188. {
  189. if (_aoMatchPositionC1 != null)
  190. return _aoMatchPositionC1.Value;
  191. return 0;
  192. }
  193. }
  194. [Subscription(AITRfProperty.RFMatchPositionC2SetPoint)]
  195. public float MatchPositionC2SetPoint
  196. {
  197. get
  198. {
  199. if (_aoMatchPositionC2 != null)
  200. return _aoMatchPositionC2.Value;
  201. return 0;
  202. }
  203. }
  204. [Subscription(AITRfProperty.Voltage)]
  205. public float Voltage
  206. {
  207. get
  208. {
  209. return _aiVoltage == null ? 0 : _aiVoltage.Value;
  210. }
  211. }
  212. [Subscription(AITRfProperty.Current)]
  213. public float Current
  214. {
  215. get
  216. {
  217. return _aiCurrent == null ? 0 : _aiCurrent.Value;
  218. }
  219. }
  220. private DateTime _powerOnStartTime;
  221. private TimeSpan _powerOnElapsedTime;
  222. public string PowerOnTime
  223. {
  224. get
  225. {
  226. if (IsRfOn)
  227. _powerOnElapsedTime = DateTime.Now - _powerOnStartTime;
  228. return string.Format("{0}:{1}:{2}", ((int)_powerOnElapsedTime.TotalHours).ToString("00"),
  229. _powerOnElapsedTime.Minutes.ToString("00"), (_powerOnElapsedTime.Seconds > 0 ? (_powerOnElapsedTime.Seconds + 1) : 0).ToString("00"));
  230. }
  231. }
  232. public bool EnablePulsing
  233. {
  234. get
  235. {
  236. return _scEnablePulsingFunction == null || _scEnablePulsingFunction.Value;
  237. }
  238. }
  239. public bool EnableC1C2Position
  240. {
  241. get
  242. {
  243. return _scEnableC1C2Position == null || _scEnableC1C2Position.Value;
  244. }
  245. }
  246. public bool EnableReflectPower
  247. {
  248. get
  249. {
  250. return _scEnableReflectPower == null || _scEnableReflectPower.Value;
  251. }
  252. }
  253. public bool EnableVoltageCurrent
  254. {
  255. get
  256. {
  257. return _scEnableVoltageCurrent == null || _scEnableVoltageCurrent.Value;
  258. }
  259. }
  260. private DIAccessor _diStatus = null;
  261. private DIAccessor _diIntlk = null;
  262. private DIAccessor _diOffline;
  263. private DIAccessor _diOverTemp;
  264. private DIAccessor _diIArc;
  265. private DIAccessor _diVArc;
  266. private DIAccessor _diBreakState;
  267. private DIAccessor _diHighReflectPower;
  268. private DIAccessor _diMatchCommWithGenerator;
  269. private DIAccessor _diRFCBAlarm;
  270. private DOAccessor _doPowerOn = null;
  271. private AIAccessor _aiReflectedPower = null;
  272. private AIAccessor _aiForwardPower = null;
  273. private AIAccessor _aiMatchPresetMode = null;
  274. private AIAccessor _aiMatchMode = null;
  275. private AIAccessor _aiMatchPositionC1 = null;
  276. private AIAccessor _aiMatchPositionC2 = null;
  277. private AIAccessor _aiVoltage;
  278. private AIAccessor _aiCurrent;
  279. private AOAccessor _aoPower = null;
  280. private AOAccessor _aoWorkMode = null;
  281. private AOAccessor _aoPulsingFrency = null;
  282. private AOAccessor _aoPulsingDutyCycle = null;
  283. private AOAccessor _aoMatchPresetMode = null;
  284. private AOAccessor _aoMatchMode = null;
  285. private AOAccessor _aoMatchPositionC1 = null;
  286. private AOAccessor _aoMatchPositionC2 = null;
  287. private AOAccessor _aoCoefficient = null;
  288. //SC
  289. private SCItem<int> _scMatchPresetMode = null;
  290. private SCItem<int> _scMatchMode = null;
  291. private SCItem<double> _scMatchPositionC1 = null;
  292. private SCItem<double> _scMatchPositionC2 = null;
  293. private SCItem<double> _scPowerAlarmRange = null;
  294. private SCItem<double> _scPowerAlarmTime = null;
  295. private SCItem<double> _scReflectPowerAlarmRange = null;
  296. private SCItem<double> _scReflectPowerAlarmTime = null;
  297. private SCItem<double> _scPowerRange;
  298. private SCItem<double> _scCoefficient;
  299. private SCItem<bool> _scEnablePulsingFunction;
  300. private SCItem<bool> _scEnableC1C2Position;
  301. private SCItem<bool> _scEnableReflectPower;
  302. private SCItem<bool> _scEnableVoltageCurrent;
  303. private SCItem<double> _scRegulationFactor;
  304. private F_TRIG _interlockTrig = new F_TRIG();
  305. private R_TRIG _rfOnTrigger = new R_TRIG();
  306. private R_TRIG _trigOffline = new R_TRIG();
  307. private R_TRIG _trigOverTemp = new R_TRIG();
  308. private ToleranceChecker _checkerPower;
  309. private ToleranceChecker _checkerReflectPower;
  310. private R_TRIG _trigHighReflectPower = new R_TRIG();
  311. private R_TRIG _trigMatchCommWithGenerator = new R_TRIG();
  312. private R_TRIG _trigRFCBAlarm=new R_TRIG();
  313. readonly DeviceTimer _powerOnTimer = new DeviceTimer();
  314. public IoRf(string module, XmlElement node)
  315. {
  316. base.Module = module;
  317. base.Name = node.GetAttribute("id");
  318. base.Display = node.GetAttribute("display");
  319. base.DeviceID = node.GetAttribute("schematicId");
  320. _diStatus = ParseDiNode("diOnOffFeedback", node);
  321. _diOffline = ParseDiNode("diOffline", node);
  322. _diIntlk = ParseDiNode("diInterlock", node);
  323. _diOverTemp = ParseDiNode("diOverTemp", node);
  324. _diIArc = ParseDiNode("diIArc", node);
  325. _diVArc = ParseDiNode("diVArc", node);
  326. _diBreakState = ParseDiNode("diBreakerState", node);
  327. _diHighReflectPower = ParseDiNode("diHighReflectPower", node);
  328. _diMatchCommWithGenerator = ParseDiNode("diMatchCommWithGenerator", node);
  329. _diRFCBAlarm = ParseDiNode("diRFCBAlarm", node);
  330. _doPowerOn = ParseDoNode("doOnOff", node);
  331. _aiReflectedPower = ParseAiNode("aiReflectPower", node);
  332. _aiForwardPower = ParseAiNode("aiForwardPower", node);
  333. _aiMatchPresetMode = ParseAiNode("aiMatchPresetMode", node);
  334. _aiMatchMode = ParseAiNode("aiMatchMode", node);
  335. _aiMatchPositionC1 = ParseAiNode("aiMatchPositionC1", node);
  336. _aiMatchPositionC2 = ParseAiNode("aiMatchPositionC2", node);
  337. _aiVoltage = ParseAiNode("aiVoltage", node);
  338. _aiCurrent = ParseAiNode("aiCurrent", node);
  339. _aoPower = ParseAoNode("aoPower", node);
  340. _aoWorkMode = ParseAoNode("aoWorkMode", node);
  341. _aoPulsingFrency = ParseAoNode("aoFrequency", node);
  342. _aoPulsingDutyCycle = ParseAoNode("aoDuty", node);
  343. _aoMatchPresetMode = ParseAoNode("aoMatchPresetMode", node);
  344. _aoMatchMode = ParseAoNode("aoMatchMode", node);
  345. _aoMatchPositionC1 = ParseAoNode("aoMatchPositionC1", node);
  346. _aoMatchPositionC2 = ParseAoNode("aoMatchPositionC2", node);
  347. _aoCoefficient = ParseAoNode("aoCoefficient", node);
  348. _scMatchPresetMode = ParseScNodeInteger("scMatchPresetMode", node);
  349. _scMatchMode = ParseScNodeInteger("scMatchMode", node);
  350. _scMatchPositionC1 = ParseScNodeDouble("scMatchPositionC1", node);
  351. _scMatchPositionC2 = ParseScNodeDouble("scMatchPositionC2", node);
  352. _scPowerAlarmRange = ParseScNodeDouble("scPowerAlarmRange", node);
  353. _scPowerAlarmTime = ParseScNodeDouble("scPowerAlarmTime", node);
  354. _scReflectPowerAlarmRange = ParseScNodeDouble("scReflectPowerAlarmRange", node);
  355. _scReflectPowerAlarmTime = ParseScNodeDouble("scReflectPowerAlarmTime", node);
  356. _scPowerRange = ParseScNodeDouble("scPowerRange", node);
  357. _scCoefficient = ParseScNodeDouble("scCoefficient", node);
  358. _scEnablePulsingFunction = ParseScNodeBool("scEnablePulsingFunction", node);
  359. _scEnableC1C2Position = ParseScNodeBool("scEnableC1C2Position", node);
  360. _scEnableReflectPower = ParseScNodeBool("scEnableReflectPower", node);
  361. _scEnableVoltageCurrent = ParseScNodeBool("scEnableVoltageCurrent", node);
  362. _scRegulationFactor = ParseScNodeDouble("scPowerRegulationFactor", node);
  363. }
  364. public bool Initialize()
  365. {
  366. DATA.Subscribe(string.Format("Device.{0}.{1}", Module, Name), () =>
  367. {
  368. AITRfData data = new AITRfData()
  369. {
  370. DeviceName = Name,
  371. DeviceSchematicId = DeviceID,
  372. DisplayName = Display,
  373. ForwardPower = RFForwardPower,
  374. ReflectPower = RFReflectPower,
  375. IsInterlockOk = RFInterlock,
  376. IsRfOn = IsRfOn,
  377. PowerSetPoint = PowerSetPoint,
  378. FrequencySetPoint = FrequencySetPoint,
  379. DutySetPoint = DutySetPoint,
  380. ScalePower = ScalePower,
  381. ScaleDuty = ScaleDuty,
  382. ScaleFrequency = ScaleFrequency,
  383. UnitDuty = UnitDuty,
  384. UnitFrequency = UnitFrequency,
  385. UnitPower = UnitPower,
  386. WorkMode = (int)WorkMode,
  387. PowerOnElapsedTime = PowerOnTime,
  388. EnablePulsing = EnablePulsing,
  389. EnableC1C2Position = EnableC1C2Position,
  390. EnableReflectPower = EnableReflectPower,
  391. EnableVoltageCurrent = EnableVoltageCurrent,
  392. MatchMode = (int)MatchMode,
  393. MatchPresetMode = MatchProcessMode,
  394. MatchPositionC1 = MatchPositionC1,
  395. MatchPositionC2 = MatchPositionC2,
  396. MatchPositionC1SetPoint = MatchPositionC1SetPoint,
  397. MatchPositionC2SetPoint = MatchPositionC2SetPoint,
  398. Voltage = Voltage,
  399. Current = Current,
  400. };
  401. return data;
  402. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  403. if (_aoWorkMode != null)
  404. _aoWorkMode.Value = (float)RfMode.ContinuousWaveMode;
  405. if (_aoMatchMode != null)
  406. _aoMatchMode.Value = _scMatchMode != null ? _scMatchMode.Value : 0;
  407. if (_aoMatchPositionC1 != null)
  408. _aoMatchPositionC1.Value = _scMatchPositionC1 != null ? (float)_scMatchPositionC1.Value : 50;
  409. if (_aoMatchPositionC2 != null)
  410. _aoMatchPositionC2.Value = _scMatchPositionC2 != null ? (float)_scMatchPositionC2.Value : 50;
  411. //if (_aoMatchPresetMode != null)
  412. // _aoMatchPresetMode.Value = _scMatchPresetMode != null ? _scMatchPresetMode.Value : (int)RfMatchPresetMode.Hold;
  413. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetPowerOnOff), (out string reason, int time, object[] param) =>
  414. {
  415. bool isOn = Convert.ToBoolean((string)param[0]);
  416. bool res = this.SetPowerOnOff(isOn, out string str);
  417. reason = str;
  418. return res;
  419. });
  420. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetMode), (out string reason, int time, object[] param) =>
  421. {
  422. reason = string.Empty;
  423. RfMode mode = (RfMode)Enum.Parse(typeof(RfMode), (string)param[0], true);
  424. if (_aoWorkMode != null)
  425. {
  426. _aoWorkMode.Value = mode == RfMode.ContinuousWaveMode ? 1 : 2;
  427. }
  428. reason = string.Format("Set RF work mode to " + mode.ToString());
  429. return true;
  430. });
  431. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetContinuousPower), (out string reason, int time, object[] param) =>
  432. {
  433. float power = (float)Convert.ToDouble((string)param[0]);
  434. power = Math.Max(0, power);
  435. power = Math.Min(ScalePower, power);
  436. _aoPower.Value = power;
  437. reason = string.Format("RF set Power {0}", _aoPower.Value);
  438. return true;
  439. });
  440. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetPulsingPower), (out string reason, int time, object[] param) =>
  441. {
  442. float frequency = (float)Convert.ToDouble((string)param[1]);
  443. frequency = Math.Max(0, frequency);
  444. frequency = Math.Min(ScaleFrequency, frequency);
  445. _aoPulsingFrency.Value = frequency;
  446. float duty = (float)Convert.ToDouble((string)param[2]);
  447. duty = Math.Max(0, duty);
  448. duty = Math.Min(ScaleDuty, duty);
  449. _aoPulsingDutyCycle.Value = duty;
  450. float power = (float)Convert.ToDouble((string)param[0]);
  451. power = Math.Max(0, power);
  452. power = Math.Min(ScalePower, power);
  453. _aoPower.Value = power;
  454. reason = string.Format("RF set Frequency:{0}, Duty:{1}, Power:{2}", frequency, duty, power);
  455. return true;
  456. });
  457. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetPulsingFrequency),
  458. (out string reason, int time, object[] param) =>
  459. {
  460. reason = string.Empty;
  461. if (_aoPulsingFrency != null)
  462. {
  463. float frequency = (float)Convert.ToDouble((string)param[0]);
  464. frequency = Math.Max(0, frequency);
  465. frequency = Math.Min(ScaleFrequency, frequency);
  466. _aoPulsingFrency.Value = frequency;
  467. reason = string.Format("RF set Frequency:{0}", frequency);
  468. }
  469. return true;
  470. });
  471. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetPulsingDuty), (out string reason, int time, object[] param) =>
  472. {
  473. reason = string.Empty;
  474. if (_aoPulsingDutyCycle != null)
  475. {
  476. float duty = (float)Convert.ToDouble((string)param[0]);
  477. duty = Math.Max(0, duty);
  478. duty = Math.Min(ScaleDuty, duty);
  479. _aoPulsingDutyCycle.Value = duty;
  480. reason = string.Format("RF set Duty:{0} ", duty);
  481. }
  482. return true;
  483. });
  484. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetPower), (out string reason, int time, object[] param) =>
  485. {
  486. reason = string.Empty;
  487. float power = (float)Convert.ToDouble((string)param[0]);
  488. power = Math.Max(0, power);
  489. power = Math.Min(ScalePower, power);
  490. _aoPower.Value = power;
  491. reason = string.Format("RF set Power:{0}", power);
  492. return true;
  493. });
  494. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetMatchPositionC1), (out string reason, int time, object[] param) =>
  495. {
  496. float c1 = (float)Convert.ToDouble((string)param[0]);
  497. c1 = Math.Max((float)_scMatchPositionC1.RangeLowLimit, c1);
  498. c1 = Math.Min((float)_scMatchPositionC1.RangeUpLimit, c1);
  499. _aoMatchPositionC1.Value = c1;
  500. reason = string.Format("Set RF match position c1 :{0}", c1);
  501. return true;
  502. });
  503. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetMatchPositionC2), (out string reason, int time, object[] param) =>
  504. {
  505. float c2 = (float)Convert.ToDouble((string)param[0]);
  506. c2 = Math.Max((float)_scMatchPositionC1.RangeLowLimit, c2);
  507. c2 = Math.Min((float)_scMatchPositionC1.RangeUpLimit, c2);
  508. _aoMatchPositionC2.Value = c2;
  509. reason = string.Format("Set RF match position c2 :{0}", c2);
  510. return true;
  511. });
  512. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetMatchPosition), (out string reason, int time, object[] param) =>
  513. {
  514. return SetMatchPosition(Convert.ToDouble((string)param[0]), Convert.ToDouble((string)param[1]), out reason);
  515. });
  516. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetMatchMode), (out string reason, int time, object[] param) =>
  517. {
  518. return SetMatchMode(Convert.ToInt32((string)param[0]), out reason);
  519. });
  520. DEVICE.Register(String.Format("{0}.{1}", Name, AITRfOperation.SetMatchProcessMode), (out string reason, int time, object[] param) =>
  521. {
  522. RfMatchModeProcess mode = (RfMatchModeProcess)Enum.Parse(typeof(RfMatchModeProcess), (string)param[0], true);
  523. _aoMatchPresetMode.Value = (float)mode;
  524. reason = $"Match mode set to {mode}";
  525. return true;
  526. });
  527. return true;
  528. }
  529. public void Stop()
  530. {
  531. string reason = String.Empty;
  532. _aoPower.Value = 0;
  533. }
  534. public void Terminate()
  535. {
  536. }
  537. public void Monitor()
  538. {
  539. try
  540. {
  541. if (_powerOnTimer.IsTimeout() && !_diStatus.Value)
  542. {
  543. EV.PostMessage(Module, EventEnum.DefaultAlarm, "The RF generator is offline");
  544. SetPowerOnOff(false, out string str);
  545. _powerOnTimer.Stop();
  546. }
  547. if (_aoCoefficient != null && _scCoefficient != null)
  548. {
  549. _aoCoefficient.Value = (float)_scCoefficient.Value;
  550. }
  551. if (_checkerPower == null)
  552. _checkerPower = new ToleranceChecker(_scPowerAlarmTime.Value);
  553. if (_checkerReflectPower == null)
  554. _checkerReflectPower = new ToleranceChecker(_scReflectPowerAlarmTime.Value);
  555. _interlockTrig.CLK = _diIntlk.Value;
  556. if (_interlockTrig.Q)
  557. {
  558. EV.PostMessage(Module, EventEnum.RFInterlockFailed);
  559. }
  560. _rfOnTrigger.CLK = IsRfOn;
  561. if (_rfOnTrigger.Q)
  562. {
  563. _powerOnStartTime = DateTime.Now;
  564. _checkerPower.Reset(_scPowerAlarmTime.Value);
  565. _checkerReflectPower.Reset(_scReflectPowerAlarmTime.Value);
  566. }
  567. if (_rfOnTrigger.M)
  568. {
  569. _checkerPower.Monitor(RFForwardPower, PowerSetPoint - _scPowerAlarmRange.Value, PowerSetPoint + _scPowerAlarmRange.Value, _scPowerAlarmTime.Value);
  570. if (_checkerPower.Trig)
  571. {
  572. string reason;
  573. EV.PostMessage(Module, EventEnum.ToleranceAlarm, Module, Display,
  574. String.Format("Forward power {3} out of range[{0},{1}] in {2} seconds",
  575. (PowerSetPoint - _scPowerAlarmRange.Value).ToString("0"),
  576. (PowerSetPoint + _scPowerAlarmRange.Value).ToString("0"),
  577. _scPowerAlarmTime.Value.ToString("0"),
  578. RFForwardPower.ToString("0")));
  579. SetPowerOnOff(false, out reason);
  580. }
  581. _checkerReflectPower.Monitor(RFReflectPower, double.MinValue, _scReflectPowerAlarmRange.Value, _scReflectPowerAlarmTime.Value);
  582. if (_checkerReflectPower.Trig)
  583. {
  584. string reason;
  585. EV.PostMessage(Module, EventEnum.ToleranceAlarm, Module, Display,
  586. String.Format("Reflect power {2} out of range[0,{0}] in {1} seconds",
  587. _scReflectPowerAlarmRange.Value.ToString("0"),
  588. _scReflectPowerAlarmTime.Value.ToString("0"),
  589. RFReflectPower.ToString("0")));
  590. SetPowerOnOff(false, out reason);
  591. }
  592. }
  593. _trigOffline.CLK = IsOffline;
  594. if (_trigOffline.Q)
  595. {
  596. EV.PostMessage(Module, EventEnum.DefaultAlarm, "The RF generator is offline");
  597. }
  598. _trigOverTemp.CLK = IsOverTemp;
  599. if (_trigOverTemp.Q)
  600. {
  601. EV.PostMessage(Module, EventEnum.RfOverTemp);
  602. }
  603. if (_diHighReflectPower != null)
  604. {
  605. _trigHighReflectPower.CLK = _diHighReflectPower.Value;
  606. if (_trigOffline.Q)
  607. {
  608. EV.PostMessage(Module, EventEnum.DefaultAlarm, "RF trig high reflect power");
  609. }
  610. }
  611. if (_diMatchCommWithGenerator != null)
  612. {
  613. _trigMatchCommWithGenerator.CLK = !_diMatchCommWithGenerator.Value;
  614. if (_trigMatchCommWithGenerator.Q)
  615. {
  616. EV.PostMessage(Module, EventEnum.DefaultAlarm, "RF trig match not communicate with generator");
  617. }
  618. }
  619. _trigRFCBAlarm.CLK = _diRFCBAlarm !=null&& _diRFCBAlarm.Value;
  620. if (_trigRFCBAlarm.Q)
  621. {
  622. EV.PostMessage(Module, EventEnum.DefaultAlarm, "RF Circuit Broaker Trip Alarm");
  623. }
  624. }
  625. catch (Exception ex)
  626. {
  627. LOG.Write(ex);
  628. throw ex;
  629. }
  630. }
  631. public void Reset()
  632. {
  633. _interlockTrig.RST = true;
  634. _trigOffline.RST = true;
  635. _trigOverTemp.RST = true;
  636. _trigMatchCommWithGenerator.RST = true;
  637. _trigHighReflectPower.RST = true;
  638. _trigRFCBAlarm.RST = true;
  639. }
  640. public bool SetPowerOnOff(bool isOn, out string reason)
  641. {
  642. if (!_diIntlk.Value)
  643. {
  644. reason = string.Format("RF interlock is not satisfied,can not be on");
  645. return false;
  646. }
  647. if (!isOn)
  648. {
  649. PowerSetPoint = 0;
  650. }
  651. bool result = _doPowerOn.SetValue(isOn, out reason);
  652. if (result)
  653. {
  654. reason = string.Format("Set RF power " + (isOn ? "On" : "Off"));
  655. if (isOn)
  656. _powerOnTimer.Start(5000);
  657. else
  658. _powerOnTimer.Stop();
  659. }
  660. else
  661. {
  662. EV.PostAlarmLog(Module, reason);
  663. }
  664. return result;
  665. }
  666. public bool SetMatchMode(int mode, out string reason)
  667. {
  668. if (_aoMatchMode == null)
  669. {
  670. reason = "System do not support setting match mode.";
  671. return false;
  672. }
  673. _aoMatchMode.Value = mode;
  674. reason = string.Format("Match mode set to {0} ", mode);
  675. return true;
  676. }
  677. public bool SetMatchPosition(double c1, double c2, out string reason)
  678. {
  679. reason = string.Empty;
  680. if (_scMatchPositionC1 != null && _aoMatchPositionC1 != null)
  681. {
  682. double c1FilterValue = c1;
  683. c1FilterValue = Math.Min(_scMatchPositionC1.RangeUpLimit, c1FilterValue);
  684. c1FilterValue = Math.Max(_scMatchPositionC2.RangeLowLimit, c1FilterValue);
  685. _aoMatchPositionC1.Value = (float)c1FilterValue;
  686. reason = string.Format("Match position C1 set to {0} ", c1FilterValue);
  687. }
  688. if (_scMatchPositionC2 != null && _aoMatchPositionC2 != null)
  689. {
  690. double c2FilterValue = c2;
  691. c2FilterValue = Math.Min(_scMatchPositionC2.RangeUpLimit, c2FilterValue);
  692. c2FilterValue = Math.Max(_scMatchPositionC2.RangeLowLimit, c2FilterValue);
  693. _aoMatchPositionC2.Value = (float)c2FilterValue;
  694. reason += string.Format("Match position C2 set to {0}", c2FilterValue);
  695. }
  696. return true;
  697. }
  698. }
  699. }