FaHost.cs 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  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. LOG.WriteExeption("Handle_S7F17 Exception: ", ex);
  446. //give reply to host
  447. SECsMessage messageToReply = _gem.Services.ProcessProgram.DeleteProcessProgramAcknowledge(4/*error*/);
  448. _gem.SendReply(messageToReply, e.TransactionID);
  449. }
  450. }
  451. protected void DeleteAllRecipes(out string reason)
  452. {
  453. reason = string.Empty;
  454. var recipes = RecipeFileManager.Instance.GetSequenceNameList();
  455. foreach (var name in recipes)
  456. {
  457. if (!RecipeFileManager.Instance.DeleteSequence(name))
  458. {
  459. EV.PostWarningLog("System", $"Can not delete {name}, delete all failed.");
  460. return;
  461. }
  462. }
  463. EV.PostInfoLog("System", "All recipe deleted");
  464. }
  465. protected void DeleteRecipe(List<string> recipeFiles, out string reason)
  466. {
  467. reason = string.Empty;
  468. foreach (var name in recipeFiles)
  469. {
  470. if (!RecipeFileManager.Instance.DeleteSequence(name))
  471. {
  472. EV.PostWarningLog("System", $"Can not delete {name}.");
  473. return;
  474. }
  475. else
  476. {
  477. EV.PostWarningLog("System", $"Delete recipe {name}.");
  478. }
  479. }
  480. }
  481. private void Handle_S7F3(SECsPrimaryInEventArgs e)
  482. {
  483. try
  484. {
  485. //LOG.Write("Handle_S7F4, Request down load recipe");
  486. string ppid = e.Inputs.DataItem[0][0].Value.ToString();
  487. string reason = string.Empty;
  488. // Get the format of PPBODY
  489. SECsFormat bodyType = e.Inputs.DataItem[0][1].Format;
  490. bool recipeSuccess = false;
  491. if (bodyType == SECsFormat.Binary)
  492. {
  493. recipeSuccess = DownLoadRecipeInByte(ppid, (byte[])e.Inputs.DataItem[0][1].Value, out reason);
  494. }
  495. else
  496. {
  497. recipeSuccess = DownLoadRecipe(ppid, e.Inputs.DataItem[0][1].ToString(), out reason);
  498. }
  499. if (recipeSuccess)
  500. {
  501. SECsMessage acknowledge = _gem.Services.ProcessProgram.ProcessProgramAcknowledge(0);
  502. _gem.SendReply(acknowledge, e.TransactionID);
  503. }
  504. else
  505. {
  506. //1:download recipe body fail:Permission Not Granted
  507. //2:download recipe body fail:Length Error
  508. //3:download recipe body fail:Matrix Overflow
  509. //4:download recipe body fail:PPID Not Found
  510. //5:download recipe body fail:Mode Unsupported
  511. SECsMessage acknowledge = _gem.Services.ProcessProgram.ProcessProgramAcknowledge(5);
  512. _gem.SendReply(acknowledge, e.TransactionID);
  513. }
  514. }
  515. catch (Exception ex)
  516. {
  517. //LOG.Write("Handle_S7F4 exception:" + ex.Message);
  518. LOG.WriteExeption("Handle_S7F4 exception:", ex);
  519. SECsMessage acknowledge = _gem.Services.ProcessProgram.ProcessProgramAcknowledge(1);
  520. _gem.SendReply(acknowledge, e.TransactionID);
  521. }
  522. }
  523. protected bool DownLoadRecipe(string name, string content, out string reason)
  524. {
  525. bool ret = false;
  526. reason = string.Empty;
  527. ret = RecipeFileManager.Instance.SaveSequence(name, content, false);
  528. if (!ret)
  529. {
  530. reason = string.Format("save recipe content failed,recipeName:{0}", name);
  531. //LOG.Write(reason);
  532. }
  533. return ret;
  534. }
  535. protected bool DownLoadRecipeInByte(string name, byte[] content, out string reason)
  536. {
  537. bool ret = false;
  538. reason = string.Empty;
  539. ret = RecipeFileManager.Instance.SaveSequence(name, System.Text.Encoding.UTF8.GetString(content), false);
  540. if (!ret)
  541. {
  542. reason = string.Format("save recipe content failed,recipeName:{0}", name);
  543. //LOG.Write(reason);
  544. }
  545. return ret;
  546. }
  547. /// <summary>
  548. /* 0 = OK
  549. 1 = Already have
  550. 2 = No space
  551. 3 = Invalid PPID
  552. 4 = Busy, try later
  553. 5 = Will not accept
  554. >5 = Other error
  555. 6-63 Reserved
  556. */
  557. ///</summary>
  558. /// <param name="e"></param>
  559. private void Handle_S7F1(SECsPrimaryInEventArgs e)
  560. {
  561. try
  562. {
  563. //LOG.Write("Handle_S7F1, Process Program Load Inquire");
  564. string ppid = e.Inputs.DataItem[0][0].Value.ToString();
  565. var recipeList = RecipeFileManager.Instance.GetSequenceNameList();
  566. int ppGrant = 0;
  567. if (!recipeList.Contains(ppid))
  568. ppGrant = 3;
  569. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 2, false);
  570. reply.DataItem.Add("PPGNT", ppGrant, SECsFormat.Binary);
  571. _gem.SendReply(reply, e.TransactionID);
  572. }
  573. catch (Exception ex)
  574. {
  575. LOG.WriteExeption("Handle_S7F1 exception:", ex);
  576. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 0, false);
  577. _gem.SendReply(reply, e.TransactionID);
  578. }
  579. }
  580. private void Handle_S7F5(SECsPrimaryInEventArgs e)
  581. {
  582. try
  583. {
  584. //LOG.Write("Handle_S7F5,Used to request the transfer of a process program");
  585. string ppid = e.Inputs.DataItem[0].ToString();
  586. string reason = string.Empty;
  587. string data = RecipeFileManager.Instance.GetSequence(ppid, false);
  588. if (!string.IsNullOrEmpty(data))
  589. {
  590. byte[] ppbody = System.Text.Encoding.UTF8.GetBytes(data);
  591. SECsMessage recipetToReply = _gem.Services.ProcessProgram.ProcessProgramData(ppid, ppbody);
  592. _gem.SendReply(recipetToReply, e.TransactionID);
  593. }
  594. else
  595. {
  596. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 6, false);
  597. reply.DataItem.AddList();
  598. reply.DataItem[0].Add("RVIACK", 0x01/*abnormal*/, SECsFormat.Binary);
  599. reply.DataItem[0].Add("CPVALUE", reason, SECsFormat.Ascii);
  600. _gem.SendReply(reply, e.TransactionID);
  601. }
  602. }
  603. catch (Exception ex)
  604. {
  605. LOG.WriteExeption("Handle_S7F6 exception:", ex);
  606. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 6, false);
  607. reply.DataItem.AddList();
  608. _gem.SendReply(reply, e.TransactionID);
  609. }
  610. }
  611. private void Handle_S7F19(SECsPrimaryInEventArgs e)
  612. {
  613. try
  614. {
  615. string reason = string.Empty;
  616. //LOG.Write("Handle_S7F19, Request the transmission of the current equipment process program directory");
  617. var recipeList = RecipeFileManager.Instance.GetSequenceNameList();
  618. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 20, false);
  619. reply.DataItem.AddList();
  620. for (int rNum = 0; rNum < recipeList.Count; rNum++)
  621. {
  622. reply.DataItem[0].Add("PPID", recipeList[rNum], SECsFormat.Ascii);
  623. }
  624. _gem.SendReply(reply, e.TransactionID);
  625. }
  626. catch (Exception ex)
  627. {
  628. LOG.WriteExeption("Handle_S7F19 exception:", ex);
  629. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 0, false);
  630. _gem.SendReply(reply, e.TransactionID);
  631. }
  632. }
  633. private void Handle_S7F25(SECsPrimaryInEventArgs e)
  634. {
  635. try
  636. {
  637. var ppid = e.Inputs.DataItem[0].Value.ToString();
  638. //LOG.Write("Handle_S7F25, request a particular process program from the other");
  639. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 26, false);
  640. reply.DataItem.AddList();
  641. var parameters = GetRecipe(ppid, out string reason);
  642. if (parameters != null)
  643. {
  644. reply.DataItem[0].Add("PPID", ppid, SECsFormat.Ascii);
  645. reply.DataItem[0].Add("MDLN", _gem.EquipmentModel.Nameable.model, SECsFormat.Ascii);
  646. reply.DataItem[0].Add("SOFTREV", _gem.EquipmentModel.Nameable.softwareRev, SECsFormat.Ascii);
  647. reply.DataItem[0].AddList();
  648. reply.DataItem[0][3].AddList();
  649. reply.DataItem[0][3][0].Add("CCODE", 1, SECsFormat.U1);
  650. reply.DataItem[0][3][0].AddList();
  651. for (int i = 0; i < parameters.Count; i++)
  652. {
  653. reply.DataItem[0][3][0][1].Add($"PPARM{i + 1}", parameters[i], SECsFormat.Ascii);
  654. }
  655. }
  656. else
  657. {
  658. EV.PostWarningLog("FA", $"Request {ppid} failed, {reason}");
  659. }
  660. _gem.SendReply(reply, e.TransactionID);
  661. }
  662. catch (Exception ex)
  663. {
  664. LOG.WriteExeption("Handle_S7F25 exception:", ex);
  665. SECsMessage reply = _gem.Services.CustomMessage.CreateMessage(7, 0, false);
  666. _gem.SendReply(reply, e.TransactionID);
  667. }
  668. }
  669. public List<string> GetRecipe(string sequenceName, out string reason)
  670. {
  671. List<string> result = new List<string>();
  672. reason = string.Empty;
  673. try
  674. {
  675. string content = RecipeFileManager.Instance.GetSequence(sequenceName, false);
  676. if (string.IsNullOrEmpty(content))
  677. {
  678. content = RecipeFileManager.Instance.LoadRecipe("", sequenceName, false);
  679. }
  680. result.Add(content);
  681. }
  682. catch (Exception ex)
  683. {
  684. LOG.WriteExeption(ex);
  685. reason = ex.Message;
  686. }
  687. return result;
  688. }
  689. public List<string> GetFormattedSequence(string sequenceName, out string reason)
  690. {
  691. List<string> result = new List<string>();
  692. try
  693. {
  694. string sequenceData = RecipeFileManager.Instance.GetSequence(sequenceName, false);
  695. XmlDocument recipeDoc = new XmlDocument();
  696. recipeDoc.LoadXml(sequenceData);
  697. XmlNodeList stepNodeList = recipeDoc.SelectNodes("/Aitex/TableSequenceData/Step");
  698. for (int i = 0; i < stepNodeList.Count; i++)
  699. {
  700. XmlElement stepNode = stepNodeList[i] as XmlElement;
  701. Dictionary<string, string> dic = new Dictionary<string, string>();
  702. //遍历Step节点
  703. foreach (XmlAttribute att in stepNode.Attributes)
  704. {
  705. result.Add($"STEP{i + 1}/{att.Name}:{att.Value}");
  706. }
  707. }
  708. reason = string.Empty;
  709. }
  710. catch (Exception ex)
  711. {
  712. LOG.WriteExeption(ex);
  713. reason = ex.Message;
  714. }
  715. return result;
  716. }
  717. public List<string> GetFormattedRecipe(string recipeName, out string reason)
  718. {
  719. List<string> result = new List<string>();
  720. try
  721. {
  722. string sequenceData = RecipeFileManager.Instance.LoadRecipe("", recipeName, false);
  723. XmlDocument recipeDoc = new XmlDocument();
  724. recipeDoc.LoadXml(sequenceData);
  725. XmlNodeList stepNodeList = recipeDoc.SelectNodes("/TableRecipeData/Step");
  726. for (int i = 0; i < stepNodeList.Count; i++)
  727. {
  728. XmlElement stepNode = stepNodeList[i] as XmlElement;
  729. Dictionary<string, string> dic = new Dictionary<string, string>();
  730. //遍历Step节点
  731. foreach (XmlAttribute att in stepNode.Attributes)
  732. {
  733. result.Add($"STEP{i + 1}/{att.Name}:{att.Value}");
  734. }
  735. //遍历Step子节点中所有的attribute属性节点
  736. foreach (XmlElement subStepNode in stepNode.ChildNodes)
  737. {
  738. foreach (XmlAttribute att in subStepNode.Attributes)
  739. {
  740. result.Add($"STEP{i + 1}/{subStepNode.Name}/{att.Name}:{att.Value}");
  741. }
  742. //遍历Step子节点的子节点中所有的attribute属性节点
  743. foreach (XmlElement subsubStepNode in subStepNode.ChildNodes)
  744. {
  745. foreach (XmlAttribute att in subsubStepNode.Attributes)
  746. {
  747. result.Add($"STEP{i + 1}/{subStepNode.Name}/{subsubStepNode.Name}/{att.Name}:{att.Value}");
  748. }
  749. }
  750. }
  751. }
  752. reason = string.Empty;
  753. }
  754. catch (Exception ex)
  755. {
  756. LOG.WriteExeption(ex);
  757. reason = ex.Message;
  758. }
  759. return result;
  760. }
  761. /// <summary>
  762. /// Single terminal message process
  763. /// S10F3 Format
  764. /// L,2
  765. /// 1. <TID>
  766. /// 2. <TEXT>
  767. /// </summary>
  768. /// <param name="e"></param>
  769. private void Handle_S10F3(SECsPrimaryInEventArgs e)
  770. {
  771. try
  772. {
  773. //LOG.Write("Process host single terminal message");
  774. string terminalMessage = e.Inputs.DataItem["Ln"]["TEXT"].ToString();
  775. // notify equipment to show terminal message
  776. OnReceivedSingleTerminalMessage(terminalMessage);
  777. // acknowledge Host
  778. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(0);
  779. reply.Function = 4;
  780. _gem.SendReply(reply, e.TransactionID);
  781. }
  782. catch (Exception ex)
  783. {
  784. LOG.WriteExeption("Handle_S10F3 Exception: ", ex);
  785. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(1/*will not display*/);
  786. reply.Function = 4;
  787. _gem.SendReply(reply, e.TransactionID);
  788. }
  789. }
  790. /// <summary>
  791. /// Multiple terminal message process
  792. /// S10F5 Format
  793. /// L,2
  794. /// 1. <TID>
  795. /// 2. L,N
  796. /// 1. <TEXT1>
  797. /// .
  798. /// .
  799. /// n.<TEXTn>
  800. /// </summary>
  801. /// <param name="e"></param>
  802. private void Handle_S10F5(SECsPrimaryInEventArgs e)
  803. {
  804. try
  805. {
  806. //LOG.Write("Process host multiple terminal message");
  807. List<string> receivedMultipleMessages = new List<string>();
  808. string message = string.Empty;
  809. for (int i = 0; i < e.Inputs.DataItem[0][1].Count; i++)
  810. {
  811. receivedMultipleMessages.Add((string)e.Inputs.DataItem[0][1][i].Value);
  812. }
  813. // notify equipment to show terminal message
  814. OnReceivedMultipleTerminalMessage(receivedMultipleMessages);
  815. // acknowledge Host
  816. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(0);
  817. reply.Function = 6;
  818. _gem.SendReply(reply, e.TransactionID);
  819. }
  820. catch (Exception ex)
  821. {
  822. LOG.WriteExeption("Handle_S10F5 Exception: ", ex);
  823. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(1/*will not display*/);
  824. reply.Function = 6;
  825. _gem.SendReply(reply, e.TransactionID);
  826. }
  827. }
  828. /// <summary>
  829. /// On single terminal message received
  830. /// </summary>
  831. /// <param name="terminalMessage"></param>
  832. protected virtual void OnReceivedSingleTerminalMessage(string terminalMessage)
  833. {
  834. EV.Notify("Host", EventTerminalMessage, terminalMessage);
  835. }
  836. /// <summary>
  837. /// On multiple terminal message received
  838. /// </summary>
  839. /// <param name="terminalMessage"></param>
  840. protected virtual void OnReceivedMultipleTerminalMessage(List<string> terminalMessage)
  841. {
  842. foreach (var message in terminalMessage)
  843. {
  844. EV.Notify("Host", EventTerminalMessage, message);
  845. }
  846. }
  847. public void Terminate()
  848. {
  849. _faMonitorThread.Stop();
  850. _logCleaner.Stop();
  851. }
  852. public void Enable()
  853. {
  854. _gem.SetEnable();
  855. }
  856. public void Disable()
  857. {
  858. _gem.SetDisable();
  859. }
  860. public void NotifyEvent(string eventName, Dictionary<string, string> dvid, Dictionary<string, object> objDvid)
  861. {
  862. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, objDvid = objDvid, EventName = eventName, IsAlarm = false });
  863. }
  864. public void NotifyAlarm(string alarmName, Dictionary<string, string> dvid, Dictionary<string, object> objDvid, string text)
  865. {
  866. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, objDvid = objDvid, EventName = alarmName, IsAlarm = true, Text = text});
  867. }
  868. public void NotifyEvent(string eventName, Dictionary<string, string> dvid)
  869. {
  870. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, EventName = eventName, IsAlarm = false });
  871. }
  872. public void NotifyAlarm(string alarmName, Dictionary<string, string> dvid, string text)
  873. {
  874. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, EventName = alarmName, IsAlarm = true, Text = text});
  875. }
  876. public void SetLocalControl()
  877. {
  878. Task.Factory.StartNew(() =>
  879. {
  880. _gem.SetLocal();
  881. });
  882. }
  883. public void SetRemoteControl()
  884. {
  885. Task.Factory.StartNew(() =>
  886. {
  887. _gem.SetRemote();
  888. });
  889. }
  890. public void SetEnableSpooling()
  891. {
  892. Task.Factory.StartNew(() =>
  893. {
  894. _gem.SetAttribute(GEMVariables.SpoolEnabled, AttributeType.EC, "true");
  895. });
  896. }
  897. public void SetDisableSpooling()
  898. {
  899. Task.Factory.StartNew(() =>
  900. {
  901. _gem.SetAttribute(GEMVariables.SpoolEnabled, AttributeType.EC, "false");
  902. });
  903. }
  904. public bool MonitorFaTask()
  905. {
  906. try
  907. {
  908. SynchronizeSVIDValue();
  909. FaEventItem ev;
  910. while (_lstEvent.TryDequeue(out ev))
  911. {
  912. if (ev.dvid != null)
  913. {
  914. foreach (var dvid in ev.dvid)
  915. {
  916. SetDVIDValue(dvid.Key, dvid.Value);
  917. }
  918. }
  919. if (ev.objDvid != null)
  920. {
  921. foreach (var dvid in ev.objDvid)
  922. {
  923. SetDVIDValue(dvid.Key, dvid.Value);
  924. }
  925. }
  926. SetDVIDValue(DVIDName.EventName, ev.EventName);
  927. if (ev.IsAlarm)
  928. {
  929. SetAlarm(ev.EventName, ev.Text);
  930. }
  931. else
  932. {
  933. SendEvent(ev.EventName);
  934. }
  935. //Thread.Sleep(500);
  936. }
  937. }
  938. catch (Exception ex)
  939. {
  940. System.Diagnostics.Trace.WriteLine(ex);
  941. }
  942. return true;
  943. }
  944. private void OnCommunicationStateChanged(object sender, SECsEventArgs e)
  945. {
  946. if (_gem.CommunicationState == CommunicationState.EnabledCommunicating)
  947. {
  948. if (SC.ContainsItem("System.FA.DefaultToOnline") && SC.GetValue<bool>("System.FA.DefaultToOnline"))
  949. _gem.SetOnline();
  950. if (SC.ContainsItem("System.FA.DefaultToRemote") && SC.GetValue<bool>("System.FA.DefaultToRemote"))
  951. _gem.SetRemote();
  952. }
  953. }
  954. /// <summary>
  955. /// Send terminal message to host
  956. /// </summary>
  957. /// <param name="message"></param>
  958. public void SendTerminalMessageToHost(string message)
  959. {
  960. if (!_gem.IsConnected || _gem.CommunicationState == CommunicationState.Disabled
  961. || _gem.CommunicationState == CommunicationState.WaitDelay
  962. || _gem.CommunicationState == CommunicationState.EnabledNotCommunicating)
  963. {
  964. EV.PostWarningLog("FA", "Host not connected, send terminal message failed.");
  965. return;
  966. }
  967. //LOG.Write("Send terminal message to host:" + message);
  968. Task.Factory.StartNew(() =>
  969. {
  970. SECsMessage secsMsg = _gem.Services.TerminalDisplay.TerminalRequest(message);
  971. _gem.Send(secsMsg);
  972. });
  973. }
  974. public void SynchronizeSVIDValue()
  975. {
  976. try
  977. {
  978. foreach (SVID sv in _gem.EquipmentModel.StatusVariables.SVIDCollection)
  979. {
  980. if (sv != null && !_systemBuildInVariables.Contains(sv.logicalName))
  981. {
  982. if (sv.valueType == SECSFormats.List)
  983. {
  984. List<string> svData = _equipment.GetListSvidValue(sv.logicalName);
  985. if (svData != null && svData.Count > 0)
  986. {
  987. SECsDataItem data = new SECsDataItem(SECsFormat.List);
  988. foreach (var item in svData)
  989. {
  990. data.Add(item, item);
  991. }
  992. _gem.SetListAttribute(sv.logicalName, AttributeType.SV, data);
  993. }
  994. else
  995. {
  996. SECsDataItem data = new SECsDataItem(SECsFormat.List);
  997. data.Clear();
  998. _gem.SetListAttribute(sv.logicalName, AttributeType.SV, data);
  999. }
  1000. }
  1001. else
  1002. {
  1003. string svDataValue = _equipment.GetSvidValue(sv.logicalName);
  1004. if (!string.IsNullOrEmpty(svDataValue))
  1005. {
  1006. if (sv.valueType == SECSFormats.Boolean) svDataValue = ConvertToBoolean(svDataValue).ToString();
  1007. _gem.SetAttribute(sv.logicalName, AttributeType.SV, svDataValue);
  1008. }
  1009. }
  1010. }
  1011. }
  1012. }
  1013. catch (Exception ex)
  1014. {
  1015. LOG.WriteExeption("Synchronize FA Model Data exception:", ex);
  1016. }
  1017. }
  1018. private bool SetDVIDValue(string localName, object value)
  1019. {
  1020. if (value == null) return false;
  1021. if (_gem.EquipmentModel == null || !_gem.EquipmentModel.DataVariables.DVIDCollection.IsExistLogicalName(localName))
  1022. return false;
  1023. foreach (VariableType dv in _gem.EquipmentModel.DataVariables.DVIDCollection)
  1024. {
  1025. if (dv.logicalName == localName)
  1026. {
  1027. if (localName == "RecipeStepEndDataSummary")
  1028. {
  1029. List<FdcDataItem> lwsdata = (List<FdcDataItem>)value;
  1030. SECsDataItem ldata = new SECsDataItem(SECsFormat.List);
  1031. foreach (FdcDataItem wsd in lwsdata)
  1032. {
  1033. SECsDataItem data = new SECsDataItem(SECsFormat.List);
  1034. data.Add("Process item", wsd.Name);
  1035. data.Add("Min", wsd.MinValue.ToString());
  1036. data.Add("Max", wsd.MaxValue.ToString());
  1037. data.Add("Mean", wsd.MeanValue.ToString());
  1038. data.Add("SetPoint", wsd.SetPoint.ToString());
  1039. data.Add("Std", wsd.StdValue.ToString());
  1040. data.Add("SampleCount", wsd.SampleCount.ToString());
  1041. ldata.Add(data);
  1042. }
  1043. _gem.SetListAttribute(localName, AttributeType.DV, ldata);
  1044. return true;
  1045. }
  1046. if (dv.valueType == SECSFormats.Boolean)
  1047. {
  1048. value = ConvertToBoolean(Convert.ToString(value)).ToString();
  1049. }
  1050. break;
  1051. }
  1052. }
  1053. _gem.SetAttribute(localName, AttributeType.DV, Convert.ToString(value));
  1054. return true;
  1055. }
  1056. private bool SetDVIDValue(string localName, string value)
  1057. {
  1058. if (value == null) return false;
  1059. //if (!string.IsNullOrEmpty(value))
  1060. //{
  1061. if (_gem.EquipmentModel == null || !_gem.EquipmentModel.DataVariables.DVIDCollection.IsExistLogicalName(localName))
  1062. return false;
  1063. foreach (VariableType dv in _gem.EquipmentModel.DataVariables.DVIDCollection)
  1064. {
  1065. if (dv.logicalName == localName)
  1066. {
  1067. if (dv.valueType == SECSFormats.Boolean)
  1068. {
  1069. value = ConvertToBoolean(value).ToString();
  1070. }
  1071. break;
  1072. }
  1073. }
  1074. _gem.SetAttribute(localName, AttributeType.DV, value);
  1075. //}
  1076. return true;
  1077. }
  1078. private bool ConvertToBoolean(string value)
  1079. {
  1080. if (value == "0" || value.ToLower() == "false") return false;
  1081. else return true;
  1082. }
  1083. private void SendEvent(string eventName)
  1084. {
  1085. try
  1086. {
  1087. if (_gem.EquipmentModel != null)
  1088. {
  1089. var allEvents = _gem.GetAllEnabledEvents();
  1090. if (allEvents.Contains(eventName))
  1091. {
  1092. _gem.SendCollectionEvent(eventName);
  1093. }
  1094. else
  1095. {
  1096. //LOG.Write(string.Format("sendEvent failed,not find:", eventName));
  1097. }
  1098. //LOG.Write(string.Format("【FA2SendEvent--{0}】", eventName));
  1099. }
  1100. }
  1101. catch (Exception ex)
  1102. {
  1103. LOG.WriteExeption("SendEvent Error:", ex);
  1104. }
  1105. }
  1106. public void SetAlarm(string alarmTag, string text)
  1107. {
  1108. Task.Factory.StartNew(() =>
  1109. {
  1110. //if (_gem.IsAlarmSet(alarmTag))
  1111. //{
  1112. // _gem.ClearAlarm(alarmTag);
  1113. //}
  1114. var allAlarms = _gem.GetAllEnabledAlarms();
  1115. if (allAlarms.Contains(alarmTag))
  1116. {
  1117. _gem.EquipmentModel.Alarms[alarmTag].description = text;
  1118. _gem.SetAlarm(alarmTag);
  1119. }
  1120. else
  1121. {
  1122. //WriteLog(string.Format("sendAlarm failed,not find:", alarmTag));
  1123. }
  1124. //WriteLog(string.Format("【FA3SetAlarm--{0}】", alarmTag));
  1125. });
  1126. }
  1127. public void ClearAlarm(string alarmTag)
  1128. {
  1129. try
  1130. {
  1131. var allsetalarms = _gem.GetAllSetAlarms();
  1132. if (allsetalarms != null && allsetalarms.Count > 0 && allsetalarms.Contains(alarmTag))
  1133. _gem.ClearAlarm(alarmTag);
  1134. if (string.IsNullOrEmpty(alarmTag))
  1135. {
  1136. foreach (var allsetalarm in allsetalarms)
  1137. {
  1138. _gem.ClearAlarm(allsetalarm.ToString());
  1139. }
  1140. }
  1141. }
  1142. catch (Exception ex)
  1143. {
  1144. LOG.WriteExeption($"Clear Alarm Error : ", ex);
  1145. }
  1146. }
  1147. }
  1148. }