FaHost.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  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 VirgoRT.HostWrapper;
  17. namespace VirgoRT.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 pathName, out string reason)
  668. {
  669. List<string> result = new List<string>();
  670. reason = string.Empty;
  671. try
  672. {
  673. string content = string.Empty;
  674. if (RecipeFileManager.Instance.CheckSequenceFileExist(pathName))
  675. content = RecipeFileManager.Instance.GetSequence(pathName, false);
  676. if (string.IsNullOrEmpty(content))
  677. {
  678. if (pathName.StartsWith("PMA") && !pathName.StartsWith("PMA\\Process") &&
  679. !pathName.StartsWith("PMA\\Clean"))
  680. pathName = pathName.Replace("PMA", "PMA\\Process");
  681. if (pathName.StartsWith("PMB") && !pathName.StartsWith("PMB\\Process") &&
  682. !pathName.StartsWith("PMB\\Clean"))
  683. pathName = pathName.Replace("PMB", "PMB\\Process");
  684. content = RecipeFileManager.Instance.LoadRecipe("", pathName, false);
  685. }
  686. result.Add(content);
  687. }
  688. catch (Exception ex)
  689. {
  690. LOG.Write(ex);
  691. reason = ex.Message;
  692. }
  693. return result;
  694. }
  695. public List<string> GetFormattedSequence(string sequenceName, out string reason)
  696. {
  697. List<string> result = new List<string>();
  698. try
  699. {
  700. string sequenceData = RecipeFileManager.Instance.GetSequence(sequenceName, false);
  701. XmlDocument recipeDoc = new XmlDocument();
  702. recipeDoc.LoadXml(sequenceData);
  703. XmlNodeList stepNodeList = recipeDoc.SelectNodes("/Aitex/TableSequenceData/Step");
  704. for (int i = 0; i < stepNodeList.Count; i++)
  705. {
  706. XmlElement stepNode = stepNodeList[i] as XmlElement;
  707. Dictionary<string, string> dic = new Dictionary<string, string>();
  708. //遍历Step节点
  709. foreach (XmlAttribute att in stepNode.Attributes)
  710. {
  711. result.Add($"STEP{i + 1}/{att.Name}:{att.Value}");
  712. }
  713. }
  714. reason = string.Empty;
  715. }
  716. catch (Exception ex)
  717. {
  718. LOG.Write(ex);
  719. reason = ex.Message;
  720. }
  721. return result;
  722. }
  723. public List<string> GetFormattedRecipe(string recipeName, out string reason)
  724. {
  725. List<string> result = new List<string>();
  726. try
  727. {
  728. string sequenceData = RecipeFileManager.Instance.LoadRecipe("", recipeName, false);
  729. XmlDocument recipeDoc = new XmlDocument();
  730. recipeDoc.LoadXml(sequenceData);
  731. XmlNodeList stepNodeList = recipeDoc.SelectNodes("/TableRecipeData/Step");
  732. for (int i = 0; i < stepNodeList.Count; i++)
  733. {
  734. XmlElement stepNode = stepNodeList[i] as XmlElement;
  735. Dictionary<string, string> dic = new Dictionary<string, string>();
  736. //遍历Step节点
  737. foreach (XmlAttribute att in stepNode.Attributes)
  738. {
  739. result.Add($"STEP{i + 1}/{att.Name}:{att.Value}");
  740. }
  741. //遍历Step子节点中所有的attribute属性节点
  742. foreach (XmlElement subStepNode in stepNode.ChildNodes)
  743. {
  744. foreach (XmlAttribute att in subStepNode.Attributes)
  745. {
  746. result.Add($"STEP{i + 1}/{subStepNode.Name}/{att.Name}:{att.Value}");
  747. }
  748. //遍历Step子节点的子节点中所有的attribute属性节点
  749. foreach (XmlElement subsubStepNode in subStepNode.ChildNodes)
  750. {
  751. foreach (XmlAttribute att in subsubStepNode.Attributes)
  752. {
  753. result.Add($"STEP{i + 1}/{subStepNode.Name}/{subsubStepNode.Name}/{att.Name}:{att.Value}");
  754. }
  755. }
  756. }
  757. }
  758. reason = string.Empty;
  759. }
  760. catch (Exception ex)
  761. {
  762. LOG.Write(ex);
  763. reason = ex.Message;
  764. }
  765. return result;
  766. }
  767. /// <summary>
  768. /// Single terminal message process
  769. /// S10F3 Format
  770. /// L,2
  771. /// 1. <TID>
  772. /// 2. <TEXT>
  773. /// </summary>
  774. /// <param name="e"></param>
  775. private void Handle_S10F3(SECsPrimaryInEventArgs e)
  776. {
  777. try
  778. {
  779. LOG.Write("Process host single terminal message");
  780. string terminalMessage = e.Inputs.DataItem["Ln"]["TEXT"].ToString();
  781. // notify equipment to show terminal message
  782. OnReceivedSingleTerminalMessage(terminalMessage);
  783. // acknowledge Host
  784. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(0);
  785. reply.Function = 4;
  786. _gem.SendReply(reply, e.TransactionID);
  787. }
  788. catch (Exception ex)
  789. {
  790. LOG.Write("Handle_S10F3 Exception: " + ex.Message);
  791. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(1/*will not display*/);
  792. reply.Function = 4;
  793. _gem.SendReply(reply, e.TransactionID);
  794. }
  795. }
  796. /// <summary>
  797. /// Multiple terminal message process
  798. /// S10F5 Format
  799. /// L,2
  800. /// 1. <TID>
  801. /// 2. L,N
  802. /// 1. <TEXT1>
  803. /// .
  804. /// .
  805. /// n.<TEXTn>
  806. /// </summary>
  807. /// <param name="e"></param>
  808. private void Handle_S10F5(SECsPrimaryInEventArgs e)
  809. {
  810. try
  811. {
  812. LOG.Write("Process host multiple terminal message");
  813. List<string> receivedMultipleMessages = new List<string>();
  814. string message = string.Empty;
  815. for (int i = 0; i < e.Inputs.DataItem[0][1].Count; i++)
  816. {
  817. receivedMultipleMessages.Add((string)e.Inputs.DataItem[0][1][i].Value);
  818. }
  819. // notify equipment to show terminal message
  820. OnReceivedMultipleTerminalMessage(receivedMultipleMessages);
  821. // acknowledge Host
  822. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(0);
  823. reply.Function = 6;
  824. _gem.SendReply(reply, e.TransactionID);
  825. }
  826. catch (Exception ex)
  827. {
  828. LOG.Write("Handle_S10F5 Exception: " + ex.Message);
  829. SECsMessage reply = _gem.Services.TerminalDisplay.TerminalDisplayAcknowledge(1/*will not display*/);
  830. reply.Function = 6;
  831. _gem.SendReply(reply, e.TransactionID);
  832. }
  833. }
  834. /// <summary>
  835. /// On single terminal message received
  836. /// </summary>
  837. /// <param name="terminalMessage"></param>
  838. protected virtual void OnReceivedSingleTerminalMessage(string terminalMessage)
  839. {
  840. EV.Notify("Host", EventTerminalMessage, terminalMessage);
  841. }
  842. /// <summary>
  843. /// On multiple terminal message received
  844. /// </summary>
  845. /// <param name="terminalMessage"></param>
  846. protected virtual void OnReceivedMultipleTerminalMessage(List<string> terminalMessage)
  847. {
  848. foreach (var message in terminalMessage)
  849. {
  850. EV.Notify("Host", EventTerminalMessage, message);
  851. }
  852. }
  853. public void Terminate()
  854. {
  855. _faMonitorThread.Stop();
  856. _logCleaner.Stop();
  857. }
  858. public void Enable()
  859. {
  860. _gem.SetEnable();
  861. }
  862. public void Disable()
  863. {
  864. _gem.SetDisable();
  865. }
  866. public void NotifyEvent(string eventName, Dictionary<string, string> dvid, Dictionary<string, object> objDvid)
  867. {
  868. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, objDvid = objDvid, EventName = eventName, IsAlarm = false });
  869. }
  870. public void NotifyAlarm(string alarmName, Dictionary<string, string> dvid, Dictionary<string, object> objDvid, string text)
  871. {
  872. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, objDvid = objDvid, EventName = alarmName, IsAlarm = true, Text = text});
  873. }
  874. public void NotifyEvent(string eventName, Dictionary<string, string> dvid)
  875. {
  876. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, EventName = eventName, IsAlarm = false });
  877. }
  878. public void NotifyAlarm(string alarmName, Dictionary<string, string> dvid, string text)
  879. {
  880. _lstEvent.Enqueue(new FaEventItem() { dvid = dvid, EventName = alarmName, IsAlarm = true, Text = text});
  881. }
  882. public void SetLocalControl()
  883. {
  884. Task.Factory.StartNew(() =>
  885. {
  886. _gem.SetLocal();
  887. });
  888. }
  889. public void SetRemoteControl()
  890. {
  891. Task.Factory.StartNew(() =>
  892. {
  893. _gem.SetRemote();
  894. });
  895. }
  896. public void SetEnableSpooling()
  897. {
  898. Task.Factory.StartNew(() =>
  899. {
  900. _gem.SetAttribute(GEMVariables.SpoolEnabled, AttributeType.EC, "true");
  901. });
  902. }
  903. public void SetDisableSpooling()
  904. {
  905. Task.Factory.StartNew(() =>
  906. {
  907. _gem.SetAttribute(GEMVariables.SpoolEnabled, AttributeType.EC, "false");
  908. });
  909. }
  910. public bool MonitorFaTask()
  911. {
  912. try
  913. {
  914. SynchronizeSVIDValue();
  915. FaEventItem ev;
  916. while (_lstEvent.TryDequeue(out ev))
  917. {
  918. if (ev.dvid != null)
  919. {
  920. foreach (var dvid in ev.dvid)
  921. {
  922. SetDVIDValue(dvid.Key, dvid.Value);
  923. }
  924. }
  925. if (ev.objDvid != null)
  926. {
  927. foreach (var dvid in ev.objDvid)
  928. {
  929. SetDVIDValue(dvid.Key, dvid.Value);
  930. }
  931. }
  932. SetDVIDValue(DVIDName.EventName, ev.EventName);
  933. if (ev.IsAlarm)
  934. {
  935. SetAlarm(ev.EventName, ev.Text);
  936. }
  937. else
  938. {
  939. SendEvent(ev.EventName);
  940. }
  941. //Thread.Sleep(500);
  942. }
  943. }
  944. catch (Exception ex)
  945. {
  946. System.Diagnostics.Trace.WriteLine(ex);
  947. }
  948. return true;
  949. }
  950. private void OnCommunicationStateChanged(object sender, SECsEventArgs e)
  951. {
  952. if (_gem.CommunicationState == CommunicationState.EnabledCommunicating)
  953. {
  954. if (SC.ContainsItem("System.FA.DefaultToOnline") && SC.GetValue<bool>("System.FA.DefaultToOnline"))
  955. _gem.SetOnline();
  956. if (SC.ContainsItem("System.FA.DefaultToRemote") && SC.GetValue<bool>("System.FA.DefaultToRemote"))
  957. _gem.SetRemote();
  958. }
  959. }
  960. /// <summary>
  961. /// Send terminal message to host
  962. /// </summary>
  963. /// <param name="message"></param>
  964. public void SendTerminalMessageToHost(string message)
  965. {
  966. if (!_gem.IsConnected || _gem.CommunicationState == CommunicationState.Disabled
  967. || _gem.CommunicationState == CommunicationState.WaitDelay
  968. || _gem.CommunicationState == CommunicationState.EnabledNotCommunicating)
  969. {
  970. EV.PostWarningLog("FA", "Host not connected, send terminal message failed.");
  971. return;
  972. }
  973. LOG.Write("Send terminal message to host:" + message);
  974. Task.Factory.StartNew(() =>
  975. {
  976. SECsMessage secsMsg = _gem.Services.TerminalDisplay.TerminalRequest(message);
  977. _gem.Send(secsMsg);
  978. });
  979. }
  980. public void SynchronizeSVIDValue()
  981. {
  982. try
  983. {
  984. foreach (SVID sv in _gem.EquipmentModel.StatusVariables.SVIDCollection)
  985. {
  986. if (sv != null && !_systemBuildInVariables.Contains(sv.logicalName))
  987. {
  988. if (sv.valueType == SECSFormats.List)
  989. {
  990. List<string> svData = _equipment.GetListSvidValue(sv.logicalName);
  991. if (svData != null && svData.Count > 0)
  992. {
  993. SECsDataItem data = new SECsDataItem(SECsFormat.List);
  994. foreach (var item in svData)
  995. {
  996. data.Add(item, item);
  997. }
  998. _gem.SetListAttribute(sv.logicalName, AttributeType.SV, data);
  999. }
  1000. else
  1001. {
  1002. SECsDataItem data = new SECsDataItem(SECsFormat.List);
  1003. data.Clear();
  1004. _gem.SetListAttribute(sv.logicalName, AttributeType.SV, data);
  1005. }
  1006. }
  1007. else
  1008. {
  1009. string svDataValue = _equipment.GetSvidValue(sv.logicalName);
  1010. if (!string.IsNullOrEmpty(svDataValue))
  1011. {
  1012. if (sv.valueType == SECSFormats.Boolean) svDataValue = ConvertToBoolean(svDataValue).ToString();
  1013. _gem.SetAttribute(sv.logicalName, AttributeType.SV, svDataValue);
  1014. }
  1015. }
  1016. }
  1017. }
  1018. }
  1019. catch (Exception ex)
  1020. {
  1021. LOG.Write("Synchronize FA Model Data exception:" + ex.Message);
  1022. }
  1023. }
  1024. private bool SetDVIDValue(string localName, object value)
  1025. {
  1026. if (value == null) return false;
  1027. if (_gem.EquipmentModel == null || !_gem.EquipmentModel.DataVariables.DVIDCollection.IsExistLogicalName(localName))
  1028. return false;
  1029. foreach (VariableType dv in _gem.EquipmentModel.DataVariables.DVIDCollection)
  1030. {
  1031. if (dv.logicalName == localName)
  1032. {
  1033. if (localName == "RecipeStepEndDataSummary")
  1034. {
  1035. List<FdcDataItem> lwsdata = (List<FdcDataItem>)value;
  1036. SECsDataItem ldata = new SECsDataItem(SECsFormat.List);
  1037. foreach (FdcDataItem wsd in lwsdata)
  1038. {
  1039. SECsDataItem data = new SECsDataItem(SECsFormat.List);
  1040. data.Add("Process item", wsd.Name);
  1041. data.Add("Min", wsd.MinValue.ToString());
  1042. data.Add("Max", wsd.MaxValue.ToString());
  1043. data.Add("Mean", wsd.MeanValue.ToString());
  1044. data.Add("SetPoint", wsd.SetPoint.ToString());
  1045. data.Add("Std", wsd.StdValue.ToString());
  1046. data.Add("SampleCount", wsd.SampleCount.ToString());
  1047. ldata.Add(data);
  1048. }
  1049. _gem.SetListAttribute(localName, AttributeType.DV, ldata);
  1050. return true;
  1051. }
  1052. if (dv.valueType == SECSFormats.Boolean)
  1053. {
  1054. value = ConvertToBoolean(Convert.ToString(value)).ToString();
  1055. }
  1056. break;
  1057. }
  1058. }
  1059. _gem.SetAttribute(localName, AttributeType.DV, Convert.ToString(value));
  1060. return true;
  1061. }
  1062. private bool SetDVIDValue(string localName, string value)
  1063. {
  1064. if (value == null) return false;
  1065. //if (!string.IsNullOrEmpty(value))
  1066. //{
  1067. if (_gem.EquipmentModel == null || !_gem.EquipmentModel.DataVariables.DVIDCollection.IsExistLogicalName(localName))
  1068. return false;
  1069. foreach (VariableType dv in _gem.EquipmentModel.DataVariables.DVIDCollection)
  1070. {
  1071. if (dv.logicalName == localName)
  1072. {
  1073. if (dv.valueType == SECSFormats.Boolean)
  1074. {
  1075. value = ConvertToBoolean(value).ToString();
  1076. }
  1077. break;
  1078. }
  1079. }
  1080. _gem.SetAttribute(localName, AttributeType.DV, value);
  1081. //}
  1082. return true;
  1083. }
  1084. private bool ConvertToBoolean(string value)
  1085. {
  1086. if (value == "0" || value.ToLower() == "false") return false;
  1087. else return true;
  1088. }
  1089. private void SendEvent(string eventName)
  1090. {
  1091. try
  1092. {
  1093. if (_gem.EquipmentModel != null)
  1094. {
  1095. var allEvents = _gem.GetAllEnabledEvents();
  1096. if (allEvents.Contains(eventName))
  1097. {
  1098. _gem.SendCollectionEvent(eventName);
  1099. }
  1100. else
  1101. {
  1102. //LOG.Write(string.Format("sendEvent failed,not find:", eventName));
  1103. }
  1104. //LOG.Write(string.Format("【FA2SendEvent--{0}】", eventName));
  1105. }
  1106. }
  1107. catch (Exception ex)
  1108. {
  1109. LOG.Write("SendEvent Error:" + ex.Message);
  1110. }
  1111. }
  1112. public void SetAlarm(string alarmTag, string text)
  1113. {
  1114. Task.Factory.StartNew(() =>
  1115. {
  1116. //if (_gem.IsAlarmSet(alarmTag))
  1117. //{
  1118. // _gem.ClearAlarm(alarmTag);
  1119. //}
  1120. var allAlarms = _gem.GetAllEnabledAlarms();
  1121. if (allAlarms.Contains(alarmTag))
  1122. {
  1123. _gem.EquipmentModel.Alarms[alarmTag].description = text;
  1124. _gem.SetAlarm(alarmTag);
  1125. }
  1126. else
  1127. {
  1128. //WriteLog(string.Format("sendAlarm failed,not find:", alarmTag));
  1129. }
  1130. //WriteLog(string.Format("【FA3SetAlarm--{0}】", alarmTag));
  1131. });
  1132. }
  1133. public void ClearAlarm(string alarmTag)
  1134. {
  1135. try
  1136. {
  1137. var allsetalarms = _gem.GetAllSetAlarms();
  1138. if (allsetalarms != null && allsetalarms.Count > 0 && allsetalarms.Contains(alarmTag))
  1139. _gem.ClearAlarm(alarmTag);
  1140. if (string.IsNullOrEmpty(alarmTag))
  1141. {
  1142. foreach (var allsetalarm in allsetalarms)
  1143. {
  1144. _gem.ClearAlarm(allsetalarm.ToString());
  1145. }
  1146. }
  1147. }
  1148. catch (Exception ex)
  1149. {
  1150. LOG.Write($"Clear Alarm Error : {ex.Message}");
  1151. }
  1152. }
  1153. }
  1154. }