- Home /
The question is answered, right answer was accepted
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)
Answer by ronenz · Apr 21, 2016 at 07:16 PM
This is one of those weird things... Use this syntax for ports >10.
new SerialPort("\\\\.\\COM11",9600);
How to necro a 3 year old post :p
Either way, I had this problem very recently aswell :p Took me a while to get an answer to this aswell :p
I used the following to conect to any port now, similar to your answer but looks slightly better in my opinion :p
new SerialPort(@"\\.\" + portname, 9600);
Since this is actually an off-topic question and it has already been answered i will close the question and lock the comments since it seems to get bumped all the time.
The SerialPort class comes with the .NET / $$anonymous$$ono framework and has no relation to Unity.
Answer by MLH1407 · Feb 24, 2013 at 05:59 PM
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 :)
Follow this Question
Related Questions
Sending Data From Unity To Arduino 0 Answers
send string to serial port on android 0 Answers
Unity crashes with serial ports 0 Answers
Transform Unity Object with Arduino 2 Answers
Serial Callbacks/Error Reporting. 0 Answers