VATS651.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  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 MECF.Framework.Common.Device.Bases;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Common;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO.Ports;
  14. using System.Linq;
  15. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.ThrottleValves.VAT
  16. {
  17. public class VATS651 : ThrottleValveBase, IConnection
  18. {
  19. public string Address => Connection?.Address;
  20. public override bool IsConnected => Connection != null && 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 string PortStatus { get; set; } = "Closed";
  30. private VATS651Connection _connection;
  31. public VATS651Connection Connection
  32. {
  33. get { return _connection; }
  34. }
  35. public override AITThrottleValveData DeviceData
  36. {
  37. get
  38. {
  39. return new AITThrottleValveData()
  40. {
  41. Module = Module,
  42. DisplayName = Name,
  43. DeviceName = Name,
  44. DeviceSchematicId = DeviceID,
  45. UnitPosition = "%",
  46. UnitPressure = "mTorr",
  47. MaxValuePosition = 100,
  48. MaxValuePressure = 1000,
  49. PositionFeedback = PositionFeedback,
  50. PositionSetPoint = PositionSetPoint,
  51. PressureFeedback = PressureFeedback,
  52. PressureSetPoint = PressureSetPoint,
  53. Mode = (int)Mode,
  54. };
  55. }
  56. }
  57. private R_TRIG _trigError = new R_TRIG();
  58. private bool _isAlarm;
  59. private R_TRIG _trigCommunicationError = new R_TRIG();
  60. private R_TRIG _trigRetryConnect = new R_TRIG();
  61. private PeriodicJob _thread;
  62. private SCConfigItem _scPressureSensorRange;
  63. private SCConfigItem _scPressureCommunicationRange;
  64. private SCConfigItem _scPositionCommunicationRange;
  65. private SCConfigItem _scSensorResponseTime;
  66. private SCConfigItem _scRampTime;
  67. private SCConfigItem _scGainFactor;
  68. private SCConfigItem _scValveSpeed;
  69. private SCConfigItem _scBaudRate;
  70. private SCConfigItem _scDataBits;
  71. private SCConfigItem _scParity;
  72. private SCConfigItem _scStopBits;
  73. private LinkedList<HandlerBase> _lstHandler = new LinkedList<HandlerBase>();
  74. private LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
  75. private Dictionary<string, string> _errorCodeReferenceDic;
  76. private object _locker = new object();
  77. private RD_TRIG _learnTrig = new RD_TRIG();
  78. private bool _enableLog;
  79. private string _scRoot;
  80. private string _setMode;
  81. public VATS651(string module, string name, string scRoot = "") : base()
  82. {
  83. _scRoot = scRoot;
  84. base.Module = module;
  85. base.Name = name;
  86. }
  87. public bool Initialize(string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
  88. {
  89. base.Initialize();
  90. _enableLog = true;
  91. _connection = new VATS651Connection(portName, baudRate, dataBits, parity, stopBits);
  92. _connection.EnableLog(_enableLog);
  93. if (_connection.Connect())
  94. {
  95. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  96. }
  97. _thread = new PeriodicJob(1000, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  98. return true;
  99. }
  100. public override bool Initialize()
  101. {
  102. if (string.IsNullOrEmpty(_scRoot))
  103. {
  104. ScBasePath = $"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}";
  105. _scPressureSensorRange = SC.GetConfigItem($"{ScBasePath}.{Name}.PressureSensorRange");
  106. _scPressureCommunicationRange = SC.GetConfigItem($"{ScBasePath}.{Name}.PressureCommunicationRange");
  107. _scPositionCommunicationRange = SC.GetConfigItem($"{ScBasePath}.{Name}.PositionCommunicationRange");
  108. _scSensorResponseTime = SC.GetConfigItem($"{ScBasePath}.{Name}.SensorResponseTime");
  109. _scRampTime = SC.GetConfigItem($"{ScBasePath}.{Name}.RampTime");
  110. _scGainFactor = SC.GetConfigItem($"{ScBasePath}.{Name}.GainFactor");
  111. _scValveSpeed = SC.GetConfigItem($"{ScBasePath}.{Name}.ValveSpeed");
  112. _scStableCriteria = SC.GetConfigItem($"{ScBasePath}.{Name}.StableCriteria");
  113. string portName = SC.GetStringValue($"{ScBasePath}.{Name}.Address");
  114. _enableLog = SC.GetValue<bool>($"{ScBasePath}.{Name}.EnableLogMessage");
  115. _scBaudRate = SC.GetConfigItem($"{ScBasePath}.{Name}.BaudRate");
  116. _scDataBits = SC.GetConfigItem($"{ScBasePath}.{Name}.DataBits");
  117. _scParity = SC.GetConfigItem($"{ScBasePath}.{Name}.Parity");
  118. _scStopBits = SC.GetConfigItem($"{ScBasePath}.{Name}.StopBits");
  119. _connection = new VATS651Connection(portName
  120. , _scBaudRate?.IntValue ?? 9600
  121. , _scDataBits?.IntValue ?? 7
  122. , (Parity)(_scParity?.IntValue ?? 2)
  123. , (StopBits)(_scStopBits?.IntValue ?? 1));
  124. }
  125. else
  126. {
  127. _scPressureSensorRange = SC.GetConfigItem($"{_scRoot}.PressureSensorRange");
  128. _scPressureCommunicationRange = SC.GetConfigItem($"{_scRoot}.PressureCommunicationRange");
  129. _scPositionCommunicationRange = SC.GetConfigItem($"{_scRoot}.PositionCommunicationRange");
  130. _scSensorResponseTime = SC.GetConfigItem($"{_scRoot}.SensorResponseTime");
  131. _scRampTime = SC.GetConfigItem($"{_scRoot}.RampTime");
  132. _scGainFactor = SC.GetConfigItem($"{_scRoot}.GainFactor");
  133. _scValveSpeed = SC.GetConfigItem($"{_scRoot}.ValveSpeed");
  134. _scStableCriteria = SC.GetConfigItem($"{_scRoot}.StableCriteria");
  135. string portName = SC.GetStringValue($"{_scRoot}.Address");
  136. _enableLog = SC.GetValue<bool>($"{_scRoot}.EnableLogMessage");
  137. _scBaudRate = SC.GetConfigItem($"{_scRoot}.BaudRate");
  138. _scDataBits = SC.GetConfigItem($"{_scRoot}.DataBits");
  139. _scParity = SC.GetConfigItem($"{_scRoot}.Parity");
  140. _scStopBits = SC.GetConfigItem($"{_scRoot}.StopBits");
  141. int bautRate = SC.GetValue<int>($"{_scRoot}.BaudRate");
  142. int dataBits = SC.GetValue<int>($"{_scRoot}.DataBits");
  143. Enum.TryParse(SC.GetStringValue($"{_scRoot}.Parity"), out Parity parity);
  144. Enum.TryParse(SC.GetStringValue($"{_scRoot}.StopBits"), out StopBits stopBits);
  145. _connection = new VATS651Connection(portName
  146. , bautRate
  147. , dataBits
  148. , parity
  149. , stopBits);
  150. }
  151. _connection.EnableLog(_enableLog);
  152. if (_connection.Connect())
  153. {
  154. PortStatus = "Open";
  155. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  156. }
  157. _thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  158. InitHandler();
  159. _lstMonitorHandler.AddLast(new VATS651QueryStatusHandler(this));
  160. _lstMonitorHandler.AddLast(new VATS651QueryLearnStatusHandler(this));
  161. _errorCodeReferenceDic = new Dictionary<string, string>()
  162. {
  163. {"000001", "Parity error" },
  164. {"000002", "Input buffer overflow (to many characters)" },
  165. {"000003", "Framing error (data length, number of stop bits)" },
  166. {"000004", "Overrun (Service interface: Input buffer register overflow)" },
  167. {"000010", "<CR> or <LF> missing" },
  168. {"000011", ": missing" },
  169. {"000012", "Invalid number of characters (between : and )" },
  170. {"000023", "Invalid value" },
  171. {"000030", "Value out of range" },
  172. {"000040", "Pressure mode, Zero or Learn without Sensor" },
  173. {"000041", "Command not applicable for hardware configuration" },
  174. {"000060", "ZERO disabled" },
  175. {"000080", "Command not accepted due to local operation" },
  176. {"000081", "Command not accepted, Service Interface locked" },
  177. {"000082", "Command not accepted due to synchronization, CLOSED or OPEN by digital input, safety mode or fatal error" },
  178. {"000089", "Not accepted calibration and test mode" },
  179. };
  180. //for recipe
  181. OP.Subscribe($"{Module}.{Name}.SetPressure", (out string reason, int time, object[] param) =>
  182. {
  183. reason = string.Empty;
  184. var pressure = Convert.ToSingle(param[0]);
  185. if (Math.Abs(PressureSetPoint - pressure) > 0.0001)
  186. SetPressure(pressure);
  187. return true;
  188. });
  189. //for recipe
  190. OP.Subscribe($"{Module}.{Name}.SetPosition", (out string reason, int time, object[] param) =>
  191. {
  192. reason = string.Empty;
  193. var position = Convert.ToSingle(param[0]);
  194. if (Math.Abs(PositionSetPoint - position) > 0.0001)
  195. {
  196. PositionSetPoint = position;
  197. lock (_locker)
  198. {
  199. _lstHandler.AddLast(new VATS651SetPositionHandler(this, (int)(PositionSetPoint * _scPositionCommunicationRange.IntValue / 100)));
  200. }
  201. }
  202. return true;
  203. });
  204. //for recipe
  205. OP.Subscribe($"{Module}.{Name}.SetMode", (out string reason, int time, object[] param) =>
  206. {
  207. reason = string.Empty;
  208. var mode = param[0].ToString();
  209. _setMode = mode;
  210. if (mode == PressureCtrlMode.TVClose.ToString())
  211. {
  212. SetControlMode(PressureCtrlMode.TVClose);
  213. return true;
  214. }
  215. if (mode == PressureCtrlMode.TVOpen.ToString())
  216. {
  217. SetControlMode(PressureCtrlMode.TVOpen);
  218. return true;
  219. }
  220. if (mode.ToLower().Contains("pressure"))
  221. {
  222. SetControlMode(PressureCtrlMode.TVPressureCtrl);
  223. }
  224. else
  225. {
  226. SetControlMode(PressureCtrlMode.TVPositionCtrl);
  227. }
  228. return true;
  229. });
  230. //for recipe
  231. OP.Subscribe($"{Module}.{Name}.SetGainFactor", (out string reason, int time, object[] param) =>
  232. {
  233. reason = string.Empty;
  234. var gain = Convert.ToSingle(param[0]);
  235. if (gain > 0)
  236. {
  237. lock (_locker)
  238. {
  239. _lstHandler.AddLast(new VATS651SetGainFactorHandler(this, Convert.ToSingle(param[0])));
  240. }
  241. }
  242. return true;
  243. });
  244. //for recipe
  245. OP.Subscribe($"{Module}.{Name}.SetSensorResponseTime", (out string reason, int time, object[] param) =>
  246. {
  247. reason = string.Empty;
  248. lock (_locker)
  249. {
  250. _lstHandler.AddLast(new VATS651SetSensorDelayHandler(this, Convert.ToSingle(param[0])));
  251. }
  252. return true;
  253. });
  254. //for recipe
  255. OP.Subscribe($"{Module}.{Name}.SetSetpointRampTime", (out string reason, int time, object[] param) =>
  256. {
  257. reason = string.Empty;
  258. lock (_locker)
  259. {
  260. _lstHandler.AddLast(new VATS651SetRampTimeHandler(this, Convert.ToSingle(param[0])));
  261. }
  262. return true;
  263. });
  264. //for recipe
  265. OP.Subscribe($"{Module}.{Name}.SetValveSpeed", (out string reason, int time, object[] param) =>
  266. {
  267. reason = string.Empty;
  268. var speed = (int)Convert.ToSingle(param[0]);
  269. if (speed >= 1)
  270. {
  271. lock (_locker)
  272. {
  273. _lstHandler.AddLast(new VATS651SetValveSpeedHandler(this, speed));
  274. }
  275. }
  276. return true;
  277. });
  278. DATA.Subscribe($"{Module}.{Name}.IsConnected", () => IsConnected);
  279. DATA.Subscribe($"{Module}.{Name}.Address", () => Address);
  280. OP.Subscribe($"{Module}.{Name}.Reconnect", (string cmd, object[] args) =>
  281. {
  282. Disconnect();
  283. Reset();
  284. Connect();
  285. return true;
  286. });
  287. base.Initialize();
  288. return true;
  289. }
  290. protected override void InitSc()
  291. {
  292. _scEnableAlarm = SC.GetConfigItem($"{_scRoot}.EnableAlarm");
  293. _scPressureAlarmTime = SC.GetConfigItem($"{_scRoot}.AlarmTime");
  294. _scPositionAlarmTime = SC.GetConfigItem($"{_scRoot}.AlarmTime");
  295. _scPressureAlarmRange = SC.GetConfigItem($"{_scRoot}.PressureAlarmRange");
  296. _scPositionAlarmRange = SC.GetConfigItem($"{_scRoot}.PositionAlarmRange");
  297. _scPressureWarningTime = SC.GetConfigItem($"{_scRoot}.WarningTime");
  298. _scPositionWarningTime = SC.GetConfigItem($"{_scRoot}.WarningTime");
  299. _scPressureWarningRange = SC.GetConfigItem($"{_scRoot}.PressureWarningRange");
  300. _scPositionWarningRange = SC.GetConfigItem($"{_scRoot}.PositionWarningRange");
  301. _scPressureFineTuningValue = SC.GetConfigItem($"{Mode}.FineTuning.{Name}Pressure");
  302. _scPositionFineTuningValue = SC.GetConfigItem($"{Module}.FineTuning.{Name}Position");
  303. _scRecipeIgnoreTime = SC.GetConfigItem($"{_scRoot}.RecipeIgnoreTime");
  304. _scStableCriteria = SC.GetConfigItem($"{_scRoot}.StableCriteria");
  305. _scFineTuningEnable = SC.GetConfigItem($"{Module}.FineTuning.IsEnable");
  306. }
  307. public override void CheckTolerance()
  308. {
  309. if (!EnableAlarm || (RecipeIgnoreTime > 0 && _recipeIgnoreTimer.GetElapseTime() < RecipeIgnoreTime * 1000))
  310. return;
  311. if (Mode == PressureCtrlMode.TVPressureCtrl && PressureSetPoint > 0)
  312. {
  313. _tolerancePressureAlarmChecker.Monitor(PressureFeedback, (PressureSetPoint * (1 - PressureAlarmRange / 100)), (PressureSetPoint * (1 + PressureAlarmRange / 100)), PressureAlarmTime);
  314. _tolerancePressureWarningChecker.Monitor(PressureFeedback, (PressureSetPoint * (1 - PressureWarningRange / 100)), (PressureSetPoint * (1 + PressureWarningRange / 100)), PressureWarningTime);
  315. }
  316. if (Mode == PressureCtrlMode.TVPositionCtrl && PositionSetPoint > 0)
  317. {
  318. _tolerancePositionAlarmChecker.Monitor(PositionFeedback, (PositionSetPoint * (1 - PositionAlarmRange / 100)), (PositionSetPoint * (1 + PositionAlarmRange / 100)), PositionAlarmTime);
  319. _tolerancePositionWarningChecker.Monitor(PositionFeedback, (PositionSetPoint * (1 - PositionWarningRange / 100)), (PositionSetPoint * (1 + PositionWarningRange / 100)), PositionWarningTime);
  320. }
  321. //if (_tolerancePressureAlarmChecker.Trig)
  322. //{
  323. // EV.PostMessage(Module, EventEnum.ToleranceAlarm, Module, Name,
  324. // String.Format("Pressure out of range in {0} seconds", PressureAlarmTime.ToString("0")));
  325. //}
  326. //else if (_tolerancePressureWarningChecker.Trig)
  327. //{
  328. // EV.PostMessage(Module, EventEnum.ToleranceWarning, Module, Name,
  329. // String.Format("Pressure out of range in {0} seconds", PressureWarningTime.ToString("0")));
  330. //}
  331. //if (_tolerancePositionAlarmChecker.Trig)
  332. //{
  333. // EV.PostMessage(Module, EventEnum.ToleranceAlarm, Module, Name,
  334. // String.Format("Position out of range in {0} seconds", PositionAlarmTime.ToString("0")));
  335. //}
  336. //else if (_tolerancePositionWarningChecker.Trig)
  337. //{
  338. // EV.PostMessage(Module, EventEnum.ToleranceWarning, Module, Name,
  339. // String.Format("Position out of range in {0} seconds", PositionWarningTime.ToString("0")));
  340. //}
  341. }
  342. public bool InitConnection(string portName, int bautRate, int dataBits, Parity parity, StopBits stopBits)
  343. {
  344. _connection = new VATS651Connection(portName, bautRate, dataBits, parity, stopBits);
  345. if (_connection.Connect())
  346. {
  347. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  348. }
  349. _thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  350. return true;
  351. }
  352. private bool OnTimer()
  353. {
  354. try
  355. {
  356. _connection.MonitorTimeout();
  357. if (!_connection.IsConnected || _connection.IsCommunicationError)
  358. {
  359. lock (_locker)
  360. {
  361. _lstHandler.Clear();
  362. }
  363. _trigRetryConnect.CLK = !_connection.IsConnected;
  364. if (_trigRetryConnect.Q)
  365. {
  366. _connection.SetPortAddress(SC.GetStringValue($"{(!string.IsNullOrEmpty(_scRoot) ? _scRoot + "." : "")}{Module}.{Name}.Address"));
  367. if (!_connection.Connect())
  368. {
  369. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
  370. }
  371. else
  372. {
  373. InitHandler();
  374. }
  375. }
  376. return true;
  377. }
  378. HandlerBase handler = null;
  379. if (!_connection.IsBusy)
  380. {
  381. lock (_locker)
  382. {
  383. if (_lstHandler.Count == 0)
  384. {
  385. foreach (var monitorHandler in _lstMonitorHandler)
  386. {
  387. _lstHandler.AddLast(monitorHandler);
  388. }
  389. }
  390. if (_lstHandler.Count > 0)
  391. {
  392. handler = _lstHandler.First.Value;
  393. _lstHandler.RemoveFirst();
  394. }
  395. }
  396. if (handler != null)
  397. {
  398. _connection.Execute(handler);
  399. }
  400. }
  401. }
  402. catch (Exception ex)
  403. {
  404. LOG.Write(ex);
  405. }
  406. return true;
  407. }
  408. public override void Monitor()
  409. {
  410. try
  411. {
  412. base.Monitor();
  413. _trigCommunicationError.CLK = _connection.IsCommunicationError;
  414. if (_trigCommunicationError.Q)
  415. {
  416. EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  417. }
  418. }
  419. catch (Exception ex)
  420. {
  421. LOG.Write(ex);
  422. }
  423. }
  424. public override void Reset()
  425. {
  426. _trigError.RST = true;
  427. _connection.SetCommunicationError(false, "");
  428. _trigCommunicationError.RST = true;
  429. //_enableLog = SC.GetValue<bool>($"{ScBasePath}.{Name}.EnableLogMessage");
  430. _trigRetryConnect.RST = true;
  431. if (_isAlarm)
  432. {
  433. lock (_locker)
  434. {
  435. _lstHandler.AddLast(new VATS651ResetHandler(this));
  436. }
  437. }
  438. base.Reset();
  439. }
  440. private void InitHandler()
  441. {
  442. lock (_locker)
  443. {
  444. _lstHandler.AddLast(new VATS651SetAccessModeHandler(this));
  445. _lstHandler.AddLast(new VATS651SetValveSpeedHandler(this, _scValveSpeed.IntValue));
  446. _lstHandler.AddLast(new VATS651SetSensorDelayHandler(this, (float)_scSensorResponseTime.DoubleValue));
  447. _lstHandler.AddLast(new VATS651SetRampTimeHandler(this, (float)_scRampTime.DoubleValue));
  448. _lstHandler.AddLast(new VATS651SetGainFactorHandler(this, (float)_scGainFactor.DoubleValue));
  449. }
  450. }
  451. public void PerformRawCommand(string command, string comandArgument)
  452. {
  453. lock (_locker)
  454. {
  455. _lstHandler.AddLast(new VATS651RawCommandHandler(this, command, comandArgument));
  456. }
  457. }
  458. public void PerformRawCommand(string command)
  459. {
  460. lock (_locker)
  461. {
  462. _lstHandler.AddLast(new VATS651RawCommandHandler(this, command));
  463. }
  464. }
  465. public override void SetClose()
  466. {
  467. lock (_locker)
  468. {
  469. _lstHandler.AddLast(new VATS651CloseValveHandler(this));
  470. }
  471. }
  472. public override void SetOpen()
  473. {
  474. lock (_locker)
  475. {
  476. _lstHandler.AddLast(new VATS651OpenValveHandler(this));
  477. }
  478. }
  479. public void Hold()
  480. {
  481. lock (_locker)
  482. {
  483. _lstHandler.AddLast(new VATS651HoldValveHandler(this));
  484. }
  485. }
  486. public override void SetPosition(float position)
  487. {
  488. if (position < 0 || position > 100)
  489. {
  490. EV.PostWarningLog(Module, $"{Module} {Name} set position {position}, out of range [0, 100]");
  491. return;
  492. }
  493. PositionSetPoint = position;
  494. if (Math.Abs(position) < 0.001)
  495. {
  496. SetClose();
  497. }
  498. else
  499. {
  500. lock (_locker)
  501. {
  502. if (_scPositionCommunicationRange != null)
  503. {
  504. _lstHandler.AddLast(new VATS651SetPositionHandler(this, (int)(position * _scPositionCommunicationRange.IntValue / 100)));
  505. }
  506. else
  507. {
  508. _lstHandler.AddLast(new VATS651SetPositionHandler(this, (int)(position)));
  509. }
  510. }
  511. }
  512. }
  513. public override void SetPressure(float pressure)
  514. {
  515. if (pressure < 0 || (_scPressureSensorRange != null && pressure > _scPressureSensorRange.IntValue))
  516. {
  517. int value = _scPressureSensorRange == null ? 0 : _scPressureSensorRange.IntValue;
  518. EV.PostWarningLog(Module, $"{Module} {Name} set pressure {value}, out of range [0, {value}]");
  519. return;
  520. }
  521. PressureSetPoint = pressure;
  522. lock (_locker)
  523. {
  524. if (_scPressureCommunicationRange != null)
  525. {
  526. _lstHandler.AddLast(new VATS651SetPressureHandler(this, (int)(pressure * _scPressureCommunicationRange.IntValue / _scPressureSensorRange.IntValue)));
  527. }
  528. else
  529. {
  530. _lstHandler.AddLast(new VATS651SetPressureHandler(this, (int)(pressure)));
  531. }
  532. }
  533. }
  534. public void SetAcessMode(string mode)
  535. {
  536. lock (_locker)
  537. {
  538. _lstHandler.AddLast(new VATS651SetAccessModeHandler(this));
  539. }
  540. }
  541. public override void SetControlMode(PressureCtrlMode mode)
  542. {
  543. EV.PostInfoLog(Module, $"set {Module}.{Name} control mode to {mode}");
  544. if (mode == PressureCtrlMode.TVClose)
  545. {
  546. lock (_locker)
  547. {
  548. _lstHandler.AddLast(new VATS651CloseValveHandler(this));
  549. }
  550. }
  551. else if (mode == PressureCtrlMode.TVOpen)
  552. {
  553. lock (_locker)
  554. {
  555. _lstHandler.AddLast(new VATS651OpenValveHandler(this));
  556. }
  557. }
  558. else if (mode == PressureCtrlMode.TVPositionCtrl)
  559. {
  560. lock (_locker)
  561. {
  562. var position = PositionSetPoint > 0 ? PositionSetPoint : 1;
  563. if (_scPositionCommunicationRange != null)
  564. {
  565. _lstHandler.AddLast(new VATS651SetPositionHandler(this, (int)(position * _scPositionCommunicationRange.IntValue / 100)));
  566. }
  567. else
  568. {
  569. _lstHandler.AddLast(new VATS651SetPositionHandler(this, (int)(position)));
  570. }
  571. }
  572. }
  573. else if (mode == PressureCtrlMode.TVPressureCtrl)
  574. {
  575. lock (_locker)
  576. {
  577. var pressure = PressureSetPoint > 0 ? PressureSetPoint : 1;
  578. if (_scPressureCommunicationRange != null)
  579. {
  580. _lstHandler.AddLast(new VATS651SetPressureHandler(this, (int)(pressure * _scPressureCommunicationRange.IntValue / _scPressureSensorRange.IntValue)));
  581. }
  582. else
  583. {
  584. _lstHandler.AddLast(new VATS651SetPressureHandler(this, (int)(pressure)));
  585. }
  586. }
  587. }
  588. }
  589. public override void Learn()
  590. {
  591. if (_learnTrig.M)
  592. {
  593. EV.PostWarningLog(Module, $"{Module} {Name} is already at learning state");
  594. return;
  595. }
  596. _learnTrig.RST = true;
  597. lock (_locker)
  598. {
  599. _lstHandler.AddLast(new VATS651LearnHandler(this, _scPressureCommunicationRange.IntValue));
  600. }
  601. }
  602. public void SetValveConfig(string setVal)
  603. {
  604. lock (_locker)
  605. {
  606. _lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:04", setVal));
  607. }
  608. }
  609. public void SetSensorConfig(string setVal)
  610. {
  611. lock (_locker)
  612. {
  613. _lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:01", setVal));
  614. }
  615. }
  616. public void SetSensorScale(string setVal)
  617. {
  618. lock (_locker)
  619. {
  620. _lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:05", setVal));
  621. }
  622. }
  623. public void SetSensor1Linearization(string setVal)
  624. {
  625. lock (_locker)
  626. {
  627. _lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:17", setVal));
  628. }
  629. }
  630. public void SetSensor2Linearization(string setVal)
  631. {
  632. lock (_locker)
  633. {
  634. _lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:18", setVal));
  635. }
  636. }
  637. public void SetSensorAverage(string setVal)
  638. {
  639. lock (_locker)
  640. {
  641. _lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:19", setVal));
  642. }
  643. }
  644. public void SetCommRangeConfig(string setVal)
  645. {
  646. lock (_locker)
  647. {
  648. _lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:21", setVal));
  649. }
  650. }
  651. public void SetInterfaceConfig(string setVal)
  652. {
  653. lock (_locker)
  654. {
  655. _lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:20", setVal));
  656. }
  657. }
  658. public void SetValveSpeed(int speed)
  659. {
  660. //valve speed, 1 ... 1000 (1 = min. speed, 1000 = max. speed)
  661. if (speed < 1 || speed > 1000)
  662. {
  663. EV.PostWarningLog(Module, $"{Module} {Name} set speed {speed}, out of range [1, 1000]");
  664. return;
  665. }
  666. lock (_locker)
  667. {
  668. _lstHandler.AddLast(new VATS651SetValveSpeedHandler(this, speed));
  669. }
  670. }
  671. public void SetPressureControllerMode(string setVal)
  672. {
  673. lock (_locker)
  674. {
  675. _lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:02Z00", setVal));
  676. }
  677. }
  678. public void SetPressureControllerConfig(string pressureController, string parameterNumber, string parameterValue)
  679. {
  680. lock (_locker)
  681. {
  682. _lstHandler.AddLast(new VATS651SimpleActionHandler(this, "s:02", pressureController + parameterNumber + parameterValue));
  683. }
  684. }
  685. public void ResetError(string reset)
  686. {
  687. lock (_locker)
  688. {
  689. _lstHandler.AddLast(new VATS651ResetHandler(this));
  690. }
  691. }
  692. internal void SetPositionFeedback(int value)
  693. {
  694. if (_scPositionCommunicationRange != null)
  695. PositionFeedback = 100.0f * value / _scPositionCommunicationRange.IntValue;
  696. else
  697. PositionFeedback = value;
  698. }
  699. internal void SetPressureFeedback(int value)
  700. {
  701. if (_scPressureCommunicationRange != null && _scPressureSensorRange != null)
  702. PressureFeedback = 1.0f * value / _scPressureCommunicationRange.IntValue * _scPressureSensorRange.IntValue;
  703. else
  704. {
  705. PressureFeedback = value;
  706. }
  707. }
  708. internal void SetLearnStatus(bool isRunning, string info)
  709. {
  710. _learnTrig.CLK = isRunning;
  711. if (_learnTrig.R)
  712. {
  713. EV.PostInfoLog(Module, $"{Module} {Name} learning start");
  714. }
  715. if (_learnTrig.T)
  716. {
  717. EV.PostInfoLog(Module, $"{Module} {Name} learning finished, result {info}");
  718. }
  719. }
  720. internal void NoteActionCompleted(string command)
  721. {
  722. if (command == "C:")
  723. {
  724. CloseValveCompleted = true;
  725. }
  726. else if (command == "O:")
  727. {
  728. OpenValveCompleted = true;
  729. }
  730. else if (command == "R:")
  731. {
  732. SetPositonCompleted = true;
  733. }
  734. else if (command == "S:")
  735. {
  736. SetPressureCompleted = true;
  737. }
  738. else if (command == "c:01")
  739. {
  740. SetAcessModeCompleted = true;
  741. }
  742. else if (command == "s:04")
  743. {
  744. SetValveConfigCompleted = true;
  745. }
  746. else if (command == "s:01")
  747. {
  748. SetSensorConfigCompleted = true;
  749. }
  750. else if (command == "s:05")
  751. {
  752. SetSensorScaleCompleted = true;
  753. }
  754. else if (command == "s:17")
  755. {
  756. SetSensor1LinearizationCompleted = true;
  757. }
  758. else if (command == "s:18")
  759. {
  760. SetSensor2LinearizationCompleted = true;
  761. }
  762. else if (command == "s:19")
  763. {
  764. SetSensorAverageCompleted = true;
  765. }
  766. else if (command == "s:21")
  767. {
  768. SetCommRangeConfigCompleted = true;
  769. }
  770. else if (command == "s:20")
  771. {
  772. SetInterfaceConfigCompleted = true;
  773. }
  774. else if (command == "V:")
  775. {
  776. SetValveSpeedCompleted = true;
  777. }
  778. else if (command == "c:82")
  779. {
  780. ResetErrorCompleted = true;
  781. }
  782. else if (command == "s:02Z00")
  783. {
  784. SetPressureControllerModeCompleted = true;
  785. }
  786. else if (command == "s:02")
  787. {
  788. SetPressureControllerConfigCompleted = true;
  789. }
  790. }
  791. internal void NoteQueryResult(string command, string queryResult)
  792. {
  793. if (command == "A:")
  794. {
  795. Position = queryResult;
  796. }
  797. else if (command == "P:")
  798. {
  799. Pressure = queryResult;
  800. }
  801. else if (command == "i:60")
  802. {
  803. Sensor1Offset = queryResult;
  804. }
  805. else if (command == "i:61")
  806. {
  807. Sensor2Offset = queryResult;
  808. }
  809. else if (command == "i:64")
  810. {
  811. Sensor1Reading = queryResult;
  812. }
  813. else if (command == "i:65")
  814. {
  815. Sensor2Reading = queryResult;
  816. }
  817. else if (command == "i:30")
  818. {
  819. DeviceStatus = queryResult;
  820. }
  821. else if (command == "i:50")
  822. {
  823. VATError = queryResult;
  824. }
  825. else if (command == "i:51")
  826. {
  827. VATWarning = queryResult;
  828. }
  829. }
  830. internal void NoteSetCompleted(string command, string parameter)
  831. {
  832. //if(command == "SWAA")
  833. //{
  834. // AlignAngleSet = double.Parse(parameter);
  835. //}
  836. //else if(command == "SWS")
  837. //{
  838. // WaferSizeSet = double.Parse(parameter);
  839. //}
  840. }
  841. public void MonitorRawCommand(bool isSelected, string command, string comandArgument)
  842. {
  843. lock (_locker)
  844. {
  845. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(VATS651RawCommandHandler) && ((VATS651Handler)handler)._command == command);
  846. if (isSelected)
  847. {
  848. if (!existHandlers.Any())
  849. _lstMonitorHandler.AddFirst(new VATS651RawCommandHandler(this, command, comandArgument));
  850. }
  851. else
  852. {
  853. if (existHandlers.Any())
  854. {
  855. _lstMonitorHandler.Remove(existHandlers.First());
  856. }
  857. }
  858. }
  859. }
  860. public void MonitorRawCommand(bool isSelected, string command)
  861. {
  862. lock (_locker)
  863. {
  864. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(VATS651RawCommandHandler) && ((VATS651Handler)handler)._command == command);
  865. if (isSelected)
  866. {
  867. if (!existHandlers.Any())
  868. _lstMonitorHandler.AddFirst(new VATS651RawCommandHandler(this, command));
  869. }
  870. else
  871. {
  872. if (existHandlers.Any())
  873. {
  874. _lstMonitorHandler.Remove(existHandlers.First());
  875. }
  876. }
  877. }
  878. }
  879. public void RequestPositoin(bool isSelected)
  880. {
  881. SimpleRequest(isSelected, "A:");
  882. }
  883. public void RequestPressure(bool isSelected)
  884. {
  885. SimpleRequest(isSelected, "P:");
  886. }
  887. public void RequestSensor1Offset(bool isSelected)
  888. {
  889. SimpleRequest(isSelected, "i:60");
  890. }
  891. public void RequestSensor2Offset(bool isSelected)
  892. {
  893. SimpleRequest(isSelected, "i:61");
  894. }
  895. public void RequestSensor1Reading(bool isSelected)
  896. {
  897. SimpleRequest(isSelected, "i:64");
  898. }
  899. public void RequestSensor2Reading(bool isSelected)
  900. {
  901. SimpleRequest(isSelected, "i:65");
  902. }
  903. public void RequestDeviceStatus(bool isSelected)
  904. {
  905. SimpleRequest(isSelected, "i:30");
  906. }
  907. public void RequestError(bool isSelected)
  908. {
  909. SimpleRequest(isSelected, "i:50");
  910. }
  911. public void RequestWarnings(bool isSelected)
  912. {
  913. SimpleRequest(isSelected, "i:51");
  914. }
  915. public void QueryAllStatus()
  916. {
  917. lock (_locker)
  918. {
  919. _lstHandler.AddLast(new VATS651QueryStatusHandler(this));
  920. }
  921. }
  922. private void SimpleRequest(bool isSelected, string command)
  923. {
  924. lock (_locker)
  925. {
  926. var existHandlers = _lstMonitorHandler.Where(handler => handler.GetType() == typeof(VATS651SimpleQueryHandler) && ((VATS651SimpleQueryHandler)handler)._command == command);
  927. if (isSelected)
  928. {
  929. if (!existHandlers.Any())
  930. _lstMonitorHandler.AddFirst(new VATS651SimpleQueryHandler(this, command));
  931. }
  932. else
  933. {
  934. if (existHandlers.Any())
  935. {
  936. _lstMonitorHandler.Remove(existHandlers.First());
  937. }
  938. }
  939. }
  940. }
  941. public bool SetPositonCompleted { get; private set; }
  942. public bool SetPressureCompleted { get; private set; }
  943. public bool SetAcessModeCompleted { get; private set; }
  944. public bool ResetErrorCompleted { get; private set; }
  945. public string Position { get; private set; }
  946. public bool CloseValveCompleted { get; private set; }
  947. public bool OpenValveCompleted { get; private set; }
  948. public string Pressure { get; private set; }
  949. public string Sensor1Offset { get; private set; }
  950. public string Sensor2Offset { get; private set; }
  951. public string Sensor1Reading { get; private set; }
  952. public string Sensor2Reading { get; private set; }
  953. public string DeviceStatus { get; private set; }
  954. public string VATError { get; private set; }
  955. public string VATWarning { get; private set; }
  956. public bool SetValveConfigCompleted { get; private set; }
  957. public bool SetSensorConfigCompleted { get; private set; }
  958. public bool SetPressureControllerModeCompleted { get; private set; }
  959. public bool SetPressureControllerConfigCompleted { get; private set; }
  960. public bool SetSensorScaleCompleted { get; private set; }
  961. public bool SetSensor1LinearizationCompleted { get; private set; }
  962. public bool SetSensor2LinearizationCompleted { get; private set; }
  963. public bool SetSensorAverageCompleted { get; private set; }
  964. public bool SetCommRangeConfigCompleted { get; private set; }
  965. public bool SetInterfaceConfigCompleted { get; private set; }
  966. public bool SetValveSpeedCompleted { get; private set; }
  967. private R_TRIG _trigWarningMessage = new R_TRIG();
  968. public void NoteError(string errorCode)
  969. {
  970. if (errorCode != null)
  971. {
  972. _trigWarningMessage.CLK = true;
  973. string content = errorCode;
  974. if (_errorCodeReferenceDic != null && _errorCodeReferenceDic.ContainsKey(errorCode))
  975. content = _errorCodeReferenceDic[errorCode];
  976. if (_trigWarningMessage.Q)
  977. {
  978. EV.PostWarningLog(Module, $"{Module}.{Name} error, {content}");
  979. }
  980. _isAlarm = true;
  981. }
  982. else
  983. {
  984. _isAlarm = false;
  985. }
  986. }
  987. internal void NoteRawCommandInfo(string command, string data)
  988. {
  989. //var curIOResponse = IOResponseList.Find(res => res.SourceCommandName == command);
  990. //if (curIOResponse != null)
  991. //{
  992. // IOResponseList.Remove(curIOResponse);
  993. //}
  994. //IOResponseList.Add(new IOResponse() { SourceCommand = command, ResonseContent = data, ResonseRecievedTime = DateTime.Now });
  995. }
  996. }
  997. }