MainWindow.xaml.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using Aitex.Common.Util;
  2. using Aitex.Core.RT.IOCore;
  3. using Aitex.Core.Util;
  4. using athosSimulator.IO;
  5. using athosSimulator.LoadPort;
  6. using athosSimulator.PreAligner;
  7. using MECF.Framework.Common.IOCore;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Diagnostics;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. using System.Timers;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. using System.Windows.Documents;
  21. using System.Windows.Input;
  22. using System.Windows.Media;
  23. using System.Windows.Media.Imaging;
  24. using System.Windows.Navigation;
  25. using System.Windows.Shapes;
  26. using IOs = Aitex.Core.RT.IOCore.IO;
  27. namespace athosSimulator
  28. {
  29. /// <summary>
  30. /// MainWindow.xaml 的交互逻辑
  31. /// </summary>
  32. public partial class MainWindow : Window
  33. {
  34. public SimulatorPlc Plc { get; set; }
  35. public ObservableCollection<NotifiableIoItem> DIs { get; set; }
  36. public ObservableCollection<NotifiableIoItem> DOs { get; set; }
  37. public ObservableCollection<NotifiableIoItem> AIs { get; set; }
  38. public ObservableCollection<NotifiableIoItem> AOs { get; set; }
  39. private PeriodicJob _task;
  40. public MainWindow()
  41. {
  42. InitializeComponent();
  43. IOShow();
  44. DISource.ItemsSource = DIs;
  45. DOSource.ItemsSource = DOs;
  46. AISource.ItemsSource = AIs;
  47. AOSource.ItemsSource = AOs;
  48. _task = new PeriodicJob(500, IOShow, "Simulator",true);
  49. }
  50. //设置IO值 以及刷新
  51. private bool IOShow()
  52. {
  53. List<DIAccessor> diItems = IOs.GetDiList("Simulator->IO");
  54. if (diItems != null)
  55. {
  56. DIs = new ObservableCollection<NotifiableIoItem>();
  57. foreach (var diItem in diItems)
  58. {
  59. NotifiableIoItem item = new NotifiableIoItem()
  60. {
  61. Name = diItem.Name,
  62. Index = diItem.Index,
  63. Description = diItem.Description,
  64. BoolValue = diItem.Value,
  65. Address = diItem.Addr,
  66. BlockOffset = diItem.BlockOffset,
  67. BlockIndex = diItem.Index,
  68. };
  69. DIs.Add(item);
  70. }
  71. };
  72. List<DOAccessor> doItems = IOs.GetDoList("Simulator->IO");
  73. if (doItems != null)
  74. {
  75. DOs = new ObservableCollection<NotifiableIoItem>();
  76. foreach (var doItem in doItems)
  77. {
  78. NotifiableIoItem item = new NotifiableIoItem()
  79. {
  80. Name = doItem.Name,
  81. Index = doItem.Index,
  82. Description = doItem.Description,
  83. BoolValue = doItem.Value,
  84. Address = doItem.Addr,
  85. BlockOffset = doItem.BlockOffset,
  86. BlockIndex = doItem.Index,
  87. };
  88. DOs.Add(item);
  89. }
  90. };
  91. if (AIs == null)
  92. {
  93. List<AIAccessor> aiItems = IOs.GetAiList("Simulator->IO");
  94. if (aiItems != null)
  95. {
  96. AIs = new ObservableCollection<NotifiableIoItem>();
  97. foreach (var ioItem in aiItems)
  98. {
  99. NotifiableIoItem item = new NotifiableIoItem()
  100. {
  101. Name = ioItem.Name,
  102. Index = ioItem.Index,
  103. Description = ioItem.Description,
  104. ShortValue = ioItem.Value,
  105. Address = ioItem.Addr,
  106. BlockOffset = ioItem.BlockOffset,
  107. BlockIndex = ioItem.Index,
  108. };
  109. AIs.Add(item);
  110. }
  111. }
  112. }
  113. if (AOs == null)
  114. {
  115. List<AOAccessor> aoItems = IOs.GetAoList("Simulator->IO");
  116. if (aoItems != null)
  117. {
  118. AOs = new ObservableCollection<NotifiableIoItem>();
  119. foreach (var ioItem in aoItems)
  120. {
  121. NotifiableIoItem item = new NotifiableIoItem()
  122. {
  123. Name = ioItem.Name,
  124. Index = ioItem.Index,
  125. Description = ioItem.Description,
  126. ShortValue = ioItem.Value,
  127. Address = ioItem.Addr,
  128. BlockOffset = ioItem.BlockOffset,
  129. BlockIndex = ioItem.Index,
  130. };
  131. AOs.Add(item);
  132. }
  133. }
  134. }
  135. return true;
  136. }
  137. private void CheckBox_Checked(object sender, RoutedEventArgs e)
  138. {
  139. IOs.DO[GetDOName(e)].Value = true;
  140. //DOAccessor do1 = IoManager.Instance.GetIO<DOAccessor>(GetDOName(e));
  141. //string reason = "";
  142. //bool flag = do1.SetValue(true,out reason);
  143. }
  144. private void CheckBox_UnChecked(object sender, RoutedEventArgs e)
  145. {
  146. IOs.DO[GetDOName(e)].Value = false;
  147. //DOAccessor do1 = IoManager.Instance.GetIO<DOAccessor>(GetDOName(e));
  148. //string reason = "";
  149. //bool flag = do1.SetValue(true,out reason);
  150. }
  151. private string GetDOName(RoutedEventArgs e) => ((NotifiableIoItem)((CheckBox)e.OriginalSource).DataContext).Name;
  152. }
  153. }