We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexSuggestions & BugsSoftware,  Documentation,  Website Suggestions › A suggestion for the Serial library
Page Index Toggle Pages: 1
A suggestion for the Serial library (Read 610 times)
A suggestion for the Serial library
May 23rd, 2007, 2:49pm
 
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.
Page Index Toggle Pages: 1