IoMfc.cs 25 KB

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