private void CmdClearLog_OnClick(object sender, RoutedEventArgs e) { if (_ctx != null) { _ctx.Send(state => { TxtLogView.Clear(); }, null); } }
private void OpenCom() { TxtLogView.Clear(); ComPortInformation comInfo = CmbComPorts.SelectedItem as ComPortInformation; if (comInfo == null) { throw new Exception("COM Port is invalid"); } Log("Open COM Port: " + comInfo.DeviceCaption); CloseCom(); _serialPort = new SerialPort(comInfo.DeviceId, 9600, Parity.None); _serialPort.DataReceived += SerialPortOnDataReceived; _serialPort.ErrorReceived += SerialPortOnErrorReceived; try { _serialPort.Open(); } catch (Exception ex) { Log(string.Format("Open failed: {0}", ex.Message)); CloseCom(); } }