I've been using the serial library recently, and I've found an annoyance related to the Java type
byte.
All numeric types in Java are signed, so the range of values for a
byte is [-128, 127]. Mostly, when I'm reading serial data, I'd like unsigned information, and I think this is fairly common.
I propose that the Serial library should include functions for returning
int[], similar to the
readBytes() functions. Java represents bytes as 32bit values anyway, so there's no space saving to bytes. In fact, I suggest that the internal buffer should be
int[] and another read function should be added:
Code:public int read(int outgoing[])
I also wonder if a function to peek at incoming data would simplify some client code...
Code:public int peek() {
if (bufferIndex == bufferLast) return -1;
synchronized (buffer) {
return buffer[bufferIndex] & 0xff;
}
}
I'd be happy to donate an implementation, if there is interest.