I'm trying to open a COM port in C# but I'm getting an IO Exception with the error message:
The parameter is incorrect
I saw this post: SerialPort.Open() --IOException — “The parameter is incorrect.”
which describes the same problem, but setting RtsEnable
to true
did not resolve my problem (nothing changed).
Here's my code:
cmp_Comport.PortName = "COM6";
cmp_Comport.BaudRate = 9600;
cmp_Comport.Parity = Parity.None;
cmp_Comport.StopBits = StopBits.One;
cmp_Comport.DataBits = 8;
cmp_Comport.Handshake = Handshake.None;
cmp_Comport.RtsEnable = true;
cmp_Comport.DataReceived += new SerialDataReceivedEventHandler(CMP_DadaReceived);
cmp_Comport.Open(); // ==> Causes exception
Here's the full exception stack trace:
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.InternalResources.WinIOError()
at System.IO.Ports.SerialStream.InitializeDCB(Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Boolean discardNull)
at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at MyProject.Comport.CMP_Open(Int32 ind, String& error) in C:...\MyProject\Comport.cs:line 83
Note that in another software, e.g. Hercules, the same port opens just fine.