IOView.xaml.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Controls.Primitives;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using Aitex.Core.RT.IOCore;
  16. using Aitex.Core.Util;
  17. namespace Aitex.Triton160.UI.Views
  18. {
  19. /// <summary>
  20. /// Interaction logic for IOView.xaml
  21. /// </summary>
  22. public partial class IOView : UserControl
  23. {
  24. private bool _isLoaded;
  25. Dictionary<string, ToggleButton> _dicDiButton = new Dictionary<string, ToggleButton>();
  26. Dictionary<string, ToggleButton> _dicDoButton = new Dictionary<string, ToggleButton>();
  27. Dictionary<string, CheckBox> _dicDoCheckBox = new Dictionary<string, CheckBox>();
  28. Dictionary<string, TextBlock> _dicAiTitle = new Dictionary<string, TextBlock>();
  29. Dictionary<string, Label> _dicAiValueAscii = new Dictionary<string, Label>();
  30. Dictionary<string, Label> _dicAiValueDecimal = new Dictionary<string, Label>();
  31. Dictionary<string, Label> _dicAiInputAscii = new Dictionary<string, Label>();
  32. Dictionary<string, TextBox> _dicAiInputDecimal = new Dictionary<string, TextBox>();
  33. Dictionary<string, Button> _dicAiButton = new Dictionary<string, Button>();
  34. Dictionary<string, Func<Int16, string>> _dicAiDisplayConverter = new Dictionary<string, Func<short, string>>();
  35. Dictionary<string, Func<string, Int16>> _dicAiSetPointConverter = new Dictionary<string, Func<string, short>>();
  36. Dictionary<string, TextBlock> _dicAoTitle = new Dictionary<string, TextBlock>();
  37. Dictionary<string, Label> _dicAoValueAscii = new Dictionary<string, Label>();
  38. Dictionary<string, Label> _dicAoValueDecimal = new Dictionary<string, Label>();
  39. Dictionary<string, Label> _dicAoInputAscii = new Dictionary<string, Label>();
  40. Dictionary<string, TextBox> _dicAoInputDecimal = new Dictionary<string, TextBox>();
  41. Dictionary<string, Button> _dicAoButton = new Dictionary<string, Button>();
  42. Dictionary<string, CheckBox> _dicAoCheckBox = new Dictionary<string, CheckBox>();
  43. public IOView()
  44. {
  45. InitializeComponent();
  46. this.Loaded += new RoutedEventHandler(IOView_Loaded);
  47. }
  48. void IOView_Loaded(object sender, RoutedEventArgs e)
  49. {
  50. if (_isLoaded)
  51. return;
  52. _isLoaded = true;
  53. InitDi();
  54. InitDo();
  55. InitAi();
  56. InitAo();
  57. }
  58. private void InitDi()
  59. {
  60. List<Tuple<int, int, string>> diList = Singleton<IOManager>.Instance.GetIONameList(IOType.DI);
  61. foreach (var item in diList)
  62. {
  63. ToggleButton btn = new ToggleButton();
  64. //btn.Click += new RoutedEventHandler(btn_Click);
  65. btn.Content = string.Format("DI-{0}: {1}", item.Item1, item.Item3.Substring(2));
  66. btn.Tag = item;
  67. btn.Height = 23;
  68. btn.Padding = new Thickness(2, 0, 0, 0);
  69. btn.Margin = new Thickness(5, 3, 0, 0);
  70. btn.Width = 250;
  71. btn.FontSize = 13;
  72. btn.Foreground = new SolidColorBrush(Colors.Black);
  73. btn.Focusable = false;
  74. btn.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
  75. btn.Background = new SolidColorBrush(Colors.LightGray);
  76. _dicDiButton[item.Item3] = btn;
  77. diPanel.Children.Add(btn);
  78. }
  79. }
  80. private void InitDo()
  81. {
  82. List<Tuple<int, int, string>> dOList = Singleton<IOManager>.Instance.GetIONameList(IOType.DO);
  83. foreach (var item in dOList)
  84. {
  85. StackPanel sp = new StackPanel();
  86. sp.Orientation = Orientation.Horizontal;
  87. Viewbox v = new Viewbox();
  88. v.Margin = new Thickness(-1);
  89. v.Width = 30;
  90. v.Height = 30;
  91. CheckBox cb = new CheckBox();
  92. cb.Tag = item;
  93. cb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
  94. //cb.Checked += new RoutedEventHandler(cb_Checked);
  95. //cb.Unchecked += new RoutedEventHandler(cb_Unchecked);
  96. cb.Margin = new Thickness(5, 0, 2, 0);
  97. _dicDoCheckBox[item.Item3] = cb;
  98. v.Child = cb;
  99. sp.Children.Add(v);
  100. ToggleButton btn = new ToggleButton();
  101. //btn.Click += new RoutedEventHandler(btn_Click);
  102. btn.Content = string.Format("DO-{0}: {1}", item.Item1, item.Item3.Substring(2));
  103. btn.Tag = item;
  104. btn.Height = 25;
  105. btn.Padding = new Thickness(2, 0, 0, 0);
  106. btn.Margin = new Thickness(0, 1, 0, 0);
  107. btn.Width = 250;
  108. btn.FontSize = 13;
  109. btn.Foreground = new SolidColorBrush(Colors.Black);
  110. btn.Focusable = false;
  111. btn.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
  112. btn.Background = new SolidColorBrush(Colors.LightGray);
  113. _dicDoButton[item.Item3] = btn;
  114. sp.Children.Add(btn);
  115. doPanel.Children.Add(sp);
  116. }
  117. }
  118. void InitAi()
  119. {
  120. List<Tuple<int, int, string>> diList = IO.GetIONameList(IOType.AI);
  121. foreach (var item in diList)
  122. {
  123. StackPanel sp = new StackPanel();
  124. sp.Orientation = Orientation.Vertical;
  125. sp.Margin = new Thickness(5, 5, 0, 0);
  126. sp.Background = new SolidColorBrush(Colors.LightGray);
  127. sp.Width = 240;
  128. sp.Height = 90;
  129. //----------------Line 1
  130. TextBlock tb = new TextBlock();
  131. tb.Text = string.Format("AI-{0}: {1}", item.Item1, item.Item3.Substring(3));
  132. tb.Tag = item;
  133. tb.Height = 25;
  134. tb.Margin = new Thickness(2, 5, 0, 0);
  135. tb.Padding = new Thickness(3, 0, 0, 0);
  136. tb.TextAlignment = TextAlignment.Left;
  137. tb.FontSize = 13;
  138. tb.Width = 240;
  139. _dicAiTitle[item.Item3] = tb;
  140. sp.Children.Add(tb);
  141. //--------------Line 2
  142. StackPanel sp1 = new StackPanel();
  143. sp1.Orientation = Orientation.Horizontal;
  144. Label lb = new Label();
  145. lb.BorderThickness = new Thickness(1);
  146. lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
  147. lb.Width = 80;
  148. lb.Height = 25;
  149. lb.FontSize = 13;
  150. lb.Tag = item;
  151. lb.Margin = new Thickness(2, 2, 0, 0);
  152. _dicAiValueAscii[item.Item3] = lb;
  153. sp1.Children.Add(lb);
  154. lb = new Label();
  155. lb.BorderThickness = new Thickness(1);
  156. lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
  157. lb.Width = 80;
  158. lb.Height = 25;
  159. lb.FontSize = 13;
  160. lb.Tag = item;
  161. lb.Margin = new Thickness(2, 2, 0, 0);
  162. _dicAiValueDecimal[item.Item3] = lb;
  163. sp1.Children.Add(lb);
  164. sp.Children.Add(sp1);
  165. //--------------Line 3
  166. StackPanel sp2 = new StackPanel();
  167. sp2.Orientation = Orientation.Horizontal;
  168. lb = new Label();
  169. lb.BorderThickness = new Thickness(1);
  170. lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
  171. lb.Width = 80;
  172. lb.Height = 25;
  173. lb.FontSize = 13;
  174. lb.Tag = item;
  175. lb.Margin = new Thickness(2, 2, 0, 0);
  176. _dicAiInputAscii[item.Item3] = lb;
  177. sp2.Children.Add(lb);
  178. TextBox text = new TextBox();
  179. text.Tag = item;
  180. text.Width = 80;
  181. text.Height = 25;
  182. text.Margin = new Thickness(2, 2, 0, 0);
  183. //text.PreviewKeyDown += new KeyEventHandler(text_PreviewKeyDown);
  184. //text.PreviewTextInput += new TextCompositionEventHandler(text_PreviewTextInput);
  185. _dicAiInputDecimal[item.Item3] = text;
  186. sp2.Children.Add(text);
  187. Button btn = new Button();
  188. //btn.Click += new RoutedEventHandler(btn_Click);
  189. btn.Content = "设置";
  190. btn.Tag = item;
  191. btn.Height = 25;
  192. btn.Padding = new Thickness(2, 0, 0, 0);
  193. btn.Margin = new Thickness(3, 1, 0, 0);
  194. btn.Width = 60;
  195. btn.FontSize = 13;
  196. btn.Focusable = false;
  197. _dicAiButton[item.Item3] = btn;
  198. sp2.Children.Add(btn);
  199. sp.Children.Add(sp2);
  200. aiPanel.Children.Add(sp);
  201. }
  202. }
  203. void InitAo( )
  204. {
  205. List<Tuple<int, int, string>> diList = Singleton<IOManager>.Instance.GetIONameList(IOType.AO);
  206. foreach (var item in diList)
  207. {
  208. StackPanel sp = new StackPanel();
  209. sp.Orientation = Orientation.Vertical;
  210. sp.Margin = new Thickness(5, 5, 0, 0);
  211. sp.Background = new SolidColorBrush(Colors.LightGray);
  212. sp.Width = 240;
  213. sp.Height = 90;
  214. //----------------Line 1
  215. StackPanel sp0 = new StackPanel();
  216. sp0.Orientation = Orientation.Horizontal;
  217. Viewbox v = new Viewbox();
  218. //v.Margin = new Thickness(-1);
  219. v.Width = 30;
  220. v.Height = 30;
  221. CheckBox cb = new CheckBox();
  222. cb.Tag = item;
  223. cb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
  224. //cb.Checked += new RoutedEventHandler(cb_Checked);
  225. //cb.Unchecked += new RoutedEventHandler(cb_Unchecked);
  226. cb.Margin = new Thickness(5, 0, 2, 0);
  227. _dicAoCheckBox[item.Item3] = cb;
  228. v.Child = cb;
  229. sp0.Children.Add(v);
  230. TextBlock tb = new TextBlock();
  231. tb.Text = string.Format("AO-{0}: {1}", item.Item1, item.Item3.Substring(3));
  232. tb.Tag = item;
  233. tb.Height = 25;
  234. tb.Margin = new Thickness(2, 5, 0, 0);
  235. tb.Padding = new Thickness(3, 0, 0, 0);
  236. tb.TextAlignment = TextAlignment.Left;
  237. tb.FontSize = 13;
  238. tb.Width = 240;
  239. sp0.Children.Add(tb);
  240. sp.Children.Add(sp0);
  241. //--------------Line 2
  242. StackPanel sp1 = new StackPanel();
  243. sp1.Orientation = Orientation.Horizontal;
  244. Label lb = new Label();
  245. lb.BorderThickness = new Thickness(1);
  246. lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
  247. lb.Width = 80;
  248. lb.Height = 25;
  249. lb.FontSize = 13;
  250. lb.Tag = item;
  251. lb.Margin = new Thickness(2, 2, 0, 0);
  252. _dicAoValueAscii[item.Item3] = lb;
  253. sp1.Children.Add(lb);
  254. lb = new Label();
  255. lb.BorderThickness = new Thickness(1);
  256. lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
  257. lb.Width = 80;
  258. lb.Height = 25;
  259. lb.FontSize = 13;
  260. lb.Tag = item;
  261. lb.Margin = new Thickness(2, 2, 0, 0);
  262. _dicAoValueDecimal[item.Item3] = lb;
  263. sp1.Children.Add(lb);
  264. sp.Children.Add(sp1);
  265. //--------------Line 3
  266. StackPanel sp2 = new StackPanel();
  267. sp2.Orientation = Orientation.Horizontal;
  268. lb = new Label();
  269. lb.BorderThickness = new Thickness(1);
  270. lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
  271. lb.Width = 80;
  272. lb.Height = 25;
  273. lb.FontSize = 13;
  274. lb.Tag = item;
  275. lb.Margin = new Thickness(2, 2, 0, 0);
  276. _dicAoInputAscii[item.Item3] = lb;
  277. sp2.Children.Add(lb);
  278. TextBox text = new TextBox();
  279. text.Tag = item;
  280. text.Width = 80;
  281. text.Height = 25;
  282. text.Margin = new Thickness(2, 2, 0, 0);
  283. _dicAoInputDecimal[item.Item3] = text;
  284. sp2.Children.Add(text);
  285. Button btn = new Button();
  286. //btn.Click += new RoutedEventHandler(btn_Click);
  287. btn.Content = "设置";
  288. btn.Tag = item;
  289. btn.Height = 25;
  290. btn.Padding = new Thickness(2, 0, 0, 0);
  291. btn.Margin = new Thickness(3, 1, 0, 0);
  292. btn.Width = 60;
  293. btn.FontSize = 13;
  294. btn.Focusable = false;
  295. btn.IsEnabled = false;
  296. _dicAoButton[item.Item3] = btn;
  297. sp2.Children.Add(btn);
  298. sp.Children.Add(sp2);
  299. aoPanel.Children.Add(sp);
  300. }
  301. }
  302. }
  303. }