Recipe.cs 18 KB

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