public void InitComList() { string[] ports = SerialPort.GetPortNames(); if (ports.Length != 0) { foreach (string comport in ports) { ComList.Add(comport); } ComString = ComList.ElementAt(0); } }
public void UpdateComList() { string[] ports = SerialPort.GetPortNames(); string temp = ComString; ComList.Clear(); foreach (string item in ports) { if ((ComList.Where(x => x == item).FirstOrDefault() == null)) { ComList.Add(item); } } if (ComList.Contains(ComString)) { ComString = temp; } }