Recipe.cs 22 KB

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