Example #1
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("Запись файлов в устройство завершена");
        }
Example #2
0
 public MainForm()
 {
     InitializeComponent();
     SetVersionInformation();
     _writeButtonState           = WriteButtonState.WRITE;
     _deiceManager               = new DevicesManager();
     DevicesManager.DeviceNumber = Convert.ToByte(_deviceNumberTextBox.Text);
     _moduleManager              = new ModuleManager();
     _queryProgress              = new Progress <QueryReport>(OnQueryProgressChanged);
     ConnectionManager.Progress  = _queryProgress;
 }
Example #3
0
 public MainForm()
 {
     InitializeComponent();
     SetVersionInformation();
     _writeButtonState              = WriteButtonState.WRITE;
     _deiceManager                  = new DevicesManager();
     DevicesManager.DeviceNumber    = Convert.ToByte(_deviceNumberTextBox.Text);
     _moduleManager                 = new ModuleManager();
     _queryProgress                 = new Progress <QueryReport>(OnQueryProgressChanged);
     ConnectionManager.SelectedPort = Settings.Default.Port.ToString();
     ConnectionManager.Progress     = _queryProgress;
     _comportLable.Text             = "COM" + ConnectionManager.SelectedPort;
 }