I am trying to open COM1, but get a strange error every time I call SerialPort.Open()
.
The error is:
The given port name does not start with COM/com or does not resolve to a valid serial port. Parameter name: portName
The code is very simple:
SerialPort port = new SerialPort("COM1", 19200, Parity.None, 8, StopBits.One);
port.Handshake = Handshake.RequestToSend;
port.Open();
If I call SerialPort.GetPortNames()
, it returns one port called "COM1".
I've verified that I have a "COM1" on my computer, and I'm not using it in any other applications. When I run the code on another computer, it works. My system is running Windows Vista. The version of .NET is 2.0.
Is there a security setting I have to change somewhere? I'm logged in as an admin, and have UAC turned off.
More info
I used Process Explorer and confirmed that nothing is using \Device\Serial0.
Workaround
I installed a USB-Serial adaptor (COM3), and it works fine. Go figure. There must be a problem with COM1.
The error "Could not open serial port", means that you do not have the correct comm port selected in Projects. Go to "Options" -> "Project Options" -> on the Communications Tab, choose the correct "Serial Port" under "Serial Options".
This error indicates "Access is denied". You may see this error when when attempting to use an already open COM port, it's been used by other program. You could try close other software that may be using the port in the Task manager, and try again.
I had this problem too. It turned out that I had a printer set to use the COM port I was trying to open. Once I changed the printer to use another port the port opened just fine.
Try to use the notation \.\COMX instead of just COMX. Ensure you escape the characters: "\\.\COM1"
Edit:Wops, SO escapes my \ so it should be like this (ommit spaces): "\ \ \ \ . \ \ COM1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With