OmronEJ1.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using MECF.Framework.Common.Communications;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.IO.Ports;
  12. using System.Threading;
  13. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Temperatures.Omrons
  14. {
  15. public class AdressInfo
  16. {
  17. public string Name { get; set; }
  18. public byte DeviceAddress { get; set; }
  19. public int UnitAddress { get; set; }
  20. public int Length { get; set; }
  21. public int Data;
  22. public string Remark { get; set; }//H3-N2-H4-N5-H6(H3代表连续3个地址有数据,N2代表H3与H4中间有两个地址为预留)
  23. }
  24. public class OmronEJ1 : BaseDevice, IConnection, IDevice
  25. {
  26. public event Action<int, int, short[]> OnVariableReadout; //slave, start address, data
  27. public class AddressMapItem
  28. {
  29. public string Name { get; set; }
  30. public int SlaveAddress { get; set; }
  31. public int AddressFeedback { get; set; }
  32. public int AddressSetPoint { get; set; }
  33. public int AddressAlarm { get; set; }
  34. public int AddressStatus { get; set; }
  35. public int Channel { get; set; }
  36. public AddressMapItem(string name, int slaveAddress, int addressFeedback, int addressSetpoint, int addressAlarm, int addressStatus, int channel)
  37. {
  38. Name = name;
  39. SlaveAddress = slaveAddress;
  40. AddressFeedback = addressFeedback;
  41. AddressSetPoint = addressSetpoint;
  42. AddressAlarm = addressAlarm;
  43. AddressStatus = addressStatus;
  44. Channel = channel;
  45. }
  46. }
  47. public Dictionary<int, string> AbnormalCode = new Dictionary<int, string>()
  48. {
  49. { 1,"ncorrect function code, this machine does not correspond to the function code." },
  50. { 2,"Incorrect data address" },
  51. { 3,"Incorrect data." },
  52. { 4,"operation error" },
  53. };
  54. public Dictionary<string, AdressInfo> _dicAdressInfo = new Dictionary<string, AdressInfo>()//配置最多32个数据
  55. {
  56. {"Channel1Setting1", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0x0240,Length = 1 } },//手册 11-3
  57. {"Channel1Setting2", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0x0440,Length = 1 } },
  58. {"Channel1Setting3", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0x0640,Length = 1 } },
  59. {"Channel1Setting4", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0x0840,Length = 1 } },
  60. {"Channel2Setting1", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0x0240,Length = 1 } },//手册 11-3
  61. {"Channel2Setting2", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0x0440,Length = 1 } },
  62. {"Channel2Setting3", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0x0640,Length = 1 } },
  63. {"Channel2Setting4", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0x0840,Length = 1 } },
  64. {"Channel3Setting1", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0x0240,Length = 1 } },//手册 11-3
  65. {"Channel3Setting2", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0x0440,Length = 1 } },
  66. {"Channel3Setting3", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0x0640,Length = 1 } },
  67. {"Channel3Setting4", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0x0840,Length = 1 } },
  68. {"Channel1RunALL", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0xFFFF,Length = 1,Data=0x0AFF} },
  69. {"Channel1Run1", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0A00} },
  70. {"Channel1Run2", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0A01} },
  71. {"Channel1Run3", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0A02} },
  72. {"Channel1Run4", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0xFFFF,Length = 1,Data=0x0A03} },
  73. {"Channel2RunALL", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0xFFFF,Length = 1,Data=0x0AFF } },
  74. {"Channel2Run1", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0A00} },
  75. {"Channel2Run2", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0A01} },
  76. {"Channel2Run3", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0A02} },
  77. {"Channel2Run4", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0A03} },
  78. {"Channel3RunALL", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0xFFFF,Length = 1,Data=0x0AFF } },
  79. {"Channel3Run1", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0A00} },
  80. {"Channel3Run2", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0A01 } },
  81. {"Channel3Run3", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0A02} },
  82. {"Channel3Run4", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0xFFFF,Length = 1,Data=0x0A03} },
  83. {"Channel1StopALL", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0xFFFF,Length = 1,Data=0x0BFF } },
  84. {"Channel1Stop1", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0B00} },
  85. {"Channel1Stop2", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0B01} },
  86. {"Channel1Stop3", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0B02} },
  87. {"Channel1Stop4", new AdressInfo() { DeviceAddress=0x01, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0B03} },
  88. {"Channel2StopALL", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0BFF} },
  89. {"Channel2Stop1", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0B00} },
  90. {"Channel2Stop2", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0xFFFF,Length = 1,Data=0x0B01} },
  91. {"Channel2Stop3", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0xFFFF,Length = 1,Data=0x0B02 } },
  92. {"Channel2Stop4", new AdressInfo() { DeviceAddress=0x02, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0B03} },
  93. {"Channel3StopALL", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0BFF} },
  94. {"Channel3Stop1", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0B00} },
  95. {"Channel3Stop2", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0B01} },
  96. {"Channel3Stop3", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0B02} },
  97. {"Channel3Stop4", new AdressInfo() { DeviceAddress=0x03, UnitAddress = 0xFFFF,Length = 1 ,Data=0x0B03} },
  98. };
  99. private OmronEJ1Connection _connection;
  100. private bool _activeMonitorStatus;
  101. private int _errorCode;
  102. private R_TRIG _trigCommunicationError = new R_TRIG();
  103. private R_TRIG _trigRetryConnect = new R_TRIG();
  104. private PeriodicJob _thread;
  105. private int tempCount = 1;
  106. private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
  107. private object _locker = new object();
  108. private bool _enableLog = true;
  109. private string _scRoot;
  110. private int _tempWarningMaxDiff = 1; //报警最大温度(实际温度与设定温度之间的差值)
  111. private R_TRIG[] TempWarningTrig = new R_TRIG[12]; //温度报警
  112. string[] WarningInfo = new string[12]
  113. { "HeatTMAPanel", "HeatTCSPanel", "OuterPanel",
  114. "MidPanel", "InnerPanel", "HeatShowerOuter", "HeatShowerInner",
  115. "HeatShowerMid", "HeatDptPanel", "HeatLeakSource", "HeatLeakBypass", "HeatDptGate" };
  116. public float[] ActualTemp = new float[12];
  117. public float[] SettingTemp = new float[12];
  118. public string Address
  119. {
  120. get; set;
  121. }
  122. public bool IsConnected
  123. {
  124. get
  125. {
  126. return _connection != null && _connection.IsConnected && !_connection.IsCommunicationError;
  127. }
  128. }
  129. public int _connecteTimes { get; set; }
  130. public bool EnableContinuousQuery { get; set; }
  131. public bool Connect()
  132. {
  133. return _connection.Connect();
  134. }
  135. public bool Disconnect()
  136. {
  137. return _connection.Disconnect();
  138. }
  139. public OmronEJ1(string module, string name, string scRoot) : base(module, name, name, name)
  140. {
  141. _scRoot = scRoot;
  142. _activeMonitorStatus = true;
  143. EnableContinuousQuery = true;
  144. }
  145. ~OmronEJ1()
  146. {
  147. _connection.Disconnect();
  148. }
  149. public void QueryTemp()
  150. {
  151. lock (_locker)
  152. {
  153. //_lstHandler.Clear();
  154. _lstHandler.AddLast(new OmronEJ1ReadVariableHandler(this, 1, 0x0080, 16));
  155. _lstHandler.AddLast(new OmronEJ1ReadVariableHandler(this, 1, 0x0081, 16));
  156. _lstHandler.AddLast(new OmronEJ1ReadVariableHandler(this, 2, 0x0080, 16));
  157. _lstHandler.AddLast(new OmronEJ1ReadVariableHandler(this, 2, 0x0081, 16));
  158. _lstHandler.AddLast(new OmronEJ1ReadVariableHandler(this, 2, 0x0082, 16));
  159. _lstHandler.AddLast(new OmronEJ1ReadVariableHandler(this, 2, 0x0083, 16));
  160. _lstHandler.AddLast(new OmronEJ1ReadVariableHandler(this, 3, 0x0080, 16));
  161. _lstHandler.AddLast(new OmronEJ1ReadVariableHandler(this, 3, 0x0081, 16));
  162. _lstHandler.AddLast(new OmronEJ1ReadVariableHandler(this, 3, 0x0082, 16));
  163. _lstHandler.AddLast(new OmronEJ1ReadVariableHandler(this, 3, 0x0083, 16));
  164. }
  165. //_lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel1 Actual1 Temp", 0x01, 0x02, 0x00, 0x00, 0x01));
  166. //_lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel1 Setting1 Temp", 0x01, 0x02, 0x40, 0x00, 0x01));
  167. //_lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel1 Actual2 Temp", 0x01, 0x04, 0x00, 0x00, 0x01));
  168. //_lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel1 Setting2 Temp", 0x01, 0x04, 0x40, 0x00, 0x01));
  169. //_lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel1 Actual3 Temp", 0x01, 0x06, 0x00, 0x00, 0x01));
  170. //_lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel1 Setting3 Temp", 0x01, 0x06, 0x40, 0x00, 0x01));
  171. //_lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel1 Actual4 Temp", 0x01, 0x08, 0x00, 0x00, 0x01));
  172. //_lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel1 Setting4 Temp", 0x01, 0x08, 0x40, 0x00, 0x01));
  173. //if (moduleCount >= 2)
  174. //{
  175. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel2 Actual1 Temp", 0x02, 0x02, 0x00, 0x00, 0x01));
  176. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel2 Setting1 Temp", 0x02, 0x02, 0x40, 0x00, 0x01));
  177. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel2 Actual2 Temp", 0x02, 0x04, 0x00, 0x00, 0x01));
  178. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel2 Setting2 Temp", 0x02, 0x04, 0x40, 0x00, 0x01));
  179. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel2 Actual3 Temp", 0x02, 0x06, 0x00, 0x00, 0x01));
  180. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel2 Setting3 Temp", 0x02, 0x06, 0x40, 0x00, 0x01));
  181. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel2 Actual4 Temp", 0x02, 0x08, 0x00, 0x00, 0x01));
  182. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel2 Setting4 Temp", 0x02, 0x08, 0x40, 0x00, 0x01));
  183. //}
  184. //if (moduleCount >= 3)
  185. //{
  186. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel3 Actual1 Temp", 0x03, 0x02, 0x00, 0x00, 0x01));
  187. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel3 Setting1 Temp", 0x03, 0x02, 0x40, 0x00, 0x01));
  188. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel3 Actual2 Temp", 0x03, 0x04, 0x0, 0x00, 0x01));
  189. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel3 Setting2 Temp", 0x03, 0x04, 0x40, 0x00, 0x01));
  190. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel3 Actual3 Temp", 0x03, 0x06, 0x0, 0x00, 0x01));
  191. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel3 Setting3 Temp", 0x03, 0x06, 0x40, 0x00, 0x01));
  192. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel3 Actual4 Temp", 0x03, 0x08, 0x00, 0x00, 0x01));
  193. // _lstHandler.AddLast(new OmronEJ1QueryHandler(this, "Query Channel3 Setting4 Temp", 0x03, 0x08, 0x40, 0x00, 0x01));
  194. //}
  195. }
  196. public void ResetDevice()
  197. {
  198. }
  199. public void QueryError()
  200. {
  201. EV.PostInfoLog(Module, "Query error");
  202. }
  203. public bool Initialize(string portName, int baudRate, int dataBits, Parity parity, StopBits stopBits)
  204. {
  205. _enableLog = true;
  206. _connection = new OmronEJ1Connection(portName, baudRate, dataBits, parity, stopBits, "", false);
  207. _connection.EnableLog(_enableLog);
  208. EnableContinuousQuery = false;
  209. if (_connection.Connect())
  210. {
  211. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  212. }
  213. _thread = new PeriodicJob(200, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  214. return true;
  215. }
  216. public bool Initialize()
  217. {
  218. string portName = SC.GetStringValue($"{_scRoot}.Address");
  219. int baudRate = SC.GetValue<int>($"{_scRoot}.BaudRate");
  220. int dataBits = SC.GetValue<int>($"{_scRoot}.DataBits");
  221. Parity parity = (Parity)Enum.Parse(typeof(Parity), SC.GetStringValue($"{_scRoot}.Parity"));
  222. StopBits stopBits = (StopBits)Enum.Parse(typeof(StopBits), SC.GetStringValue($"{_scRoot}.StopBits"));
  223. Address = portName;
  224. _enableLog = SC.GetValue<bool>($"{_scRoot}.EnableLogMessage");
  225. _connection = new OmronEJ1Connection(portName, baudRate, dataBits, parity, stopBits);
  226. _connection.EnableLog(_enableLog);
  227. int count = SC.ContainsItem("System.ComPortRetryCount") ? SC.GetValue<int>("System.ComPortRetryCount") : 5;
  228. int sleep = SC.ContainsItem("System.ComPortRetryDelayTime") ? SC.GetValue<int>("System.ComPortRetryDelayTime") : 2;
  229. if (sleep <= 0 || sleep > 10)
  230. sleep = 2;
  231. int retry = 0;
  232. do
  233. {
  234. _connection.Disconnect();
  235. Thread.Sleep(sleep * 1000);
  236. if (_connection.Connect())
  237. {
  238. EV.PostInfoLog(Module, $"{Name} connected");
  239. break;
  240. }
  241. if (count > 0 && retry++ > count)
  242. {
  243. LOG.Write($"Retry connect {Module}.{Name} stop retry.");
  244. EV.PostAlarmLog(Module, $"Can't connect to {Module}.{Name}.");
  245. break;
  246. }
  247. Thread.Sleep(sleep * 1000);
  248. LOG.Write($"Retry connect {Module}.{Name} for the {retry + 1} time.");
  249. } while (true);
  250. _thread = new PeriodicJob(200, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  251. ConnectionManager.Instance.Subscribe($"{Name}", this);
  252. DATA.Subscribe($"{Module}.{Name}.IsConnected", () => IsConnected);
  253. DATA.Subscribe($"{Module}.{Name}.Address", () => Address);
  254. OP.Subscribe($"{Module}.{Name}.Reconnect", (string cmd, object[] args) => {
  255. Disconnect();
  256. Reset();
  257. Connect();
  258. return true;
  259. });
  260. return true;
  261. }
  262. private bool OnTimer()
  263. {
  264. try
  265. {
  266. _connection.MonitorTimeout();
  267. if (!_connection.IsConnected || _connection.IsCommunicationError)
  268. {
  269. lock (_locker)
  270. {
  271. _lstHandler.Clear();
  272. }
  273. _trigRetryConnect.CLK = !_connection.IsConnected;
  274. if (_trigRetryConnect.Q)
  275. {
  276. _connection.SetPortAddress(SC.GetStringValue($"{_scRoot}.Address"));
  277. if (!_connection.Connect())
  278. {
  279. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
  280. }
  281. }
  282. if (_connecteTimes++ < 3)
  283. _connection.ForceClear();
  284. else _connecteTimes = 4;
  285. return true;
  286. }
  287. HandlerBase handler = null;
  288. lock (_locker)
  289. {
  290. if (_lstHandler.Count == 0 && EnableContinuousQuery)
  291. QueryTemp();
  292. //if (_lstHandler.Count > 0 && !_connection.IsBusy)
  293. //{
  294. // handler = _lstHandler.First.Value;
  295. // _lstHandler.RemoveFirst();
  296. // if (handler != null)
  297. // {
  298. // _connection.Execute(handler);
  299. // }
  300. //}
  301. while (_lstHandler.Count > 0)
  302. {
  303. _connection.MonitorTimeout();
  304. if (!_connection.IsBusy)
  305. {
  306. handler = _lstHandler.First.Value;
  307. _lstHandler.RemoveFirst();
  308. if (handler != null)
  309. {
  310. _connection.Execute(handler);
  311. }
  312. }
  313. Thread.Sleep(10);
  314. }
  315. }
  316. //Thread.Sleep(30);
  317. }
  318. catch (Exception ex)
  319. {
  320. LOG.Write(ex);
  321. }
  322. return true;
  323. }
  324. internal void NoteError()
  325. {
  326. }
  327. public void Monitor()
  328. {
  329. try
  330. {
  331. _connection.EnableLog(_enableLog);
  332. if (_connecteTimes < 4) return;
  333. _trigCommunicationError.CLK = _connection.IsCommunicationError;
  334. if (_trigCommunicationError.Q)
  335. {
  336. for (int i = 0; i < 12; i++)
  337. {
  338. ActualTemp[i] = 0;
  339. SettingTemp[i] = 0;
  340. }
  341. EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  342. }
  343. MonitorWarning();
  344. }
  345. catch (Exception ex)
  346. {
  347. LOG.Write(ex);
  348. }
  349. }
  350. private void MonitorWarning()
  351. {
  352. for (int i = 0; i < 12; i++)
  353. {
  354. if (TempWarningTrig[i] == null)
  355. continue;
  356. TempWarningTrig[i].CLK = SettingTemp[i] > 0 && _tempWarningMaxDiff > 0 && Math.Abs(ActualTemp[i] - SettingTemp[i]) > _tempWarningMaxDiff;
  357. if (TempWarningTrig[i].Q)
  358. {
  359. EV.PostWarningLog(Module, $"{WarningInfo[i]},the difference between the actual value and the set value is too large");
  360. }
  361. }
  362. }
  363. public void Reset()
  364. {
  365. _connecteTimes = 0;
  366. _connection.SetCommunicationError(false, "");
  367. _trigCommunicationError.RST = true;
  368. _enableLog = SC.GetValue<bool>($"{_scRoot}.EnableLogMessage");
  369. _trigRetryConnect.RST = true;
  370. for (int i = 0; i < 12; i++)
  371. {
  372. if (TempWarningTrig[i] != null)
  373. TempWarningTrig[i].RST = true;
  374. }
  375. }
  376. public void RespondAbnormal(int funcode, int abnormalcode)
  377. {
  378. if (funcode == 0x83)
  379. {
  380. foreach (var code in AbnormalCode)
  381. {
  382. if (code.Key == abnormalcode)
  383. EV.PostWarningLog(Name, $"Query Abnormal:{code.Value}");
  384. }
  385. }
  386. if (funcode == 0x90 || funcode == 0x86)
  387. {
  388. foreach (var code in AbnormalCode)
  389. {
  390. if (code.Key == abnormalcode)
  391. EV.PostWarningLog(Name, $"Write Abnormal:{code.Value}");
  392. }
  393. }
  394. }
  395. public void SetActiveMonitor(bool active)
  396. {
  397. _activeMonitorStatus = active;
  398. }
  399. public void SetActiveMonitorHandler(bool active)
  400. {
  401. lock (_locker)
  402. {
  403. _lstHandler.Clear();
  404. int[] channelOn = new int[] { 0x0A00, 0x0A01, 0x0A02, 0x0A03 };
  405. int[] channelOff = new int[] { 0x0B00, 0x0B01, 0x0B02, 0x0B03 };
  406. //_lstHandler.AddLast(new OmronEJ1ReadVariableHandler(this, slaveAddress, 0xFFFF, isOn ? channelOn[channel] : channelOff[channel]));
  407. }
  408. //return true;
  409. }
  410. public void SetErrorCode(int errorCode)
  411. {
  412. _errorCode = errorCode;
  413. }
  414. public void Terminate()
  415. {
  416. _connection.Disconnect();
  417. }
  418. public void NoteVariableReadout(int slaveAddress, int startAddress, short[] value)
  419. {
  420. if (OnVariableReadout != null)
  421. OnVariableReadout(slaveAddress, startAddress, value);
  422. }
  423. public bool SetChannelRunStop(int slaveAddress, int channel, bool isOn)
  424. {
  425. lock (_locker)
  426. {
  427. //_lstHandler.Clear();
  428. int[] channelOn = new int[] { 0x0A00, 0x0A01, 0x0A02, 0x0A03 };
  429. int[] channelOff = new int[] { 0x0B00, 0x0B01, 0x0B02, 0x0B03 };
  430. _lstHandler.AddLast(new OmronEJ1WriteVariableHandler(this, slaveAddress, 0xFFFF, isOn ? channelOn[channel] : channelOff[channel]));
  431. }
  432. return true;
  433. }
  434. public bool SetTemperature(int slaveAddress, int addressSetPoint, int temperature)
  435. {
  436. lock (_locker)
  437. {
  438. //_lstHandler.Clear();
  439. _lstHandler.AddLast(new OmronEJ1WriteVariableHandler(this, slaveAddress, addressSetPoint, temperature));
  440. }
  441. return true;
  442. }
  443. }
  444. }