/// <summary> /// Unloads the current device, and opens the next device /// </summary> /// <param name="device"></param> private async Task StartDevice(NmeaParser.NmeaDevice device) { //Clean up old device if (currentDevice != null) { currentDevice.MessageReceived -= device_MessageReceived; if (currentDevice.IsOpen) { await currentDevice.CloseAsync(); } currentDevice.Dispose(); if (gnssMonitorView.Monitor != null) { gnssMonitorView.Monitor.LocationChanged -= Monitor_LocationChanged; gnssMonitorView.Monitor = monitor = null; } mapplot.Clear(); } output.Text = ""; messages.Clear(); gprmcView.Message = null; gpggaView.Message = null; gpgsaView.Message = null; gpgllView.Message = null; pgrmeView.Message = null; satView.ClearGsv(); satSnr.ClearGsv(); //Start new device currentDevice = device; foreach (var child in MessagePanel.Children.OfType <UnknownMessageControl>().ToArray()) { MessagePanel.Children.Remove(child); } currentDevice.MessageReceived += device_MessageReceived; 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 BluetoothDevice bd) { currentDeviceInfo.Text = $"Bluetooth {bd.Service.Device.Name}"; } await device.OpenAsync(); gnssMonitorView.Monitor = monitor = new GnssMonitor(device); gnssMonitorView.Monitor.LocationChanged += Monitor_LocationChanged; view2d.GnssMonitor = monitor; view3d.GnssMonitor = monitor; }
private void Stop() { if (listener != null) { listener.MessageReceived -= Listener_MessageReceived; } socket?.Close(); socket?.Dispose(); socket = null; listener?.CloseAsync(); listener = null; }
/// <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.GsvMessage = null; //Start new device currentDevice = device; currentDevice.MessageReceived += device_MessageReceived; view2d.NmeaDevice = device; view3d.NmeaDevice = device; 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); } }