According to the MSDN site, SerialPort.Write is supposed to return the number of bytes written:
C#
[MethodImplAttribute(InternalCall)]
public int Write (
byte[] buffer,
int offset,
int count
)
Parameters
buffer
The byte array that contains the data to write to the port.
offset
The zero-based byte offset in the buffer parameter at which to begin copying bytes to the port.
count
The number of bytes to write.
Return Value
The number of bytes written.
This code works
private static int bytesUploaded = 0;
public static bool uploadBlock(byte[] bytesToSend)
{
consolePort.Write(bytesToSend, 0, bytesToSend.Length);
consolePort.Flush();
return true;
}
but this code give a "Cannot implicitly convert type ‘void’ to ‘int’ " error
Gives the same error. I always assume that I’m doing something wrong and am not usually disappointed. But in this case the error is pretty clear that SerialPort.write is returning a void which seems to be at odds with the MSDN page. Maybe for once it isn’t my mistake.
@ Gene - Actually, according to the actual implementation, MSDN is wrong. It does in fact return a void. A bug report should be submitted to either A) Return a value or B) Fix the documentation on MSDN.
Some of the methods in NETMF are not exactly implemented the same wa as in win.net. To make it worse, the NETMF api docs are sometimes a copy of the win.net docs. Sometimes whole methods are missing, even the docs says it’s there. In NETMF it is often better to trust intelli sense