public async Task <ModuleInformation> ReadModuleInformation(IDeviceSpecification deviceSpecification, byte devicenumber, int i) { ModuleInformation moduleInformation = new ModuleInformation(); try { ushort[] answer = await ConnectionManager.Connection.ModbusMasterController.ReadHoldingRegistersAsync(devicenumber, (ushort)(deviceSpecification.StartAddInfo + MODULE_INFO_SIZE * i), MODULE_INFO_SIZE, "Чтение информации о модуле"); byte[] answerBytes = Common.TOBYTES(answer, false); char[] str = Common.GetChars(answerBytes).Select(o => o == '\0' ? ' ' : o).ToArray(); string str1 = new string(str, 0, 16); string str2 = new string(str, 16, 16); string str3 = new string(str, 32, 16); var addingInfo = answerBytes.Skip(16).Select(o => (byte)o).Take(16).ToArray(); moduleInformation = new ModuleInformation(str1, addingInfo, str3, (byte)i); moduleInformation.ModulePositionOnSpecification = deviceSpecification.ModuleTypes[i]; moduleInformation.ControlType = deviceSpecification.ControlType; } catch (Exception e) { throw; } return(moduleInformation); }
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; }
public MailService() { this._textProvider = (IMvxTextProvider)Mvx.get_IoCProvider().Resolve <IMvxTextProvider>(); this._deviceSpecification = (IDeviceSpecification)Mvx.get_IoCProvider().Resolve <IDeviceSpecification>(); this._studentDataService = (IStudentDataService)Mvx.get_IoCProvider().Resolve <IStudentDataService>(); this._webNavigation = (IWebNavigation)Mvx.get_IoCProvider().Resolve <IWebNavigation>(); }
public void ExecuteFile(string _fileName, string _pathString, IDeviceSpecification deviceSpecification) { using (Process executeProcess = new Process()) { log.Clear(); _syncContext = SynchronizationContext.Current; CreateCommandString(deviceSpecification); executeProcess.StartInfo.FileName = _fileName; executeProcess.StartInfo.Arguments = CommandString; executeProcess.StartInfo.CreateNoWindow = true; //executeProcess.StartInfo.Verb = "runas"; executeProcess.StartInfo.UseShellExecute = false; executeProcess.StartInfo.RedirectStandardOutput = true; executeProcess.StartInfo.RedirectStandardError = true; executeProcess.StartInfo.RedirectStandardInput = true; executeProcess.StartInfo.StandardErrorEncoding = Encoding.GetEncoding(866); executeProcess.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(866); executeProcess.OutputDataReceived += (sender, args) => ToLog(args.Data); executeProcess.ErrorDataReceived += (sender, args) => ToLog(args.Data); executeProcess.Start(); //executeProcess.BeginOutputReadLine(); executeProcess.BeginErrorReadLine(); executeProcess.StandardInput.WriteLine(_pathString); executeProcess.StandardInput.WriteLine(CommandString); //executeProcess.StandardInput.Flush(); executeProcess.StandardInput.Close(); executeProcess.StandardInput.Dispose(); executeProcess.WaitForExit(0); } }
private void OnBurnFirmwareCommand() { try { _burnDeviceButton.Enabled = false; _outputRichTextBox.Clear(); workActions.OpenOCDDirectory = OpenOCDDirectory; workActions.OpenOCDExecName = OpenOCDExecName; _currentDevice = new DeviceSpecification(FirmwareFile, ProcType); try { workActions.ExecuteFile("cmd.exe", @"cd " + OpenOCDDirectory, _currentDevice); } catch (Exception ThreadException) { MessageBox.Show(ThreadException.Message.ToString()); } _burnDeviceButton.Enabled = true; } catch (Exception e) { MessageBox.Show(e.Message.ToString()); _burnDeviceButton.Enabled = true; } }
private void UpdRowsTypes_event(object sender, EventArgs e) { specification = ((Stand)sender).DeviceSpecification; TitlesDevice = specification.Titles; RangeTypesLabels = specification.RangeTypesLabels; Modifications = specification.Modifications; Modification2 = specification.Modifications2; ThreadTypes = specification.ThreadTypes; Classes = specification.Classes; OutPortType = specification.OutPortType; UpdRangeRow(); }
/// <summary> /// Проверка на содержание устройства в списке допустимых устройств /// </summary> /// <param name="device"></param> /// <returns></returns> private bool IsDeviceConteins(string device) { foreach (var type in AvailableDeviceSpecifications) { if (type.DeviceName == device) { _currentDeviceSpecification = type; return(true); } } return(false); }
public EugyintezesApi( ISecureStore secureStore, IMobileApi mobileApi, IUserAgentService userAgentData, IDataViewer dataViewer) { this._secureStore = secureStore; this._mobileApi = mobileApi; this._userAgentData = userAgentData; this._dataViewer = dataViewer; this._deviceSpecification = (IDeviceSpecification)Mvx.get_IoCProvider().Resolve <IDeviceSpecification>(); }
private void CreateCommandString(IDeviceSpecification _currentDevice) { _commandString.Clear(); _commandString.Append(OpenOCDExecName); _commandString.Append(" -f "); _commandString.Append(_currentDevice.ProcType); _commandString.Append(@" -c init -c ""reset halt"" -c ""flash write_image erase " + _currentDevice.FirmwareFile); _commandString.Append(@""" -c ""reset run"" -c shutdown"); log.AppendLine("Сформирована командная строка: " + CommandString); log.AppendLine(""); log.AppendLine("Выполнение команды: "); }
public async Task <IDeviceSpecification> IdentifyDevice(byte devicenumber) { bool checkAllAdress = false; ushort[] answerforMr; ushort[] answerforOther; _currentDeviceSpecification = new UnknownDeviceSpecification(); try { answerforMr = await ConnectionManager.Connection.ModbusMasterController.ReadHoldingRegistersAsync(devicenumber, 0x500, 0x10, "Определение типа устройства"); if (VersionForMR(answerforMr)) { return(_currentDeviceSpecification); } } catch (Exception e) { } try { answerforOther = await ConnectionManager.Connection.ModbusMasterController.ReadHoldingRegistersAsync(devicenumber, 0x1f00, 0x18, "Определение типа устройства"); if (VersionForOther(answerforOther)) { return(_currentDeviceSpecification); } } catch (Exception e) { throw; } return(_currentDeviceSpecification); }