MainWindow.xaml.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using Aitex.Core.RT.IOCore;
  2. using Aitex.Core.UI.MVVM;
  3. using Aitex.Core.Util;
  4. using athosSimulator.IO;
  5. using athosSimulator.LoadPort;
  6. using athosSimulator.Robot;
  7. using MECF.Framework.Common.IOCore;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Data.SqlClient;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Input;
  15. using IOs = Aitex.Core.RT.IOCore.IO;
  16. namespace athosSimulator
  17. {
  18. /// <summary>
  19. /// MainWindow.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class MainWindow : Window
  22. {
  23. private string[] _lp1slotMap = new string[25];
  24. private string[] _lp2slotMap = new string[25];
  25. public static readonly DependencyProperty LP1SlotMapProperty = DependencyProperty.Register("LP1SlotMap", typeof(string), typeof(MainWindow));
  26. public string LP1SlotMap
  27. {
  28. get { return (string)this.GetValue(LP1SlotMapProperty); }
  29. set { this.SetValue(LP1SlotMapProperty, value); }
  30. }
  31. public static readonly DependencyProperty LP2SlotMapProperty = DependencyProperty.Register("LP2SlotMap", typeof(string), typeof(MainWindow));
  32. public string LP2SlotMap
  33. {
  34. get { return (string)this.GetValue(LP2SlotMapProperty); }
  35. set { this.SetValue(LP2SlotMapProperty, value); }
  36. }
  37. public SimulatorPlc Plc { get; set; }
  38. public ICommand SetCommand { get; private set; }
  39. public ObservableCollection<NotifiableIoItem> DIs { get; set; }
  40. public ObservableCollection<NotifiableIoItem> DOs { get; set; }
  41. public ObservableCollection<NotifiableIoItem> AIs { get; set; }
  42. public ObservableCollection<NotifiableIoItem> AOs { get; set; }
  43. private PeriodicJob _task;
  44. private RorzeRobot751Simulator _robotSimulator;
  45. private Hirata _lp1Simulator;
  46. private Hirata _lp2Simulator;
  47. private Hirata _lp3Simulator;
  48. public MainWindow()
  49. {
  50. InitializeComponent();
  51. IOShow();
  52. DISource.ItemsSource = DIs;
  53. DOSource.ItemsSource = DOs;
  54. AISource.ItemsSource = AIs;
  55. AOSource.ItemsSource = AOs;
  56. _task = new PeriodicJob(500, IOShow, "Simulator",true);
  57. _robotSimulator = SystemSimulator.Instance.RobotSimulator;
  58. _lp1Simulator = SystemSimulator.Instance.LP1Simulator;
  59. _lp2Simulator = SystemSimulator.Instance.LP2Simulator;
  60. //_lp3Simulator = SystemSimulator.Instance.LP3Simulator;
  61. //SetCommand = new DelegateCommand<object>(OnSetValue);
  62. }
  63. //设置IO值 以及刷新
  64. private bool IOShow()
  65. {
  66. List<DIAccessor> diItems = IOs.GetDiList("Simulator->IO");
  67. if (diItems != null)
  68. {
  69. DIs = new ObservableCollection<NotifiableIoItem>();
  70. foreach (var diItem in diItems)
  71. {
  72. NotifiableIoItem item = new NotifiableIoItem()
  73. {
  74. Name = diItem.Name,
  75. Index = diItem.Index,
  76. Description = diItem.Description,
  77. BoolValue = diItem.Value,
  78. Address = diItem.Addr,
  79. BlockOffset = diItem.BlockOffset,
  80. BlockIndex = diItem.Index,
  81. };
  82. DIs.Add(item);
  83. }
  84. };
  85. List<DOAccessor> doItems = IOs.GetDoList("Simulator->IO");
  86. if (doItems != null)
  87. {
  88. DOs = new ObservableCollection<NotifiableIoItem>();
  89. foreach (var doItem in doItems)
  90. {
  91. NotifiableIoItem item = new NotifiableIoItem()
  92. {
  93. Name = doItem.Name,
  94. Index = doItem.Index,
  95. Description = doItem.Description,
  96. BoolValue = doItem.Value,
  97. Address = doItem.Addr,
  98. BlockOffset = doItem.BlockOffset,
  99. BlockIndex = doItem.Index,
  100. };
  101. DOs.Add(item);
  102. }
  103. };
  104. if (AIs == null)
  105. {
  106. List<AIAccessor> aiItems = IOs.GetAiList("Simulator->IO");
  107. if (aiItems != null)
  108. {
  109. AIs = new ObservableCollection<NotifiableIoItem>();
  110. foreach (var ioItem in aiItems)
  111. {
  112. NotifiableIoItem item = new NotifiableIoItem()
  113. {
  114. Name = ioItem.Name,
  115. Index = ioItem.Index,
  116. Description = ioItem.Description,
  117. ShortValue = ioItem.Value,
  118. Address = ioItem.Addr,
  119. BlockOffset = ioItem.BlockOffset,
  120. BlockIndex = ioItem.Index,
  121. };
  122. AIs.Add(item);
  123. }
  124. }
  125. }
  126. if (AOs == null)
  127. {
  128. List<AOAccessor> aoItems = IOs.GetAoList("Simulator->IO");
  129. if (aoItems != null)
  130. {
  131. AOs = new ObservableCollection<NotifiableIoItem>();
  132. foreach (var ioItem in aoItems)
  133. {
  134. NotifiableIoItem item = new NotifiableIoItem()
  135. {
  136. Name = ioItem.Name,
  137. Index = ioItem.Index,
  138. Description = ioItem.Description,
  139. ShortValue = ioItem.Value,
  140. Address = ioItem.Addr,
  141. BlockOffset = ioItem.BlockOffset,
  142. BlockIndex = ioItem.Index,
  143. };
  144. AOs.Add(item);
  145. }
  146. }
  147. }
  148. return true;
  149. }
  150. private void CheckBox_DOChecked(object sender, RoutedEventArgs e)
  151. {
  152. IOs.DO[GetDOName(e)].Value = true;
  153. DOAccessor do1 = IoManager.Instance.GetIO<DOAccessor>(GetDOName(e));
  154. string reason = "";
  155. bool flag = do1.SetValue(true, out reason);
  156. }
  157. private void CheckBox_DOUnChecked(object sender, RoutedEventArgs e)
  158. {
  159. IOs.DO[GetDOName(e)].Value = false;
  160. DOAccessor do1 = IoManager.Instance.GetIO<DOAccessor>(GetDOName(e));
  161. string reason = "";
  162. bool flag = do1.SetValue(false, out reason);
  163. }
  164. private void CheckBox_DIChecked(object sender, RoutedEventArgs e)
  165. {
  166. IOs.DI[GetDIName(e)].Value = true;
  167. //DIAccessor do1 = IoManager.Instance.GetIO<DIAccessor>(GetDIName(e));
  168. //string reason = "";
  169. //bool flag = do1.SetValue(true, out reason);
  170. }
  171. private void CheckBox_DIUnChecked(object sender, RoutedEventArgs e)
  172. {
  173. IOs.DI[GetDIName(e)].Value = false;
  174. //DIAccessor do1 = IoManager.Instance.GetIO<DIAccessor>(GetDIName(e));
  175. //string reason = "";
  176. //bool flag = do1.SetValue(true, out reason);
  177. }
  178. private string GetDOName(RoutedEventArgs e) => ((NotifiableIoItem)((CheckBox)e.OriginalSource).DataContext).Name;
  179. private string GetDIName(RoutedEventArgs e) => ((NotifiableIoItem)((CheckBox)e.OriginalSource).DataContext).Name;
  180. /// <summary>
  181. /// LP1 Wafer Operation
  182. /// </summary>
  183. /// <param name="sender"></param>
  184. /// <param name="e"></param>
  185. private void LP1SetAll(object sender, RoutedEventArgs e)
  186. {
  187. for (int i = 0; i < _lp1slotMap.Length; i++)
  188. {
  189. _lp1slotMap[i] = "1";
  190. }
  191. LP1SlotMap = string.Join("", _lp1slotMap);
  192. _lp1Simulator.MapStr = LP1SlotMap;
  193. }
  194. private void LP1SetRandom(object sender, RoutedEventArgs e)
  195. {
  196. Random _rd = new Random();
  197. for (int i = 0; i < _lp1slotMap.Length; i++)
  198. {
  199. //_slotMap[i] = (i % 9).ToString();
  200. _lp1slotMap[i] = _rd.Next(0, 10) < 6 ? "0" : "1";
  201. }
  202. LP1SlotMap = string.Join("", _lp1slotMap);
  203. _lp1Simulator.MapStr = LP1SlotMap;
  204. }
  205. private void LP1ClearAll(object sender, RoutedEventArgs e)
  206. {
  207. for (int i = 0; i < _lp1slotMap.Length; i++)
  208. {
  209. _lp1slotMap[i] = "0";
  210. }
  211. LP1SlotMap = string.Join("", _lp1slotMap);
  212. _lp1Simulator.MapStr = LP1SlotMap;
  213. }
  214. /// <summary>
  215. /// LP2 Wafer Operation
  216. /// </summary>
  217. /// <param name="sender"></param>
  218. /// <param name="e"></param>
  219. private void LP2SetAll(object sender, RoutedEventArgs e)
  220. {
  221. for (int i = 0; i < _lp2slotMap.Length; i++)
  222. {
  223. _lp2slotMap[i] = "1";
  224. }
  225. LP2SlotMap = string.Join("", _lp2slotMap);
  226. _lp2Simulator.MapStr = LP2SlotMap;
  227. }
  228. private void LP2SetRandom(object sender, RoutedEventArgs e)
  229. {
  230. Random _rd = new Random();
  231. for (int i = 0; i < _lp2slotMap.Length; i++)
  232. {
  233. //_slotMap[i] = (i % 9).ToString();
  234. _lp2slotMap[i] = _rd.Next(0, 10) < 6 ? "0" : "1";
  235. }
  236. LP2SlotMap = string.Join("", _lp2slotMap);
  237. _lp2Simulator.MapStr = LP2SlotMap;
  238. }
  239. private void LP2ClearAll(object sender, RoutedEventArgs e)
  240. {
  241. for (int i = 0; i < _lp2slotMap.Length; i++)
  242. {
  243. _lp2slotMap[i] = "0";
  244. }
  245. LP2SlotMap = string.Join("", _lp2slotMap);
  246. _lp2Simulator.MapStr = LP2SlotMap;
  247. }
  248. }
  249. }