FujikinMFC.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO.Ports;
  4. using System.Linq;
  5. using Aitex.Core.Common;
  6. using Aitex.Core.Common.DeviceData;
  7. using Aitex.Core.RT.Device;
  8. using Aitex.Core.RT.Device.Unit;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.SCCore;
  13. using Aitex.Core.Util;
  14. using MECF.Framework.Common.Communications;
  15. using MECF.Framework.Common.Device.Bases;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Common;
  17. using Newtonsoft.Json;
  18. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.MFCs.FujikinMFC
  19. {
  20. public class FujikinMFC : SerialPortDevice, IConnection
  21. {
  22. public string Address { get { return _address; } }
  23. public bool IsConnected { get; }
  24. public bool Connect()
  25. {
  26. return true;
  27. }
  28. public bool Disconnect()
  29. {
  30. return true;
  31. }
  32. public string PortStatus { get; set; } = "Closed";
  33. private FujikinMFCConnection _connection;
  34. public FujikinMFCConnection Connection
  35. {
  36. get { return _connection; }
  37. }
  38. private R_TRIG _trigError = new R_TRIG();
  39. private R_TRIG _trigCommunicationError = new R_TRIG();
  40. private R_TRIG _trigRetryConnect = new R_TRIG();
  41. private PeriodicJob _thread;
  42. private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
  43. private LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
  44. public List<IOResponse> IOResponseList { get; set; } = new List<IOResponse>();
  45. private object _locker = new object();
  46. private bool _enableLog;
  47. private string _address;
  48. private string _scRoot;
  49. public FujikinMFC(string module, string name, string scRoot, string portName) : base(module, name)
  50. {
  51. _scRoot = scRoot;
  52. PortName = portName;
  53. }
  54. private void ResetPropertiesAndResponses()
  55. {
  56. foreach (var ioResponse in IOResponseList)
  57. {
  58. ioResponse.ResonseContent = null;
  59. ioResponse.ResonseRecievedTime = DateTime.Now;
  60. }
  61. }
  62. public override bool Initialize(string portName)
  63. {
  64. base.Initialize(portName);
  65. ResetPropertiesAndResponses();
  66. if (_connection != null && _connection.IsConnected && PortName == portName)
  67. return true;
  68. if (_connection != null && _connection.IsConnected)
  69. _connection.Disconnect();
  70. PortName = portName;
  71. _address = SC.GetStringValue($"{_scRoot}.{Module}.{Name}.DeviceAddress");
  72. _enableLog = SC.GetValue<bool>($"{_scRoot}.{Module}.{Name}.EnableLogMessage");
  73. _connection = new FujikinMFCConnection(PortName);
  74. _connection.EnableLog(_enableLog);
  75. if (_connection.Connect())
  76. {
  77. PortStatus = "Open";
  78. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  79. }
  80. _thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  81. return true;
  82. }
  83. public bool InitConnection(string portName, int bautRate, int dataBits, Parity parity, StopBits stopBits)
  84. {
  85. _connection = new FujikinMFCConnection(portName, bautRate, dataBits, parity, stopBits);
  86. if (_connection.Connect())
  87. {
  88. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  89. }
  90. _thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  91. return true;
  92. }
  93. private bool OnTimer()
  94. {
  95. try
  96. {
  97. //_connection.MonitorTimeout();
  98. if (!_connection.IsConnected || _connection.IsCommunicationError)
  99. {
  100. lock (_locker)
  101. {
  102. _lstHandler.Clear();
  103. }
  104. _trigRetryConnect.CLK = !_connection.IsConnected;
  105. if (_trigRetryConnect.Q)
  106. {
  107. _connection.SetPortAddress(SC.GetStringValue($"{ScBasePath}.{Name}.Address"));
  108. if (!_connection.Connect())
  109. {
  110. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
  111. }
  112. else
  113. {
  114. //_lstHandler.AddLast(new FujikinMFCQueryPinHandler(this, _deviceAddress));
  115. //_lstHandler.AddLast(new FujikinMFCSetCommModeHandler(this, _deviceAddress, EnumRfPowerCommunicationMode.Host));
  116. }
  117. }
  118. return true;
  119. }
  120. HandlerBase handler = null;
  121. if (!_connection.IsBusy)
  122. {
  123. lock (_locker)
  124. {
  125. if (_lstHandler.Count == 0)
  126. {
  127. foreach (var monitorHandler in _lstMonitorHandler)
  128. {
  129. _lstHandler.AddLast(monitorHandler);
  130. }
  131. }
  132. if (_lstHandler.Count > 0)
  133. {
  134. handler = _lstHandler.First.Value;
  135. _lstHandler.RemoveFirst();
  136. }
  137. }
  138. if (handler != null)
  139. {
  140. _connection.Execute(handler);
  141. }
  142. }
  143. }
  144. catch (Exception ex)
  145. {
  146. LOG.Write(ex);
  147. }
  148. return true;
  149. }
  150. internal void NoteNAK()
  151. {
  152. ResponseNAK = true;
  153. }
  154. public override void Monitor()
  155. {
  156. try
  157. {
  158. //_connection.EnableLog(_enableLog);
  159. _trigCommunicationError.CLK = _connection.IsCommunicationError;
  160. if (_trigCommunicationError.Q)
  161. {
  162. EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  163. }
  164. }
  165. catch (Exception ex)
  166. {
  167. LOG.Write(ex);
  168. }
  169. }
  170. public override void Reset()
  171. {
  172. _trigError.RST = true;
  173. _connection.SetCommunicationError(false, "");
  174. _trigCommunicationError.RST = true;
  175. //_enableLog = SC.GetValue<bool>($"{ScBasePath}.{Name}.EnableLogMessage");
  176. _trigRetryConnect.RST = true;
  177. base.Reset();
  178. }
  179. internal void NoteActionCompleted()
  180. {
  181. }
  182. public override bool Home(out string reason)
  183. {
  184. return base.Home(out reason);
  185. }
  186. #region Command Functions
  187. public void PerformRawCommand(string commandType, string command, string comandArgument)
  188. {
  189. lock (_locker)
  190. {
  191. _lstHandler.AddLast(new FujikinMFCRawCommandHandler(this, commandType, command, comandArgument));
  192. }
  193. }
  194. internal void NoteExcetionInfo(byte value)
  195. {
  196. //parse exception status here
  197. ExceptionInfo = value;
  198. }
  199. public void ResetMFC()
  200. {
  201. lock (_locker)
  202. {
  203. _lstHandler.AddLast(new FujikinMFCResetHandler(this));
  204. }
  205. }
  206. public void SetFlowTotalizerAlarmEnable(bool enableValue)
  207. {
  208. lock (_locker)
  209. {
  210. _lstHandler.AddLast(new FujikinMFCSetEnableHandler(this, "65,01,B5", enableValue.ToString()));
  211. }
  212. }
  213. public void SetFlowTotalizerAlarmEnable(string enableValue)
  214. {
  215. lock (_locker)
  216. {
  217. _lstHandler.AddLast(new FujikinMFCSetEnableHandler(this, "65,01,B5", enableValue));
  218. }
  219. }
  220. public void SetFlowTotalizerAlarmLevel(int value)
  221. {
  222. lock (_locker)
  223. {
  224. _lstHandler.AddLast(new FujikinMFCSet32BitValueHandler(this, "65,01,B6", value));
  225. }
  226. }
  227. public void SetFlowTotalizerAlarmLevel(string value)
  228. {
  229. lock (_locker)
  230. {
  231. _lstHandler.AddLast(new FujikinMFCSet32BitValueHandler(this, "65,01,B6", int.Parse(value)));
  232. }
  233. }
  234. public void SetFlowMeterAlarmEnable(string enableValue)
  235. {
  236. lock (_locker)
  237. {
  238. _lstHandler.AddLast(new FujikinMFCSetEnableHandler(this, "65,01,B6", enableValue));
  239. }
  240. }
  241. public void SetFlowMeterAlarmTripPointHigh(string value)
  242. {
  243. lock (_locker)
  244. {
  245. _lstHandler.AddLast(new FujikinMFCSet16BitValueHandler(this, "68,01,11", short.Parse(value)));
  246. }
  247. }
  248. public void SetFlowMeterZeroEnable(string enableValue)
  249. {
  250. lock (_locker)
  251. {
  252. _lstHandler.AddLast(new FujikinMFCSetEnableHandler(this, "68,01,A5", enableValue));
  253. }
  254. }
  255. public void SetFlowMeterRequestedZero(string value)
  256. {
  257. lock (_locker)
  258. {
  259. _lstHandler.AddLast(new FujikinMFCSet8BitValueHandler(this, "68,01,BA", byte.Parse(value)));
  260. }
  261. }
  262. public void SetFlowControllerControlModeSelection(string value)
  263. {
  264. lock (_locker)
  265. {
  266. _lstHandler.AddLast(new FujikinMFCSet8BitValueHandler(this, "69,01,03", byte.Parse(value)));
  267. }
  268. }
  269. public void SetFlowControllerDefaultControlMode(string value)
  270. {
  271. lock (_locker)
  272. {
  273. _lstHandler.AddLast(new FujikinMFCSet8BitValueHandler(this, "69,01,04", byte.Parse(value)));
  274. }
  275. }
  276. public void SetFlowControllerFreezeFollow(string value)
  277. {
  278. lock (_locker)
  279. {
  280. _lstHandler.AddLast(new FujikinMFCSet8BitValueHandler(this, "69,01,05", byte.Parse(value)));
  281. }
  282. }
  283. public void SetFlowControllerSetPoint(string value)
  284. {
  285. lock (_locker)
  286. {
  287. _lstHandler.AddLast(new FujikinMFCSet16BitValueHandler(this, "69,01,A4", short.Parse(value)));
  288. }
  289. }
  290. public void SetValveDriverValveOverride(string value)
  291. {
  292. lock (_locker)
  293. {
  294. _lstHandler.AddLast(new FujikinMFCSet8BitValueHandler(this, "6A,01,01", byte.Parse(value)));
  295. }
  296. }
  297. public void SetValveDriverRampTime(string value)
  298. {
  299. lock (_locker)
  300. {
  301. _lstHandler.AddLast(new FujikinMFCSet32BitValueHandler(this, "6A,01,A4", int.Parse(value)));
  302. }
  303. }
  304. internal void NoteAlarmDetail(short value)
  305. {
  306. //parse
  307. AlarmDetail = value;
  308. }
  309. public void ReadExceptionStatus(bool isSelected)
  310. {
  311. lock (_locker)
  312. {
  313. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadExceptionStatusHandler));
  314. if (isSelected)
  315. {
  316. if (!existHandlers.Any())
  317. _lstMonitorHandler.AddFirst(new FujikinMFCReadExceptionStatusHandler(this));
  318. }
  319. else
  320. {
  321. if (existHandlers.Any())
  322. {
  323. _lstMonitorHandler.Remove(existHandlers.First());
  324. }
  325. }
  326. }
  327. }
  328. internal void NoteWarningDetail(short value)
  329. {
  330. //parse
  331. WarningDetail = value;
  332. }
  333. public void ReadAlarmDetail(bool isSelected)
  334. {
  335. lock (_locker)
  336. {
  337. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadExceptionStatusHandler));
  338. if (isSelected)
  339. {
  340. if (!existHandlers.Any())
  341. _lstMonitorHandler.AddFirst(new FujikinMFCReadAlarmDetailHandler(this));
  342. }
  343. else
  344. {
  345. if (existHandlers.Any())
  346. {
  347. _lstMonitorHandler.Remove(existHandlers.First());
  348. }
  349. }
  350. }
  351. }
  352. public void ReadWarningDetail(bool isSelected)
  353. {
  354. lock (_locker)
  355. {
  356. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadExceptionStatusHandler));
  357. if (isSelected)
  358. {
  359. if (!existHandlers.Any())
  360. _lstMonitorHandler.AddFirst(new FujikinMFCReadWarningDetailHandler(this));
  361. }
  362. else
  363. {
  364. if (existHandlers.Any())
  365. {
  366. _lstMonitorHandler.Remove(existHandlers.First());
  367. }
  368. }
  369. }
  370. }
  371. public bool FlowTotalizerAlarmEnable { get; set; }
  372. public void ReadFlowTotalizerAlarmEnable(bool isSelected)
  373. {
  374. lock (_locker)
  375. {
  376. string propName = "FlowTotalizerAlarmEnable";
  377. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadEnableHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  378. if (isSelected)
  379. {
  380. if (!existHandlers.Any())
  381. _lstMonitorHandler.AddFirst(new FujikinMFCReadEnableHandler(this, "65,01,B5", propName));
  382. }
  383. else
  384. {
  385. if (existHandlers.Any())
  386. {
  387. _lstMonitorHandler.Remove(existHandlers.First());
  388. }
  389. }
  390. }
  391. }
  392. public int FlowTotalizerAlarmLevel { get; set; }
  393. public void ReadFlowTotalizerAlarmLevel(bool isSelected)
  394. {
  395. lock (_locker)
  396. {
  397. string propName = "FlowTotalizerAlarmLevel";
  398. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead32BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  399. if (isSelected)
  400. {
  401. if (!existHandlers.Any())
  402. _lstMonitorHandler.AddFirst(new FujikinMFCRead32BitHandler(this, "65,01,B6", propName));
  403. }
  404. else
  405. {
  406. if (existHandlers.Any())
  407. {
  408. _lstMonitorHandler.Remove(existHandlers.First());
  409. }
  410. }
  411. }
  412. }
  413. //parse set
  414. public short FlowMeterStatus { get; set; }
  415. public void ReadFlowMeterStatus(bool isSelected)
  416. {
  417. lock (_locker)
  418. {
  419. string propName = "FlowMeterStatus";
  420. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  421. if (isSelected)
  422. {
  423. if (!existHandlers.Any())
  424. _lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "68,01,07", propName));
  425. }
  426. else
  427. {
  428. if (existHandlers.Any())
  429. {
  430. _lstMonitorHandler.Remove(existHandlers.First());
  431. }
  432. }
  433. }
  434. }
  435. public bool FlowMeterAlarmEnable { get; set; }
  436. public void ReadFlowMeterAlarmEnable(bool isSelected)
  437. {
  438. lock (_locker)
  439. {
  440. string propName = "FlowMeterAlarmEnable";
  441. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadEnableHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  442. if (isSelected)
  443. {
  444. if (!existHandlers.Any())
  445. _lstMonitorHandler.AddFirst(new FujikinMFCReadEnableHandler(this, "68,01,08", propName));
  446. }
  447. else
  448. {
  449. if (existHandlers.Any())
  450. {
  451. _lstMonitorHandler.Remove(existHandlers.First());
  452. }
  453. }
  454. }
  455. }
  456. public short FlowMeterAlarmTripPointHigh { get; set; }
  457. public void ReadFlowMeterAlarmTripPointHigh(bool isSelected)
  458. {
  459. lock (_locker)
  460. {
  461. string propName = "FlowMeterAlarmTripPointHigh";
  462. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead16BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  463. if (isSelected)
  464. {
  465. if (!existHandlers.Any())
  466. _lstMonitorHandler.AddFirst(new FujikinMFCRead16BitHandler(this, "68,01,11", propName));
  467. }
  468. else
  469. {
  470. if (existHandlers.Any())
  471. {
  472. _lstMonitorHandler.Remove(existHandlers.First());
  473. }
  474. }
  475. }
  476. }
  477. public bool FlowMeterZeroEnable { get; set; }
  478. public void ReadFlowMeterZeroEnable(bool isSelected)
  479. {
  480. lock (_locker)
  481. {
  482. string propName = "FlowMeterZeroEnable";
  483. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCReadEnableHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  484. if (isSelected)
  485. {
  486. if (!existHandlers.Any())
  487. _lstMonitorHandler.AddFirst(new FujikinMFCReadEnableHandler(this, "68,01,A5", propName));
  488. }
  489. else
  490. {
  491. if (existHandlers.Any())
  492. {
  493. _lstMonitorHandler.Remove(existHandlers.First());
  494. }
  495. }
  496. }
  497. }
  498. public short FlowMeterRequestedZero { get; set; }
  499. public void ReadFlowMeterRequestedZero(bool isSelected)
  500. {
  501. lock (_locker)
  502. {
  503. string propName = "FlowMeterRequestedZero";
  504. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  505. if (isSelected)
  506. {
  507. if (!existHandlers.Any())
  508. _lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "68,01,BA", propName));
  509. }
  510. else
  511. {
  512. if (existHandlers.Any())
  513. {
  514. _lstMonitorHandler.Remove(existHandlers.First());
  515. }
  516. }
  517. }
  518. }
  519. public short FlowControllerControlModeSelection { get; set; }
  520. public void ReadFlowControllerControlModeSelection(bool isSelected)
  521. {
  522. lock (_locker)
  523. {
  524. string propName = "FlowControllerControlModeSelection";
  525. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  526. if (isSelected)
  527. {
  528. if (!existHandlers.Any())
  529. _lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "69,01,03", propName));
  530. }
  531. else
  532. {
  533. if (existHandlers.Any())
  534. {
  535. _lstMonitorHandler.Remove(existHandlers.First());
  536. }
  537. }
  538. }
  539. }
  540. public short FlowControllerFreezeFollow { get; set; }
  541. public void ReadFlowControllerFreezeFollow(bool isSelected)
  542. {
  543. lock (_locker)
  544. {
  545. string propName = "FlowControllerFreezeFollow";
  546. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  547. if (isSelected)
  548. {
  549. if (!existHandlers.Any())
  550. _lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "69,01,05", propName));
  551. }
  552. else
  553. {
  554. if (existHandlers.Any())
  555. {
  556. _lstMonitorHandler.Remove(existHandlers.First());
  557. }
  558. }
  559. }
  560. }
  561. //parse set
  562. public short FlowControllerStatus { get; set; }
  563. public void ReadFlowControllerStatus(bool isSelected)
  564. {
  565. lock (_locker)
  566. {
  567. string propName = "FlowControllerStatus";
  568. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  569. if (isSelected)
  570. {
  571. if (!existHandlers.Any())
  572. _lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "69,01,0A", propName));
  573. }
  574. else
  575. {
  576. if (existHandlers.Any())
  577. {
  578. _lstMonitorHandler.Remove(existHandlers.First());
  579. }
  580. }
  581. }
  582. }
  583. public short FlowControllerDefaultControlMode { get; set; }
  584. public void ReadFlowControllerDefaultControlMode(bool isSelected)
  585. {
  586. lock (_locker)
  587. {
  588. string propName = "FlowControllerDefaultControlMode";
  589. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  590. if (isSelected)
  591. {
  592. if (!existHandlers.Any())
  593. _lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "69,01,04", propName));
  594. }
  595. else
  596. {
  597. if (existHandlers.Any())
  598. {
  599. _lstMonitorHandler.Remove(existHandlers.First());
  600. }
  601. }
  602. }
  603. }
  604. public int FlowMeterTotalizerData { get; set; }
  605. public void ReadFlowMeterTotalizerData(bool isSelected)
  606. {
  607. lock (_locker)
  608. {
  609. string propName = "FlowMeterTotalizerData";
  610. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead32BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  611. if (isSelected)
  612. {
  613. if (!existHandlers.Any())
  614. _lstMonitorHandler.AddFirst(new FujikinMFCRead32BitHandler(this, "68,01,B2", propName));
  615. }
  616. else
  617. {
  618. if (existHandlers.Any())
  619. {
  620. _lstMonitorHandler.Remove(existHandlers.First());
  621. }
  622. }
  623. }
  624. }
  625. public short FlowControllerSetPoint { get; set; }
  626. public void ReadFlowControllerSetPoint(bool isSelected)
  627. {
  628. lock (_locker)
  629. {
  630. string propName = "FlowControllerSetPoint";
  631. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead16BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  632. if (isSelected)
  633. {
  634. if (!existHandlers.Any())
  635. _lstMonitorHandler.AddFirst(new FujikinMFCRead16BitHandler(this, "69,01,A4", propName));
  636. }
  637. else
  638. {
  639. if (existHandlers.Any())
  640. {
  641. _lstMonitorHandler.Remove(existHandlers.First());
  642. }
  643. }
  644. }
  645. }
  646. public short ValveDriverValveOverride { get; set; }
  647. public void ReadValveDriverValveOverride(bool isSelected)
  648. {
  649. lock (_locker)
  650. {
  651. string propName = "ValveDriverValveOverride";
  652. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  653. if (isSelected)
  654. {
  655. if (!existHandlers.Any())
  656. _lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "6A,01,01", propName));
  657. }
  658. else
  659. {
  660. if (existHandlers.Any())
  661. {
  662. _lstMonitorHandler.Remove(existHandlers.First());
  663. }
  664. }
  665. }
  666. }
  667. //parse set
  668. public short ValveDriverStatus { get; set; }
  669. public void ReadValveDriverStatus(bool isSelected)
  670. {
  671. lock (_locker)
  672. {
  673. string propName = "ValveDriverStatus";
  674. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  675. if (isSelected)
  676. {
  677. if (!existHandlers.Any())
  678. _lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "6A,01,07", propName));
  679. }
  680. else
  681. {
  682. if (existHandlers.Any())
  683. {
  684. _lstMonitorHandler.Remove(existHandlers.First());
  685. }
  686. }
  687. }
  688. }
  689. public short ValveDriverValveType { get; set; }
  690. public void ReadValveDriverValveType(bool isSelected)
  691. {
  692. lock (_locker)
  693. {
  694. string propName = "ValveDriverValveType";
  695. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead8BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  696. if (isSelected)
  697. {
  698. if (!existHandlers.Any())
  699. _lstMonitorHandler.AddFirst(new FujikinMFCRead8BitHandler(this, "6A,01,A0", propName));
  700. }
  701. else
  702. {
  703. if (existHandlers.Any())
  704. {
  705. _lstMonitorHandler.Remove(existHandlers.First());
  706. }
  707. }
  708. }
  709. }
  710. public short ValveDriverFilteredSetpoint { get; set; }
  711. public void ReadValveDriverFilteredSetpoint(bool isSelected)
  712. {
  713. lock (_locker)
  714. {
  715. string propName = "ValveDriverFilteredSetpoint";
  716. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead16BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  717. if (isSelected)
  718. {
  719. if (!existHandlers.Any())
  720. _lstMonitorHandler.AddFirst(new FujikinMFCRead16BitHandler(this, "6A,01,A6", propName));
  721. }
  722. else
  723. {
  724. if (existHandlers.Any())
  725. {
  726. _lstMonitorHandler.Remove(existHandlers.First());
  727. }
  728. }
  729. }
  730. }
  731. public short ValveDriverIndicatedFlow { get; set; }
  732. public void ReadValveDriverIndicatedFlow(bool isSelected)
  733. {
  734. lock (_locker)
  735. {
  736. string propName = "ValveDriverIndicatedFlow";
  737. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead16BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  738. if (isSelected)
  739. {
  740. if (!existHandlers.Any())
  741. _lstMonitorHandler.AddFirst(new FujikinMFCRead16BitHandler(this, "6A,01,A9", propName));
  742. }
  743. else
  744. {
  745. if (existHandlers.Any())
  746. {
  747. _lstMonitorHandler.Remove(existHandlers.First());
  748. }
  749. }
  750. }
  751. }
  752. public short ValveDriverValveVoltage { get; set; }
  753. public void ReadValveDriverValveVoltage(bool isSelected)
  754. {
  755. lock (_locker)
  756. {
  757. string propName = "ValveDriverValveVoltage";
  758. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead16BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  759. if (isSelected)
  760. {
  761. if (!existHandlers.Any())
  762. _lstMonitorHandler.AddFirst(new FujikinMFCRead16BitHandler(this, "6A,01,B6", propName));
  763. }
  764. else
  765. {
  766. if (existHandlers.Any())
  767. {
  768. _lstMonitorHandler.Remove(existHandlers.First());
  769. }
  770. }
  771. }
  772. }
  773. public int ValveDriverRampTime { get; set; }
  774. public void ReadValveDriverRampTime(bool isSelected)
  775. {
  776. lock (_locker)
  777. {
  778. string propName = "ValveDriverRampTime";
  779. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRead32BitHandler) && ((FujikinMFCHandler)handler).DevicePropName == propName);
  780. if (isSelected)
  781. {
  782. if (!existHandlers.Any())
  783. _lstMonitorHandler.AddFirst(new FujikinMFCRead32BitHandler(this, "6A,01,A4", propName));
  784. }
  785. else
  786. {
  787. if (existHandlers.Any())
  788. {
  789. _lstMonitorHandler.Remove(existHandlers.First());
  790. }
  791. }
  792. }
  793. }
  794. internal void NoteResetCompleted()
  795. {
  796. ResetCompleted = true;
  797. }
  798. public void MonitorRawCommand(bool isSelected, string commandType, string command, string comandArgument)
  799. {
  800. lock (_locker)
  801. {
  802. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(FujikinMFCRawCommandHandler) && ((FujikinMFCHandler)handler)._commandType == commandType && ((FujikinMFCHandler)handler)._command == command);
  803. if (isSelected)
  804. {
  805. if (!existHandlers.Any())
  806. _lstMonitorHandler.AddFirst(new FujikinMFCRawCommandHandler(this, commandType, command, comandArgument));
  807. }
  808. else
  809. {
  810. if (existHandlers.Any())
  811. {
  812. _lstMonitorHandler.Remove(existHandlers.First());
  813. }
  814. }
  815. }
  816. }
  817. #endregion
  818. #region Properties
  819. public string Error { get; private set; }
  820. public short ExceptionInfo { get; private set; }
  821. public bool ResetCompleted { get; private set; }
  822. public bool ResponseNAK { get; private set; }
  823. public short WarningDetail { get; private set; }
  824. public short AlarmDetail { get; private set; }
  825. #endregion
  826. #region Note Functions
  827. private R_TRIG _trigWarningMessage = new R_TRIG();
  828. public void NoteError(string reason)
  829. {
  830. if (reason != null)
  831. {
  832. _trigWarningMessage.CLK = true;
  833. if (_trigWarningMessage.Q)
  834. {
  835. EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
  836. }
  837. Error = reason;
  838. }
  839. else
  840. {
  841. Error = null;
  842. }
  843. }
  844. internal void NoteRawCommandInfo(string command, string data)
  845. {
  846. var curIOResponse = IOResponseList.Find(res => res.SourceCommandName == command);
  847. if (curIOResponse != null)
  848. {
  849. IOResponseList.Remove(curIOResponse);
  850. }
  851. IOResponseList.Add(new IOResponse() { SourceCommand = command, ResonseContent = data, ResonseRecievedTime = DateTime.Now });
  852. }
  853. internal void NoteRawCommandInfo(string commandType, string command, string data, bool isAck)
  854. {
  855. var curIOResponse = IOResponseList.Find(res => res.SourceCommandType == commandType && res.SourceCommand == command);
  856. if (curIOResponse != null)
  857. {
  858. IOResponseList.Remove(curIOResponse);
  859. }
  860. IOResponseList.Add(new IOResponse() { SourceCommandType = commandType, SourceCommand = command, ResonseContent = data, IsAck = isAck, ResonseRecievedTime = DateTime.Now });
  861. }
  862. #endregion
  863. }
  864. }