首页 > 代码库 > C#串口通信->自动获取串口号

C#串口通信->自动获取串口号

 

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.IO.Ports; 6  7 namespace SerialPortExample1 8 { 9     class Program10     {11         static void Main(string[] args)12         {13             // Get a list of serial port names.14             string[] ports = SerialPort.GetPortNames();15 16             Console.WriteLine("The following serial ports were found:");17 18             // Display each port name to the console.19             foreach (string port in ports)20             {21                 Console.WriteLine(port);22             }23 24             Console.ReadLine();25 26         }27     }28 }

---恢复内容结束---

C#串口通信->自动获取串口号