Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();
            if (null == Application.Current)
            {
                new System.Windows.Application();
            }
            mListBox.ItemsSource      = logs;
            mOpenMenuButton.Click    += mOpenMenuButton_Click;
            mSettingMenuButton.Click += mSettingMenuButton_Click;
            mApplication              = Application.Current;
            XDocument xml = XDocument.Load(Environment.CurrentDirectory + @"\configuration.xml");

            mPorts = (from Port in xml.Descendants("Port")
                      select new RTUSerialPort((from Slave in Port.Descendants("Slave")
                                                select new RTUSlave(byte.Parse(Slave.Attribute("SlaveId").Value), (from Parameter in Slave.Descendants("Parameter")
                                                                                                                   select new Parameter(Parameter.Attribute("Type").Value, ushort.Parse(Parameter.Attribute("Address").Value), Parameter.Attribute("Name").Value)).ToArray <Parameter>(), Slave.Attribute("SlaveName").Value)).ToArray <RTUSlave>(), Port.Attribute("PortName").Value, Port.Attribute("DisplayName").Value)).ToArray <RTUSerialPort>();
            Loaded += delegate
            {
                rowCount    = (int)Math.Floor(mVoltageGrid.ActualHeight / 320);
                columnCount = (int)Math.Floor(mVoltageGrid.ActualWidth / 320);
                PageCount   = 0;
                for (int i = 0; i < mPorts.Count(); i++)
                {
                    for (int j = 0; j < mPorts[i].mSlaves.Count(); j++)
                    {
                        PageCount++;
                    }
                }
                var x = PageCount / (rowCount * columnCount);
                var y = PageCount % (rowCount * columnCount);;
                PageCount = y > 0 ? x + 1 : x;
                for (int i = 0; i < rowCount; i++)
                {
                    mVoltageGrid.RowDefinitions.Add(new RowDefinition());
                }
                for (int i = 0; i < columnCount; i++)
                {
                    mVoltageGrid.ColumnDefinitions.Add(new ColumnDefinition());
                }
                JumpToPage(1);
                ConfigDialog dialog = new ConfigDialog(true);
                dialog.Owner = this;
                if (dialog.ShowDialog() == true)
                {
                    RtuHelper helper = new RtuHelper(mPorts, OnMessage, dialog.mBaudrate, dialog.mParity, dialog.mDataBits, dialog.mStopBit);
                }
                else
                {
                    RtuHelper helper = new RtuHelper(mPorts, OnMessage);
                }
            };
        }