private async void readFlashButton_Click(object sender, EventArgs e) { string[] filename; if (!(_saveFileDialogFlash.FileName == String.Empty)) { filename = _saveFileDialogFlash.FileName.Split('\\'); _saveFileDialogFlash.FileName = filename[filename.Length - 1]; } else { _saveFileDialogFlash.FileName = String.Empty; } if (this._saveFileDialogFlash.ShowDialog() == DialogResult.OK) { ModuleWritterController controller = new ModuleWritterController(this._moduleInformation, TypeOfMemory.BOOT_FLASH, DevicesManager.DeviceNumber, (ushort)Convert.ToUInt16(_startReadPage.Text), (ushort)Convert.ToUInt16(_countReadPage.Text)); try { byte[] result = await controller.ReadPage(progressFlash); Common.SwapArrayItems(ref result); File.WriteAllBytes(this._saveFileDialogFlash.FileName, result); MessageBox.Show("Файл успешно сохранен"); } catch (Exception exception) { MessageErrorBox messageErrorBox = new MessageErrorBox(exception.Message, "Неудалось прочитать файл Flash"); messageErrorBox.ShowErrorMessageForm(); } } }
private async void _readDiscretRelayButton1_Click(object sender, EventArgs e) { string[] filename; if (!(_saveFileDialogRelayDiscret.FileName == String.Empty)) { filename = _saveFileDialogRelayDiscret.FileName.Split('\\'); _saveFileDialogRelayDiscret.FileName = filename[filename.Length - 1]; } else { _saveFileDialogRelayDiscret.FileName = String.Empty; } if (this._saveFileDialogRelayDiscret.ShowDialog() == DialogResult.OK) { this._relayDiscretCheckBox.Text = this._saveFileDialogRelayDiscret.FileName; ModuleWritterController controller = new ModuleWritterController(this._moduleInformation, TypeOfMemory.RALAY_DISCRET, DevicesManager.DeviceNumber); try { byte[] result = await controller.ReadPage(progressRelay); Common.SwapArrayItems(ref result); File.WriteAllBytes(this._saveFileDialogRelayDiscret.FileName, result); MessageBox.Show("Файл успешно сохранен"); } catch (Exception exception) { MessageErrorBox messageErrorBox = new MessageErrorBox(exception.Message, "Неудалось прочитать файл"); messageErrorBox.ShowErrorMessageForm(); } } }
public async Task WriteFile() { if (_workProgramCheckBox.Checked) { ModuleWritterController controller = new ModuleWritterController(this._moduleInformation, TypeOfMemory.WORK, DevicesManager.DeviceNumber, _data); try { await controller.StartSave(progressWork); } catch (Exception e) { throw new Exception(e.Message); } } if (_eepromCheckBox.Checked) { ModuleWritterController controller = new ModuleWritterController(this._moduleInformation, TypeOfMemory.EEPROM, DevicesManager.DeviceNumber, _dataEeprom); try { await controller.StartSaveForAnotherMemmoryType(progressEProm); _eepromCheckBox.Checked = false; } catch (Exception e) { throw new Exception(e.Message); } } if (_relayDiscretCheckBox.Checked) { ModuleWritterController controller = new ModuleWritterController(this._moduleInformation, TypeOfMemory.RALAY_DISCRET, DevicesManager.DeviceNumber, _dataDiscretRelay); try { await controller.StartSaveForAnotherMemmoryType(progressRelay); _relayDiscretCheckBox.Checked = false; } catch (Exception e) { throw new Exception(e.Message); } } if (_flashCheckBox.Checked) { ModuleWritterController controller = new ModuleWritterController(this._moduleInformation, TypeOfMemory.BOOT_FLASH, DevicesManager.DeviceNumber, _dataFlash, (ushort)Convert.ToUInt16(_startReadPage.Text), (ushort)Convert.ToUInt16(_countReadPage.Text)); try { await controller.StartSaveForAnotherMemmoryType(progressFlash); } catch (Exception e) { throw new Exception(e.Message); } } }
private async void _clearModuleButton_Click(object sender, EventArgs e) { try { await ModuleWritterController.ClearModule(_moduleInformation); NeedRefreshAction?.Invoke(_moduleInformation.ModulePosition); } catch (Exception exception) { MessageBox.Show("Не удалось очистить модуль"); NeedRefreshAction?.Invoke(_moduleInformation.ModulePosition); } }
private async void _toWorkStateButton_Click(object sender, EventArgs e) { try { await ModuleWritterController.ModuleToWork(_moduleInformation); MessageBox.Show("Модуль переведен в рабочий режим"); NeedRefreshAction?.Invoke(_moduleInformation.ModulePosition); } catch (Exception exception) { MessageBox.Show("Не удалось перевести в рабочий режим"); NeedRefreshAction?.Invoke(_moduleInformation.ModulePosition); } }
public async Task WriteFile() { if (this._workProgramCheckFile.Checked) { ModuleWritterController moduleWritter = new ModuleWritterController(this.Information, TypeOfMemory.WORK, DevicesManager.DeviceNumber, this._data); try { await moduleWritter.StartSave(_progressBarReport); } catch (Exception e) { this.State = ModuleStates.ERROR_WRITEFILE_TO_MODULE; throw new Exception(e.Message); } } }
private async void _writeFlashButton_Click(object sender, EventArgs e) { try { ModuleWritterController controller = new ModuleWritterController(this._moduleInformation, TypeOfMemory.BOOT_FLASH, DevicesManager.DeviceNumber, _dataFlash, (ushort)Convert.ToUInt16(_startReadPage.Text), (ushort)Convert.ToUInt16(_countReadPage.Text)); await controller.StartSaveForAnotherMemmoryType(progressFlash); _flashCheckBox.Checked = false; MessageBox.Show("Запись файла завершена"); } catch (Exception exception) { MessageErrorBox messageErrorBox = new MessageErrorBox(exception.Message, "Неудалось записать файл Flash"); messageErrorBox.ShowErrorMessageForm(); } }
private async void _writeDiscretRelayButton_Click(object sender, EventArgs e) { try { ModuleWritterController controller = new ModuleWritterController(this._moduleInformation, TypeOfMemory.RALAY_DISCRET, DevicesManager.DeviceNumber, _dataDiscretRelay); await controller.StartSaveForAnotherMemmoryType(progressEProm); _relayDiscretCheckBox.Checked = false; MessageBox.Show("Запись файла завершена"); } catch (Exception exception) { MessageErrorBox messageErrorBox = new MessageErrorBox(exception.Message, "Неудалось записать файл "); messageErrorBox.ShowErrorMessageForm(); } }
private async void _toWorkState_Click(object sender, EventArgs e) { try { await ModuleWritterController.ModuleMLKToWork(_moduleInformation); await Task.Delay(1500); ConnectionManager.Connection.Serialport.BaudRate = 115200; MessageBox.Show("Запрос на перевод модуля в рабочий режим отправлен"); NeedRefreshAction?.Invoke(_moduleInformation.ModulePosition); } catch (Exception exception) { MessageErrorBox messageErrorBox = new MessageErrorBox(exception.Message, "Ошибка перевода в режим загрузчика"); messageErrorBox.ShowErrorMessageForm(); } }
private async void _chooseFile_Click(object sender, EventArgs e) { switch (State) { case ModuleStates.ERROR_WORK_STRING: { //this.SetFilePath(); //ErrorButtonClick(); return; } case ModuleStates.CLEAR: { if (openFileDialogDevInfo.ShowDialog() == DialogResult.OK) { var devInfo = File.ReadAllText(openFileDialogDevInfo.FileName); try { await ModuleWritterController.WriteDevInfo(_moduleInformation, devInfo); MessageBox.Show("Тип устройства успешно записан"); NeedRefreshAction?.Invoke(_moduleInformation.ModulePosition); } catch (Exception exception) { Console.WriteLine(exception); throw; } } return; } case ModuleStates.WITHOUTTYPE: { return; } default: { this.OpenFile(); break; } } }
private async void _toLoaderState_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Перевести в режим загрузчика?", "Внимание", MessageBoxButtons.YesNo); if (dr == DialogResult.No) { return; } try { ModuleWritterController.ModuleMLKToloader(_moduleInformation); Thread.Sleep(500); ConnectionManager.Connection.Serialport.BaudRate = 230400; MessageBox.Show("Запрос на перевод в режим загрузчика отправлен"); NeedRefreshAction?.Invoke(_moduleInformation.ModulePosition); } catch (Exception exception) { MessageErrorBox messageErrorBox = new MessageErrorBox(exception.Message, "Ошибка перевода в режим загрузчика"); messageErrorBox.ShowErrorMessageForm(); } }
private async void _toBootloaderButton_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Перевести в режим загрузчика?", "Внимание", MessageBoxButtons.YesNo); if (dr == DialogResult.No) { return; } else { try { await ModuleWritterController.ModuleToloader(_moduleInformation); } catch (Exception exception) { MessageBox.Show("Не удалось перевести в режим загрузчика"); NeedRefreshAction?.Invoke(_moduleInformation.ModulePosition); return; } MessageBox.Show("Модуль переведен в режим загрузчика"); NeedRefreshAction?.Invoke(_moduleInformation.ModulePosition); } }
public async Task SetLoader(ModuleWritterController moduleWritterController) { try { _moduleWritterController = moduleWritterController; byte[] result = await _moduleWritterController.ReadPage(_progress); _config = new AllConfig(result); } catch (Exception e) { MessageErrorBox me = new MessageErrorBox(e.Message, "Создать конфигурацию по умолчанию?"); bool res = me.ShowErrorMessageForm(); if (res) { _config = new AllConfig(); } } ShowRelay(); ShowDiscret(); ShowDiode(); ShowSystemDiode(); }