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. [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 bool m_EnableRamp;
  209. public bool EnableRamp
  210. {
  211. get { return m_EnableRamp; }
  212. set { m_EnableRamp = value; InvokePropertyChanged("EnableRamp"); }
  213. }
  214. private string m_EPDConfigName;
  215. public string EPDConfigName
  216. {
  217. get { return m_EPDConfigName; }
  218. set { m_EPDConfigName = value; InvokePropertyChanged("EPDConfigName"); }
  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 int m_OverEtchPercent;
  233. public int OverEtchPercent
  234. {
  235. get { return m_OverEtchPercent; }
  236. set { m_OverEtchPercent = value;InvokePropertyChanged("OverEtchPercent"); }
  237. }
  238. private bool m_CycleStart;
  239. public bool CycleStart
  240. {
  241. get { return m_CycleStart;}
  242. set { m_CycleStart = value; InvokePropertyChanged("CycleStart"); }
  243. }
  244. private bool m_CycleEnd;
  245. public bool CycleEnd
  246. {
  247. get { return m_CycleEnd;}
  248. set { m_CycleEnd = value; InvokePropertyChanged("CycleEnd"); }
  249. }
  250. private int m_CycleNumber;
  251. public int CycleNumber
  252. {
  253. get { return m_CycleNumber;}
  254. set { m_CycleNumber = value; InvokePropertyChanged("CycleNumber"); }
  255. }
  256. public PressureUnitMode PressureUnitMode { get; set; }
  257. private ObservableCollection<Object> lstUnit = new ObservableCollection<Object>();
  258. public ObservableCollection<Object> LstUnit
  259. {
  260. get { return lstUnit; }
  261. set { lstUnit = value; InvokePropertyChanged("LstUnit"); }
  262. }
  263. private Stopwatch _stepTimer = new Stopwatch();
  264. public long ElapsedTime()
  265. {
  266. return _stepTimer.ElapsedMilliseconds;
  267. }
  268. public void StartStepTimer()
  269. {
  270. _stepTimer.Restart();
  271. }
  272. private long _lastEPDStepTimne = 0;
  273. public void RecordEPDStepTime()
  274. {
  275. _lastEPDStepTimne = _stepTimer.ElapsedMilliseconds;
  276. }
  277. public long GetLastEPDStepTime()
  278. {
  279. return _lastEPDStepTimne;
  280. }
  281. public RState Start()
  282. {
  283. starter(this);
  284. foreach (var unit in lstUnit)
  285. {
  286. var processUnit = unit as ProcessUnitBase;
  287. if (processUnit != null)
  288. {
  289. var state = processUnit.Start(this);
  290. if (state != RState.Running)
  291. return state;
  292. }
  293. else
  294. return RState.Failed;
  295. }
  296. return RState.Running;
  297. }
  298. public RState Run()
  299. {
  300. if (checker(this) == RState.End)
  301. return RState.End;
  302. bool bStable = true;
  303. foreach (var unit in lstUnit)
  304. {
  305. var processUnit = unit as ProcessUnitBase;
  306. if (processUnit != null)
  307. {
  308. var state = processUnit.Run(this);
  309. if(Type == StepType.Stable)
  310. {
  311. if (state != RState.Running && state != RState.End)
  312. return state;
  313. if (state == RState.Running)
  314. bStable = false;
  315. }
  316. else
  317. {
  318. if (state != RState.Running)
  319. return state;
  320. }
  321. }
  322. else
  323. return RState.Failed;
  324. }
  325. return (Type == StepType.Stable && bStable) ? RState.End : RState.Running;
  326. }
  327. public void End()
  328. {
  329. foreach (var unit in lstUnit)
  330. {
  331. var processUnit = unit as ProcessUnitBase;
  332. if (processUnit != null)
  333. {
  334. processUnit.End(this);
  335. }
  336. }
  337. ender(this);
  338. }
  339. public double RampFactor()
  340. {
  341. return _stepTimer.ElapsedMilliseconds / (Time * 1000.0);
  342. }
  343. public void AppendUnit(ProcessUnitBase unit)
  344. {
  345. lstUnit.Append(unit);
  346. }
  347. public event PropertyChangedEventHandler PropertyChanged;
  348. public void InvokePropertyChanged(string propertyName)
  349. {
  350. if (PropertyChanged != null)
  351. {
  352. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  353. }
  354. }
  355. }
  356. public class Recipe: INotifyPropertyChanged
  357. {
  358. private RecipeHead m_Header = new RecipeHead();
  359. public RecipeHead Header
  360. {
  361. get { return m_Header; }
  362. set { m_Header = value; InvokePropertyChanged("Header"); }
  363. }
  364. private ObservableCollection<RecipeStep> m_Steps;
  365. public ObservableCollection<RecipeStep> Steps
  366. {
  367. get { return m_Steps; }
  368. set { m_Steps = value; InvokePropertyChanged("Steps"); }
  369. }
  370. public static Recipe Load(string recipeFile)
  371. {
  372. var recipe= JsonConvert.DeserializeObject<Recipe>(recipeFile);
  373. if (recipe == null)
  374. {
  375. return null;
  376. }
  377. foreach (var step in recipe.Steps)
  378. {
  379. ObservableCollection<ProcessUnitBase> unit = new ObservableCollection<ProcessUnitBase>();
  380. //int count = step.LstUnit.Count / 2;
  381. //for (int i = 0; i < count; i++)
  382. //{
  383. // Type t = Type.GetType(step.LstUnit[i].ToString());
  384. // //unit.Add(JsonConvert.DeserializeObject<t>(step.LstUnit[i+count].ToString()));
  385. // unit.Add(JsonConvert.DeserializeObject<ProcessUnitBase>(step.LstUnit[i + count].ToString()));
  386. //}
  387. //var item = step.LstUnit[0];
  388. for (int i=0;i< step.LstUnit.Count; i++)
  389. {
  390. //object item=step.LstUnit[i];
  391. //step.LstUnit[i].
  392. string value = step.LstUnit[i].ToString();
  393. string[] striparr = value.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  394. string item1= striparr[1].Remove(0, 15);
  395. string item2 = item1.Remove(item1.Length - 2, 2);
  396. //var item= value.Substring(value.IndexOf("UnitName"));
  397. //Type t = Type.GetType(value);
  398. switch (item2)
  399. {
  400. case "PressureModeUnit":
  401. unit.Add(JsonConvert.DeserializeObject<PressureByPressureModeUnit>(step.LstUnit[i].ToString()));
  402. break;
  403. //case "PressureByValveModeUnit":
  404. // unit.Add(JsonConvert.DeserializeObject<PressureByValveModeUnit>(step.LstUnit[i].ToString()));
  405. // break;
  406. case "TCPUnit":
  407. unit.Add(JsonConvert.DeserializeObject<TCPUnit>(step.LstUnit[i].ToString()));
  408. break;
  409. case "BiasUnit":
  410. unit.Add(JsonConvert.DeserializeObject<BiasUnit>(step.LstUnit[i].ToString()));
  411. break;
  412. case "GasControlUnit":
  413. unit.Add(JsonConvert.DeserializeObject<GasControlUnit>(step.LstUnit[i].ToString()));
  414. break;
  415. case "ESCHVUnit":
  416. unit.Add(JsonConvert.DeserializeObject<ESCHVUnit>(step.LstUnit[i].ToString()));
  417. break;
  418. case "ProcessKitUnit":
  419. unit.Add(JsonConvert.DeserializeObject<ProcessKitUnit>(step.LstUnit[i].ToString()));
  420. break;
  421. }
  422. }
  423. step.LstUnit.Clear();
  424. unit.ToList().ForEach(x =>
  425. {
  426. step.LstUnit.Add(x);
  427. });
  428. }
  429. return recipe;
  430. }
  431. public bool Validate()
  432. {
  433. return true;
  434. }
  435. public bool Save(string recipeFile)
  436. {
  437. return true;
  438. }
  439. public event PropertyChangedEventHandler PropertyChanged;
  440. public void InvokePropertyChanged(string propertyName)
  441. {
  442. if (PropertyChanged != null)
  443. {
  444. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  445. }
  446. }
  447. }
  448. public class RecipeUnity
  449. {
  450. public static string ConvertJsonString(string str)
  451. {
  452. JsonSerializer serializer = new JsonSerializer();
  453. TextReader tr = new StringReader(str);
  454. JsonTextReader jtr = new JsonTextReader(tr);
  455. object obj = serializer.Deserialize(jtr);
  456. if (obj != null)
  457. {
  458. StringWriter textWriter = new StringWriter();
  459. JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
  460. {
  461. Formatting = Newtonsoft.Json.Formatting.Indented,
  462. Indentation = 4,
  463. IndentChar = ' '
  464. };
  465. serializer.Serialize(jsonWriter, obj);
  466. return textWriter.ToString();
  467. }
  468. else
  469. {
  470. return str;
  471. }
  472. }
  473. public static string RecipeToString(Recipe recipe)
  474. {
  475. return JsonConvert.SerializeObject(recipe);
  476. }
  477. public static String CreateRecipe(RecipeType recipeType,string recipeName)
  478. {
  479. Recipe recipe = new Recipe();
  480. recipe.Header = new RecipeHead();
  481. recipe.Header.CreateTime = DateTime.Now.ToString();
  482. recipe.Header.Type = recipeType;
  483. recipe.Header.Name = recipeName;
  484. recipe.Header.LastModifiedBy = "Admin";
  485. recipe.Steps = new ObservableCollection<RecipeStep>();
  486. recipe.Steps.Add(new RecipeStep()
  487. {
  488. StepNo=1,
  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. }