BaecChiller.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.OperationCenter;
  5. using Aitex.Core.RT.SCCore;
  6. using Aitex.Core.Util;
  7. using MECF.Framework.Common.CommonData.DeviceData;
  8. using MECF.Framework.Common.Communications;
  9. using MECF.Framework.Common.Device.Bases;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Chillers.BaecChiller
  16. {
  17. public class BaecChiller : ChillerBase, IConnection
  18. {
  19. public string Address => Connection.Address;
  20. public override bool IsConnected => Connection.IsConnected && !_connection.IsCommunicationError;
  21. public bool Connect()
  22. {
  23. return _connection.Connect();
  24. }
  25. public bool Disconnect()
  26. {
  27. return _connection.Disconnect();
  28. }
  29. public byte SlaveAddress { get; private set; } = 0x01;
  30. public string PortStatus { get; set; } = "Closed";
  31. private BaecChillerConnection _connection;
  32. public BaecChillerConnection Connection
  33. {
  34. get { return _connection; }
  35. }
  36. public override AITChillerData1 DeviceData
  37. {
  38. get
  39. {
  40. return new AITChillerData1()
  41. {
  42. Module = Module,
  43. DeviceName = Name,
  44. DisplayName = Name,
  45. IsCH1On = IsCH1On,
  46. IsCH2On = IsCH2On,
  47. IsCH1Alarm = IsCH1Alarm,
  48. IsCH2Alarm = IsCH2Alarm,
  49. CH1Temperature = CH1TemperatureFeedback,
  50. CH2Temperature = CH2TemperatureFeedback,
  51. CH1TemperatureSetPoint = CH1TemperatureSetpoint,
  52. CH2TemperatureSetPoint = CH2TemperatureSetpoint,
  53. CH1WaterFlow = CH1WaterFlow,
  54. CH2WaterFlow = CH2WaterFlow,
  55. FormatString = "f1",
  56. TemperatureHighLimit = TemperatureHighLimit,
  57. TemperatureLowLimit = TemperatureLowLimit,
  58. };
  59. }
  60. }
  61. public override float TemperatureHighLimit => (float)_scTemperatureMaxValue.DoubleValue;
  62. public override float TemperatureLowLimit => (float)_scTemperatureMinValue.DoubleValue;
  63. private R_TRIG _trigError = new R_TRIG();
  64. private R_TRIG _trigCommunicationError = new R_TRIG();
  65. private R_TRIG _trigRetryConnect = new R_TRIG();
  66. private PeriodicJob _thread;
  67. private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
  68. private LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
  69. private DeviceTimer _QueryTimer = new DeviceTimer();
  70. private readonly int _QueryInterval = 2000;
  71. private object _locker = new object();
  72. private bool _enableLog;
  73. private string _address;
  74. private string _scRoot;
  75. private SCConfigItem _scTemperatureMaxValue;
  76. private SCConfigItem _scTemperatureMinValue;
  77. public BaecChiller(string module, string name, string scRoot) : base()
  78. {
  79. _scRoot = scRoot;
  80. base.Module = module;
  81. base.Name = name;
  82. }
  83. public override bool Initialize()
  84. {
  85. base.Initialize();
  86. _scTemperatureMaxValue = SC.GetConfigItem($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.TemperatureMaxValue");
  87. _scTemperatureMinValue = SC.GetConfigItem($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.TemperatureMinValue");
  88. _address = SC.GetStringValue($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.Address");
  89. _enableLog = SC.GetValue<bool>($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.EnableLogMessage");
  90. _connection = new BaecChillerConnection(_address);
  91. _connection.EnableLog(_enableLog);
  92. if (_connection.Connect())
  93. {
  94. PortStatus = "Open";
  95. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  96. }
  97. //_lstMonitorHandler.AddLast(new CommetRFMatchGetActualCapHandler(this));
  98. _thread = new PeriodicJob(2000, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  99. _QueryTimer.Start(_QueryInterval);
  100. _lstMonitorHandler.AddLast(new BaecChillerGetStatusHandler(this));
  101. DATA.Subscribe($"{Module}.{Name}.IsConnected", () => IsConnected);
  102. DATA.Subscribe($"{Module}.{Name}.Address", () => Address);
  103. OP.Subscribe($"{Module}.{Name}.Reconnect", (string cmd, object[] args) =>
  104. {
  105. Disconnect();
  106. Connect();
  107. return true;
  108. });
  109. return true;
  110. }
  111. private bool OnTimer()
  112. {
  113. try
  114. {
  115. //_connection.MonitorTimeout();
  116. if (!_connection.IsConnected || _connection.IsCommunicationError)
  117. {
  118. lock (_locker)
  119. {
  120. _lstHandler.Clear();
  121. }
  122. _trigRetryConnect.CLK = !_connection.IsConnected;
  123. if (_trigRetryConnect.Q)
  124. {
  125. _connection.SetPortAddress(SC.GetStringValue($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.Address"));
  126. if (!_connection.Connect())
  127. {
  128. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
  129. }
  130. else
  131. {
  132. //_lstHandler.AddLast(new RisshiChillerQueryPinHandler(this, _deviceAddress));
  133. //_lstHandler.AddLast(new RisshiChillerSetCommModeHandler(this, _deviceAddress, EnumRfPowerCommunicationMode.Host));
  134. }
  135. }
  136. return true;
  137. }
  138. HandlerBase handler = null;
  139. if (!_connection.IsBusy)
  140. {
  141. lock (_locker)
  142. {
  143. if (_lstHandler.Count == 0)
  144. {
  145. foreach (var monitorHandler in _lstMonitorHandler)
  146. {
  147. _lstHandler.AddLast(monitorHandler);
  148. }
  149. }
  150. if (_lstHandler.Count > 0)
  151. {
  152. handler = _lstHandler.First.Value;
  153. _lstHandler.RemoveFirst();
  154. }
  155. }
  156. if (handler != null)
  157. {
  158. _connection.Execute(handler);
  159. }
  160. }
  161. }
  162. catch (Exception ex)
  163. {
  164. LOG.Write(ex);
  165. }
  166. return true;
  167. }
  168. public override void Monitor()
  169. {
  170. try
  171. {
  172. //_connection.EnableLog(_enableLog);
  173. _trigCommunicationError.CLK = _connection.IsCommunicationError;
  174. if (_trigCommunicationError.Q)
  175. {
  176. EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  177. }
  178. }
  179. catch (Exception ex)
  180. {
  181. LOG.Write(ex);
  182. }
  183. }
  184. public override void Reset()
  185. {
  186. _trigError.RST = true;
  187. _connection.SetCommunicationError(false, "");
  188. _trigCommunicationError.RST = true;
  189. //_enableLog = SC.GetValue<bool>($"{ScBasePath}.{Name}.EnableLogMessage");
  190. _trigRetryConnect.RST = true;
  191. base.Reset();
  192. }
  193. #region Command Functions
  194. public void SetTemperature(string angle)
  195. {
  196. lock (_locker)
  197. {
  198. //_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWAA", angle));
  199. }
  200. }
  201. public void SetTempHighWarning(string angle)
  202. {
  203. lock (_locker)
  204. {
  205. //_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWAA", angle));
  206. }
  207. }
  208. public void SetTempLowWarning(string angle)
  209. {
  210. lock (_locker)
  211. {
  212. //_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWAA", angle));
  213. }
  214. }
  215. public void SetRemoteMode(string angle)
  216. {
  217. lock (_locker)
  218. {
  219. //_lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWS", angle));
  220. }
  221. }
  222. public void SetRunMode(string waferSize)
  223. {
  224. lock (_locker)
  225. {
  226. // _lstHandler.AddLast(new RisshiChillerSimpleSetHandler(this, "SWS", waferSize));
  227. }
  228. }
  229. public override void SetChillerCH1OnOff(bool isOn)
  230. {
  231. lock (_locker)
  232. {
  233. _lstHandler.AddLast(new BaecChillerSetOnOffHandler(this, true, isOn));
  234. }
  235. }
  236. public override void SetChillerCH2OnOff(bool isOn)
  237. {
  238. lock (_locker)
  239. {
  240. _lstHandler.AddLast(new BaecChillerSetOnOffHandler(this, false, isOn));
  241. }
  242. }
  243. public override void SetChillerCH1Temperature(float temp)
  244. {
  245. lock (_locker)
  246. {
  247. _lstHandler.AddLast(new BaecChillerSetTemperatureHandler(this, true, temp));
  248. }
  249. }
  250. public override void SetChillerCH2Temperature(float temp)
  251. {
  252. lock (_locker)
  253. {
  254. _lstHandler.AddLast(new BaecChillerSetTemperatureHandler(this, false, temp));
  255. }
  256. }
  257. #endregion
  258. #region Properties
  259. public string Error { get; private set; }
  260. #endregion
  261. #region Note Functions
  262. private R_TRIG _trigWarningMessage = new R_TRIG();
  263. public void NoteError(string reason)
  264. {
  265. if (!string.IsNullOrEmpty(reason))
  266. {
  267. _trigWarningMessage.CLK = true;
  268. if (_trigWarningMessage.Q)
  269. {
  270. EV.PostWarningLog(Module, $"{Module}.{Name} error, {reason}");
  271. }
  272. Error = reason;
  273. }
  274. else
  275. {
  276. Error = null;
  277. }
  278. }
  279. #endregion
  280. }
  281. }