Recipe.cs 22 KB

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