Why does my COM port not exist?

So this code gets all the serial ports, and makes them into a selectiongrid with one button for each port.

When you click one of the COM ports, it goes to the line after the snip:

    string[] ports;
    ports = SerialPort.GetPortNames();
    selectionGridInt = GUI.SelectionGrid (new Rect (25, 25, 300, 60), selectionGridInt, ports, 1);
(snip)
    SerialPort SerialStream = new SerialPort(ports[selectionGridInt], 9600, Parity.None, 8, StopBits.One);

But I get an error: Port “COM11” does not exist. (COM11 is the name of the button I click, and is the only serial port on my system.) I don’t understand: I’m getting the name of the port from the system, so why is it saying it doesn’t exist?

(I don’t know where that “5.” comes from on the last line, I didn’t write it there)

This is one of those weird things…
Use this syntax for ports >10.

new SerialPort("\\\\.\\COM11",9600);

Why?
https://support.microsoft.com/en-us/kb/115831

i read somewhere that with serial ports you kan go up to COM9 caused by some 2-digit problem … can anyone confirm this ?
if that is the problem you could just filter out the 2 digit ports … im wrestling with the serial port my self - but i haven’t that many so i cant reproduce the problem here :slight_smile: