public override void ReadFromConfig() { ComPort = GetConfigString("COM1", "ComPort"); BaudRate = GetConfigInt(57600, "BaudRate"); ComPorts.Clear(); foreach (var port in SerialPort.GetPortNames()) { ComPorts.Add(port); } if (ComPorts.Count == 0) { ComPorts.Add("COM1"); } BaudRates.Clear(); BaudRates.Add(300); BaudRates.Add(1200); BaudRates.Add(2400); BaudRates.Add(4800); BaudRates.Add(9600); BaudRates.Add(14400); BaudRates.Add(19200); BaudRates.Add(28800); BaudRates.Add(38400); BaudRates.Add(57600); BaudRates.Add(115200); }
public MainViewModel() { OpenFile = new RelayCommand(() => { OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "Text files (*.txt)|*.txt" }; if (openFileDialog.ShowDialog() != true) { return; } SenderTextBox = File.ReadAllText(openFileDialog.FileName); }); Send = new RelayCommand(() => { if (_modemTalking == null || _selectedCom == null) { MessageBox.Show("Choose serial port."); return; } if (SenderTextBox == null) { MessageBox.Show("Enter message to be sent."); return; } _modemTalking.Send(SenderTextBox); }); RefreshPorts = new RelayCommand(() => { _modemTalking?.Close(); _selectedCom = null; ComPorts?.Clear(); foreach (var portName in SerialPort.GetPortNames()) { ComPorts?.Add(portName); } }); ClosePorts = new RelayCommand(() => { _modemTalking?.Close(); }); }
public MainViewModel() { OpenFile = new RelayCommand(() => { OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "Text files (*.txt)|*.txt" }; if (openFileDialog.ShowDialog() != true) { return; } SenderTextBox = File.ReadAllText(openFileDialog.FileName); }); Send = new RelayCommand(() => { if (_senderModem == null || _selectedSenderCom == null) { MessageBox.Show("Choose serial port."); return; } if (SenderTextBox == null) { MessageBox.Show("Enter message to be sent."); return; } Task.Run(() => _senderModem.Send(Encoding.GetEncoding(28591).GetBytes(SenderTextBox))); }); BackgroundWorker reciveWorker = new BackgroundWorker(); reciveWorker.DoWork += ReciveMessage; reciveWorker.RunWorkerCompleted += ReciveWorker_RunWorkerCompleted; Receive = new RelayCommand(() => { if (_reciverModem == null) { MessageBox.Show("Choose serial port."); return; } if (!reciveWorker.IsBusy) { reciveWorker.RunWorkerAsync(); } }); RefreshPorts = new RelayCommand(() => { _senderModem?.Close(); _reciverModem?.Close(); _selectedReciverCom = null; _selectedSenderCom = null; ComPorts?.Clear(); foreach (var portName in SerialPort.GetPortNames()) { ComPorts?.Add(portName); } }); }