I have a board that has a CP2102N device on it.
I have an issue toggling RTS when using C# on Windows 10.
After opening the port, any call to "myPort.RtsEnable" causes an :
System.IO.IOException: A device attached to the system is not functioning.
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.SerialStream.set_RtsEnable(Boolean value)
at System.IO.Ports.SerialPort.set_RtsEnable(Boolean value)
This ***only*** happens with C#. If I do the same with Java, everything is fine.
Also, if I set RTS *before* I open the port, no exception, but once the port is opened, any call to set_RtsEnable causes the exception.
C# Code snippet follows (compiled using Visual Studio 2017):
myPort.BaudRate = Convert.ToInt32("115200"); myPort.DataBits = Convert.ToInt16("8"); myPort.StopBits = System.IO.Ports.StopBits.One;
myPort.Handshake = System.IO.Ports.Handshake.None;
myPort.Parity = System.IO.Ports.Parity.None myPort.Open(); myPort.DtrEnable = false; //<-- These are fine myPort.DtrEnable = true; //<-- These are fine myPort.RtsEnable = true; //<-- Causes the exception!!!!!
DTR however works as expected, no issues. It is only when RTS is set.
The first call to RtsEnable causes the exception.
Interestingly enough, I have a different board that has a CP2102 (no 'N') on it and everything works as expected!!
Is there a bug in the CP2102N or the corresponding driver for the 'N' version?
I have another similar board that has a CP210X device (note not an 'N' version) that works as expected, so this seems to be an issue with the CP2102N and the Windows driver.
To my knowledge, a reasonable configuation is the pre-condition of the opening operation. If user need to use the flow control functioning, they should enable it before open the COM port.
And the wild guess for the different behavior of Java and C# is that they may have different default processing for the COM port.
My views are my own and do not necessarily represent the views of Silicon Labs
Well SI have acknowledged that this is a possible/probable bug and are looking into it.
BTW, RTS is often used these days for other than flow control.
For example, to control some board function such as reset.
I just happen to be using a C# SW package that assumes this is the case. Not my design.