WagoView.xaml.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using Aitex.Core.UI.MVVM;
  2. using Aitex.Core.Utilities;
  3. using CyberX8_Simulator.Devices;
  4. using MECF.Framework.Simulator.Core.Commons;
  5. using MECF.Framework.Simulator.Core.Driver;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Navigation;
  20. using System.Windows.Shapes;
  21. namespace CyberX8_Simulator.Views
  22. {
  23. /// <summary>
  24. /// WagoView.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class WagoView : UserControl
  27. {
  28. public WagoView()
  29. {
  30. InitializeComponent();
  31. this.Loaded += OnViewLoaded;
  32. }
  33. private void OnViewLoaded(object sender, RoutedEventArgs e)
  34. {
  35. (DataContext as TimerViewModelBase)?.Start();
  36. }
  37. }
  38. class WagoViewModel : SocketDeviceViewModel
  39. {
  40. #region 属性
  41. public string Title
  42. {
  43. get { return "Wago Simulator"; }
  44. }
  45. private string _DOSelectedItem;
  46. [IgnorePropertyChange]
  47. public string DOSelectedItem
  48. {
  49. get
  50. {
  51. return _DOSelectedItem;
  52. }
  53. set
  54. {
  55. _DOSelectedItem = value;
  56. }
  57. }
  58. private int _DOInputValue;
  59. [IgnorePropertyChange]
  60. public int DOInputValue
  61. {
  62. get
  63. {
  64. return _DOInputValue;
  65. }
  66. set
  67. {
  68. _DOInputValue = value;
  69. }
  70. }
  71. private string _DISelectedItem;
  72. [IgnorePropertyChange]
  73. public string DISelectedItem
  74. {
  75. get
  76. {
  77. return _DISelectedItem;
  78. }
  79. set
  80. {
  81. _DISelectedItem = value;
  82. }
  83. }
  84. private int _DIInputValue;
  85. [IgnorePropertyChange]
  86. public int DIInputValue
  87. {
  88. get
  89. {
  90. return _DIInputValue;
  91. }
  92. set
  93. {
  94. _DIInputValue = value;
  95. }
  96. }
  97. private string _AOSelectedItem;
  98. [IgnorePropertyChange]
  99. public string AOSelectedItem
  100. {
  101. get
  102. {
  103. return _AOSelectedItem;
  104. }
  105. set
  106. {
  107. _AOSelectedItem = value;
  108. }
  109. }
  110. private short _AOInputValue;
  111. [IgnorePropertyChange]
  112. public short AOInputValue
  113. {
  114. get
  115. {
  116. return _AOInputValue;
  117. }
  118. set
  119. {
  120. _AOInputValue = value;
  121. }
  122. }
  123. private string _AISelectedItem;
  124. [IgnorePropertyChange]
  125. public string AISelectedItem
  126. {
  127. get
  128. {
  129. return _AISelectedItem;
  130. }
  131. set
  132. {
  133. _AISelectedItem = value;
  134. }
  135. }
  136. private short _AIInputValue;
  137. [IgnorePropertyChange]
  138. public short AIInputValue
  139. {
  140. get
  141. {
  142. return _AIInputValue;
  143. }
  144. set
  145. {
  146. _AIInputValue = value;
  147. }
  148. }
  149. #endregion
  150. public ObservableCollection<string> DONameItems { get; set; }
  151. public ObservableCollection<string> DINameItems { get; set; }
  152. public ObservableCollection<string> AONameItems { get; set; }
  153. public ObservableCollection<string> AINameItems { get; set; }
  154. public ObservableCollection<int> DigitalInputSelected { get; set; }
  155. private WagoSocketSimulator _sim;
  156. public ICommand SetDICommand { get; set; }
  157. public ICommand SetDOCommand { get; set; }
  158. public ICommand SetAICommand { get; set; }
  159. public ICommand SetAOCommand { get; set; }
  160. public WagoViewModel(string str) : base("WagoViewModel")
  161. {
  162. InitData();
  163. SetDICommand = new DelegateCommand<object>(SetDIAction);
  164. SetDOCommand = new DelegateCommand<object>(SetDOAction);
  165. SetAICommand = new DelegateCommand<object>(SetAIAction);
  166. SetAOCommand = new DelegateCommand<object>(SetAOAction);
  167. int.TryParse(str, out int port);
  168. _sim = new WagoSocketSimulator(port);
  169. Init(_sim);
  170. }
  171. private void SetDIAction(object obj)
  172. {
  173. _sim.UpdataDIBytes(DISelectedItem, DIInputValue);
  174. }
  175. private void SetDOAction(object obj)
  176. {
  177. _sim.UpdataDOBytes(DOSelectedItem, DOInputValue);
  178. }
  179. private void SetAIAction(object obj)
  180. {
  181. _sim.UpdataAIShorts(AISelectedItem, AIInputValue);
  182. }
  183. private void SetAOAction(object obj)
  184. {
  185. _sim.UpdataAOShorts(AOSelectedItem, AOInputValue);
  186. }
  187. private void InitData()
  188. {
  189. DigitalInputSelected = new ObservableCollection<int> { 0, 1 };
  190. DONameItems = new ObservableCollection<string>
  191. { "DO1","DO2","DO3","c_LoaderA_LS_Vacuum","DO4","DO5","DO6","DO7","DO8"
  192. ,"DO9","DO10","DO11","DO12","DO12","DO13","DO14","DO15","DO16","DO17","DO18",
  193. "c_LOADERA_DOOR_UNLOCK","DO20","DO21"};
  194. DINameItems = new ObservableCollection<string>
  195. { "r_Cassette_1_150","r_Cassette_1_100","r_DRIP_TRAY_FLUID_DETECTION"};
  196. AONameItems = new ObservableCollection<string> { "AO0", "AO1" };
  197. AINameItems = new ObservableCollection<string> { "r_LoaderA_LS_Vacuum_anlg", "AI1" };
  198. }
  199. }
  200. }