Esempio n. 1
0
        private async void _connectButton_Click(object sender, EventArgs e)
        {
            _panelControl.Controls.Clear();
            ConnectionManager.Connection = new ComConnection(Convert.ToByte(ConnectionManager.SelectedPort));
            if (ConnectionManager.Connection.TryOpenConnection())
            {
                try
                {
                    _deviceSpecification = await _deiceManager.IdentifyDevice(Convert.ToByte(_deviceNumberTextBox.Text));
                }
                catch (Exception exception)
                {
                    MessageErrorBox message = new MessageErrorBox(exception.Message, "Не удолось подключиться к устройству");
                    message.ShowErrorMessageForm();
                    return;
                }
                if (_deviceSpecification is UnknownDeviceSpecification)
                {
                    if (_deiceManager.GetdeviceName != String.Empty)
                    {
                        MessageBox.Show(String.Format("Работа с {0} невозможна", _deiceManager.GetdeviceName));
                    }
                    else
                    {
                        MessageBox.Show("Работа с подключенным устройством невозможна");
                    }
                }

                else
                {
                    await SetControl();
                }
            }
            _readInformationButton.Enabled = true;
        }
Esempio n. 2
0
        private async Task RefreshModule(int modulenumber)
        {
            try
            {
                ModuleInformation moduleInformation = await _moduleManager.ReadModuleInformation(_deviceSpecification,
                                                                                                 Convert.ToByte(_deviceNumberTextBox.Text), modulenumber);

                if (_deviceSpecification.ControlType == ControlType.MRTYPE)
                {
                    MrModuleControl control = _panelControl.Controls[modulenumber] as MrModuleControl;
                    control.Information = moduleInformation;
                }
                else
                {
                    ModuleControl control = _panelControl.Controls[modulenumber] as ModuleControl;
                    control.Information = moduleInformation;
                }
            }
            catch (Exception e)
            {
                MessageErrorBox message = new MessageErrorBox(e.Message, "Не удалось прочитать информацию о модуле");
                message.ShowErrorMessageForm();
                _panelControl.Controls.Remove(_panelControl.Controls[modulenumber]);
            }
        }
Esempio n. 3
0
        private async Task WriteToDevice()
        {
            _writeButtonState = WriteButtonState.STOP;
            _cancellationTokenSource?.Dispose();
            _cancellationTokenSource = new CancellationTokenSource();
            int i = 0;

            //_writeToDeviceButton.Enabled = false;

            foreach (Control control in _panelControl.Controls)
            {
                IModuleControlInerface c = control as IModuleControlInerface;
                if (c != null)
                {
                    if (!_cancellationTokenSource.Token.IsCancellationRequested)
                    {
                        try
                        {
                            await c.WriteFile();
                            await RefreshModule(i);
                        }
                        catch (Exception e)
                        {
                            if (_deviceSpecification.ControlType == ControlType.MRTYPE)
                            {
                                MessageErrorBox messageErrorBox =
                                    new MessageErrorBox(e.Message,
                                                        "Неудалось записать файл прошивки" + Environment.NewLine + "Продолжить запись");
                                if (!messageErrorBox.ShowErrorMessageForm())
                                {
                                    _writeButtonState            = WriteButtonState.WRITE;
                                    _writeToDeviceButton.Text    = "Записать в устройство";
                                    _writeToDeviceButton.Enabled = true;
                                    return;
                                }
                            }
                            else
                            {
                                MessageErrorBox messageErrorBox =
                                    new MessageErrorBox(e.Message, "Неудалось записать файл прошивки");
                                messageErrorBox.ShowErrorMessageForm();
                                _writeButtonState            = WriteButtonState.WRITE;
                                _writeToDeviceButton.Text    = "Записать в устройство";
                                _writeToDeviceButton.Enabled = true;
                            }
                        }
                        finally
                        {
                            await RefreshModule(i);

                            i++;
                        }
                    }
                }
            }
            _writeButtonState            = WriteButtonState.WRITE;
            _writeToDeviceButton.Text    = "Записать в устройство";
            _writeToDeviceButton.Enabled = true;
            MessageBox.Show("Запись файлов в устройство завершена");
        }
Esempio n. 4
0
        private async Task SetMrModuleControl()
        {
            _panelControl.Controls.Clear();
            int y = 0;

            try
            {
                for (int i = 0; i < _deviceSpecification.ModulesCount; i++)
                {
                    MrModuleControl   control           = new MrModuleControl();
                    ModuleInformation moduleInformation = await _moduleManager.ReadModuleInformation(_deviceSpecification, Convert.ToByte(_deviceNumberTextBox.Text), i);

                    control.Information = moduleInformation;
                    control.Anchor      = (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top);
                    control.TypeModule  = _deviceSpecification.ModuleTypes[i];
                    control.Location    = new Point(0, y);
                    control.Width       = _panelControl.Width;
                    _panelControl.Controls.Add(control);
                    y = y + control.Height;
                    (control as IModuleControlInerface).NeedRefreshAction += (j) =>
                    {
                        RefreshModule(j);
                    };
                }
            }
            catch (Exception e)
            {
                MessageErrorBox message = new MessageErrorBox(e.Message, "Не удалось прочитать информацию о модулях");
                message.ShowErrorMessageForm();
            }
        }