Read this once more carefully:
RecvBuffer(buffer: pointer; length: integer) has nothing to do with the result of WaitingData, ...
I understood this. however, I used WaitingData to check if i can read something and this way also if the serial connection is still alive.
My question was now that when I use CanRead if i must fear that also CanRead sometimes tell me that I cannot while in fact I can. I fear this and want to avoid another hour-long debug session to maybe realize that this is the case.
Concerning the error 9997 issue, I think this is a hardware thing. When I got this error I can also not access the COM port using the Arduino serial monitor, even when only try to read data. I also used the Arduino IDE's serial monitor and when I send with this e.g. every second a read command the COM connection got lost and then there is no other way than to replug the USB cable.
And it is sometimes even more strange: despite nobody is at the desk and I can be sure that nothing is moving at the setup, suddenly the serial connection times out and Windows re-initiates the connection but using a doubled registry entry. For example the COM port was "COM29", then there are in the Windows registry two "COM29" entries. The funny thing is that sometimes it doesn't matter what of the two ports one accesses (I rely here always on the Arduino Serial monitor), sometimes it does and sometimes both are inaccessible. There are cases in which even replugging the USB cable does not clean the registry entries. I thought it is dependent on the particular Laptop, bit meanwhile I tested even using an old 32bit Win 7, desktop PCs, brand new laptops, in total 7 different PCs and the situation is the same. And not only the USB plug soldered to the sensor has an influence, also the used USB hub.
Since January I am fighting this issue. It seems serial connections via USB are not very robust. :'(