private void RefreshComPorts() { var coms = SerialPort.GetPortNames(); foreach (var p in coms) { if (!ComPorts.Contains(p)) { ComPorts.AddSorted(p); } } foreach (var p in ComPorts.ToList()) { if (!coms.Contains(p)) { ComPorts.Remove(p); } } if (SelectedComPort == null && ComPorts.Count > 0) { SelectedComPort = ComPorts.First(); } }
private void CheckForNewPortsAsync() { IEnumerable <string> ports = SerialPort.GetPortNames().OrderBy(s => s); foreach (string comPort in ComPorts) { if (!ports.Contains(comPort)) { ComPorts.Remove(comPort); } } foreach (var port in ports) { if (!ComPorts.Contains(port)) { AddPort(port); } } }