0

I've recently come across this problem. The software developed in my company does an heavy use of System.IO.Ports.SerialPort for COM port connections. We have now a new embedded PC we're working on, and, when i try to do SerialPort.Open() it throws an exception saying "The data area passed to a system call is too small".

After various tests i found out that other softwares (eg Terminal2, Hercules) can succesfully open said COM port with the same configuration (Baud Rate, Parity, etc), send and receive data, so i think that there's something wrong with the .net Framework's SerialPort implementation (nothing new under the sun).

In device manager these ports are listed as "UartSub Device (COMX)", and the location is Intel(R) Serial IO UART Host Controller. This is at the moment the only difference with the previous system (where SerialPort works fine) i can tell.

Any advice?

EDIT - Adding code snippet for clarity.

SerialPort SP = new SerialPort(CmbPorts.Text.ToString().Trim(), 
                    115200, Parity.None, 8, StopBits.One);

SP.Handshake = Handshake.None;

SP.Open();

This is the StackTrace:

   at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
   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 TestUartCOMPort.Form1.BtnConnect_Click(Object sender, EventArgs e) in C:\Workspace\Projects\TestUartCOMPort\TestUartCOMPort\Form1.cs:line 49
AlbertoA
  • 93
  • 6
  • Hmmm, I have seen this once before. Are you using a virtual COM port? I recall this happened with a virtual com port and the issue ended up being it wasn't setup correctly (I think maybe a baud rate issue). You'll have to make sure the software you use for the virtual COM port is setup correctly. – Baddack Nov 08 '19 at 00:49
  • Unfortunately in this case there's no virtual COM port, it's just what's displayed after the Intel drivers' installation.. And then there's the fact that other software can work with the COM port without problems. – AlbertoA Nov 11 '19 at 14:45
  • Your best bet is to run the debugger and step through the code and see exactly where that error is being thrown. You might try and run the program in compatibility mode. I have a feeling it's a threading issue, but since you haven't posted any code I can't really help. – Baddack Nov 11 '19 at 18:42
  • I added a snippet in the original post. This is called in UI thread, there aren't other threads as this application is just used to test if it's possible to open that COM port. Compatibility mode throws the same exception, the point where the exception is thrown is SP.Open(); Thanks anyways for the help! – AlbertoA Nov 12 '19 at 15:40
  • See https://stackoverflow.com/questions/14885288/io-exception-error-when-using-serialport-open – Baddack Nov 12 '19 at 18:08

0 Answers0