123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.Util;
- namespace Aitex.Triton160.UI.Views
- {
- /// <summary>
- /// Interaction logic for IOView.xaml
- /// </summary>
- public partial class IOView : UserControl
- {
- private bool _isLoaded;
- Dictionary<string, ToggleButton> _dicDiButton = new Dictionary<string, ToggleButton>();
- Dictionary<string, ToggleButton> _dicDoButton = new Dictionary<string, ToggleButton>();
- Dictionary<string, CheckBox> _dicDoCheckBox = new Dictionary<string, CheckBox>();
- Dictionary<string, TextBlock> _dicAiTitle = new Dictionary<string, TextBlock>();
- Dictionary<string, Label> _dicAiValueAscii = new Dictionary<string, Label>();
- Dictionary<string, Label> _dicAiValueDecimal = new Dictionary<string, Label>();
- Dictionary<string, Label> _dicAiInputAscii = new Dictionary<string, Label>();
- Dictionary<string, TextBox> _dicAiInputDecimal = new Dictionary<string, TextBox>();
- Dictionary<string, Button> _dicAiButton = new Dictionary<string, Button>();
- Dictionary<string, Func<Int16, string>> _dicAiDisplayConverter = new Dictionary<string, Func<short, string>>();
- Dictionary<string, Func<string, Int16>> _dicAiSetPointConverter = new Dictionary<string, Func<string, short>>();
- Dictionary<string, TextBlock> _dicAoTitle = new Dictionary<string, TextBlock>();
- Dictionary<string, Label> _dicAoValueAscii = new Dictionary<string, Label>();
- Dictionary<string, Label> _dicAoValueDecimal = new Dictionary<string, Label>();
- Dictionary<string, Label> _dicAoInputAscii = new Dictionary<string, Label>();
- Dictionary<string, TextBox> _dicAoInputDecimal = new Dictionary<string, TextBox>();
- Dictionary<string, Button> _dicAoButton = new Dictionary<string, Button>();
- Dictionary<string, CheckBox> _dicAoCheckBox = new Dictionary<string, CheckBox>();
- public IOView()
- {
- InitializeComponent();
- this.Loaded += new RoutedEventHandler(IOView_Loaded);
- }
- void IOView_Loaded(object sender, RoutedEventArgs e)
- {
- if (_isLoaded)
- return;
- _isLoaded = true;
- InitDi();
- InitDo();
- InitAi();
- InitAo();
- }
- private void InitDi()
- {
- List<Tuple<int, int, string>> diList = Singleton<IOManager>.Instance.GetIONameList(IOType.DI);
- foreach (var item in diList)
- {
- ToggleButton btn = new ToggleButton();
- //btn.Click += new RoutedEventHandler(btn_Click);
- btn.Content = string.Format("DI-{0}: {1}", item.Item1, item.Item3.Substring(2));
- btn.Tag = item;
- btn.Height = 23;
- btn.Padding = new Thickness(2, 0, 0, 0);
- btn.Margin = new Thickness(5, 3, 0, 0);
- btn.Width = 250;
- btn.FontSize = 13;
- btn.Foreground = new SolidColorBrush(Colors.Black);
- btn.Focusable = false;
- btn.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
- btn.Background = new SolidColorBrush(Colors.LightGray);
- _dicDiButton[item.Item3] = btn;
- diPanel.Children.Add(btn);
- }
- }
- private void InitDo()
- {
- List<Tuple<int, int, string>> dOList = Singleton<IOManager>.Instance.GetIONameList(IOType.DO);
- foreach (var item in dOList)
- {
- StackPanel sp = new StackPanel();
- sp.Orientation = Orientation.Horizontal;
- Viewbox v = new Viewbox();
- v.Margin = new Thickness(-1);
- v.Width = 30;
- v.Height = 30;
- CheckBox cb = new CheckBox();
- cb.Tag = item;
- cb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
- //cb.Checked += new RoutedEventHandler(cb_Checked);
- //cb.Unchecked += new RoutedEventHandler(cb_Unchecked);
- cb.Margin = new Thickness(5, 0, 2, 0);
- _dicDoCheckBox[item.Item3] = cb;
- v.Child = cb;
- sp.Children.Add(v);
- ToggleButton btn = new ToggleButton();
- //btn.Click += new RoutedEventHandler(btn_Click);
- btn.Content = string.Format("DO-{0}: {1}", item.Item1, item.Item3.Substring(2));
- btn.Tag = item;
- btn.Height = 25;
- btn.Padding = new Thickness(2, 0, 0, 0);
- btn.Margin = new Thickness(0, 1, 0, 0);
- btn.Width = 250;
- btn.FontSize = 13;
- btn.Foreground = new SolidColorBrush(Colors.Black);
- btn.Focusable = false;
- btn.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left;
- btn.Background = new SolidColorBrush(Colors.LightGray);
- _dicDoButton[item.Item3] = btn;
- sp.Children.Add(btn);
- doPanel.Children.Add(sp);
- }
- }
- void InitAi()
- {
- List<Tuple<int, int, string>> diList = IO.GetIONameList(IOType.AI);
- foreach (var item in diList)
- {
- StackPanel sp = new StackPanel();
- sp.Orientation = Orientation.Vertical;
- sp.Margin = new Thickness(5, 5, 0, 0);
- sp.Background = new SolidColorBrush(Colors.LightGray);
- sp.Width = 240;
- sp.Height = 90;
- //----------------Line 1
- TextBlock tb = new TextBlock();
- tb.Text = string.Format("AI-{0}: {1}", item.Item1, item.Item3.Substring(3));
- tb.Tag = item;
- tb.Height = 25;
- tb.Margin = new Thickness(2, 5, 0, 0);
- tb.Padding = new Thickness(3, 0, 0, 0);
- tb.TextAlignment = TextAlignment.Left;
- tb.FontSize = 13;
- tb.Width = 240;
- _dicAiTitle[item.Item3] = tb;
- sp.Children.Add(tb);
- //--------------Line 2
- StackPanel sp1 = new StackPanel();
- sp1.Orientation = Orientation.Horizontal;
- Label lb = new Label();
- lb.BorderThickness = new Thickness(1);
- lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
- lb.Width = 80;
- lb.Height = 25;
- lb.FontSize = 13;
- lb.Tag = item;
- lb.Margin = new Thickness(2, 2, 0, 0);
- _dicAiValueAscii[item.Item3] = lb;
- sp1.Children.Add(lb);
- lb = new Label();
- lb.BorderThickness = new Thickness(1);
- lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
- lb.Width = 80;
- lb.Height = 25;
- lb.FontSize = 13;
- lb.Tag = item;
- lb.Margin = new Thickness(2, 2, 0, 0);
- _dicAiValueDecimal[item.Item3] = lb;
- sp1.Children.Add(lb);
- sp.Children.Add(sp1);
- //--------------Line 3
- StackPanel sp2 = new StackPanel();
- sp2.Orientation = Orientation.Horizontal;
- lb = new Label();
- lb.BorderThickness = new Thickness(1);
- lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
- lb.Width = 80;
- lb.Height = 25;
- lb.FontSize = 13;
- lb.Tag = item;
- lb.Margin = new Thickness(2, 2, 0, 0);
- _dicAiInputAscii[item.Item3] = lb;
- sp2.Children.Add(lb);
- TextBox text = new TextBox();
- text.Tag = item;
- text.Width = 80;
- text.Height = 25;
- text.Margin = new Thickness(2, 2, 0, 0);
- //text.PreviewKeyDown += new KeyEventHandler(text_PreviewKeyDown);
- //text.PreviewTextInput += new TextCompositionEventHandler(text_PreviewTextInput);
- _dicAiInputDecimal[item.Item3] = text;
- sp2.Children.Add(text);
- Button btn = new Button();
- //btn.Click += new RoutedEventHandler(btn_Click);
- btn.Content = "设置";
- btn.Tag = item;
- btn.Height = 25;
- btn.Padding = new Thickness(2, 0, 0, 0);
- btn.Margin = new Thickness(3, 1, 0, 0);
- btn.Width = 60;
- btn.FontSize = 13;
- btn.Focusable = false;
- _dicAiButton[item.Item3] = btn;
- sp2.Children.Add(btn);
- sp.Children.Add(sp2);
- aiPanel.Children.Add(sp);
- }
- }
- void InitAo( )
- {
- List<Tuple<int, int, string>> diList = Singleton<IOManager>.Instance.GetIONameList(IOType.AO);
- foreach (var item in diList)
- {
- StackPanel sp = new StackPanel();
- sp.Orientation = Orientation.Vertical;
- sp.Margin = new Thickness(5, 5, 0, 0);
- sp.Background = new SolidColorBrush(Colors.LightGray);
- sp.Width = 240;
- sp.Height = 90;
- //----------------Line 1
- StackPanel sp0 = new StackPanel();
- sp0.Orientation = Orientation.Horizontal;
- Viewbox v = new Viewbox();
- //v.Margin = new Thickness(-1);
- v.Width = 30;
- v.Height = 30;
- CheckBox cb = new CheckBox();
- cb.Tag = item;
- cb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
- //cb.Checked += new RoutedEventHandler(cb_Checked);
- //cb.Unchecked += new RoutedEventHandler(cb_Unchecked);
- cb.Margin = new Thickness(5, 0, 2, 0);
- _dicAoCheckBox[item.Item3] = cb;
- v.Child = cb;
- sp0.Children.Add(v);
- TextBlock tb = new TextBlock();
- tb.Text = string.Format("AO-{0}: {1}", item.Item1, item.Item3.Substring(3));
- tb.Tag = item;
- tb.Height = 25;
- tb.Margin = new Thickness(2, 5, 0, 0);
- tb.Padding = new Thickness(3, 0, 0, 0);
- tb.TextAlignment = TextAlignment.Left;
- tb.FontSize = 13;
- tb.Width = 240;
- sp0.Children.Add(tb);
- sp.Children.Add(sp0);
- //--------------Line 2
- StackPanel sp1 = new StackPanel();
- sp1.Orientation = Orientation.Horizontal;
- Label lb = new Label();
- lb.BorderThickness = new Thickness(1);
- lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
- lb.Width = 80;
- lb.Height = 25;
- lb.FontSize = 13;
- lb.Tag = item;
- lb.Margin = new Thickness(2, 2, 0, 0);
- _dicAoValueAscii[item.Item3] = lb;
- sp1.Children.Add(lb);
- lb = new Label();
- lb.BorderThickness = new Thickness(1);
- lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
- lb.Width = 80;
- lb.Height = 25;
- lb.FontSize = 13;
- lb.Tag = item;
- lb.Margin = new Thickness(2, 2, 0, 0);
- _dicAoValueDecimal[item.Item3] = lb;
- sp1.Children.Add(lb);
- sp.Children.Add(sp1);
- //--------------Line 3
- StackPanel sp2 = new StackPanel();
- sp2.Orientation = Orientation.Horizontal;
- lb = new Label();
- lb.BorderThickness = new Thickness(1);
- lb.BorderBrush = new SolidColorBrush(Colors.DimGray);
- lb.Width = 80;
- lb.Height = 25;
- lb.FontSize = 13;
- lb.Tag = item;
- lb.Margin = new Thickness(2, 2, 0, 0);
- _dicAoInputAscii[item.Item3] = lb;
- sp2.Children.Add(lb);
- TextBox text = new TextBox();
- text.Tag = item;
- text.Width = 80;
- text.Height = 25;
- text.Margin = new Thickness(2, 2, 0, 0);
- _dicAoInputDecimal[item.Item3] = text;
- sp2.Children.Add(text);
- Button btn = new Button();
- //btn.Click += new RoutedEventHandler(btn_Click);
- btn.Content = "设置";
- btn.Tag = item;
- btn.Height = 25;
- btn.Padding = new Thickness(2, 0, 0, 0);
- btn.Margin = new Thickness(3, 1, 0, 0);
- btn.Width = 60;
- btn.FontSize = 13;
- btn.Focusable = false;
- btn.IsEnabled = false;
- _dicAoButton[item.Item3] = btn;
- sp2.Children.Add(btn);
- sp.Children.Add(sp2);
- aoPanel.Children.Add(sp);
- }
- }
- }
- }
|