Ejemplo n.º 1
0
        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();
            }
        }
        public void LoadPorts()
        {
            IEnumerable <string> ports    = SerialReader.GetAvailablePorts();
            List <string>        toChange = new List <string>();

            //Search not non-existent
            foreach (var port in ComPorts)
            {
                if (!ports.Contains(port))
                {
                    toChange.Add(port);
                }
            }
            //Delete not non-existent
            ComPorts.RemoveRange(toChange);
            toChange.Clear();
            //Search New
            foreach (var port in ports)
            {
                if (!ComPorts.Contains(port))
                {
                    toChange.Add(port);
                }
            }
            //Add New
            ComPorts.AddRange(toChange);
            //Select One if needed
            if (SelectedComPort == null || !ComPorts.Contains(SelectedComPort))
            {
                SelectedComPort = ComPorts.FirstOrDefault();
            }
        }
Ejemplo n.º 3
0
        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);
                }
            }
        }