FaHost.cs 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  1. using Aitex.Common.Util;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.Log;
  4. using Aitex.Core.RT.RecipeCenter;
  5. using Aitex.Core.RT.SCCore;
  6. using Aitex.Core.Util;
  7. using FabConnect.SecsGemInterface.Common;
  8. using FabConnect.SecsGemInterface.Common.ToolModel;
  9. using FabConnect.SecsGemInterface.GemModel;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using System.Xml;
  15. using MECF.Framework.Common.CommonData;
  16. using Venus_RT.HostWrapper;
  17. namespace Venus_RT.FAs
  18. {
  19. public class FaHost : IFaHost
  20. {
  21. public string FaCommunicationState
  22. {
  23. get { return _gem.CommunicationState.ToString(); }
  24. }
  25. public string FaControlState
  26. {
  27. get { return _gem.ControlState.ToString(); }
  28. }
  29. public string FaControlSubState
  30. {
  31. get
  32. {
  33. return _gem.ControlRemoteSwitch.ToString();
  34. }
  35. }
  36. public bool IsConnected
  37. {
  38. get { return _gem.CommunicationState == CommunicationState.EnabledCommunicating; }
  39. }
  40. public int SpoolingState
  41. {
  42. get
  43. {
  44. return (int)_gem.SpoolingState;
  45. }
  46. }
  47. public string SpoolingActual
  48. {
  49. get
  50. {
  51. return
  52. _gem.GetAttribute(GEMVariables.SpoolCountActual, AttributeType.SV)
  53. ;
  54. }
  55. }
  56. public string SpoolingTotal
  57. {
  58. get { return _gem.GetAttribute(GEMVariables.SpoolCountTotal, AttributeType.SV); }
  59. }
  60. public string SpoolingFullTime
  61. {
  62. get { return _gem.GetAttribute(GEMVariables.SpoolFullTime, AttributeType.SV); }
  63. }
  64. public string SpoolingStartTime
  65. {
  66. get { return _gem.GetAttribute(GEMVariables.SpoolStartTime, AttributeType.SV); }
  67. }
  68. public bool IsSpoolingEnable
  69. {
  70. get { return Convert.ToBoolean(_gem.GetAttribute(GEMVariables.SpoolEnabled, AttributeType.EC)); }
  71. }
  72. private readonly GEMController _gem = new GEMController();
  73. public IHostCallback _equipment;
  74. private HashSet<string> _systemBuildInEc = new HashSet<string>();
  75. private HashSet<string> _systemBuildInVariables = new HashSet<string>();
  76. private PeriodicJob _faMonitorThread;
  77. private FixSizeQueue<FaEventItem> _lstEvent = new FixSizeQueue<FaEventItem>(300);
  78. FALogFileCleaner _logCleaner = new FALogFileCleaner();
  79. private ControlState _state = ControlState.Unknown;
  80. private const string EventTerminalMessage = "TerminalMessage";
  81. public void Initialize(IHostCallback equipment, string modelFile)
  82. {
  83. _equipment = equipment;
  84. _gem.CommunicationStateChanged += OnCommunicationStateChanged;
  85. _gem.RemoteCommandS2F49In += _gem_RemoteCommandS2F49In; ;
  86. _gem.PrimaryMessageIn += _gem_PrimaryMessageIn;
  87. _gem.ControlStateChanged += _gem_ControlStateChanged;
  88. _gem.ShowTrialMessageBox = false;
  89. _gem.AutoPPDataReply = false;
  90. _gem.Initialize(modelFile, PathManager.GetLogDir());
  91. _gem.EquipmentModel.GemConnection.HSMS.localIPAddress = SC.GetStringValue("System.FA.LocalIpAddress");
  92. _gem.EquipmentModel.GemConnection.HSMS.localPortNumber = SC.GetValue<int>("System.FA.LocalPortNumber");
  93. _gem.EquipmentModel.GemConnection.HSMS.T3Timeout = SC.GetValue<int>("System.FA.T3Timeout");
  94. _gem.EquipmentModel.GemConnection.HSMS.T5Timeout = SC.GetValue<int>("System.FA.T5Timeout");
  95. _gem.EquipmentModel.GemConnection.HSMS.T6Timeout = SC.GetValue<int>("System.FA.T6Timeout");
  96. _gem.EquipmentModel.GemConnection.HSMS.T7Timeout = SC.GetValue<int>("System.FA.T7Timeout");
  97. _gem.EquipmentModel.GemConnection.HSMS.T8Timeout = SC.GetValue<int>("System.FA.T8Timeout");
  98. _gem.ReInitialize();
  99. //get system build in ec
  100. _systemBuildInEc = new HashSet<string>();
  101. _systemBuildInEc.Add("EstablishCommunicationsTimeout");
  102. _systemBuildInEc.Add("MaxSpoolTransmit");
  103. _systemBuildInEc.Add("OverWriteSpool");
  104. _systemBuildInEc.Add("MaxSpoolCapacity");
  105. _systemBuildInEc.Add("SpoolEnabled");
  106. _systemBuildInEc.Add("TimeFormat");
  107. //initial system build in variable
  108. _systemBuildInVariables.Add("AlarmsEnabled");
  109. _systemBuildInVariables.Add("AlarmsSet");
  110. _systemBuildInVariables.Add("Clock");
  111. _systemBuildInVariables.Add("ControlState");
  112. _systemBuildInVariables.Add("EventsEnabled");
  113. _systemBuildInVariables.Add("PPExecName");
  114. _systemBuildInVariables.Add("PreviousProcessState");
  115. _systemBuildInVariables.Add("ProcessState");
  116. _systemBuildInVariables.Add("SpoolCountActual");
  117. _systemBuildInVariables.Add("SpoolCountTotal");
  118. _systemBuildInVariables.Add("SpoolFullTime");
  119. _systemBuildInVariables.Add("SpoolStartTime");
  120. _systemBuildInVariables.Add("SpoolState");
  121. _systemBuildInVariables.Add("SpoolSubstate");
  122. _logCleaner.Run();
  123. _faMonitorThread = new PeriodicJob(200, MonitorFaTask, "Monitor FA Thread", true);
  124. EV.Subscribe(new EventItem("Host", EventTerminalMessage, "{0}", EventLevel.Warning, EventType.EventUI_Notify));
  125. }
  126. private void _gem_ControlStateChanged(object sender, SECsEventArgs e)
  127. {
  128. if (_state != _gem.ControlState)
  129. {
  130. _state = _gem.ControlState;
  131. if (_state == ControlState.OnlineRemote)
  132. {
  133. //EV.PostInfoLog("FA", Aitex.RT.Properties.Resources.HostControlModeChangeTo_stateNotifySystemChangeToAutoMode);
  134. //Singleton<PMEntity>.Instance.PostMsg((int)PMEntity.MSG.SetAutoMode);
  135. }
  136. }
  137. }
  138. public void Invoke(string method, object[] args)
  139. {
  140. switch (method)
  141. {
  142. case "FAEnable":
  143. _gem.SetEnable();
  144. break;
  145. case "FADisable":
  146. _gem.SetDisable();
  147. break;
  148. case "FAOnline":
  149. _gem.SetOnline();
  150. break;
  151. case "FAOffline":
  152. _gem.SetOffline();
  153. break;
  154. case "FALocal":
  155. _gem.SetLocal();
  156. break;
  157. case "FARemote":
  158. _gem.SetRemote();
  159. break;
  160. case "FAEnableSpooling":
  161. SetEnableSpooling();
  162. break;
  163. case "FADisableSpooling":
  164. SetDisableSpooling();
  165. break;
  166. }
  167. }
  168. private bool _gem_RemoteCommandS2F41In(SECsTransaction trans)
  169. {
  170. try
  171. {
  172. bool ret = true;
  173. string reason = string.Empty;
  174. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(2, 42, false);
  175. reply.DataItem.AddList();
  176. if (ret)
  177. {
  178. reply.DataItem[0].Add("HCACK", 0, SECsFormat.Binary);
  179. }
  180. _gem.SendReply(reply, trans.Id);
  181. }
  182. catch (Exception ex)
  183. {
  184. //LOG.Write(string.Format("Handle_S2F41 Exception: {0}", ex.Message));
  185. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(2, 42, false);
  186. reply.DataItem.AddList();
  187. reply.DataItem[0].Add("HCACK", 3/*At least one parameter is invalid*/, SECsFormat.Binary);
  188. reply.DataItem[0].AddList();
  189. reply.DataItem[0][1].AddList();
  190. reply.DataItem[0][1].Add("CPVALUE", ex.Message, SECsFormat.Ascii);
  191. _gem.SendReply(reply, trans.Id);
  192. }
  193. return true;
  194. }
  195. private bool _gem_RemoteCommandS2F49In(SECsTransaction trans)
  196. {
  197. try
  198. {
  199. bool ret = true;
  200. string reason = string.Empty;
  201. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(2, 50, false);
  202. string remoteCommandName = trans.Primary.DataItem[0][2].ToString();
  203. switch (remoteCommandName.ToUpper())
  204. {
  205. case "MAPCASSETTE":
  206. {
  207. if (trans.Primary.DataItem[0][3][0][0].ToString() != "PortID")
  208. throw new Exception($"MAPCASSETTE Command Format Not Correct, CPNAME1 should be PortID");
  209. string portID = trans.Primary.DataItem[0][3][0][1].ToString();
  210. ret = _equipment.MapCassette(portID, out reason);
  211. }
  212. break;
  213. case "PP-SELECT":
  214. {
  215. if (trans.Primary.DataItem[0][3][0][0].ToString() != "PortID")
  216. throw new Exception($"PP-SELECT Command Format Not Correct, CPNAME1 should be PortID");
  217. if (trans.Primary.DataItem[0][3][1][0].ToString() != "JobID")
  218. throw new Exception($"PP-SELECT Command Format Not Correct, CPNAME2 should be JobID");
  219. if (trans.Primary.DataItem[0][3][2][0].ToString() != "LotID")
  220. throw new Exception($"PP-SELECT Command Format Not Correct, CPNAME3 should be LotID");
  221. if (trans.Primary.DataItem[0][3][3][0].ToString() != "SequenceID")
  222. throw new Exception($"PP-SELECT Command Format Not Correct, CPNAME4 should be SequenceID");
  223. string[] slotSequence = new string[25];
  224. for (int i = 0; i < 25; i++)
  225. {
  226. slotSequence[i] = trans.Primary.DataItem[0][3][3][1][i].ToString();
  227. if (slotSequence[i].Contains("*null"))
  228. slotSequence[i] = string.Empty;
  229. }
  230. string portID = trans.Primary.DataItem[0][3][0][1].ToString();
  231. string jobID = trans.Primary.DataItem[0][3][1][1].ToString();
  232. string lotID = trans.Primary.DataItem[0][3][2][1].ToString();
  233. ret = _equipment.PPSelect(portID, jobID, lotID, slotSequence, out reason);
  234. }
  235. break;
  236. case "STARTJOB":
  237. {
  238. if (trans.Primary.DataItem[0][3][0][0].ToString() != "JobID")
  239. throw new Exception($"STARTJOB Command Format Not Correct, CPNAME1 should be JobID");
  240. string jobID = trans.Primary.DataItem[0][3][0][1].ToString();
  241. ret = _equipment.StartJob(jobID, out reason);
  242. }
  243. break;
  244. case "ABORTJOB":
  245. {
  246. if (trans.Primary.DataItem[0][3][0][0].ToString() != "JobID")
  247. throw new Exception($"ABORTJOB Command Format Not Correct, CPNAME1 should be JobID");
  248. string jobID = trans.Primary.DataItem[0][3][0][1].ToString();
  249. ret = _equipment.AbortJob(jobID, out reason);
  250. }
  251. break;
  252. case "PAUSEJOB":
  253. {
  254. if (trans.Primary.DataItem[0][3][0][0].ToString() != "JobID")
  255. throw new Exception($"PAUSEJOB Command Format Not Correct, CPNAME1 should be JobID");
  256. string jobID = trans.Primary.DataItem[0][3][0][1].ToString();
  257. ret = _equipment.PauseJob(jobID, out reason);
  258. }
  259. break;
  260. case "RESUMEJOB":
  261. {
  262. if (trans.Primary.DataItem[0][3][0][0].ToString() != "JobID")
  263. throw new Exception($"RESUMEJOB Command Format Not Correct, CPNAME1 should be JobID");
  264. string jobID = trans.Primary.DataItem[0][3][0][1].ToString();
  265. ret = _equipment.ResumeJob(jobID, out reason);
  266. }
  267. break;
  268. case "STOPJOB":
  269. {
  270. if (trans.Primary.DataItem[0][3][0][0].ToString() != "JobID")
  271. throw new Exception($"STOPJOB Command Format Not Correct, CPNAME1 should be JobID");
  272. string jobID = trans.Primary.DataItem[0][3][0][1].ToString();
  273. ret = _equipment.StopJob(jobID, out reason);
  274. }
  275. break;
  276. case "LOAD":
  277. {
  278. if (trans.Primary.DataItem[0][3][0][0].ToString() != "PortID")
  279. throw new Exception($"LOAD Command Format Not Correct, CPNAME1 should be PortID");
  280. string portID = trans.Primary.DataItem[0][3][0][1].ToString();
  281. ret = _equipment.Load(portID, out reason);
  282. }
  283. break;
  284. case "UNLOAD":
  285. {
  286. if (trans.Primary.DataItem[0][3][0][0].ToString() != "PortID")
  287. throw new Exception($"UNLOAD Command Format Not Correct, CPNAME1 should be PortID");
  288. string portID = trans.Primary.DataItem[0][3][0][1].ToString();
  289. ret = _equipment.Unload(portID, out reason);
  290. }
  291. break;
  292. case "LOCK":
  293. {
  294. if (trans.Primary.DataItem[0][3][0][0].ToString() != "PortID")
  295. throw new Exception($"LOCK Command Format Not Correct, CPNAME1 should be PortID");
  296. string portID = trans.Primary.DataItem[0][3][0][1].ToString();
  297. ret = _equipment.Lock(portID, out reason);
  298. }
  299. break;
  300. case "UNLOCK":
  301. {
  302. if (trans.Primary.DataItem[0][3][0][0].ToString() != "PortID")
  303. throw new Exception($"UNLOCK Command Format Not Correct, CPNAME1 should be PortID");
  304. string portID = trans.Primary.DataItem[0][3][0][1].ToString();
  305. ret = _equipment.Unlock(portID, out reason);
  306. }
  307. break;
  308. case "READID":
  309. {
  310. if (trans.Primary.DataItem[0][3][0][0].ToString() != "PortID")
  311. throw new Exception($"READID Command Format Not Correct, CPNAME1 should be PortID");
  312. string portID = trans.Primary.DataItem[0][3][0][1].ToString();
  313. ret = _equipment.ReadID(portID, out reason);
  314. }
  315. break;
  316. case "WRITEID":
  317. {
  318. if (trans.Primary.DataItem[0][3][0][0].ToString() != "PortID")
  319. throw new Exception($"WRITEID Command Format Not Correct, CPNAME1 should be PortID");
  320. if (trans.Primary.DataItem[0][3][1][0].ToString() != "CarrierID")
  321. throw new Exception($"WRITEID Command Format Not Correct, CPNAME2 should be CarrierID");
  322. string portID = trans.Primary.DataItem[0][3][0][1].ToString();
  323. string carrierID = trans.Primary.DataItem[0][3][1][1].ToString();
  324. ret = _equipment.WriteID(portID, carrierID, out reason);
  325. }
  326. break;
  327. case "READTAG":
  328. {
  329. if (trans.Primary.DataItem[0][3][0][0].ToString() != "PortID")
  330. throw new Exception($"READTAG Command Format Not Correct, CPNAME1 should be PortID");
  331. string portID = trans.Primary.DataItem[0][3][0][1].ToString();
  332. ret = _equipment.ReadTag(portID, out reason);
  333. }
  334. break;
  335. case "WRITETAG":
  336. {
  337. if (trans.Primary.DataItem[0][3][0][0].ToString() != "PortID")
  338. throw new Exception($"WRITEID Command Format Not Correct, CPNAME1 should be PortID");
  339. if (trans.Primary.DataItem[0][3][1][0].ToString() != "TagData")
  340. throw new Exception($"WRITEID Command Format Not Correct, CPNAME2 should be TagData");
  341. string portID = trans.Primary.DataItem[0][3][0][1].ToString();
  342. string tagData = trans.Primary.DataItem[0][3][1][1].ToString();
  343. ret = _equipment.WriteTag(portID, tagData, out reason);
  344. }
  345. break;
  346. }
  347. reply.DataItem.AddList();
  348. if (ret)
  349. {
  350. reply.DataItem[0].Add("HCACK", 0, SECsFormat.Binary);
  351. }
  352. else
  353. {
  354. reply.DataItem[0].Add("HCACK", 3, SECsFormat.Binary);
  355. reply.DataItem[0].Add("CPVALUE", reason, SECsFormat.Ascii);
  356. }
  357. _gem.SendReply(reply, trans.Id);
  358. }
  359. catch (Exception ex)
  360. {
  361. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(2, 50, false);
  362. reply.DataItem.AddList();
  363. reply.DataItem[0].Add("HCACK", 3/*At least one parameter is invalid*/, SECsFormat.Binary);
  364. reply.DataItem[0].AddList();
  365. reply.DataItem[0][1].AddList();
  366. reply.DataItem[0][1].Add("CPVALUE", ex.Message, SECsFormat.Ascii);
  367. _gem.SendReply(reply, trans.Id);
  368. }
  369. return true;
  370. }
  371. private void _gem_PrimaryMessageIn(object sender, SECsPrimaryInEventArgs e)
  372. {
  373. string SF = "S" + e.Inputs.Stream.ToString() + "F" + e.Inputs.Function.ToString();
  374. switch (SF)
  375. {
  376. case "S7F1":
  377. Handle_S7F1(e);
  378. break;
  379. case "S7F5":
  380. Handle_S7F5(e);
  381. break;
  382. case "S7F3"://down load recipe
  383. Handle_S7F3(e); //Host must send S7F1/F2 and equipment application must either grant the host requests.
  384. break;
  385. case "S7F17":
  386. Handle_S7F17(e);
  387. break;
  388. case "S7F19":
  389. Handle_S7F19(e);
  390. break;
  391. case "S7F25":
  392. Handle_S7F25(e);
  393. break;
  394. case "S10F3"://Single terminal message
  395. Handle_S10F3(e);
  396. break;
  397. case "S10F5"://Multiple terminal message
  398. Handle_S10F5(e);
  399. break;
  400. }
  401. switch (e.EventId)
  402. {
  403. case PrimaryEventType.ProcessProgramLoadInquire: //S7F1
  404. break;
  405. }
  406. }
  407. /// <summary>
  408. /// Host requests the equipment to delete the Process Program
  409. /// L,n (Number of process programs to be deleted)
  410. /// 1. <PPID1>
  411. /// .
  412. /// .
  413. /// n. <PPIDn>
  414. /// Exception: If n=0, then delete all.
  415. /// </summary>
  416. /// <param name="e"></param>
  417. private void Handle_S7F17(SECsPrimaryInEventArgs e)
  418. {
  419. try
  420. {
  421. string reason = string.Empty;
  422. if (e.Inputs.DataItem[0].Count == 0)
  423. {
  424. //LOG.Write("Handle_S7F17, delete all recipes");
  425. DeleteAllRecipes(out reason);
  426. }
  427. else // Delete the list of selected Process Program
  428. {
  429. List<string> deleteRecipes = new List<string>();
  430. for (int i = 0; i < e.Inputs.DataItem[0].Count; i++)
  431. {
  432. string ppid = e.Inputs.DataItem[0][i].ToString();
  433. deleteRecipes.Add(ppid);
  434. //LOG.Write("Handle_S7F17, delete recipe:" + ppid);
  435. }
  436. DeleteRecipe(deleteRecipes, out reason);
  437. }
  438. //give reply to host
  439. SECsMessage messageToReply = _gem.Services.ProcessProgram.DeleteProcessProgramAcknowledge(0);
  440. _gem.SendReply(messageToReply, e.TransactionID);
  441. }
  442. catch (Exception ex)
  443. {
  444. //LOG.Write("Handle_S7F17 Exception: " + ex.Message);
  445. //give reply to host
  446. SECsMessage messageToReply = _gem.Services.ProcessProgram.DeleteProcessProgramAcknowledge(4/*error*/);
  447. _gem.SendReply(messageToReply, e.TransactionID);
  448. }
  449. }
  450. protected void DeleteAllRecipes(out string reason)
  451. {
  452. reason = string.Empty;
  453. var recipes = RecipeFileManager.Instance.GetSequenceNameList();
  454. foreach (var name in recipes)
  455. {
  456. if (!RecipeFileManager.Instance.DeleteSequence(name))
  457. {
  458. EV.PostWarningLog("System", $"Can not delete {name}, delete all failed.");
  459. return;
  460. }
  461. }
  462. EV.PostInfoLog("System", "All recipe deleted");
  463. }
  464. protected void DeleteRecipe(List<string> recipeFiles, out string reason)
  465. {
  466. reason = string.Empty;
  467. foreach (var name in recipeFiles)
  468. {
  469. if (!RecipeFileManager.Instance.DeleteSequence(name))
  470. {
  471. EV.PostWarningLog("System", $"Can not delete {name}.");
  472. return;
  473. }
  474. else
  475. {
  476. EV.PostWarningLog("System", $"Delete recipe {name}.");
  477. }
  478. }
  479. }
  480. private void Handle_S7F3(SECsPrimaryInEventArgs e)
  481. {
  482. try
  483. {
  484. //LOG.Write("Handle_S7F4, Request down load recipe");
  485. string ppid = e.Inputs.DataItem[0][0].Value.ToString();
  486. string reason = string.Empty;
  487. // Get the format of PPBODY
  488. SECsFormat bodyType = e.Inputs.DataItem[0][1].Format;
  489. bool recipeSuccess = false;
  490. if (bodyType == SECsFormat.Binary)
  491. {
  492. recipeSuccess = DownLoadRecipeInByte(ppid, (byte[])e.Inputs.DataItem[0][1].Value, out reason);
  493. }
  494. else
  495. {
  496. recipeSuccess = DownLoadRecipe(ppid, e.Inputs.DataItem[0][1].ToString(), out reason);
  497. }
  498. if (recipeSuccess)
  499. {
  500. SECsMessage acknowledge = _gem.Services.ProcessProgram.ProcessProgramAcknowledge(0);
  501. _gem.SendReply(acknowledge, e.TransactionID);
  502. }
  503. else
  504. {
  505. //1:download recipe body fail:Permission Not Granted
  506. //2:download recipe body fail:Length Error
  507. //3:download recipe body fail:Matrix Overflow
  508. //4:download recipe body fail:PPID Not Found
  509. //5:download recipe body fail:Mode Unsupported
  510. SECsMessage acknowledge = _gem.Services.ProcessProgram.ProcessProgramAcknowledge(5);
  511. _gem.SendReply(acknowledge, e.TransactionID);
  512. }
  513. }
  514. catch (Exception ex)
  515. {
  516. //LOG.Write("Handle_S7F4 exception:" + ex.Message);
  517. SECsMessage acknowledge = _gem.Services.ProcessProgram.ProcessProgramAcknowledge(1);
  518. _gem.SendReply(acknowledge, e.TransactionID);
  519. }
  520. }
  521. protected bool DownLoadRecipe(string name, string content, out string reason)
  522. {
  523. bool ret = false;
  524. reason = string.Empty;
  525. ret = RecipeFileManager.Instance.SaveSequence(name, content, false);
  526. if (!ret)
  527. {
  528. reason = string.Format("save recipe content failed,recipeName:{0}", name);
  529. //LOG.Write(reason);
  530. }
  531. return ret;
  532. }
  533. protected bool DownLoadRecipeInByte(string name, byte[] content, out string reason)
  534. {
  535. bool ret = false;
  536. reason = string.Empty;
  537. ret = RecipeFileManager.Instance.SaveSequence(name, System.Text.Encoding.UTF8.GetString(content), false);
  538. if (!ret)
  539. {
  540. reason = string.Format("save recipe content failed,recipeName:{0}", name);
  541. //LOG.Write(reason);
  542. }
  543. return ret;
  544. }
  545. /// <summary>
  546. /* 0 = OK
  547. 1 = Already have
  548. 2 = No space
  549. 3 = Invalid PPID
  550. 4 = Busy, try later
  551. 5 = Will not accept
  552. >5 = Other error
  553. 6-63 Reserved
  554. */
  555. ///</summary>
  556. /// <param name="e"></param>
  557. private void Handle_S7F1(SECsPrimaryInEventArgs e)
  558. {
  559. try
  560. {
  561. //LOG.Write("Handle_S7F1, Process Program Load Inquire");
  562. string ppid = e.Inputs.DataItem[0][0].Value.ToString();
  563. var recipeList = RecipeFileManager.Instance.GetSequenceNameList();
  564. int ppGrant = 0;
  565. if (!recipeList.Contains(ppid))
  566. ppGrant = 3;
  567. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 2, false);
  568. reply.DataItem.Add("PPGNT", ppGrant, SECsFormat.Binary);
  569. _gem.SendReply(reply, e.TransactionID);
  570. }
  571. catch (Exception ex)
  572. {
  573. //LOG.Write("Handle_S7F1 exception:" + ex.Message);
  574. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 0, false);
  575. _gem.SendReply(reply, e.TransactionID);
  576. }
  577. }
  578. private void Handle_S7F5(SECsPrimaryInEventArgs e)
  579. {
  580. try
  581. {
  582. //LOG.Write("Handle_S7F5,Used to request the transfer of a process program");
  583. string ppid = e.Inputs.DataItem[0].ToString();
  584. string reason = string.Empty;
  585. string data = RecipeFileManager.Instance.GetSequence(ppid, false);
  586. if (!string.IsNullOrEmpty(data))
  587. {
  588. byte[] ppbody = System.Text.Encoding.UTF8.GetBytes(data);
  589. SECsMessage recipetToReply = _gem.Services.ProcessProgram.ProcessProgramData(ppid, ppbody);
  590. _gem.SendReply(recipetToReply, e.TransactionID);
  591. }
  592. else
  593. {
  594. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 6, false);
  595. reply.DataItem.AddList();
  596. reply.DataItem[0].Add("RVIACK", 0x01/*abnormal*/, SECsFormat.Binary);
  597. reply.DataItem[0].Add("CPVALUE", reason, SECsFormat.Ascii);
  598. _gem.SendReply(reply, e.TransactionID);
  599. }
  600. }
  601. catch (Exception ex)
  602. {
  603. //LOG.Write("Handle_S7F6 exception:" + ex.Message);
  604. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 6, false);
  605. reply.DataItem.AddList();
  606. _gem.SendReply(reply, e.TransactionID);
  607. }
  608. }
  609. private void Handle_S7F19(SECsPrimaryInEventArgs e)
  610. {
  611. try
  612. {
  613. string reason = string.Empty;
  614. //LOG.Write("Handle_S7F19, Request the transmission of the current equipment process program directory");
  615. var recipeList = RecipeFileManager.Instance.GetSequenceNameList();
  616. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 20, false);
  617. reply.DataItem.AddList();
  618. for (int rNum = 0; rNum < recipeList.Count; rNum++)
  619. {
  620. reply.DataItem[0].Add("PPID", recipeList[rNum], SECsFormat.Ascii);
  621. }
  622. _gem.SendReply(reply, e.TransactionID);
  623. }
  624. catch (Exception ex)
  625. {
  626. //LOG.Write("Handle_S7F19 exception:" + ex.Message);
  627. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 0, false);
  628. _gem.SendReply(reply, e.TransactionID);
  629. }
  630. }
  631. private void Handle_S7F25(SECsPrimaryInEventArgs e)
  632. {
  633. try
  634. {
  635. var ppid = e.Inputs.DataItem[0].Value.ToString();
  636. //LOG.Write("Handle_S7F25, request a particular process program from the other");
  637. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 26, false);
  638. reply.DataItem.AddList();
  639. var parameters = GetRecipe(ppid, out string reason);
  640. if (parameters != null)
  641. {
  642. reply.DataItem[0].Add("PPID", ppid, SECsFormat.Ascii);
  643. reply.DataItem[0].Add("MDLN", _gem.EquipmentModel.Nameable.model, SECsFormat.Ascii);
  644. reply.DataItem[0].Add("SOFTREV", _gem.EquipmentModel.Nameable.softwareRev, SECsFormat.Ascii);
  645. reply.DataItem[0].AddList();
  646. reply.DataItem[0][3].AddList();
  647. reply.DataItem[0][3][0].Add("CCODE", 1, SECsFormat.U1);
  648. reply.DataItem[0][3][0].AddList();
  649. for (int i = 0; i < parameters.Count; i++)
  650. {
  651. reply.DataItem[0][3][0][1].Add($"PPARM{i + 1}", parameters[i], SECsFormat.Ascii);
  652. }
  653. }
  654. else
  655. {
  656. EV.PostWarningLog("FA", $"Request {ppid} failed, {reason}");
  657. }
  658. _gem.SendReply(reply, e.TransactionID);
  659. }
  660. catch (Exception ex)
  661. {
  662. //LOG.Write("Handle_S7F25 exception:" + ex.Message);
  663. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 0, false);
  664. _gem.SendReply(reply, e.TransactionID);
  665. }
  666. }
  667. public List<string> GetRecipe(string sequenceName, out string reason)
  668. {
  669. List<string> result = new List<string>();
  670. reason = string.Empty;
  671. try
  672. {
  673. string content = RecipeFileManager.Instance.GetSequence(sequenceName, false);
  674. if (string.IsNullOrEmpty(content))
  675. {
  676. content = RecipeFileManager.Instance.LoadRecipe("", sequenceName, false);
  677. }
  678. result.Add(content);
  679. }
  680. catch (Exception ex)
  681. {
  682. //LOG.Write(ex);
  683. reason = ex.Message;
  684. }
  685. return result;
  686. }
  687. public List<string> GetFormattedSequence(string sequenceName, out string reason)
  688. {
  689. List<string> result = new List<string>();
  690. try
  691. {
  692. string sequenceData = RecipeFileManager.Instance.GetSequence(sequenceName, false);
  693. XmlDocument recipeDoc = new XmlDocument();
  694. recipeDoc.LoadXml(sequenceData);
  695. XmlNodeList stepNodeList = recipeDoc.SelectNodes("/Aitex/TableSequenceData/Step");
  696. for (int i = 0; i < stepNodeList.Count; i++)
  697. {
  698. XmlElement stepNode = stepNodeList[i] as XmlElement;
  699. Dictionary<string, string> dic = new Dictionary<string, string>();
  700. //遍历Step节点
  701. foreach (XmlAttribute att in stepNode.Attributes)
  702. {
  703. result.Add($"STEP{i + 1}/{att.Name}:{att.Value}");
  704. }
  705. }
  706. reason = string.Empty;
  707. }
  708. catch (Exception ex)
  709. {
  710. //LOG.Write(ex);
  711. reason = ex.Message;
  712. }
  713. return result;
  714. }
  715. public List<string> GetFormattedRecipe(string recipeName, out string reason)
  716. {
  717. List<string> result = new List<string>();
  718. try
  719. {
  720. string sequenceData = RecipeFileManager.Instance.LoadRecipe("", recipeName, false);
  721. XmlDocument recipeDoc = new XmlDocument();
  722. recipeDoc.LoadXml(sequenceData);
  723. XmlNodeList stepNodeList = recipeDoc.SelectNodes("/TableRecipeData/Step");
  724. for (int i = 0; i < stepNodeList.Count; i++)
  725. {
  726. XmlElement stepNode = stepNodeList[i] as XmlElement;
  727. Dictionary<string, string> dic = new Dictionary<string, string>();
  728. //遍历Step节点
  729. foreach (XmlAttribute att in stepNode.Attributes)
  730. {
  731. result.Add($"STEP{i + 1}/{att.Name}:{att.Value}");
  732. }
  733. //遍历Step子节点中所有的attribute属性节点
  734. foreach (XmlElement subStepNode in stepNode.ChildNodes)
  735. {
  736. foreach (XmlAttribute att in subStepNode.Attributes)
  737. {
  738. result.Add($"STEP{i + 1}/{subStepNode.Name}/{att.Name}:{att.Value}");
  739. }
  740. //遍历Step子节点的子节点中所有的attribute属性节点
  741. foreach (XmlElement subsubStepNode in subStepNode.ChildNodes)
  742. {
  743. foreach (XmlAttribute att in subsubStepNode.Attributes)
  744. {
  745. result.Add($"STEP{i + 1}/{subStepNode.Name}/{subsubStepNode.Name}/{att.Name}:{att.Value}");
  746. }
  747. }
  748. }
  749. }
  750. reason = string.Empty;
  751. }
  752. catch (Exception ex)
  753. {
  754. //LOG.Write(ex);
  755. reason = ex.Message;
  756. }
  757. return result;
  758. }
  759. /// <summary>
  760. /// Single terminal message process
  761. /// S10F3 Format
  762. /// L,2
  763. /// 1. <TID>
  764. /// 2. <TEXT>
  765. /// </summary>
  766. /// <param name="e"></param>
  767. private void Handle_S10F3(SECsPrimaryInEventArgs e)
  768. {
  769. try
  770. {
  771. //LOG.Write("Process host single terminal message");
  772. string terminalMessage = e.Inputs.DataItem["Ln"]["TEXT"].ToString();
  773. // notify equipment to show terminal message
  774. OnReceivedSingleTerminalMessage(terminalMessage);
  775. // acknowledge Host
  776. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(0);
  777. reply.Function = 4;
  778. _gem.SendReply(reply, e.TransactionID);
  779. }
  780. catch (Exception ex)
  781. {
  782. //LOG.Write("Handle_S10F3 Exception: " + ex.Message);
  783. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(1/*will not display*/);
  784. reply.Function = 4;
  785. _gem.SendReply(reply, e.TransactionID);
  786. }
  787. }
  788. /// <summary>
  789. /// Multiple terminal message process
  790. /// S10F5 Format
  791. /// L,2
  792. /// 1. <TID>
  793. /// 2. L,N
  794. /// 1. <TEXT1>
  795. /// .
  796. /// .
  797. /// n.<TEXTn>
  798. /// </summary>
  799. /// <param name="e"></param>
  800. private void Handle_S10F5(SECsPrimaryInEventArgs e)
  801. {
  802. try
  803. {
  804. //LOG.Write("Process host multiple terminal message");
  805. List<string> receivedMultipleMessages = new List<string>();
  806. string message = string.Empty;
  807. for (int i = 0; i < e.Inputs.DataItem[0][1].Count; i++)
  808. {
  809. receivedMultipleMessages.Add((string)e.Inputs.DataItem[0][1][i].Value);
  810. }
  811. // notify equipment to show terminal message
  812. OnReceivedMultipleTerminalMessage(receivedMultipleMessages);
  813. // acknowledge Host
  814. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(0);
  815. reply.Function = 6;
  816. _gem.SendReply(reply, e.TransactionID);
  817. }
  818. catch (Exception ex)
  819. {
  820. //LOG.Write("Handle_S10F5 Exception: " + ex.Message);
  821. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(1/*will not display*/);
  822. reply.Function = 6;
  823. _gem.SendReply(reply, e.TransactionID);
  824. }
  825. }
  826. /// <summary>
  827. /// On single terminal message received
  828. /// </summary>
  829. /// <param name="terminalMessage"></param>
  830. protected virtual void OnReceivedSingleTerminalMessage(string terminalMessage)
  831. {
  832. EV.Notify("Host", EventTerminalMessage, terminalMessage);
  833. }
  834. /// <summary>
  835. /// On multiple terminal message received
  836. /// </summary>
  837. /// <param name="terminalMessage"></param>
  838. protected virtual void OnReceivedMultipleTerminalMessage(List<string> terminalMessage)
  839. {
  840. foreach (var message in terminalMessage)
  841. {
  842. EV.Notify("Host", EventTerminalMessage, message);
  843. }
  844. }
  845. public void Terminate()
  846. {
  847. _faMonitorThread.Stop();
  848. _logCleaner.Stop();
  849. }
  850. public void Enable()
  851. {
  852. _gem.SetEnable();
  853. }
  854. public void Disable()
  855. {
  856. _gem.SetDisable();
  857. }
  858. public void NotifyEvent(string eventName, Dictionary<string, string> dvid, Dictionary<string, object> objDvid)
  859. {
  860. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, objDvid = objDvid, EventName = eventName, IsAlarm = false });
  861. }
  862. public void NotifyAlarm(string alarmName, Dictionary<string, string> dvid, Dictionary<string, object> objDvid, string text)
  863. {
  864. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, objDvid = objDvid, EventName = alarmName, IsAlarm = true, Text = text});
  865. }
  866. public void NotifyEvent(string eventName, Dictionary<string, string> dvid)
  867. {
  868. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, EventName = eventName, IsAlarm = false });
  869. }
  870. public void NotifyAlarm(string alarmName, Dictionary<string, string> dvid, string text)
  871. {
  872. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, EventName = alarmName, IsAlarm = true, Text = text});
  873. }
  874. public void SetLocalControl()
  875. {
  876. Task.Factory.StartNew(() =>
  877. {
  878. _gem.SetLocal();
  879. });
  880. }
  881. public void SetRemoteControl()
  882. {
  883. Task.Factory.StartNew(() =>
  884. {
  885. _gem.SetRemote();
  886. });
  887. }
  888. public void SetEnableSpooling()
  889. {
  890. Task.Factory.StartNew(() =>
  891. {
  892. _gem.SetAttribute(GEMVariables.SpoolEnabled, AttributeType.EC, "true");
  893. });
  894. }
  895. public void SetDisableSpooling()
  896. {
  897. Task.Factory.StartNew(() =>
  898. {
  899. _gem.SetAttribute(GEMVariables.SpoolEnabled, AttributeType.EC, "false");
  900. });
  901. }
  902. public bool MonitorFaTask()
  903. {
  904. try
  905. {
  906. SynchronizeSVIDValue();
  907. FaEventItem ev;
  908. while (_lstEvent.TryDequeue(out ev))
  909. {
  910. if (ev.dvid != null)
  911. {
  912. foreach (var dvid in ev.dvid)
  913. {
  914. SetDVIDValue(dvid.Key, dvid.Value);
  915. }
  916. }
  917. if (ev.objDvid != null)
  918. {
  919. foreach (var dvid in ev.objDvid)
  920. {
  921. SetDVIDValue(dvid.Key, dvid.Value);
  922. }
  923. }
  924. SetDVIDValue(DVIDName.EventName, ev.EventName);
  925. if (ev.IsAlarm)
  926. {
  927. SetAlarm(ev.EventName, ev.Text);
  928. }
  929. else
  930. {
  931. SendEvent(ev.EventName);
  932. }
  933. //Thread.Sleep(500);
  934. }
  935. }
  936. catch (Exception ex)
  937. {
  938. System.Diagnostics.Trace.WriteLine(ex);
  939. }
  940. return true;
  941. }
  942. private void OnCommunicationStateChanged(object sender, SECsEventArgs e)
  943. {
  944. if (_gem.CommunicationState == CommunicationState.EnabledCommunicating)
  945. {
  946. if (SC.ContainsItem("System.FA.DefaultToOnline") && SC.GetValue<bool>("System.FA.DefaultToOnline"))
  947. _gem.SetOnline();
  948. if (SC.ContainsItem("System.FA.DefaultToRemote") && SC.GetValue<bool>("System.FA.DefaultToRemote"))
  949. _gem.SetRemote();
  950. }
  951. }
  952. /// <summary>
  953. /// Send terminal message to host
  954. /// </summary>
  955. /// <param name="message"></param>
  956. public void SendTerminalMessageToHost(string message)
  957. {
  958. if (!_gem.IsConnected || _gem.CommunicationState == CommunicationState.Disabled
  959. || _gem.CommunicationState == CommunicationState.WaitDelay
  960. || _gem.CommunicationState == CommunicationState.EnabledNotCommunicating)
  961. {
  962. EV.PostWarningLog("FA", "Host not connected, send terminal message failed.");
  963. return;
  964. }
  965. //LOG.Write("Send terminal message to host:" + message);
  966. Task.Factory.StartNew(() =>
  967. {
  968. SECsMessage secsMsg = _gem.Services.TerminalDisplay.TerminalRequest(message);
  969. _gem.Send(secsMsg);
  970. });
  971. }
  972. public void SynchronizeSVIDValue()
  973. {
  974. try
  975. {
  976. foreach (SVID sv in _gem.EquipmentModel.StatusVariables.SVIDCollection)
  977. {
  978. if (sv != null && !_systemBuildInVariables.Contains(sv.logicalName))
  979. {
  980. if (sv.valueType == SECSFormats.List)
  981. {
  982. List<string> svData = _equipment.GetListSvidValue(sv.logicalName);
  983. if (svData != null && svData.Count > 0)
  984. {
  985. SECsDataItem data = new SECsDataItem(SECsFormat.List);
  986. foreach (var item in svData)
  987. {
  988. data.Add(item, item);
  989. }
  990. _gem.SetListAttribute(sv.logicalName, AttributeType.SV, data);
  991. }
  992. else
  993. {
  994. SECsDataItem data = new SECsDataItem(SECsFormat.List);
  995. data.Clear();
  996. _gem.SetListAttribute(sv.logicalName, AttributeType.SV, data);
  997. }
  998. }
  999. else
  1000. {
  1001. string svDataValue = _equipment.GetSvidValue(sv.logicalName);
  1002. if (!string.IsNullOrEmpty(svDataValue))
  1003. {
  1004. if (sv.valueType == SECSFormats.Boolean) svDataValue = ConvertToBoolean(svDataValue).ToString();
  1005. _gem.SetAttribute(sv.logicalName, AttributeType.SV, svDataValue);
  1006. }
  1007. }
  1008. }
  1009. }
  1010. }
  1011. catch (Exception ex)
  1012. {
  1013. //LOG.Write("Synchronize FA Model Data exception:" + ex.Message);
  1014. }
  1015. }
  1016. private bool SetDVIDValue(string localName, object value)
  1017. {
  1018. if (value == null) return false;
  1019. if (_gem.EquipmentModel == null || !_gem.EquipmentModel.DataVariables.DVIDCollection.IsExistLogicalName(localName))
  1020. return false;
  1021. foreach (VariableType dv in _gem.EquipmentModel.DataVariables.DVIDCollection)
  1022. {
  1023. if (dv.logicalName == localName)
  1024. {
  1025. if (localName == "RecipeStepEndDataSummary")
  1026. {
  1027. List<FdcDataItem> lwsdata = (List<FdcDataItem>)value;
  1028. SECsDataItem ldata = new SECsDataItem(SECsFormat.List);
  1029. foreach (FdcDataItem wsd in lwsdata)
  1030. {
  1031. SECsDataItem data = new SECsDataItem(SECsFormat.List);
  1032. data.Add("Process item", wsd.Name);
  1033. data.Add("Min", wsd.MinValue.ToString());
  1034. data.Add("Max", wsd.MaxValue.ToString());
  1035. data.Add("Mean", wsd.MeanValue.ToString());
  1036. data.Add("SetPoint", wsd.SetPoint.ToString());
  1037. data.Add("Std", wsd.StdValue.ToString());
  1038. data.Add("SampleCount", wsd.SampleCount.ToString());
  1039. ldata.Add(data);
  1040. }
  1041. _gem.SetListAttribute(localName, AttributeType.DV, ldata);
  1042. return true;
  1043. }
  1044. if (dv.valueType == SECSFormats.Boolean)
  1045. {
  1046. value = ConvertToBoolean(Convert.ToString(value)).ToString();
  1047. }
  1048. break;
  1049. }
  1050. }
  1051. _gem.SetAttribute(localName, AttributeType.DV, Convert.ToString(value));
  1052. return true;
  1053. }
  1054. private bool SetDVIDValue(string localName, string value)
  1055. {
  1056. if (value == null) return false;
  1057. //if (!string.IsNullOrEmpty(value))
  1058. //{
  1059. if (_gem.EquipmentModel == null || !_gem.EquipmentModel.DataVariables.DVIDCollection.IsExistLogicalName(localName))
  1060. return false;
  1061. foreach (VariableType dv in _gem.EquipmentModel.DataVariables.DVIDCollection)
  1062. {
  1063. if (dv.logicalName == localName)
  1064. {
  1065. if (dv.valueType == SECSFormats.Boolean)
  1066. {
  1067. value = ConvertToBoolean(value).ToString();
  1068. }
  1069. break;
  1070. }
  1071. }
  1072. _gem.SetAttribute(localName, AttributeType.DV, value);
  1073. //}
  1074. return true;
  1075. }
  1076. private bool ConvertToBoolean(string value)
  1077. {
  1078. if (value == "0" || value.ToLower() == "false") return false;
  1079. else return true;
  1080. }
  1081. private void SendEvent(string eventName)
  1082. {
  1083. try
  1084. {
  1085. if (_gem.EquipmentModel != null)
  1086. {
  1087. var allEvents = _gem.GetAllEnabledEvents();
  1088. if (allEvents.Contains(eventName))
  1089. {
  1090. _gem.SendCollectionEvent(eventName);
  1091. }
  1092. else
  1093. {
  1094. //LOG.Write(string.Format("sendEvent failed,not find:", eventName));
  1095. }
  1096. //LOG.Write(string.Format("【FA2SendEvent--{0}】", eventName));
  1097. }
  1098. }
  1099. catch (Exception ex)
  1100. {
  1101. //LOG.Write("SendEvent Error:" + ex.Message);
  1102. }
  1103. }
  1104. public void SetAlarm(string alarmTag, string text)
  1105. {
  1106. Task.Factory.StartNew(() =>
  1107. {
  1108. //if (_gem.IsAlarmSet(alarmTag))
  1109. //{
  1110. // _gem.ClearAlarm(alarmTag);
  1111. //}
  1112. var allAlarms = _gem.GetAllEnabledAlarms();
  1113. if (allAlarms.Contains(alarmTag))
  1114. {
  1115. _gem.EquipmentModel.Alarms[alarmTag].description = text;
  1116. _gem.SetAlarm(alarmTag);
  1117. }
  1118. else
  1119. {
  1120. //WriteLog(string.Format("sendAlarm failed,not find:", alarmTag));
  1121. }
  1122. //WriteLog(string.Format("【FA3SetAlarm--{0}】", alarmTag));
  1123. });
  1124. }
  1125. public void ClearAlarm(string alarmTag)
  1126. {
  1127. try
  1128. {
  1129. var allsetalarms = _gem.GetAllSetAlarms();
  1130. if (allsetalarms != null && allsetalarms.Count > 0 && allsetalarms.Contains(alarmTag))
  1131. _gem.ClearAlarm(alarmTag);
  1132. if (string.IsNullOrEmpty(alarmTag))
  1133. {
  1134. foreach (var allsetalarm in allsetalarms)
  1135. {
  1136. _gem.ClearAlarm(allsetalarm.ToString());
  1137. }
  1138. }
  1139. }
  1140. catch (Exception ex)
  1141. {
  1142. //LOG.Write($"Clear Alarm Error : {ex.Message}");
  1143. }
  1144. }
  1145. }
  1146. }