CDC & BytesToRead

I have one more CDC related suggestion. [em]Read[/em] method works a bit differently in 4.3, it now throws “Operation timed out” exception.

Dim _cdc As New Cdc()
Dim cdcBuffer(255) As Byte

_cdc.Stream.ReadTimeout = 0
Do
    _cdc.Stream.Read(cdcBuffer, 0, 256)
Loop

Using this peace of code, I will be getting exception almost every single time. As we know, handling exceptions are not efficient and will slow this loop significantly. I would like to suggest adding [em]BytesToRead[/em] property (SerialPort class has it).

@ iamin - A BytesToRead property would definitely be helpful, but it isn’t as easy to add as the other property was. We will look into it though for a future release.

@ John - If that turns out to be too hard to implement, maybe you could offer a way to avoid throwing that exception as it was done before.

@ iamin - You can sent ReadTimeout to Timeout.Infinite to block in the function forever until data is available in the next SDK.

(This change and the LastWritten change were actually added shortly after the 2014 R5 SDK.)

[quote=“John”]
@ iamin - You can sent ReadTimeout to Timeout.Infinite to block in the function forever until data is available in the next SDK.[/quote]
[em]Timeout.Infinite[/em] option is a good addition, I was missing it as well but I could live without it.
However, [em]Timeout.Infinite[/em] does not solve the issue I am having with exceptions (I make an assumption here because I have not seen how exactly you have changed things). If I ask to read 256 bytes but there are only 10 bytes available after 1 minute, another 10 bytes available after one more minute and so on - it will block my function for 25 minutes. I could reduce 256 to 1 byte but then reading data would not be efficient if large chunks of data are received.
One of the options would be using derived classes but this request is pending ::slight_smile:

That explains how you have managed to respond so quickly to my previous request with [em]LastWritten[/em] 8)

@ iamin - Right. If you know the frequency and amount of data arriving, you can optimize around that. But we will still look into BytesToRead for the case when you don’t.