Beispiel #1
0
        private static void SetPort()
        {
            var ports = ComManager.ListComPorts();

            if (ports.Count(x => x.EqualUsbVid) > 0)
            {
                ComManager.SetComPort(ports.First(x => x.EqualUsbVid).Name);
            }
        }
        private void RefreshComPorts()
        {
            comboPorts.Items.Clear();
            // ReSharper disable once CoVariantArrayConversion
            comboPorts.Items.AddRange(ComManager.ListComPorts()
                                      .Select(x => x.Name)
                                      .ToArray());

            var selectedComPort = ComManager.GetComPort();

            if (!string.IsNullOrEmpty(selectedComPort) && comboPorts.Items.Contains(selectedComPort))
            {
                comboPorts.SelectedItem = selectedComPort;
            }
            else
            {
                if (comboPorts.Items.Count > 0)
                {
                    comboPorts.SelectedIndex = 0;
                }
            }
        }