IoMfc.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. using System;
  2. using System.Diagnostics;
  3. using System.Xml;
  4. using Aitex.Core.Common.DeviceData;
  5. using Aitex.Core.RT.DataCenter;
  6. using Aitex.Core.RT.Device;
  7. using Aitex.Core.RT.Event;
  8. using Aitex.Core.RT.IOCore;
  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.DBCore;
  14. using Venus_RT.Modules;
  15. using Aitex.Core.RT.Log;
  16. using static Venus_RT.Modules.PMs.PMGasVerificationRoutine;
  17. using Venus_Core;
  18. using MECF.Framework.Common.Equipment;
  19. namespace Venus_RT.Devices.IODevices
  20. {
  21. public enum MFCWriteMode
  22. {
  23. Flow,
  24. Percent
  25. }
  26. //will be upgrade later
  27. public class MfcBase1 : BaseDevice, IDevice
  28. {
  29. public virtual double SetPoint { get; set; }
  30. public virtual double FeedBack { get; set; }
  31. public virtual bool IsOutOfTolerance { get; }
  32. public virtual double Scale { set; get; }
  33. public virtual string DisplayName { set; get; }
  34. public virtual bool PressureAlarm { get; set; }
  35. private float _percent10Calculate;
  36. private float _percent20Calculate;
  37. private float _percent30Calculate;
  38. private float _percent40Calculate;
  39. private float _percent50Calculate;
  40. private float _percent60Calculate;
  41. private float _percent70Calculate;
  42. private float _percent80Calculate;
  43. private float _percent90Calculate;
  44. private float _percent100Calculate;
  45. private float _verificationCalculate;
  46. private float _verificationSetpoint;
  47. private string _verificationResult = "";
  48. public MfcBase1()
  49. {
  50. }
  51. public virtual bool Initialize()
  52. {
  53. DATA.Subscribe($"{Module}.{Name}.VerificationResult", () => _verificationResult);
  54. DATA.Subscribe($"{Module}.{Name}.FeedBack", () => FeedBack);
  55. DATA.Subscribe($"{Module}.{Name}.SetPoint", () => SetPoint);
  56. return true;
  57. }
  58. public virtual void Monitor()
  59. {
  60. }
  61. public virtual void Reset()
  62. {
  63. }
  64. public virtual void Terminate()
  65. {
  66. }
  67. public virtual void Ramp(int time)
  68. {
  69. }
  70. public virtual void Ramp(double target, int time)
  71. {
  72. }
  73. public virtual void StopRamp()
  74. {
  75. }
  76. public virtual void SetVerificationResult(float setpoint, float calculateFlow, bool saveResult, double time, double deviation, bool result, int verifyMode)
  77. {
  78. if (verifyMode == 0)
  79. {
  80. MFCVerificationOnePointData data = new MFCVerificationOnePointData()
  81. {
  82. Module = Module,
  83. Name = Name,
  84. Setpoint = setpoint,
  85. Calculate = calculateFlow,
  86. };
  87. MFCVerificationDataRecorder.AddOnePointData(data);
  88. }
  89. //ten points
  90. var delta = Scale / 10;
  91. _verificationResult += $"{setpoint},{calculateFlow},{time},{deviation},{result};";
  92. if (delta - 0.1 < setpoint && delta + 0.1 > setpoint)
  93. {
  94. _percent10Calculate = calculateFlow;
  95. }
  96. else if (2 * delta - 0.1 < setpoint && 2 * delta + 0.1 > setpoint)
  97. {
  98. _percent20Calculate = calculateFlow;
  99. }
  100. else if (3 * delta - 0.1 < setpoint && 3 * delta + 0.1 > setpoint)
  101. {
  102. _percent30Calculate = calculateFlow;
  103. }
  104. else if (4 * delta - 0.1 < setpoint && 4 * delta + 0.1 > setpoint)
  105. {
  106. _percent40Calculate = calculateFlow;
  107. }
  108. else if (5 * delta - 0.1 < setpoint && 5 * delta + 0.1 > setpoint)
  109. {
  110. _percent50Calculate = calculateFlow;
  111. }
  112. else if (6 * delta - 0.1 < setpoint && 6 * delta + 0.1 > setpoint)
  113. {
  114. _percent60Calculate = calculateFlow;
  115. }
  116. else if (7 * delta - 0.1 < setpoint && 7 * delta + 0.1 > setpoint)
  117. {
  118. _percent70Calculate = calculateFlow;
  119. }
  120. else if (8 * delta - 0.1 < setpoint && 8 * delta + 0.1 > setpoint)
  121. {
  122. _percent80Calculate = calculateFlow;
  123. }
  124. else if (9 * delta - 0.1 < setpoint && 9 * delta + 0.1 > setpoint)
  125. {
  126. _percent90Calculate = calculateFlow;
  127. }
  128. else if (10 * delta - 0.1 < setpoint && 10 * delta + 0.1 > setpoint)
  129. {
  130. _percent100Calculate = calculateFlow;
  131. }
  132. else
  133. {
  134. _verificationCalculate = calculateFlow;
  135. _verificationSetpoint = setpoint;
  136. }
  137. if (saveResult)
  138. {
  139. SaveVerificationData(verifyMode);
  140. }
  141. }
  142. private void SaveVerificationData(int verifyMode)
  143. {
  144. var delta = (float)(Scale / 10);
  145. MFCVerificationData data = new MFCVerificationData()
  146. {
  147. Module = Module,
  148. Name = DisplayName,
  149. Percent10Setpoint = delta,
  150. Percent10Calculate = _percent10Calculate,
  151. Percent20Setpoint = delta * 2,
  152. Percent20Calculate = _percent20Calculate,
  153. Percent30Setpoint = delta * 3,
  154. Percent30Calculate = _percent30Calculate,
  155. Percent40Setpoint = delta * 4,
  156. Percent40Calculate = _percent40Calculate,
  157. Percent50Setpoint = delta * 5,
  158. Percent50Calculate = _percent50Calculate,
  159. Percent60Setpoint = delta * 6,
  160. Percent60Calculate = _percent60Calculate,
  161. Percent70Setpoint = delta * 7,
  162. Percent70Calculate = _percent70Calculate,
  163. Percent80Setpoint = delta * 8,
  164. Percent80Calculate = _percent80Calculate,
  165. Percent90Setpoint = delta * 9,
  166. Percent90Calculate = _percent90Calculate,
  167. Percent100Setpoint = delta * 10,
  168. Percent100Calculate = _percent100Calculate,
  169. Setpoint = _verificationSetpoint,
  170. Calculate = _verificationCalculate,
  171. };
  172. MFCVerificationDataRecorder.Add(data);
  173. if (verifyMode == 1)
  174. {
  175. MFCVerificationTenPointsData tenPointsdata = new MFCVerificationTenPointsData()
  176. {
  177. Module = Module,
  178. Name = Name,
  179. Percent10Setpoint = delta,
  180. Percent10Calculate = _percent10Calculate,
  181. Percent20Setpoint = delta * 2,
  182. Percent20Calculate = _percent20Calculate,
  183. Percent30Setpoint = delta * 3,
  184. Percent30Calculate = _percent30Calculate,
  185. Percent40Setpoint = delta * 4,
  186. Percent40Calculate = _percent40Calculate,
  187. Percent50Setpoint = delta * 5,
  188. Percent50Calculate = _percent50Calculate,
  189. Percent60Setpoint = delta * 6,
  190. Percent60Calculate = _percent60Calculate,
  191. Percent70Setpoint = delta * 7,
  192. Percent70Calculate = _percent70Calculate,
  193. Percent80Setpoint = delta * 8,
  194. Percent80Calculate = _percent80Calculate,
  195. Percent90Setpoint = delta * 9,
  196. Percent90Calculate = _percent90Calculate,
  197. Percent100Setpoint = delta * 10,
  198. Percent100Calculate = _percent100Calculate,
  199. };
  200. MFCVerificationDataRecorder.AddTenPointsData(tenPointsdata);
  201. }
  202. }
  203. public void ResetVerificationData()
  204. {
  205. _percent10Calculate = 0;
  206. _percent20Calculate = 0;
  207. _percent30Calculate = 0;
  208. _percent40Calculate = 0;
  209. _percent50Calculate = 0;
  210. _percent60Calculate = 0;
  211. _percent70Calculate = 0;
  212. _percent80Calculate = 0;
  213. _percent90Calculate = 0;
  214. _percent100Calculate = 0;
  215. _verificationCalculate = 0;
  216. _verificationSetpoint = 0;
  217. _verificationResult = "";
  218. }
  219. }
  220. public class IoMfc : MfcBase1
  221. {
  222. byte[] _buffer_1 = new byte[4];
  223. byte[] _buffer_2 = new byte[4];
  224. private MFCWriteMode _writeMode;
  225. //private JetChamber m_JetChamber;
  226. public string Unit
  227. {
  228. get; set;
  229. }
  230. //[Subscription(AITMfcDataPropertyName.Scale)]
  231. public override double Scale
  232. {
  233. get
  234. {
  235. if (_scN2Scale == null || _scScaleFactor == null)
  236. return 0;
  237. return _scN2Scale.IntValue * _scScaleFactor.DoubleValue;
  238. }
  239. }
  240. //[Subscription(AITMfcDataPropertyName.SetPoint)]
  241. public override double SetPoint
  242. {
  243. get
  244. {
  245. if (_aoFlow != null)
  246. {
  247. byte[] high = BitConverter.GetBytes(_aoFlow.Buffer[_aoFlow.Index]);
  248. byte[] low = BitConverter.GetBytes(_aoFlow.Buffer[_aoFlow.Index + 1]);
  249. _buffer_1[0] = high[0];
  250. _buffer_1[1] = high[1];
  251. _buffer_1[2] = low[0];
  252. _buffer_1[3] = low[1];
  253. float flow = BitConverter.ToSingle(_buffer_1, 0);
  254. if (_writeMode == MFCWriteMode.Flow)
  255. {
  256. //if (ModuleHelper.IsPm(Module) && (m_JetChamber == JetChamber.VenusSE || m_JetChamber == JetChamber.VenusDE))
  257. //{
  258. // return flow;
  259. //}
  260. //else
  261. //{
  262. // return flow * Scale / RtInstance.ANALOG_TRANS_RANGE;
  263. //}
  264. return flow;
  265. }
  266. else
  267. {
  268. return Math.Round(flow * Scale / 100, 2);
  269. }
  270. }
  271. return 0;
  272. }
  273. set
  274. {
  275. if (_aoFlow != null)
  276. {
  277. byte[] flow;
  278. if (_writeMode == MFCWriteMode.Flow)
  279. {
  280. //if (ModuleHelper.IsPm(Module) && (m_JetChamber == JetChamber.VenusSE || m_JetChamber == JetChamber.VenusDE))
  281. //{
  282. // flow = BitConverter.GetBytes((float)value );
  283. //}
  284. //else
  285. //{
  286. // flow = BitConverter.GetBytes((float)(value * RtInstance.ANALOG_TRANS_RANGE / Scale));
  287. //}
  288. flow = BitConverter.GetBytes((float)value);
  289. }
  290. else
  291. {
  292. flow = BitConverter.GetBytes((float)(Math.Round(value / Scale * 100, 2)));
  293. }
  294. _aoFlow.Buffer[_aoFlow.Index] = BitConverter.ToInt16(flow, 0);
  295. _aoFlow.Buffer[_aoFlow.Index + 1] = BitConverter.ToInt16(flow, 2);
  296. }
  297. }
  298. }
  299. //[Subscription(AITMfcDataPropertyName.DefaultSetPoint)]
  300. public double DefaultSetPoint
  301. {
  302. get
  303. {
  304. if (_scDefaultSetPoint != null)
  305. return _scDefaultSetPoint.IntValue;
  306. return 0;
  307. }
  308. }
  309. //[Subscription(AITMfcDataPropertyName.FeedBack)]
  310. public override double FeedBack
  311. {
  312. get
  313. {
  314. if (_aiFlow != null)
  315. {
  316. byte[] high = BitConverter.GetBytes(_aiFlow.Buffer[_aiFlow.Index]);
  317. byte[] low = BitConverter.GetBytes(_aiFlow.Buffer[_aiFlow.Index + 1]);
  318. _buffer_2[0] = high[0];
  319. _buffer_2[1] = high[1];
  320. _buffer_2[2] = low[0];
  321. _buffer_2[3] = low[1];
  322. float flow = BitConverter.ToSingle(_buffer_2, 0);
  323. if (_writeMode == MFCWriteMode.Flow)
  324. {
  325. //return (_scRegulationFactor != null && _scRegulationFactor.IntValue > 0) ? flow
  326. // : flow * Scale / RtInstance.ANALOG_TRANS_RANGE;
  327. return flow;
  328. }
  329. else
  330. {
  331. return flow * Scale / 100;
  332. }
  333. }
  334. return 0;
  335. }
  336. }
  337. //[Subscription(AITMfcDataPropertyName.IsOutOfTolerance)]
  338. public override bool IsOutOfTolerance
  339. {
  340. get
  341. {
  342. return _toleranceChecker.Result;
  343. }
  344. }
  345. //[Subscription(AITMfcDataPropertyName.IsEnableAlarm)]
  346. public bool EnableAlarm
  347. {
  348. get
  349. {
  350. if (_scEnableAlarm != null)
  351. return _scEnableAlarm.BoolValue;
  352. return false;
  353. }
  354. }
  355. //[Subscription(AITMfcDataPropertyName.AlarmRange)]
  356. public double AlarmRange
  357. {
  358. get
  359. {
  360. if (_scAlarmRange != null)
  361. return _scAlarmRange.IntValue;
  362. return 0;
  363. }
  364. }
  365. //[Subscription(AITMfcDataPropertyName.AlarmTime)]
  366. public double AlarmTime
  367. {
  368. get
  369. {
  370. if (_scAlarmTime != null)
  371. return _scAlarmTime.IntValue;
  372. return 0;
  373. }
  374. }
  375. //[Subscription(AITMfcDataPropertyName.PressureAlarm)]
  376. public override bool PressureAlarm
  377. {
  378. get { return _diPressureAlarm != null ? _diPressureAlarm.Value : true; }
  379. }
  380. //[Subscription(AITMfcDataPropertyName.MfcAlarm)]
  381. public bool MfcAlarm
  382. {
  383. get
  384. {
  385. return _bMfcAlarm;
  386. }
  387. }
  388. //[Subscription(AITMfcDataPropertyName.IsEnable)]
  389. public bool Enable
  390. {
  391. get
  392. {
  393. if (_scEnable != null)
  394. return _scEnable.BoolValue;
  395. return false;
  396. }
  397. }
  398. //[Subscription(AITMfcDataPropertyName.IsOffline)]
  399. public bool IsOffline
  400. {
  401. get
  402. {
  403. if (_diOffline != null)
  404. return _diOffline.Value;
  405. return false;
  406. }
  407. }
  408. public override string DisplayName
  409. {
  410. get
  411. {
  412. if (_scGasName != null)
  413. return _scGasName.StringValue;
  414. return Display;
  415. }
  416. }
  417. private DeviceTimer rampTimer = new DeviceTimer();
  418. private double rampTarget;
  419. private double rampInitValue;
  420. private int rampTime;
  421. private bool _bMfcAlarm = false;
  422. //private bool _bRamping = false;
  423. private ToleranceChecker _toleranceChecker = new ToleranceChecker();
  424. private AIAccessor _aiFlow;
  425. private AOAccessor _aoFlow;
  426. private AOAccessor _aoRange;
  427. private DIAccessor _diOffline;
  428. private DIAccessor _diPressureAlarm;
  429. private SCConfigItem _scGasName;
  430. private SCConfigItem _scEnable;
  431. private SCConfigItem _scN2Scale;
  432. private SCConfigItem _scScaleFactor;
  433. private SCConfigItem _scAlarmRange;
  434. private SCConfigItem _scEnableAlarm;
  435. private SCConfigItem _scAlarmTime;
  436. private SCConfigItem _scDefaultSetPoint;
  437. private SCConfigItem _scRegulationFactor;
  438. private R_TRIG _trigOffline = new R_TRIG();
  439. private F_TRIG _trigPressureAlarm = new F_TRIG();
  440. private string _uniqueName;
  441. private string GasFlowOutOfTolerance = "GasFlowOutOfTolerance";
  442. //private JetChamber jetChamber = JetChamber.None;
  443. public IoMfc(string module, XmlElement node, string ioModule = "")
  444. {
  445. Unit = node.GetAttribute("unit");
  446. base.Module = module;
  447. base.Name = node.GetAttribute("id");
  448. base.Display = node.GetAttribute("display");
  449. base.DeviceID = node.GetAttribute("schematicId");
  450. _aoRange = ParseAoNode("aoRange", node, ioModule);
  451. _diOffline = ParseDiNode("diOffline", node, ioModule);
  452. _aiFlow = ParseAiNode("aiFlow", node, ioModule);
  453. _aoFlow = ParseAoNode("aoFlow", node, ioModule);
  454. _diPressureAlarm = ParseDiNode("diPressureAlarm", node, ioModule);
  455. _uniqueName = $"{Module}.{Name}";
  456. //if(ModuleHelper.IsPm(module))
  457. // m_JetChamber = (JetChamber)SC.GetValue<int>($"{module}.ChamberType");
  458. if (Module==ModuleName.TM.ToString() && Name.Contains( "LLA"))
  459. {
  460. _scGasName = SC.GetConfigItem($"LLA.{Name}.GasName");
  461. _scEnable = SC.GetConfigItem($"LLA.{Name}.Enable");
  462. _scN2Scale = SC.GetConfigItem($"LLA.{Name}.MfcN2Scale");
  463. _scScaleFactor = SC.GetConfigItem($"LLA.{Name}.MfcScaleFactor");
  464. _scAlarmRange = SC.GetConfigItem($"LLA.{Name}.MfcAlarmRange");
  465. _scEnableAlarm = SC.GetConfigItem($"LLA.{Name}.MfcEnableAlarm");
  466. _scAlarmTime = SC.GetConfigItem($"LLA.{Name}.MfcAlarmTime");
  467. _scDefaultSetPoint = SC.GetConfigItem($"LLA.{Name}.DefaultSetPoint");
  468. _scRegulationFactor = SC.GetConfigItem($"LLA.{Name}.FlowRegulationFactor");
  469. _writeMode = (MFCWriteMode)SC.GetValue<int>($"LLA.{Name}.MFCWriteMode");
  470. }
  471. else if (Module == ModuleName.TM.ToString() && Name.Contains( "LLB"))
  472. {
  473. _scGasName = SC.GetConfigItem($"LLB.{Name}.GasName");
  474. _scEnable = SC.GetConfigItem($"LLB.{Name}.Enable");
  475. _scN2Scale = SC.GetConfigItem($"LLB.{Name}.MfcN2Scale");
  476. _scScaleFactor = SC.GetConfigItem($"LLB.{Name}.MfcScaleFactor");
  477. _scAlarmRange = SC.GetConfigItem($"LLB.{Name}.MfcAlarmRange");
  478. _scEnableAlarm = SC.GetConfigItem($"LLB.{Name}.MfcEnableAlarm");
  479. _scAlarmTime = SC.GetConfigItem($"LLB.{Name}.MfcAlarmTime");
  480. _scDefaultSetPoint = SC.GetConfigItem($"LLB.{Name}.DefaultSetPoint");
  481. _scRegulationFactor = SC.GetConfigItem($"LLB.{Name}.FlowRegulationFactor");
  482. _writeMode = (MFCWriteMode)SC.GetValue<int>($"LLB.{Name}.MFCWriteMode");
  483. }
  484. else
  485. {
  486. _scGasName = SC.GetConfigItem($"{Module}.{Name}.GasName");
  487. _scEnable = SC.GetConfigItem($"{Module}.{Name}.Enable");
  488. _scN2Scale = SC.GetConfigItem($"{Module}.{Name}.MfcN2Scale");
  489. _scScaleFactor = SC.GetConfigItem($"{Module}.{Name}.MfcScaleFactor");
  490. _scAlarmRange = SC.GetConfigItem($"{Module}.{Name}.MfcAlarmRange");
  491. _scEnableAlarm = SC.GetConfigItem($"{Module}.{Name}.MfcEnableAlarm");
  492. _scAlarmTime = SC.GetConfigItem($"{Module}.{Name}.MfcAlarmTime");
  493. _scDefaultSetPoint = SC.GetConfigItem($"{Module}.{Name}.DefaultSetPoint");
  494. _scRegulationFactor = SC.GetConfigItem($"{module}.{Name}.FlowRegulationFactor");
  495. _writeMode = (MFCWriteMode)SC.GetValue<int>($"{module}.{Name}.MFCWriteMode");
  496. }
  497. #if DEBUG
  498. //Debug.Assert(!string.IsNullOrWhiteSpace(_scGasName.StringValue));
  499. //Debug.Assert(null != _scN2Scale);
  500. //Debug.Assert(null != _aoFlow);
  501. //Debug.Assert(null != _aiFlow);
  502. #endif
  503. }
  504. public override bool Initialize()
  505. {
  506. EV.Subscribe(new EventItem("Event", GasFlowOutOfTolerance, "Gas Flow Out Of Tolerance", EventLevel.Alarm, EventType.HostNotification));
  507. DATA.Subscribe($"{Module}.{Name}", () =>
  508. {
  509. AITMfcData data = new AITMfcData
  510. {
  511. Type = "MFC",
  512. UniqueName = _uniqueName,
  513. DeviceName = Name,
  514. DeviceSchematicId = DeviceID,
  515. DisplayName = DisplayName,
  516. FeedBack = FeedBack,
  517. SetPoint = SetPoint,
  518. Scale = Scale,
  519. IsOffline = IsOffline,
  520. IsWarning = PressureAlarm
  521. };
  522. return data;
  523. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  524. OP.Subscribe($"{Module}.{Name}.{AITMfcOperation.Ramp}", (name, args) =>
  525. {
  526. double target = (double)args[0];
  527. target = Math.Min(target, Scale);
  528. target = Math.Max(target, 0);
  529. Ramp(target, 0);
  530. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Ramp to {target}{Unit}");
  531. return true;
  532. });
  533. DEVICE.Register($"{Module}.{Name}.{AITMfcOperation.Ramp}", (out string reason, int time, object[] param) =>
  534. {
  535. double target = Convert.ToDouble((string)param[0]);
  536. target = Math.Min(target, Scale);
  537. target = Math.Max(target, 0);
  538. Ramp(target, time);
  539. reason = $"{Display} ramp to {target}{Unit}";
  540. return true;
  541. });
  542. OP.Subscribe($"{Module}.{Name}.SetPoint", (cmd, args) =>
  543. {
  544. SetPoint = Convert.ToDouble(args[0]);
  545. return true;
  546. });
  547. //@AAA use recipe
  548. DEVICE.Register($"{Module}.{Name}", (out string reason, int time, object[] param) =>
  549. {
  550. double target = Convert.ToDouble((string)param[0]);
  551. target = Math.Min(target, Scale);
  552. target = Math.Max(target, 0);
  553. Ramp(target, time);
  554. reason = $"{Display} ramp to {target}{Unit}";
  555. return true;
  556. });
  557. return base.Initialize();
  558. }
  559. public override void Monitor()
  560. {
  561. if (Enable)
  562. {
  563. //Ramping();
  564. CheckTolerance();
  565. if (_aoRange != null)
  566. {
  567. _SetRealFloat(_aoRange, (float)Scale);
  568. }
  569. _trigOffline.CLK = IsOffline;
  570. if (_trigOffline.Q)
  571. {
  572. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, string.Format("{0} is offline", DisplayName));
  573. _bMfcAlarm = true;
  574. }
  575. //_trigPressureAlarm.CLK = PressureAlarm;
  576. //if (_trigPressureAlarm.Q)
  577. //{
  578. // eEvent _eEvent;
  579. // switch (Display)
  580. // {
  581. // case "Gas1":
  582. // _eEvent = eEvent.ERR_MFC1_PRESSURE;
  583. // break;
  584. // case "Gas2":
  585. // _eEvent = eEvent.ERR_MFC2_PRESSURE;
  586. // break;
  587. // case "Gas3":
  588. // _eEvent = eEvent.ERR_MFC3_PRESSURE;
  589. // break;
  590. // case "Gas4":
  591. // _eEvent = eEvent.ERR_MFC4_PRESSURE;
  592. // break;
  593. // case "Gas5":
  594. // _eEvent = eEvent.ERR_MFC5_PRESSURE;
  595. // break;
  596. // case "Gas6":
  597. // _eEvent = eEvent.ERR_MFC6_PRESSURE;
  598. // break;
  599. // case "Gas7":
  600. // _eEvent = eEvent.ERR_MFC7_PRESSURE;
  601. // break;
  602. // case "Gas8":
  603. // _eEvent = eEvent.ERR_MFC8_PRESSURE;
  604. // break;
  605. // case "N2":
  606. // _eEvent = eEvent.ERR_N2_PRESSURE;
  607. // break;
  608. // default:
  609. // _eEvent = eEvent.WARN_DEVICE_INFO;
  610. // break;
  611. // }
  612. // LOG.Write(_eEvent, Module, $"{Name}, {DisplayName} Pressure Alarm");
  613. //}
  614. }
  615. }
  616. public override void Reset()
  617. {
  618. _bMfcAlarm = false;
  619. _toleranceChecker.Reset(AlarmTime);
  620. _trigPressureAlarm.RST = true;
  621. _trigOffline.RST = true;
  622. }
  623. public override void Terminate()
  624. {
  625. //_bRamping = false;
  626. Ramp(DefaultSetPoint, 0);
  627. }
  628. public override void Ramp(int time)
  629. {
  630. //_bRamping = true;
  631. Ramp(DefaultSetPoint, time);
  632. }
  633. public override void Ramp(double target, int time)
  634. {
  635. //_bRamping = true;
  636. target = Math.Max(0, target);
  637. target = Math.Min(Scale, target);
  638. rampInitValue = SetPoint; //ramp 初始值取当前设定值,而非实际读取值。零漂问题
  639. rampTime = time;
  640. rampTarget = target;
  641. rampTimer.Start(rampTime);
  642. }
  643. public override void StopRamp()
  644. {
  645. //_bRamping = false;
  646. Ramp(SetPoint, 0);
  647. }
  648. //private void Ramping()
  649. //{
  650. // if (_bRamping)
  651. // {
  652. // if (rampTimer.IsTimeout() || rampTime == 0)
  653. // {
  654. // SetPoint = rampTarget;
  655. // _bRamping = false;
  656. // }
  657. // else
  658. // {
  659. // SetPoint = rampInitValue + (rampTarget - rampInitValue) * rampTimer.GetElapseTime() / rampTime;
  660. // }
  661. // }
  662. //}
  663. private void CheckTolerance()
  664. {
  665. if (!EnableAlarm)
  666. return;
  667. // 流率检查
  668. _toleranceChecker.Monitor(FeedBack, SetPoint - Math.Abs(AlarmRange), SetPoint + Math.Abs(AlarmRange), AlarmTime);
  669. if (_toleranceChecker.Trig)
  670. {
  671. LOG.Write(eEvent.ERR_DEVICE_INFO, Module, Display + $"FeedBack {FeedBack} out of Range[{(int)(SetPoint - Math.Abs(AlarmRange))},{(int)(SetPoint + Math.Abs(AlarmRange))}] in {AlarmTime:0} seconds");
  672. EV.Notify(GasFlowOutOfTolerance);
  673. }
  674. }
  675. }
  676. }