1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| using System.IO;
namespace TemperatureTest_WPF { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void ButtonTest_Click(object sender, RoutedEventArgs e) {
string[] portsUSB = SerialPort.GetPortNames(); if (portsUSB == null || portsUSB.Length == 0) { USBlist.Items.Clear(); USBlist.Items.Add("None");
} else { USBlist.Items.Clear(); foreach (string port in portsUSB) { USBlist.Items.Add(port); }
} USBlist.SelectedIndex = USBlist.Items.Count > 0 ? 0 : -1; }
} }
|