private void stopButton_Click(object sender, RoutedEventArgs e) { if (listener != null) { gnssMonitorView.DataContext = null; _ = listener.CloseAsync(); listener.Dispose(); listener = null; startButton.IsEnabled = true; stopButton.IsEnabled = false; } }
/// <summary> /// Unloads the current device, and opens the next device /// </summary> /// <param name="device"></param> private async void StartDevice(NmeaParser.NmeaDevice device) { //Clean up old device if (currentDevice != null) { currentDevice.MessageReceived -= device_MessageReceived; if (currentDevice.IsOpen) { await currentDevice.CloseAsync(); } currentDevice.Dispose(); } output.Text = ""; messages.Clear(); gprmcView.Message = null; gpggaView.Message = null; gpgsaView.Message = null; gpgllView.Message = null; pgrmeView.Message = null; satView.GsvMessages = null; //Start new device currentDevice = device; currentDevice.MessageReceived += device_MessageReceived; var _ = currentDevice.OpenAsync(); if (device is NmeaParser.NmeaFileDevice) { currentDeviceInfo.Text = string.Format("NmeaFileDevice( file={0} )", ((NmeaParser.NmeaFileDevice)device).FileName); } else if (device is NmeaParser.SerialPortDevice) { currentDeviceInfo.Text = string.Format("SerialPortDevice( port={0}, baud={1} )", ((NmeaParser.SerialPortDevice)device).Port.PortName, ((NmeaParser.SerialPortDevice)device).Port.BaudRate); } else if (device is EthernetDevice) { currentDeviceInfo.Text = $"Ethernet device ( IP={((EthernetDevice)device).RemoteEndPoint.Address}, Port={((EthernetDevice)device).RemoteEndPoint.Port})"; } }