msdn 中的代码:using System; using System.IO.Ports;namespace SerialPortExample { class SerialPortExample { public static void Main() { // Get a list of serial port names. string[] ports = SerialPort.GetPortNames(); Console.WriteLine("The following serial ports were found:"); // Display each port name to the console. foreach(string port in ports) { Console.WriteLine(port); } Console.ReadLine(); } } } 得到名字后, 使用名字构造 SerialPort 类实例即可
using System.IO.Ports;namespace SerialPortExample
{
class SerialPortExample
{
public static void Main()
{
// Get a list of serial port names.
string[] ports = SerialPort.GetPortNames(); Console.WriteLine("The following serial ports were found:"); // Display each port name to the console.
foreach(string port in ports)
{
Console.WriteLine(port);
} Console.ReadLine();
} }
}
得到名字后, 使用名字构造 SerialPort 类实例即可