Recipe.cs 22 KB

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