Gets an array of serial port names for the current computer. : SerialPort « Development Class « C# / C Sharp






Gets an array of serial port names for the current computer.

  

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();
        }

    }
}

   
    
  








Related examples in the same category

1.Set BaudRate, Parity, ReadTimeout, StopBits for COM1 SerialPort
2.SerialPort Class represents a serial port resource.
3.Represents the method that will handle the data received event of a SerialPort object.
4.Write data to COM port