Recipe.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Converters;
  9. using Venus_Core.Attributes;
  10. namespace Venus_Core
  11. {
  12. public enum RecipeType
  13. {
  14. Chuck,
  15. DeChuck,
  16. Process,
  17. Clean,
  18. }
  19. public enum StepType
  20. {
  21. Time,
  22. Stable,
  23. EndPoint,
  24. OverEtch,
  25. }
  26. public enum ProcessModule
  27. {
  28. Pressure,
  29. TCP, // Transformer Coupled Plasma (转换耦合等离子)
  30. Bias,
  31. Gas,
  32. ESC,
  33. Process,
  34. Compound,
  35. }
  36. public enum GeneratorMode
  37. {
  38. Pulsing,
  39. CW,
  40. }
  41. public enum PressureUnitMode
  42. {
  43. Pressure,
  44. Valve
  45. }
  46. public enum Suspect
  47. {
  48. Origin,
  49. Position1,
  50. Position2,
  51. Position3
  52. }
  53. public enum TargetMode
  54. {
  55. Step,
  56. Cycle
  57. }
  58. public enum ToleranceMode
  59. {
  60. Value,
  61. Percent
  62. }
  63. public class RecipeHead : INotifyPropertyChanged
  64. {
  65. private string m_name;
  66. [IsOnlyRead]
  67. public string Name
  68. {
  69. get { return m_name; }
  70. set { m_name = value; InvokePropertyChanged("Name"); }
  71. }
  72. private string _Version = "TestVersion";
  73. public string Version
  74. {
  75. get { return _Version; }
  76. set { _Version = value; InvokePropertyChanged("Version"); }
  77. }
  78. private JetChamber _ChamberType = JetChamber.Venus;
  79. public JetChamber ChamberType
  80. {
  81. get { return _ChamberType; }
  82. set { _ChamberType = value; InvokePropertyChanged("ChamberType"); }
  83. }
  84. private RecipeType m_Type;
  85. [JsonConverter(typeof(StringEnumConverter))]
  86. public RecipeType Type
  87. {
  88. get { return m_Type; }
  89. set { m_Type = value; InvokePropertyChanged("Type"); }
  90. }
  91. private string m_ChunckRecipe;
  92. public string ChuckRecipe
  93. {
  94. get { return m_ChunckRecipe; }
  95. set { m_ChunckRecipe = value; InvokePropertyChanged("ChuckRecipe"); }
  96. }
  97. private string m_DechuckRecipe;
  98. public string DechuckRecipe
  99. {
  100. get { return m_DechuckRecipe; }
  101. set { m_DechuckRecipe = value; InvokePropertyChanged("DechuckRecipe"); }
  102. }
  103. private string m_CreateTime;
  104. [IsOnlyRead]
  105. public string CreateTime
  106. {
  107. get { return m_CreateTime; }
  108. set { m_CreateTime = value; InvokePropertyChanged("CreateTime"); }
  109. }
  110. private string m_EditTime;
  111. [IsOnlyRead]
  112. public string EditTime
  113. {
  114. get { return m_EditTime; }
  115. set { m_EditTime = value; InvokePropertyChanged("EditTime"); }
  116. }
  117. private string m_LastModifiedBy;
  118. [IsOnlyRead]
  119. public string LastModifiedBy
  120. {
  121. get { return m_LastModifiedBy; }
  122. set { m_LastModifiedBy = value; InvokePropertyChanged("LastModifiedBy"); }
  123. }
  124. private string m_Barcode;
  125. public string Barcode
  126. {
  127. get { return m_Barcode; }
  128. set { m_Barcode = value; InvokePropertyChanged("Barcode"); }
  129. }
  130. private string m_BasePressure;
  131. public string BasePressure
  132. {
  133. get { return m_BasePressure; }
  134. set { m_BasePressure = value; InvokePropertyChanged("BasePressure"); }
  135. }
  136. private string m_ChillerTemp;
  137. public string ChillerTemp
  138. {
  139. get { return m_ChillerTemp; }
  140. set { m_ChillerTemp = value; InvokePropertyChanged("ChillerTemp"); }
  141. }
  142. private int m_RFHoldTime = 1000;
  143. public int RFHoldTime
  144. {
  145. get { return m_RFHoldTime; }
  146. set { m_RFHoldTime = value; InvokePropertyChanged("RFHoldTime"); }
  147. }
  148. private int m_BiasRFHoldTime = 1000;
  149. public int BiasRFHoldTime
  150. {
  151. get { return m_BiasRFHoldTime; }
  152. set { m_BiasRFHoldTime = value; InvokePropertyChanged("BiasRFHoldTime"); }
  153. }
  154. private string m_Comment;
  155. public string Comment
  156. {
  157. get { return m_Comment; }
  158. set { m_Comment = value; InvokePropertyChanged("Comment"); }
  159. }
  160. //private string m_ChillerTemp1;
  161. //public string ChillerTemp1
  162. //{
  163. // get { return m_ChillerTemp1; }
  164. // set { m_ChillerTemp1 = value; InvokePropertyChanged("ChillerTemp1"); }
  165. //}
  166. //private string m_ChillerTemp2;
  167. //public string ChillerTemp2
  168. //{
  169. // get { return m_ChillerTemp2; }
  170. // set { m_ChillerTemp2 = value; InvokePropertyChanged("ChillerTemp2"); }
  171. //}
  172. //private string m_ChillerTemp3;
  173. //public string ChillerTemp3
  174. //{
  175. // get { return m_ChillerTemp3; }
  176. // set { m_ChillerTemp3 = value; InvokePropertyChanged("ChillerTemp3"); }
  177. //}
  178. //private string m_ChillerTemp4;
  179. //public string ChillerTemp4
  180. //{
  181. // get { return m_ChillerTemp4; }
  182. // set { m_ChillerTemp4 = value; InvokePropertyChanged("ChillerTemp4"); }
  183. //}
  184. public event PropertyChangedEventHandler PropertyChanged;
  185. public void InvokePropertyChanged(string propertyName)
  186. {
  187. if (PropertyChanged != null)
  188. {
  189. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  190. }
  191. }
  192. }
  193. public class ProcessUnitBase
  194. {
  195. [JsonIgnore]
  196. public Func<ProcessUnitBase, RecipeStep, RState> checker;
  197. [JsonIgnore]
  198. public Func<ProcessUnitBase, RecipeStep, RState> starter;
  199. [JsonIgnore]
  200. public Action<ProcessUnitBase, RecipeStep> end;
  201. //[JsonIgnore]
  202. //public string Name { get; set; }
  203. //[JsonIgnore]
  204. //public ProcessModule Moudle { get; set; }
  205. public RState Start(RecipeStep step)
  206. {
  207. if (starter != null)
  208. return starter(this, step);
  209. return RState.Running;
  210. }
  211. public RState Run(RecipeStep step)
  212. {
  213. if (checker != null)
  214. return checker(this, step);
  215. return RState.Running;
  216. }
  217. public void End(RecipeStep step)
  218. {
  219. if (end != null)
  220. end(this, step);
  221. }
  222. }
  223. [Serializable]
  224. public class RecipeStep : INotifyPropertyChanged
  225. {
  226. [JsonIgnore]
  227. public Func<RecipeStep, RState> checker;
  228. [JsonIgnore]
  229. public Func<RecipeStep, RState> starter;
  230. [JsonIgnore]
  231. public Func<RecipeStep, RState> ender;
  232. private int m_StepNo = 1;
  233. [IsOnlyRead]
  234. public int StepNo
  235. {
  236. get { return m_StepNo; }
  237. set { m_StepNo = value; InvokePropertyChanged("StepNo"); }
  238. }
  239. private StepType m_StepType;
  240. [JsonConverter(typeof(StringEnumConverter))]
  241. public StepType Type
  242. {
  243. get { return m_StepType; }
  244. set { m_StepType = value; InvokePropertyChanged("Type"); }
  245. }
  246. private int m_Time;
  247. public int Time
  248. {
  249. get { return m_Time; }
  250. set { m_Time = value; InvokePropertyChanged("Time"); }
  251. }
  252. private string m_Description;
  253. public string Description
  254. {
  255. get { return m_Description; }
  256. set { m_Description = value; InvokePropertyChanged("Description"); }
  257. }
  258. private string m_EPDConfigName;
  259. public string EPDConfig
  260. {
  261. get { return m_EPDConfigName; }
  262. set { m_EPDConfigName = value; InvokePropertyChanged("EPDConfig"); }
  263. }
  264. private int m_MinEndPointTime;
  265. public int MinEndPointTime
  266. {
  267. get { return m_MinEndPointTime; }
  268. set { m_MinEndPointTime = value; InvokePropertyChanged("MinEndPointTime"); }
  269. }
  270. private int m_MaxEndPointTime;
  271. public int MaxEndPointTime
  272. {
  273. get { return m_MaxEndPointTime; }
  274. set { m_MaxEndPointTime = value; InvokePropertyChanged("MaxEndPointTime"); }
  275. }
  276. //private bool m_EnableRamp;
  277. //public bool EnableRamp
  278. //{
  279. // get { return m_EnableRamp; }
  280. // set { m_EnableRamp = value; InvokePropertyChanged("EnableRamp"); }
  281. //}
  282. private int m_OverEtchPercent;
  283. public int OverEtchPercent
  284. {
  285. get { return m_OverEtchPercent; }
  286. set { m_OverEtchPercent = value; InvokePropertyChanged("OverEtchPercent"); }
  287. }
  288. private bool m_CycleStart;
  289. public bool CycleStart
  290. {
  291. get { return m_CycleStart; }
  292. set { m_CycleStart = value; InvokePropertyChanged("CycleStart"); }
  293. }
  294. private bool m_CycleEnd;
  295. public bool CycleEnd
  296. {
  297. get { return m_CycleEnd; }
  298. set { m_CycleEnd = value; InvokePropertyChanged("CycleEnd"); }
  299. }
  300. private int m_CycleNumber;
  301. public int CycleNumber
  302. {
  303. get { return m_CycleNumber; }
  304. set { m_CycleNumber = value; InvokePropertyChanged("CycleNumber"); }
  305. }
  306. private ObservableCollection<Object> lstUnit = new ObservableCollection<Object>();
  307. public ObservableCollection<Object> LstUnit
  308. {
  309. get { return lstUnit; }
  310. set { lstUnit = value; InvokePropertyChanged("LstUnit"); }
  311. }
  312. private Stopwatch _stepTimer = new Stopwatch();
  313. public long ElapsedTime()
  314. {
  315. return _stepTimer.ElapsedMilliseconds;
  316. }
  317. public void StartStepTimer()
  318. {
  319. _stepTimer.Restart();
  320. }
  321. private long _lastEPDStepTimne = 0;
  322. public void RecordEPDStepTime()
  323. {
  324. _lastEPDStepTimne = _stepTimer.ElapsedMilliseconds;
  325. }
  326. public long GetLastEPDStepTime()
  327. {
  328. return _lastEPDStepTimne;
  329. }
  330. public RState Start()
  331. {
  332. starter(this);
  333. foreach (var unit in lstUnit)
  334. {
  335. var processUnit = unit as ProcessUnitBase;
  336. if (processUnit != null)
  337. {
  338. var state = processUnit.Start(this);
  339. if (state != RState.Running)
  340. return state;
  341. }
  342. else
  343. return RState.Failed;
  344. }
  345. return RState.Running;
  346. }
  347. public RState Start(int steps, int currentstep)
  348. {
  349. starter(this);
  350. foreach (var unit in lstUnit)
  351. {
  352. var processUnit = unit as ProcessUnitBase;
  353. if (processUnit != null)
  354. {
  355. var state = processUnit.Start(this);
  356. if (state != RState.Running)
  357. return state;
  358. }
  359. else
  360. return RState.Failed;
  361. }
  362. return RState.Running;
  363. }
  364. public RState Run()
  365. {
  366. if (checker(this) == RState.End)
  367. return RState.End;
  368. bool bStable = true;
  369. foreach (var unit in lstUnit)
  370. {
  371. var processUnit = unit as ProcessUnitBase;
  372. if (processUnit != null)
  373. {
  374. var state = processUnit.Run(this);
  375. if (Type == StepType.Stable)
  376. {
  377. if (state != RState.Running && state != RState.End)
  378. return state;
  379. if (state == RState.Running)
  380. bStable = false;
  381. }
  382. else
  383. {
  384. if (state != RState.Running)
  385. return state;
  386. }
  387. }
  388. else
  389. return RState.Failed;
  390. }
  391. return (Type == StepType.Stable && bStable) ? RState.End : RState.Running;
  392. }
  393. public void End()
  394. {
  395. foreach (var unit in lstUnit)
  396. {
  397. var processUnit = unit as ProcessUnitBase;
  398. if (processUnit != null)
  399. {
  400. processUnit.End(this);
  401. }
  402. }
  403. ender(this);
  404. }
  405. public double RampFactor()
  406. {
  407. return _stepTimer.ElapsedMilliseconds / (Time * 1000.0);
  408. }
  409. public void AppendUnit(ProcessUnitBase unit)
  410. {
  411. lstUnit.Append(unit);
  412. }
  413. public event PropertyChangedEventHandler PropertyChanged;
  414. public void InvokePropertyChanged(string propertyName)
  415. {
  416. if (PropertyChanged != null)
  417. {
  418. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  419. }
  420. }
  421. }
  422. public class Recipe : INotifyPropertyChanged
  423. {
  424. private RecipeHead m_Header = new RecipeHead();
  425. public RecipeHead Header
  426. {
  427. get { return m_Header; }
  428. set { m_Header = value; InvokePropertyChanged("Header"); }
  429. }
  430. private ObservableCollection<RecipeStep> m_Steps;
  431. public ObservableCollection<RecipeStep> Steps
  432. {
  433. get { return m_Steps; }
  434. set { m_Steps = value; InvokePropertyChanged("Steps"); }
  435. }
  436. public static Recipe Load(string recipeFile)
  437. {
  438. var recipe = JsonConvert.DeserializeObject<Recipe>(recipeFile);
  439. if (recipe == null)
  440. {
  441. return null;
  442. }
  443. foreach (var step in recipe.Steps)
  444. {
  445. ObservableCollection<ProcessUnitBase> unit = new ObservableCollection<ProcessUnitBase>();
  446. for (int i = 0; i < step.LstUnit.Count; i++)
  447. {
  448. string value = step.LstUnit[i].ToString();
  449. string[] striparr = value.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  450. string item1 = striparr[1].Remove(0, 15);
  451. string item2 = item1.Remove(item1.Length - 2, 2);
  452. switch (item2)
  453. {
  454. case "PressureModeUnit":
  455. unit.Add(JsonConvert.DeserializeObject<PressureByPressureModeUnit>(step.LstUnit[i].ToString()));
  456. break;
  457. //case "PressureByValveModeUnit":
  458. // unit.Add(JsonConvert.DeserializeObject<PressureByValveModeUnit>(step.LstUnit[i].ToString()));
  459. // break;
  460. case "TCPUnit":
  461. unit.Add(JsonConvert.DeserializeObject<TCPUnit>(step.LstUnit[i].ToString()));
  462. break;
  463. case "BiasUnit":
  464. unit.Add(JsonConvert.DeserializeObject<BiasUnit>(step.LstUnit[i].ToString()));
  465. break;
  466. case "GasControlUnit":
  467. unit.Add(JsonConvert.DeserializeObject<GasControlUnit>(step.LstUnit[i].ToString()));
  468. break;
  469. case "ESCHVUnit":
  470. unit.Add(JsonConvert.DeserializeObject<ESCHVUnit>(step.LstUnit[i].ToString()));
  471. break;
  472. case "ProcessKitUnit":
  473. unit.Add(JsonConvert.DeserializeObject<ProcessKitUnit>(step.LstUnit[i].ToString()));
  474. break;
  475. case "HeaterUnit":
  476. unit.Add(JsonConvert.DeserializeObject<HeaterUnit>(step.LstUnit[i].ToString()));
  477. break;
  478. case "GasUnit":
  479. unit.Add(JsonConvert.DeserializeObject<Kepler2200GasControlUnit>(step.LstUnit[i].ToString()));
  480. break;
  481. }
  482. }
  483. step.LstUnit.Clear();
  484. unit.ToList().ForEach(x =>
  485. {
  486. step.LstUnit.Add(x);
  487. });
  488. }
  489. return recipe;
  490. }
  491. public bool Validate()
  492. {
  493. return true;
  494. }
  495. public bool Save(string recipeFile)
  496. {
  497. return true;
  498. }
  499. public event PropertyChangedEventHandler PropertyChanged;
  500. public void InvokePropertyChanged(string propertyName)
  501. {
  502. if (PropertyChanged != null)
  503. {
  504. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  505. }
  506. }
  507. }
  508. public class RecipeUnity
  509. {
  510. public static string ConvertJsonString(string str)
  511. {
  512. JsonSerializer serializer = new JsonSerializer();
  513. TextReader tr = new StringReader(str);
  514. JsonTextReader jtr = new JsonTextReader(tr);
  515. object obj = serializer.Deserialize(jtr);
  516. if (obj != null)
  517. {
  518. StringWriter textWriter = new StringWriter();
  519. JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
  520. {
  521. Formatting = Newtonsoft.Json.Formatting.Indented,
  522. Indentation = 4,
  523. IndentChar = ' '
  524. };
  525. serializer.Serialize(jsonWriter, obj);
  526. return textWriter.ToString();
  527. }
  528. else
  529. {
  530. return str;
  531. }
  532. }
  533. public static string RecipeToString(Recipe recipe)
  534. {
  535. return JsonConvert.SerializeObject(recipe);
  536. }
  537. public static String CreateRecipe(JetChamber currentChamber, RecipeType recipeType, string recipeName)
  538. {
  539. Recipe recipe = new Recipe();
  540. recipe.Header = new RecipeHead();
  541. recipe.Header.CreateTime = DateTime.Now.ToString();
  542. recipe.Header.EditTime = DateTime.Now.ToString();
  543. recipe.Header.Type = recipeType;
  544. recipe.Header.ChamberType = currentChamber;
  545. recipe.Header.Name = recipeName;
  546. recipe.Header.LastModifiedBy = "Admin";
  547. recipe.Steps = new ObservableCollection<RecipeStep>();
  548. RecipeStep recipeStep = new RecipeStep();
  549. recipeStep.LstUnit = GetAllUnits(currentChamber, recipeType);
  550. recipe.Steps.Add(recipeStep);
  551. var recipeString = JsonConvert.SerializeObject(recipe);
  552. return recipeString;
  553. }
  554. public static ObservableCollection<Object> GetAllUnits(JetChamber jetChamber)
  555. {
  556. ObservableCollection<Object> LstUnit = new ObservableCollection<object>();
  557. switch (jetChamber)
  558. {
  559. case JetChamber.Venus:
  560. foreach (var item in Enum.GetValues(typeof(VenusUnits)))
  561. {
  562. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  563. var obj = System.Activator.CreateInstance(t);
  564. LstUnit.Add(obj);
  565. }
  566. break;
  567. case JetChamber.Kepler2300:
  568. foreach (var item in Enum.GetValues(typeof(Kepler2300Uints)))
  569. {
  570. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  571. var obj = System.Activator.CreateInstance(t);
  572. LstUnit.Add(obj);
  573. }
  574. break;
  575. case JetChamber.Kepler2200A:
  576. foreach (var item in Enum.GetValues(typeof(Kepler2200AUnits)))
  577. {
  578. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  579. var obj = System.Activator.CreateInstance(t);
  580. LstUnit.Add(obj);
  581. }
  582. break;
  583. }
  584. return LstUnit;
  585. }
  586. public static ObservableCollection<Object> GetAllUnits(JetChamber jetChamber, RecipeType recipeType)
  587. {
  588. ObservableCollection<Object> LstUnit = new ObservableCollection<object>();
  589. switch (jetChamber)
  590. {
  591. case JetChamber.Venus:
  592. if (recipeType == RecipeType.Clean)
  593. {
  594. foreach (var item in Enum.GetValues(typeof(VenusCleanRecipeUnits)))
  595. {
  596. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  597. var obj = System.Activator.CreateInstance(t);
  598. LstUnit.Add(obj);
  599. }
  600. }
  601. else
  602. {
  603. foreach (var item in Enum.GetValues(typeof(VenusUnits)))
  604. {
  605. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  606. var obj = System.Activator.CreateInstance(t);
  607. LstUnit.Add(obj);
  608. }
  609. }
  610. break;
  611. case JetChamber.Kepler2300:
  612. if (recipeType == RecipeType.Clean)
  613. {
  614. foreach (var item in Enum.GetValues(typeof(Kepler2300CleanRecipeUints)))
  615. {
  616. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  617. var obj = System.Activator.CreateInstance(t);
  618. LstUnit.Add(obj);
  619. }
  620. }
  621. else
  622. {
  623. foreach (var item in Enum.GetValues(typeof(Kepler2300Uints)))
  624. {
  625. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  626. var obj = System.Activator.CreateInstance(t);
  627. LstUnit.Add(obj);
  628. }
  629. }
  630. break;
  631. case JetChamber.Kepler2200A:
  632. foreach (var item in Enum.GetValues(typeof(Kepler2200AUnits)))
  633. {
  634. Type t = Type.GetType($"Venus_Core.{item.ToString()}");
  635. var obj = System.Activator.CreateInstance(t);
  636. LstUnit.Add(obj);
  637. }
  638. break;
  639. }
  640. return LstUnit;
  641. }
  642. }
  643. }