SimSiasunVCEView.xaml.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. using Aitex.Core.UI.MVVM;
  2. using MECF.Framework.Simulator.Core.Commons;
  3. using MECF.Framework.Simulator.Core.Driver;
  4. using MECF.Framework.Simulator.Core.LoadPorts;
  5. using System;
  6. using System.Collections.ObjectModel;
  7. using System.ComponentModel;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Input;
  11. namespace MECF.Framework.Simulator.Core.VCE.SiasunVCE
  12. {
  13. /// <summary>
  14. /// SimSiasunVCEView.xaml 的交互逻辑
  15. /// </summary>
  16. public partial class SimSiasunVCEView : UserControl
  17. {
  18. public static readonly DependencyProperty PortProperty = DependencyProperty.Register(
  19. "Port", typeof(string), typeof(SimSiasunVCEView),
  20. new FrameworkPropertyMetadata("COM5", FrameworkPropertyMetadataOptions.AffectsRender));
  21. public string Port
  22. {
  23. get
  24. {
  25. return (string)this.GetValue(PortProperty);
  26. }
  27. set
  28. {
  29. this.SetValue(PortProperty, value);
  30. }
  31. }
  32. public SimSiasunVCEView()
  33. {
  34. InitializeComponent();
  35. this.Loaded += OnViewLoaded;
  36. }
  37. private void OnViewLoaded(object sender, RoutedEventArgs e)
  38. {
  39. if (DesignerProperties.GetIsInDesignMode(this))
  40. return;
  41. if (DataContext == null)
  42. {
  43. DataContext = new SimSiasunVCEViewModel(Port);
  44. (DataContext as TimerViewModelBase).Start();
  45. }
  46. }
  47. }
  48. class SimSiasunVCEViewModel : SerialPortDeviceViewModel
  49. {
  50. public string Title
  51. {
  52. get { return "Siasun VCE Simulator"; }
  53. }
  54. public string WaferMap
  55. {
  56. get { return _sim.SlotMap; }
  57. }
  58. public bool IsPresent
  59. {
  60. get
  61. {
  62. return _sim.IsPresent;
  63. }
  64. set
  65. {
  66. _sim.IsPresent = value;
  67. }
  68. }
  69. public bool IsProtrude
  70. {
  71. get
  72. {
  73. return _sim.IsProtrude;
  74. }
  75. set
  76. {
  77. _sim.IsProtrude = value;
  78. }
  79. }
  80. public bool IsCross
  81. {
  82. get
  83. {
  84. return _sim.IsCross;
  85. }
  86. set
  87. {
  88. _sim.IsCross = value;
  89. }
  90. }
  91. public ObservableCollection<WaferItem> WaferList { get; set; }
  92. public ICommand PlaceCommand { get; set; }
  93. public ICommand RemoveCommand { get; set; }
  94. public ICommand ClearCommand { get; set; }
  95. public ICommand SetAllCommand { get; set; }
  96. public ICommand RandomCommand { get; set; }
  97. private SimSiasunVCE _sim;
  98. public SimSiasunVCEViewModel(string port) : base("SimSiasunVCEViewModel")
  99. {
  100. PlaceCommand = new DelegateCommand<string>(Place);
  101. RemoveCommand = new DelegateCommand<string>(Remove);
  102. ClearCommand = new DelegateCommand<string>(Clear);
  103. SetAllCommand = new DelegateCommand<string>(SetAll);
  104. RandomCommand = new DelegateCommand<string>(RandomGenerateWafer);
  105. _sim = new SimSiasunVCE(port);
  106. Init(_sim);
  107. WaferList = new ObservableCollection<WaferItem>()
  108. {
  109. new WaferItem {Display = "1", Index = 2, State = 3}
  110. };
  111. }
  112. private void RandomGenerateWafer(string obj)
  113. {
  114. _sim.RandomWafer();
  115. }
  116. private void SetAll(string obj)
  117. {
  118. _sim.SetAllWafer();
  119. }
  120. private void Clear(string obj)
  121. {
  122. _sim.ClearWafer();
  123. }
  124. private void Remove(string obj)
  125. {
  126. _sim.RemoveCarrier();
  127. }
  128. private void Place(string obj)
  129. {
  130. _sim.PlaceCarrier();
  131. }
  132. }
  133. public class SimSiasunVCE : SerialPortDeviceSimulator
  134. {
  135. public string SlotMap
  136. {
  137. get { return string.Join("", _slotMap); }
  138. }
  139. private bool _isPresent;
  140. public bool IsPresent
  141. {
  142. get
  143. {
  144. return _isPresent;
  145. }
  146. set
  147. {
  148. _isPresent = value;
  149. }
  150. }
  151. public bool IsProtrude
  152. {
  153. get;
  154. set;
  155. }
  156. public bool IsCross
  157. {
  158. get;
  159. set;
  160. }
  161. private string[] _slotMap = new string[25];
  162. private bool _doorOpen = false;
  163. private string _zAxisPosition = "L";
  164. public SimSiasunVCE(string port) : base(port, -1, "\r", '\r', true)
  165. {
  166. IsPresent = true;
  167. SetAllWafer();
  168. }
  169. public void RandomWafer()
  170. {
  171. Random _rd = new Random();
  172. for (int i = 0; i < _slotMap.Length; i++)
  173. {
  174. var rtn = _rd.Next(0, 10) % 3;
  175. switch (rtn)
  176. {
  177. case 0:
  178. _slotMap[i] = "O";
  179. break;
  180. case 1:
  181. _slotMap[i] = "S";
  182. break;
  183. case 2:
  184. _slotMap[i] = IsCross ? "C": "S";
  185. break;
  186. default:
  187. break;
  188. }
  189. }
  190. }
  191. internal void SetAllWafer()
  192. {
  193. for (int i = 0; i < _slotMap.Length; i++)
  194. {
  195. _slotMap[i] = "S";
  196. }
  197. }
  198. internal void ClearWafer()
  199. {
  200. for (int i = 0; i < _slotMap.Length; i++)
  201. {
  202. _slotMap[i] = "O";
  203. }
  204. }
  205. internal void RemoveCarrier()
  206. {
  207. IsPresent = false;
  208. }
  209. internal void PlaceCarrier()
  210. {
  211. IsPresent = true;
  212. }
  213. protected override void ProcessUnsplitMessage(string message)
  214. {
  215. //Command: Q<cr>
  216. // Response: XXXXXXX_aaaa_bbbbb_cccc_ddddd < cr >
  217. string content = message.Remove(message.Length - 1);
  218. var contentArray = content.Split(',');
  219. if (message.StartsWith("A,LP")) // move to load position
  220. {
  221. _zAxisPosition = "L";
  222. }
  223. if (message.StartsWith("A,MP")) // MapCassette
  224. {
  225. _zAxisPosition = "M";
  226. }
  227. if (message.StartsWith("A,HM,ALL")) // HomeAll
  228. {
  229. _zAxisPosition = "H";
  230. }
  231. if (message.StartsWith("A,") || message.StartsWith("S,") || message.StartsWith("P,"))
  232. {
  233. if (message.StartsWith("A,DC"))
  234. {
  235. }
  236. if (contentArray[1] == "GO")
  237. {
  238. _zAxisPosition = contentArray[2];
  239. }
  240. OnWriteMessage("M,OK\r");
  241. }
  242. else if (message.StartsWith("R,"))
  243. {
  244. if (message.StartsWith("R,W2"))
  245. {
  246. if (IsPresent)
  247. {
  248. OnWriteMessage("X,W2Y\r");
  249. }
  250. else
  251. {
  252. OnWriteMessage("X,W2N\r");
  253. }
  254. return;
  255. }
  256. if (message.StartsWith("R,MI"))
  257. {
  258. if (IsPresent)
  259. {
  260. var slot = string.Join("", _slotMap);
  261. OnWriteMessage($"X,MI{slot}?????\r");
  262. }
  263. else
  264. {
  265. OnWriteMessage($"X,MIOOOOOOOOOOOOOOOOOOOOOOOOO?????\r");
  266. }
  267. return;
  268. }
  269. if (message.StartsWith("R,STAT,ARM"))
  270. {
  271. OnWriteMessage($"X,STAT{_zAxisPosition}\r");
  272. return;
  273. }
  274. if (message.StartsWith("R,STAT,DOOR"))
  275. {
  276. var open = _doorOpen ? "O":"C";
  277. OnWriteMessage($"X,DOOR{open}\r");
  278. return;
  279. }
  280. if (message.StartsWith("R,SO"))
  281. {
  282. var slideout = IsProtrude ? "Y" : "N";
  283. OnWriteMessage($"X,SO{slideout}\r");
  284. return;
  285. }
  286. OnWriteMessage("X,OK\r");
  287. }
  288. else
  289. {
  290. OnWriteMessage("M,OK\r");
  291. }
  292. }
  293. }
  294. }