Recipe.cs 19 KB

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