Recipe.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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. namespace Venus_Core
  14. {
  15. public enum RecipeType
  16. {
  17. Chuck,
  18. DeChuck,
  19. Process,
  20. Clean,
  21. }
  22. public enum StepType
  23. {
  24. Time,
  25. Stable,
  26. EndPoint,
  27. OverEtch,
  28. }
  29. public enum ProcessModule
  30. {
  31. Pressure,
  32. TCP, // Transformer Coupled Plasma (转换耦合等离子)
  33. Bias,
  34. Gas,
  35. ESC,
  36. Process,
  37. Compound,
  38. }
  39. public enum GeneratorMode
  40. {
  41. Pulsing,
  42. CW,
  43. }
  44. public enum PressureUnitMode
  45. {
  46. Pressure,
  47. Valve
  48. }
  49. public class RecipeHead: INotifyPropertyChanged
  50. {
  51. private string m_name;
  52. public string Name
  53. {
  54. get { return m_name; }
  55. set { m_name = value; InvokePropertyChanged("Name"); }
  56. }
  57. private string _Version = "TestVersion";
  58. public string Version
  59. {
  60. get { return _Version; }
  61. set { _Version = value; InvokePropertyChanged("Version"); }
  62. }
  63. private RecipeType m_Type;
  64. [JsonConverter(typeof(StringEnumConverter))]
  65. public RecipeType Type
  66. {
  67. get { return m_Type; }
  68. set { m_Type = value; InvokePropertyChanged("Type"); }
  69. }
  70. private string m_ChunckRecipe;
  71. public string ChuckRecipe
  72. {
  73. get { return m_ChunckRecipe;}
  74. set { m_ChunckRecipe = value; InvokePropertyChanged("ChuckRecipe"); }
  75. }
  76. private string m_DechuckRecipe;
  77. public string DechuckRecipe
  78. {
  79. get { return m_DechuckRecipe;}
  80. set{ m_DechuckRecipe = value;InvokePropertyChanged("DechuckRecipe");}
  81. }
  82. private string m_CreateTime;
  83. public string CreateTime
  84. {
  85. get { return m_CreateTime;}
  86. set { m_CreateTime = value; InvokePropertyChanged("CreateTime"); }
  87. }
  88. private string m_LastModifiedBy;
  89. public string LastModifiedBy
  90. {
  91. get { return m_LastModifiedBy;}
  92. set { m_LastModifiedBy = value; InvokePropertyChanged("CreateTime"); }
  93. }
  94. private string m_Barcode;
  95. public string Barcode
  96. {
  97. get { return m_Barcode;}
  98. set { m_Barcode = value; InvokePropertyChanged("Barcode"); }
  99. }
  100. private string m_BasePressure;
  101. public string BasePressure
  102. {
  103. get { return m_BasePressure;}
  104. set { m_BasePressure = value; InvokePropertyChanged("BasePressure"); }
  105. }
  106. private string m_ChillerTemp;
  107. public string ChillerTemp
  108. {
  109. get { return m_ChillerTemp;}
  110. set { m_ChillerTemp = value; InvokePropertyChanged("ChillerTemp"); }
  111. }
  112. public event PropertyChangedEventHandler PropertyChanged;
  113. public void InvokePropertyChanged(string propertyName)
  114. {
  115. if (PropertyChanged != null)
  116. {
  117. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  118. }
  119. }
  120. }
  121. public class ProcessUnitBase
  122. {
  123. [JsonIgnore]
  124. public Func<ProcessUnitBase, RecipeStep, RState> checker;
  125. [JsonIgnore]
  126. public Func<ProcessUnitBase, RecipeStep, RState> starter;
  127. [JsonIgnore]
  128. public Action<ProcessUnitBase, RecipeStep> end;
  129. //[JsonIgnore]
  130. //public string Name { get; set; }
  131. //[JsonIgnore]
  132. //public ProcessModule Moudle { get; set; }
  133. public RState Start(RecipeStep step)
  134. {
  135. if (starter != null)
  136. return starter(this, step);
  137. return RState.Running;
  138. }
  139. public RState Run(RecipeStep step)
  140. {
  141. if (checker != null)
  142. return checker(this, step);
  143. return RState.Running;
  144. }
  145. public void End(RecipeStep step)
  146. {
  147. if (end != null)
  148. end(this, step);
  149. }
  150. }
  151. public class RecipeStep:INotifyPropertyChanged
  152. {
  153. //public string m_UnitName="StepDescriptionUnit";
  154. //public string UnitName
  155. //{
  156. // get { return m_UnitName;}
  157. // set { m_UnitName = value; InvokePropertyChanged("UnitName"); }
  158. //}
  159. [JsonIgnore]
  160. public Func<RecipeStep, RState> checker;
  161. [JsonIgnore]
  162. public Func<RecipeStep, RState> starter;
  163. private StepType m_StepType;
  164. [JsonConverter(typeof(StringEnumConverter))]
  165. public StepType Type
  166. {
  167. get { return m_StepType;}
  168. set { m_StepType = value; InvokePropertyChanged("Type"); }
  169. }
  170. private int m_Time;
  171. public int Time
  172. {
  173. get { return m_Time;}
  174. set { m_Time = value; InvokePropertyChanged("Time"); }
  175. }
  176. private int m_MinEndPointTime;
  177. public int MinEndPointTime
  178. {
  179. get { return m_MinEndPointTime;}
  180. set { m_MinEndPointTime = value; InvokePropertyChanged("MinEndPointTime"); }
  181. }
  182. private int m_MaxEndPointTime;
  183. public int MaxEndPointTime
  184. {
  185. get { return m_MaxEndPointTime; }
  186. set { m_MaxEndPointTime = value; InvokePropertyChanged("MaxEndPointTime"); }
  187. }
  188. private bool m_CycleStart;
  189. public bool CycleStart
  190. {
  191. get { return m_CycleStart;}
  192. set { m_CycleStart = value; InvokePropertyChanged("CycleStart"); }
  193. }
  194. private bool m_CycleEnd;
  195. public bool CycleEnd
  196. {
  197. get { return m_CycleEnd;}
  198. set { m_CycleEnd = value; InvokePropertyChanged("CycleEnd"); }
  199. }
  200. private int m_CycleNumber;
  201. public int CycleNumber
  202. {
  203. get { return m_CycleNumber;}
  204. set { m_CycleNumber = value; InvokePropertyChanged("CycleNumber"); }
  205. }
  206. public PressureUnitMode PressureUnitMode { get; set; }
  207. private ObservableCollection<Object> lstUnit = new ObservableCollection<Object>();
  208. public ObservableCollection<Object> LstUnit
  209. {
  210. get { return lstUnit; }
  211. set { lstUnit = value; InvokePropertyChanged("LstUnit"); }
  212. }
  213. private Stopwatch _stepTimer = new Stopwatch();
  214. public long ElapsedTime()
  215. {
  216. return _stepTimer.ElapsedMilliseconds;
  217. }
  218. public RState Start()
  219. {
  220. _stepTimer.Restart();
  221. starter(this);
  222. foreach (var unit in lstUnit)
  223. {
  224. var processUnit = unit as ProcessUnitBase;
  225. if (processUnit != null)
  226. {
  227. var state = processUnit.Start(this);
  228. if (state != RState.Running)
  229. return state;
  230. }
  231. else
  232. return RState.Failed;
  233. }
  234. return RState.Running;
  235. }
  236. public RState Run()
  237. {
  238. if (checker(this) == RState.End)
  239. return RState.End;
  240. foreach (var unit in lstUnit)
  241. {
  242. var processUnit = unit as ProcessUnitBase;
  243. if (processUnit != null)
  244. {
  245. var state = processUnit.Run(this);
  246. if (state != RState.Running)
  247. return state;
  248. }
  249. else
  250. return RState.Failed;
  251. }
  252. return RState.Running;
  253. }
  254. public void End()
  255. {
  256. foreach (var unit in lstUnit)
  257. {
  258. var processUnit = unit as ProcessUnitBase;
  259. if (processUnit != null)
  260. {
  261. processUnit.End(this);
  262. }
  263. }
  264. }
  265. public double RampFactor()
  266. {
  267. return _stepTimer.ElapsedMilliseconds / (Time * 1000.0);
  268. }
  269. public void AppendUnit(ProcessUnitBase unit)
  270. {
  271. lstUnit.Append(unit);
  272. }
  273. public event PropertyChangedEventHandler PropertyChanged;
  274. public void InvokePropertyChanged(string propertyName)
  275. {
  276. if (PropertyChanged != null)
  277. {
  278. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  279. }
  280. }
  281. }
  282. public class Recipe: INotifyPropertyChanged
  283. {
  284. private RecipeHead m_Header = new RecipeHead();
  285. public RecipeHead Header
  286. {
  287. get { return m_Header; }
  288. set { m_Header = value; InvokePropertyChanged("Header"); }
  289. }
  290. private ObservableCollection<RecipeStep> m_Steps;
  291. public ObservableCollection<RecipeStep> Steps
  292. {
  293. get { return m_Steps; }
  294. set { m_Steps = value; InvokePropertyChanged("Steps"); }
  295. }
  296. public static Recipe Load(string recipeFile)
  297. {
  298. var recipe= JsonConvert.DeserializeObject<Recipe>(recipeFile);
  299. foreach (var step in recipe.Steps)
  300. {
  301. ObservableCollection<ProcessUnitBase> unit = new ObservableCollection<ProcessUnitBase>();
  302. //int count = step.LstUnit.Count / 2;
  303. //for (int i = 0; i < count; i++)
  304. //{
  305. // Type t = Type.GetType(step.LstUnit[i].ToString());
  306. // //unit.Add(JsonConvert.DeserializeObject<t>(step.LstUnit[i+count].ToString()));
  307. // unit.Add(JsonConvert.DeserializeObject<ProcessUnitBase>(step.LstUnit[i + count].ToString()));
  308. //}
  309. //var item = step.LstUnit[0];
  310. for (int i=0;i< step.LstUnit.Count; i++)
  311. {
  312. //object item=step.LstUnit[i];
  313. //step.LstUnit[i].
  314. string value = step.LstUnit[i].ToString();
  315. string[] striparr = value.Split(new string[] { "\r\n" }, StringSplitOptions.None);
  316. string item1= striparr[1].Remove(0, 15);
  317. string item2 = item1.Remove(item1.Length - 2, 2);
  318. //var item= value.Substring(value.IndexOf("UnitName"));
  319. //Type t = Type.GetType(value);
  320. switch (item2)
  321. {
  322. case "PressureByPressureModeUnit":
  323. unit.Add(JsonConvert.DeserializeObject<PressureByPressureModeUnit>(step.LstUnit[i].ToString()));
  324. break;
  325. case "PressureByValveModeUnit":
  326. unit.Add(JsonConvert.DeserializeObject<PressureByValveModeUnit>(step.LstUnit[i].ToString()));
  327. break;
  328. case "TCPUnit":
  329. unit.Add(JsonConvert.DeserializeObject<TCPUnit>(step.LstUnit[i].ToString()));
  330. break;
  331. case "BiasUnit":
  332. unit.Add(JsonConvert.DeserializeObject<BiasUnit>(step.LstUnit[i].ToString()));
  333. break;
  334. case "GasControlUnit":
  335. unit.Add(JsonConvert.DeserializeObject<GasControlUnit>(step.LstUnit[i].ToString()));
  336. break;
  337. case "ESCHVUnit":
  338. unit.Add(JsonConvert.DeserializeObject<ESCHVUnit>(step.LstUnit[i].ToString()));
  339. break;
  340. case "ProcessKitUnit":
  341. unit.Add(JsonConvert.DeserializeObject<ProcessKitUnit>(step.LstUnit[i].ToString()));
  342. break;
  343. }
  344. }
  345. step.LstUnit.Clear();
  346. unit.ToList().ForEach(x =>
  347. {
  348. step.LstUnit.Add(x);
  349. });
  350. }
  351. return recipe;
  352. }
  353. public bool Validate()
  354. {
  355. return true;
  356. }
  357. public bool Save(string recipeFile)
  358. {
  359. return true;
  360. }
  361. public event PropertyChangedEventHandler PropertyChanged;
  362. public void InvokePropertyChanged(string propertyName)
  363. {
  364. if (PropertyChanged != null)
  365. {
  366. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
  367. }
  368. }
  369. }
  370. public class RecipeUnity
  371. {
  372. public static string ConvertJsonString(string str)
  373. {
  374. JsonSerializer serializer = new JsonSerializer();
  375. TextReader tr = new StringReader(str);
  376. JsonTextReader jtr = new JsonTextReader(tr);
  377. object obj = serializer.Deserialize(jtr);
  378. if (obj != null)
  379. {
  380. StringWriter textWriter = new StringWriter();
  381. JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
  382. {
  383. Formatting = Newtonsoft.Json.Formatting.Indented,
  384. Indentation = 4,
  385. IndentChar = ' '
  386. };
  387. serializer.Serialize(jsonWriter, obj);
  388. return textWriter.ToString();
  389. }
  390. else
  391. {
  392. return str;
  393. }
  394. }
  395. public static string RecipeToString(Recipe recipe)
  396. {
  397. return JsonConvert.SerializeObject(recipe);
  398. }
  399. public static String CreateRecipe(RecipeType recipeType,string recipeName)
  400. {
  401. Recipe recipe = new Recipe();
  402. recipe.Header = new RecipeHead();
  403. recipe.Header.CreateTime = DateTime.Now.ToString();
  404. recipe.Header.Type = recipeType;
  405. recipe.Header.Name = recipeName;
  406. recipe.Header.LastModifiedBy = "Admin";
  407. recipe.Steps = new ObservableCollection<RecipeStep>();
  408. recipe.Steps.Add(new RecipeStep()
  409. {
  410. LstUnit = new ObservableCollection<Object>()
  411. {
  412. new PressureByPressureModeUnit(),
  413. new TCPUnit(),
  414. new BiasUnit(),
  415. new GasControlUnit(),
  416. new ESCHVUnit(),
  417. new ProcessKitUnit()
  418. }
  419. });
  420. var recipeString = JsonConvert.SerializeObject(recipe);
  421. //var Recipe2=JsonConvert.DeserializeObject<Recipe>(recipeString);
  422. //string test = "";
  423. //test = Recipe2.Steps[0].LstUnit[0].ToString();
  424. //var tcpinit = JsonConvert.DeserializeObject<TCPUnit>(test);
  425. return recipeString;
  426. }
  427. }
  428. }