Recipe.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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. public class RecipeStep:INotifyPropertyChanged
  180. {
  181. //public string m_UnitName="StepDescriptionUnit";
  182. //public string UnitName
  183. //{
  184. // get { return m_UnitName;}
  185. // set { m_UnitName = value; InvokePropertyChanged("UnitName"); }
  186. //}
  187. [JsonIgnore]
  188. public Func<RecipeStep, RState> checker;
  189. [JsonIgnore]
  190. public Func<RecipeStep, RState> starter;
  191. [JsonIgnore]
  192. public Func<RecipeStep, RState> ender;
  193. //private int m_StepNo;
  194. //public int StepNo
  195. //{
  196. // get { return m_StepNo; }
  197. // set { m_StepNo = value; InvokePropertyChanged("StepNo"); }
  198. //}
  199. private int m_StepNo;
  200. [IsOnlyRead]
  201. public int StepNo
  202. {
  203. get { return m_StepNo; }
  204. set { m_StepNo = value; InvokePropertyChanged("StepNo"); }
  205. }
  206. private StepType m_StepType;
  207. [JsonConverter(typeof(StringEnumConverter))]
  208. public StepType Type
  209. {
  210. get { return m_StepType;}
  211. set { m_StepType = value; InvokePropertyChanged("Type"); }
  212. }
  213. private int m_Time;
  214. public int Time
  215. {
  216. get { return m_Time;}
  217. set { m_Time = value; InvokePropertyChanged("Time"); }
  218. }
  219. private string m_EPDConfigName;
  220. public string EPDConfigName
  221. {
  222. get { return m_EPDConfigName; }
  223. set { m_EPDConfigName = value; InvokePropertyChanged("EPDConfigName"); }
  224. }
  225. private int m_MinEndPointTime;
  226. public int MinEndPointTime
  227. {
  228. get { return m_MinEndPointTime;}
  229. set { m_MinEndPointTime = value; InvokePropertyChanged("MinEndPointTime"); }
  230. }
  231. private int m_MaxEndPointTime;
  232. public int MaxEndPointTime
  233. {
  234. get { return m_MaxEndPointTime; }
  235. set { m_MaxEndPointTime = value; InvokePropertyChanged("MaxEndPointTime"); }
  236. }
  237. private int m_OverEtchPercent;
  238. public int OverEtchPercent
  239. {
  240. get { return m_OverEtchPercent; }
  241. set { m_OverEtchPercent = value;InvokePropertyChanged("OverEtchPercent"); }
  242. }
  243. private bool m_CycleStart;
  244. public bool CycleStart
  245. {
  246. get { return m_CycleStart;}
  247. set { m_CycleStart = value; InvokePropertyChanged("CycleStart"); }
  248. }
  249. private bool m_CycleEnd;
  250. public bool CycleEnd
  251. {
  252. get { return m_CycleEnd;}
  253. set { m_CycleEnd = value; InvokePropertyChanged("CycleEnd"); }
  254. }
  255. private int m_CycleNumber;
  256. public int CycleNumber
  257. {
  258. get { return m_CycleNumber;}
  259. set { m_CycleNumber = value; InvokePropertyChanged("CycleNumber"); }
  260. }
  261. public PressureUnitMode PressureUnitMode { get; set; }
  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. foreach (var step in recipe.Steps)
  379. {
  380. ObservableCollection<ProcessUnitBase> unit = new ObservableCollection<ProcessUnitBase>();
  381. //int count = step.LstUnit.Count / 2;
  382. //for (int i = 0; i < count; i++)
  383. //{
  384. // Type t = Type.GetType(step.LstUnit[i].ToString());
  385. // //unit.Add(JsonConvert.DeserializeObject<t>(step.LstUnit[i+count].ToString()));
  386. // unit.Add(JsonConvert.DeserializeObject<ProcessUnitBase>(step.LstUnit[i + count].ToString()));
  387. //}
  388. //var item = step.LstUnit[0];
  389. for (int i=0;i< step.LstUnit.Count; i++)
  390. {
  391. //object item=step.LstUnit[i];
  392. //step.LstUnit[i].
  393. string value = step.LstUnit[i].ToString();
  394. string[] striparr = value.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  395. string item1= striparr[1].Remove(0, 15);
  396. string item2 = item1.Remove(item1.Length - 2, 2);
  397. //var item= value.Substring(value.IndexOf("UnitName"));
  398. //Type t = Type.GetType(value);
  399. switch (item2)
  400. {
  401. case "PressureByPressureModeUnit":
  402. unit.Add(JsonConvert.DeserializeObject<PressureByPressureModeUnit>(step.LstUnit[i].ToString()));
  403. break;
  404. case "PressureByValveModeUnit":
  405. unit.Add(JsonConvert.DeserializeObject<PressureByValveModeUnit>(step.LstUnit[i].ToString()));
  406. break;
  407. case "TCPUnit":
  408. unit.Add(JsonConvert.DeserializeObject<TCPUnit>(step.LstUnit[i].ToString()));
  409. break;
  410. case "BiasUnit":
  411. unit.Add(JsonConvert.DeserializeObject<BiasUnit>(step.LstUnit[i].ToString()));
  412. break;
  413. case "GasControlUnit":
  414. unit.Add(JsonConvert.DeserializeObject<GasControlUnit>(step.LstUnit[i].ToString()));
  415. break;
  416. case "ESCHVUnit":
  417. unit.Add(JsonConvert.DeserializeObject<ESCHVUnit>(step.LstUnit[i].ToString()));
  418. break;
  419. case "ProcessKitUnit":
  420. unit.Add(JsonConvert.DeserializeObject<ProcessKitUnit>(step.LstUnit[i].ToString()));
  421. break;
  422. }
  423. }
  424. step.LstUnit.Clear();
  425. unit.ToList().ForEach(x =>
  426. {
  427. step.LstUnit.Add(x);
  428. });
  429. }
  430. return recipe;
  431. }
  432. public bool Validate()
  433. {
  434. return true;
  435. }
  436. public bool Save(string recipeFile)
  437. {
  438. return true;
  439. }
  440. public event PropertyChangedEventHandler PropertyChanged;
  441. public void InvokePropertyChanged(string propertyName)
  442. {
  443. if (PropertyChanged != null)
  444. {
  445. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  446. }
  447. }
  448. }
  449. public class RecipeUnity
  450. {
  451. public static string ConvertJsonString(string str)
  452. {
  453. JsonSerializer serializer = new JsonSerializer();
  454. TextReader tr = new StringReader(str);
  455. JsonTextReader jtr = new JsonTextReader(tr);
  456. object obj = serializer.Deserialize(jtr);
  457. if (obj != null)
  458. {
  459. StringWriter textWriter = new StringWriter();
  460. JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
  461. {
  462. Formatting = Newtonsoft.Json.Formatting.Indented,
  463. Indentation = 4,
  464. IndentChar = ' '
  465. };
  466. serializer.Serialize(jsonWriter, obj);
  467. return textWriter.ToString();
  468. }
  469. else
  470. {
  471. return str;
  472. }
  473. }
  474. public static string RecipeToString(Recipe recipe)
  475. {
  476. return JsonConvert.SerializeObject(recipe);
  477. }
  478. public static String CreateRecipe(RecipeType recipeType,string recipeName)
  479. {
  480. Recipe recipe = new Recipe();
  481. recipe.Header = new RecipeHead();
  482. recipe.Header.CreateTime = DateTime.Now.ToString();
  483. recipe.Header.Type = recipeType;
  484. recipe.Header.Name = recipeName;
  485. recipe.Header.LastModifiedBy = "Admin";
  486. recipe.Steps = new ObservableCollection<RecipeStep>();
  487. recipe.Steps.Add(new RecipeStep()
  488. {
  489. LstUnit = new ObservableCollection<Object>()
  490. {
  491. new PressureByPressureModeUnit(),
  492. new TCPUnit(),
  493. new BiasUnit(),
  494. new GasControlUnit(),
  495. new ESCHVUnit(),
  496. new ProcessKitUnit()
  497. }
  498. });
  499. var recipeString = JsonConvert.SerializeObject(recipe);
  500. //var Recipe2=JsonConvert.DeserializeObject<Recipe>(recipeString);
  501. //string test = "";
  502. //test = Recipe2.Steps[0].LstUnit[0].ToString();
  503. //var tcpinit = JsonConvert.DeserializeObject<TCPUnit>(test);
  504. return recipeString;
  505. }
  506. }
  507. }