Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WriteFile returning error code 995

I have searched stackoverflow and googled thoroughly for this problem but not been able to find a clue to why this problem is happening.

I am writing a program in C++ which communicates with a measurement device connected through USB. The program is multithreaded and several threads will communicate with the device. A mutex is used to guarantee that no two threads try to read or write from the device at the same time.

Commands are sent to the device using WriteFile and the responses and measured values are read using ReadFile - both operations are done synchronously.

Sometimes while reading the measured value from the device will the measurement fail with a timeout (GetLastError() returns error code 121), due to a synchronization error inside the measurement device itself - which is ok and expected.

When I try to continue the measurement, by sending a new command will WriteFile sometimes (roughly 50% of the time) fail and GetLastError() returns the error code 995 which is described in MSDN as:

ERROR_OPERATION_ABORTED

995 (0x3E3)

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

There is no thread exit after the timeout occurs and there is no cancel of any read or write operation. I am able to resume the communication only by closing and re-opening the communication with the device using CloseHandle and CreateFile. However, this will take some time from the measurement and is not an ideal solution.

My question is, why does WriteFile return the error code 995 in this case, and what can I do to avoid having to close and re-open the communication with the device?

like image 556
Mattias Johansson Avatar asked Nov 01 '22 10:11

Mattias Johansson


1 Answers

Contact the OEM of your USB-serial device -- we can't help you further with this, since we don't have access to the driver's plumbing. If the device OEM can't help you -- contact the USB-serial chipset's manufacturer; if they refuse to help, throw the USB-to-serial adapter in the garbage can and buy one with a chipset that actually has manufacturer support (such as the FTDI or Silicon Labs USB-serial chips), not some cheap clone garbage.

like image 123
LThode Avatar answered Nov 10 '22 01:11

LThode