Recipe.cs 20 KB

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