Go Down

Topic: Bug (Read 934 times) previous topic - next topic

TheNorm

Apr 09, 2012, 03:32 am Last Edit: Apr 09, 2012, 03:38 am by TheNorm Reason: 1
I'm not sure where this should go but I'm sure it's a bug.

In http://arduino.cc/en/Reference/StreamReadBytes readBytes is documented as taking either char[] or byte[] but when used with an SD File object you have to cast it to char[]. Hell it's called readBytes not readChars. Perversely enough an eithernet client wants bytes.

      This works but vice-versa fails
 
      byte bfr[outBfrSz];
     source.readBytes((char)bfr,outBfrSz);
     client->write(bfr,outBfrSz);

KE4UKZ

I noticed this too using the Serial.readBytes() function (which is inherited from the Stream library).  I didn't want to use chars because I don't want 0xff == -1.  I overloaded the Stream::readBytes() function in Stream.cpp and Stream.h to have a char * as well as a byte * version, and now it compiles happily using a byte array.

Go Up