FfuAAF.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.RT.DataCenter;
  4. using Aitex.Core.RT.Device;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.Util;
  10. using MECF.Framework.Common.Communications;
  11. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.FFUs.MayAir;
  12. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDK;
  14. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.FFUs.AAF2
  15. {
  16. public class FfuAAF : BaseDevice, IConnection, IDevice
  17. {
  18. private FfuAAFConnection _connection;
  19. private string _deviceAddress = "001";
  20. public byte DeviceAddress { get; set; }
  21. public byte GroupAddress { get; set; }
  22. public byte Speedfactor { get; set; }
  23. public int MaxSpeed1 { get; set; }
  24. public int MaxSpeed2 { get; set; }
  25. public int MaxSpeed3 { get; set; }
  26. public int Status { get; set; }
  27. private bool _isOn;
  28. private bool _activeMonitorStatus;
  29. private int _nMaxSpeed = 0;
  30. public int NMaxSpeed { get => _nMaxSpeed; }
  31. private int _errorCode;
  32. private RD_TRIG _trigPumpOnOff = new RD_TRIG();
  33. private R_TRIG _trigError = new R_TRIG();
  34. private R_TRIG _trigOverTemp = new R_TRIG();
  35. private R_TRIG _trigWarningMessage = new R_TRIG();
  36. private string _lastError = string.Empty;
  37. private R_TRIG _trigCommunicationError = new R_TRIG();
  38. private R_TRIG _trigRetryConnect = new R_TRIG();
  39. private PeriodicJob _thread;
  40. private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
  41. private object _locker = new object();
  42. private bool _enableLog
  43. {
  44. get
  45. {
  46. if (SC.ContainsItem($"{_scRoot}.{Module}.{Name}.EnableLogMessage"))
  47. return SC.GetValue<bool>($"{_scRoot}.{Module}.{Name}.EnableLogMessage");
  48. else if (SC.ContainsItem($"{Module}.{Name}.EnableLogMessage"))
  49. return SC.GetValue<bool>($"{Module}.{Name}.EnableLogMessage");
  50. return false;
  51. }
  52. }
  53. private string _scRoot;
  54. //private AsyncSerial serialPort;
  55. private int _ffuSpeed;
  56. private string[] StatusStringList = new string[] { "normal", "running fault", "stop fault" };
  57. public int Speed
  58. {
  59. get { return _ffuSpeed; }
  60. set { _ffuSpeed = value; }
  61. }
  62. public string Address
  63. {
  64. get; set;
  65. }
  66. public bool IsConnected
  67. {
  68. get
  69. {
  70. return _connection != null && _connection.IsConnected;
  71. }
  72. }
  73. public bool Connect()
  74. {
  75. return true;
  76. }
  77. public bool Disconnect()
  78. {
  79. return true;
  80. }
  81. public FfuAAF(string scRoot, string module, string name) : base(module, name, name, name)
  82. {
  83. _scRoot = scRoot;
  84. _activeMonitorStatus = true;
  85. //serialPort = new AsyncSerial(port, 9600, 8);
  86. //serialPort.OnDataChanged += (OnDataChanged);
  87. //serialPort.OnErrorHappened += (OnErrorHandler);
  88. }
  89. private void OnErrorHandler(ErrorEventArgs args)
  90. {
  91. }
  92. private void OnDataChanged(string message)
  93. {
  94. }
  95. public void SetGroupAddress(byte newGroupAddress)
  96. {
  97. _lstHandler.AddLast(new FfuAAFSetGroupAddressHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x00, newGroupAddress }));
  98. }
  99. public void GetGroupAddress()
  100. {
  101. _lstHandler.AddLast(new FfuAAFGetGroupAddressHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x00 }));
  102. }
  103. public void SetDeviceAddress(byte newDeviceAddress)
  104. {
  105. _lstHandler.AddLast(new FfuAAFSetAddressHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x01, newDeviceAddress }));
  106. }
  107. public void GetDeviceAddress()
  108. {
  109. _lstHandler.AddLast(new FfuAAFGetAddressHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x01 }));
  110. }
  111. public void QueryMaxSpeed1()
  112. {
  113. _lstHandler.AddLast(new FfuAAFQueryMaxSpeed1Handler(this, DeviceAddress, GroupAddress, new byte[] { 0x08 }));
  114. }
  115. public void QueryMaxSpeed2()
  116. {
  117. _lstHandler.AddLast(new FfuAAFQueryMaxSpeed2Handler(this, DeviceAddress, GroupAddress, new byte[] { 0x09 }));
  118. }
  119. public void QueryMaxSpeed3()
  120. {
  121. _lstHandler.AddLast(new FfuAAFQueryMaxSpeed3Handler(this, DeviceAddress, GroupAddress, new byte[] { 0x0a }));
  122. }
  123. /// <summary>
  124. /// 查转速因子
  125. /// </summary>
  126. public void QuerySpeedFactor()
  127. {
  128. _lstHandler.AddLast(new FfuAAFQuerySpeedFactorHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x11 }));
  129. }
  130. public void SetSpeedFactor(byte newSpeedFactor)
  131. {
  132. _lstHandler.AddLast(new FfuAAFSetSpeedFactorHandler(this, DeviceAddress, GroupAddress, new byte[] { 0x11, newSpeedFactor }));
  133. }
  134. public void QuerySpeed()
  135. {
  136. _lstHandler.AddLast(new FfuAAFQuerySpeedHandler(this, DeviceAddress, GroupAddress));
  137. }
  138. public void SetSpeed(int speed)
  139. {
  140. _lstHandler.AddLast(new FfuAAFSetSpeedHandler(this, DeviceAddress, GroupAddress, new byte[] { (byte)(speed * 250.0 / MaxSpeed2) }));
  141. }
  142. public void ResetDevice()
  143. {
  144. _lstHandler.AddLast(new FfuAAFResetDeviceHandler(this, DeviceAddress, GroupAddress));
  145. }
  146. public void QueryError()
  147. {
  148. _lstHandler.AddLast(new FfuAAFQueryStatusHandler(this, DeviceAddress, GroupAddress));
  149. EV.PostInfoLog(Module, "Query error");
  150. }
  151. private int ChangedStatus(int value)
  152. {
  153. int returnValue = 0;
  154. switch (value)
  155. {
  156. case 0:
  157. returnValue = 0;
  158. break;
  159. case 0x80:
  160. returnValue = 1;
  161. break;
  162. case 0x10:
  163. returnValue = 2;
  164. break;
  165. default:
  166. break;
  167. }
  168. return returnValue;
  169. }
  170. public bool Initialize()
  171. {
  172. //DATA.Subscribe($"{Module}.{Name}.Power", () => _power);
  173. //DATA.Subscribe($"{Module}.{Name}.ErrorCode", () => _errorCode);
  174. //DATA.Subscribe($"{Module}.{Name}.IsAtSpeed", () => _isAtSpeed);
  175. //DATA.Subscribe($"{Module}.{Name}.IsAccelerate", () => _isAccelerate);
  176. if(string.IsNullOrEmpty(_scRoot))
  177. {
  178. string portName = SC.GetStringValue($"{Module}.{Name}.Address");
  179. Address = portName;
  180. int address = SC.GetValue<int>($"{Module}.{Name}.DeviceAddress");
  181. DeviceAddress = (byte)address;
  182. DATA.Subscribe($"{Name}.DeviceAddress", () => DeviceAddress);
  183. GroupAddress = (byte)SC.GetValue<int>($"{Module}.{Name}.GroupAddress");
  184. DATA.Subscribe($"{Name}.GroupAddress", () => GroupAddress);
  185. Status = SC.GetValue<int>($"{Module}.{Name}.Status");
  186. DATA.Subscribe($"{Name}.Status", () => StatusStringList[ChangedStatus(Status)]);
  187. _deviceAddress = address.ToString("D3");
  188. Speedfactor = (byte)SC.GetValue<int>($"{Module}.{Name}.Speedfactor");
  189. // _nMaxSpeed = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.MaxSpeed1");
  190. MaxSpeed1 = SC.GetValue<int>($"{Module}.{Name}.MaxSpeed1");
  191. MaxSpeed2 = SC.GetValue<int>($"{Module}.{Name}.MaxSpeed2");
  192. MaxSpeed3 = SC.GetValue<int>($"{Module}.{Name}.MaxSpeed3");
  193. _ffuSpeed = SC.GetValue<int>($"{Module}.{Name}.Speed"); }
  194. else
  195. {
  196. string portName = SC.GetStringValue($"{_scRoot}.{Module}.{Name}.Address");
  197. Address = portName;
  198. int address = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.DeviceAddress");
  199. DeviceAddress = (byte)address;
  200. DATA.Subscribe($"{Name}.DeviceAddress", () => DeviceAddress);
  201. GroupAddress = (byte)SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.GroupAddress");
  202. DATA.Subscribe($"{Name}.GroupAddress", () => GroupAddress);
  203. Status = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.Status");
  204. DATA.Subscribe($"{Name}.Status", () => StatusStringList[ChangedStatus(Status)]);
  205. _deviceAddress = address.ToString("D3");
  206. Speedfactor = (byte)SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.Speedfactor");
  207. // _nMaxSpeed = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.MaxSpeed1");
  208. MaxSpeed1 = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.MaxSpeed1");
  209. MaxSpeed2 = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.MaxSpeed2");
  210. MaxSpeed3 = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.MaxSpeed3");
  211. _ffuSpeed = SC.GetValue<int>($"{_scRoot}.{Module}.{Name}.Speed");
  212. }
  213. DATA.Subscribe($"{Name}.Speedfactor", () => Speedfactor);
  214. DATA.Subscribe($"{Name}.MaxSpeed1", () => MaxSpeed1);
  215. DATA.Subscribe($"{Name}.MaxSpeed2", () => MaxSpeed2);
  216. DATA.Subscribe($"{Name}.MaxSpeed3", () => MaxSpeed3);
  217. _connection = new FfuAAFConnection(Address);
  218. _connection.EnableLog(_enableLog);
  219. if (_connection.Connect())
  220. {
  221. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  222. }
  223. _thread = new PeriodicJob(1000, OnTimer, $"{Name} MonitorHandler", true);
  224. DATA.Subscribe($"{Name}.Speed", () => _ffuSpeed);
  225. OP.Subscribe($"{Name}SetFFUGroupAddress", (cmd, param) =>
  226. {
  227. if (int.TryParse((string)param[0], out var groupAddress))
  228. {
  229. EV.PostWarningLog(Module, "Set FFU Group Address.");
  230. return false;
  231. }
  232. int.TryParse((string)param[2], out var newgroupAddress);
  233. GroupAddress = (byte)newgroupAddress;
  234. SetGroupAddress((byte)newgroupAddress);
  235. EV.PostInfoLog(Module, $"{Name}Set FFU Group Address {newgroupAddress}");
  236. return true;
  237. });
  238. OP.Subscribe($"{Name}GetFFUGroupAddress", (cmd, param) =>
  239. {
  240. if (int.TryParse((string)param[0], out var groupAddress))
  241. {
  242. EV.PostWarningLog(Module, "Get FFU Group Address.");
  243. return false;
  244. }
  245. GetGroupAddress();
  246. EV.PostInfoLog(Module, $"{Name}Get FFU Group Address {groupAddress}");
  247. return true;
  248. });
  249. OP.Subscribe($"{Name}SetFFUDeviceAddress", (cmd, param) =>
  250. {
  251. if (int.TryParse((string)param[0], out var groupAddress))
  252. {
  253. EV.PostWarningLog(Module, "Set FFU Device Address.");
  254. return false;
  255. }
  256. int.TryParse((string)param[2], out var newAddress);
  257. SetDeviceAddress((byte)newAddress);
  258. EV.PostInfoLog(Module, $"{Name}Set FFU Device Address {newAddress}");
  259. return true;
  260. });
  261. OP.Subscribe($"{Name}GetFFUDeviceAddress", (cmd, param) =>
  262. {
  263. if (int.TryParse((string)param[0], out var groupAddress))
  264. {
  265. EV.PostWarningLog(Module, "Get FFU Device Address.");
  266. return false;
  267. }
  268. GetDeviceAddress();
  269. EV.PostInfoLog(Module, $"{Name}Get FFU Device Address {groupAddress}");
  270. return true;
  271. });
  272. OP.Subscribe($"{Name}SetFFUSpeedfactor", (cmd, param) =>
  273. {
  274. if (int.TryParse((string)param[0], out var groupAddress))
  275. {
  276. EV.PostWarningLog(Module, "Set FFU speed factor.");
  277. return false;
  278. }
  279. int.TryParse((string)param[2], out var newSpeedFactor);
  280. SetSpeedFactor((byte)newSpeedFactor);
  281. EV.PostInfoLog(Module, $"{Name}Set FFU speed factor {newSpeedFactor}");
  282. return true;
  283. });
  284. OP.Subscribe($"{Name}GetFFUSpeedfactor", (cmd, param) =>
  285. {
  286. if (int.TryParse((string)param[0], out var groupAddress))
  287. {
  288. EV.PostWarningLog(Module, "Get FFU speed factor.");
  289. return false;
  290. }
  291. QuerySpeedFactor();
  292. EV.PostInfoLog(Module, $"{Name}Get FFU speed factor {groupAddress}");
  293. return true;
  294. });
  295. OP.Subscribe($"{Name}GetFFUStatus", (cmd, param) =>
  296. {
  297. if (int.TryParse((string)param[0], out var groupAddress))
  298. {
  299. EV.PostWarningLog(Module, "Get FFU Status.");
  300. return false;
  301. }
  302. QueryError();
  303. EV.PostInfoLog(Module, $"{Name}Get FFU Status {groupAddress}");
  304. return true;
  305. });
  306. OP.Subscribe($"{Name}SetFFUSpeed", (cmd, param) =>
  307. {
  308. if (param == null)
  309. {
  310. string tempName = "FFU1";
  311. if (Name == "FfuAAF1")
  312. {
  313. tempName = "FFU1";
  314. }
  315. else if(Name == "FfuAAF2")
  316. {
  317. tempName = "FFU2";
  318. }
  319. int speed = SC.GetValue<int>($"System.{tempName}FanSpeedSetPoint");
  320. SetSpeed(speed);
  321. EV.PostInfoLog(Module, $"{Name} speed set to {speed}");
  322. return true;
  323. }
  324. else
  325. {
  326. if (int.TryParse((string)param[0], out var groupAddress))
  327. {
  328. EV.PostWarningLog(Module, "invalid speed.");
  329. return false;
  330. }
  331. int.TryParse((string)param[2], out var speed);
  332. //SetSpeed((int)(speed * 250 * 1.0 / 1440));
  333. SetSpeed(speed);
  334. EV.PostInfoLog(Module, $"{Name} speed set to {speed}");
  335. return true;
  336. }
  337. });
  338. OP.Subscribe($"{Name}GetFFUSpeed", (cmd, param) =>
  339. {
  340. if (int.TryParse((string)param[0], out var groupAddress))
  341. {
  342. EV.PostWarningLog(Module, "FFU Query speed.");
  343. return false;
  344. }
  345. QuerySpeed();
  346. EV.PostInfoLog(Module, $"{Name}FFU Query Speed {groupAddress}");
  347. return true;
  348. });
  349. OP.Subscribe($"{Name}GetFFUMaxSpeed1", (cmd, param) =>
  350. {
  351. if (int.TryParse((string)param[0], out var groupAddress))
  352. {
  353. EV.PostWarningLog(Module, "Get FFU GetFFUMaxSpeed1.");
  354. return false;
  355. }
  356. QueryMaxSpeed1();
  357. EV.PostInfoLog(Module, $"{Name}Get FFU GetFFUMaxSpeed1 {groupAddress}");
  358. return true;
  359. });
  360. OP.Subscribe($"{Name}GetFFUMaxSpeed2", (cmd, param) =>
  361. {
  362. if (int.TryParse((string)param[0], out var groupAddress))
  363. {
  364. EV.PostWarningLog(Module, "Get FFU GetFFUMaxSpeed2.");
  365. return false;
  366. }
  367. QueryMaxSpeed2();
  368. EV.PostInfoLog(Module, $"{Name}Get FFU GetFFUMaxSpeed2 {groupAddress}");
  369. return true;
  370. });
  371. OP.Subscribe($"{Name}GetFFUMaxSpeed3", (cmd, param) =>
  372. {
  373. if (int.TryParse((string)param[0], out var groupAddress))
  374. {
  375. EV.PostWarningLog(Module, "Get FFU GetFFUMaxSpeed3.");
  376. return false;
  377. }
  378. QueryMaxSpeed3();
  379. EV.PostInfoLog(Module, $"{Name}Get FFU GetFFUMaxSpeed3 {groupAddress}");
  380. return true;
  381. });
  382. OP.Subscribe($"{Name}SetFFUReset", (cmd, param) =>
  383. {
  384. if (int.TryParse((string)param[0], out var groupAddress))
  385. {
  386. EV.PostWarningLog(Module, "Set FFU Reset.");
  387. return false;
  388. }
  389. ResetDevice();
  390. EV.PostInfoLog(Module, $"{Name}Set FFU Reset {groupAddress}");
  391. return true;
  392. });
  393. OP.Subscribe($"{Name}.SetFFUSpeedBySC", (cmd, param) =>
  394. {
  395. int speed = SC.GetValue<int>("System.FFUFanSpeedSetPoint");
  396. SetSpeed(speed);
  397. EV.PostInfoLog(Module, $"Set {Name} speed");
  398. return true;
  399. });
  400. ConnectionManager.Instance.Subscribe($"{Name}", this);
  401. return true;
  402. }
  403. private bool OnTimer()
  404. {
  405. try
  406. {
  407. _connection.EnableLog(_enableLog);
  408. _connection.MonitorTimeout();
  409. if (!_connection.IsConnected)// || _connection.IsCommunicationError
  410. {
  411. lock (_locker)
  412. {
  413. _lstHandler.Clear();
  414. }
  415. _trigRetryConnect.CLK = !_connection.IsConnected;
  416. if (_trigRetryConnect.Q)
  417. {
  418. _connection.SetPortAddress(SC.GetStringValue($"{_scRoot}.{Name}.Address"));
  419. if (!_connection.Connect())
  420. {
  421. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
  422. }
  423. }
  424. return true;
  425. }
  426. HandlerBase handler = null;
  427. if (!_connection.IsBusy)
  428. {
  429. lock (_locker)
  430. {
  431. if (_lstHandler.Count == 0 && _activeMonitorStatus)
  432. {
  433. QuerySpeed();
  434. }
  435. if (_lstHandler.Count > 0)
  436. {
  437. handler = _lstHandler.First.Value;
  438. _lstHandler.RemoveFirst();
  439. }
  440. }
  441. if (handler != null)
  442. {
  443. _connection.Execute(handler);
  444. }
  445. }
  446. return true;
  447. }
  448. catch (Exception ex)
  449. {
  450. LOG.Write(ex);
  451. }
  452. return true;
  453. }
  454. internal void NoteError()
  455. {
  456. }
  457. public void Monitor()
  458. {
  459. try
  460. {
  461. _connection.EnableLog(_enableLog);
  462. _trigPumpOnOff.CLK = _isOn;
  463. if (_trigPumpOnOff.R)
  464. {
  465. EV.PostInfoLog(Module, $"{Module}.{Name} is on");
  466. }
  467. if (_trigPumpOnOff.T)
  468. {
  469. EV.PostInfoLog(Module, $"{Module}.{Name} is off");
  470. }
  471. _trigCommunicationError.CLK = _connection.IsCommunicationError;
  472. if (_trigCommunicationError.Q)
  473. {
  474. EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  475. }
  476. }
  477. catch (Exception ex)
  478. {
  479. LOG.Write(ex);
  480. }
  481. }
  482. public void Terminate()
  483. {
  484. try
  485. {
  486. if (_connection != null)
  487. {
  488. _connection.Disconnect();
  489. _connection = null;
  490. }
  491. }
  492. catch (Exception ex)
  493. {
  494. LOG.Write(ex);
  495. }
  496. }
  497. public void Reset()
  498. {
  499. _trigError.RST = true;
  500. _trigOverTemp.RST = true;
  501. _trigWarningMessage.RST = true;
  502. _connection.SetCommunicationError(false, "");
  503. _trigCommunicationError.RST = true;
  504. _trigRetryConnect.RST = true;
  505. }
  506. public void SetPumpOnOff(bool isOn)
  507. {
  508. lock (_locker)
  509. {
  510. }
  511. }
  512. public void SetActiveMonitor(bool active)
  513. {
  514. _activeMonitorStatus = active;
  515. }
  516. internal void NoteOnOff(bool isOn)
  517. {
  518. _isOn = isOn;
  519. }
  520. public void SetSpeed(float speed)
  521. {
  522. lock (_locker)
  523. {
  524. _lstHandler.Clear();
  525. if (_connection.IsBusy) _connection.ForceClear();
  526. List<byte> cmddata = new List<byte>() { 0x35, 0x40, 0x0, (byte)(speed * 250.0 / _nMaxSpeed) };
  527. byte checksum = ModRTU_CRC(cmddata.ToArray());
  528. cmddata.Add(checksum);
  529. _connection.SendMessage(cmddata.ToArray());
  530. }
  531. }
  532. public void SetErrorCode(int errorCode)
  533. {
  534. _errorCode = errorCode;
  535. }
  536. public void SetError(string reason)
  537. {
  538. _trigWarningMessage.CLK = true;
  539. if (_trigWarningMessage.Q)
  540. {
  541. EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
  542. }
  543. }
  544. private static byte ModRTU_CRC(byte[] buffer)
  545. {
  546. //ushort crc = 0xFFFF;
  547. // var buf = System.Text.Encoding.UTF8.GetBytes(String.Join(Environment.NewLine, buffer));
  548. var buf = buffer;
  549. var len = buffer.Length;
  550. byte temp = buffer[0];
  551. for (int i = 1; i < buffer.Length; i++)
  552. {
  553. temp = (byte)(temp ^ buffer[i]);
  554. }
  555. return (byte)~temp;
  556. }
  557. }
  558. }