Recipe.cs 19 KB

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