Main Site Documentation

CDC's Write method does not return a value


#1

I am porting some NETMF 4.2 code where CDC is used. I have noticed that Write method in 4.3 does not return the number of bytes written as it was doing in 4.2. Why? Is it intentional? Can you bring this capability back?


#2

@ iamin -

Confirm!

[quote]
Why? Is it intentional?[/quote]
I personally think that it is intentional. It is inherited from SerialPort NETMF that also does not return number of byte written.


#3

@ iamin - Dat is mostly correct. It actually inherits from the Stream class, which has Write return void. If the call does not throw an OperationTimedOutException by the time it returns, you can assume all the bytes were written.


#4

@ John - Aha! I was thinking about TimedOutException as well. If it happens, you don’t know how many bytes were sent.


#5

@ iamin - The next SDK will add a property “LastWritten” to RawStream. It will be updated in case of a timed out exception.


/// <summary>
/// The number of bytes successfully written in the last call to any Write function.
/// </summary>
/// <remarks>
/// Since System.IO.Stream.Write returns void, we cannot return this information from our overload.
/// We also are not updating Position or Length because they are not well defined for a stream like
/// this and they would require tracking the difference yourself.
/// </remarks>
public int LastWritten { get; set; }


#6

That was fast! Merci beaucoup.
:dance: