Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the cause of System.IO.IOException on windows XP embedded version?

I am running a .Net 3.5 application on Windows XP embadded version. This application writes and reads some data over the serial (COM) port. The application works fine on my laptop (windows XP Professional) but not on windows XP embedded. I keep getting this error:

System.IO.IOException: The I/O operation has been aborted because of either a thread exit or an application request.

What could be the causing it?

Some additional info: to read, I am using ReadExisting and not Readline. Also before reading I am making sure the port is open too.

System.IO.IOException: The I/O operation has been aborted because of either a thread exit or an application request.
at System.IO.Ports.SerialStream.EndRead(IAsyncResult asyncResult)
at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count, Int32 timeout)
at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count)
at System.IO.Ports.SerialPort.ReadExisting()
at ScalesApp.Scales.handleDataReceived(Object sender, SerialDataReceivedEventArgs e)
at System.IO.Ports.SerialPort.CatchReceivedEvents(Object src, SerialDataReceivedEventArgs e)
at System.IO.Ports.SerialStream.EventLoopRunner.CallReceiveEvents(Object state)
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
like image 784
Prithis Avatar asked Feb 28 '23 11:02

Prithis


1 Answers

The problem is that the fAbortOnError is enabled in SetCommState's DCB, which explains for most of the IOExceptions thrown by the SerialPort object. Some PCs / handhelds have UARTs that enable the abort on error flag by default - so it's imperative that a serial port's init routine clears it (which Microsoft neglected to do). The SerialPort object wasn't designed with fAbortOnError enabled in mind.

I wrote a long article recently to explain this in greater detail (see this if you're interested).

like image 142
Zach Saw Avatar answered Apr 26 '23 23:04

Zach Saw