Read serial 8 bytes from Arduino buffer I am fairly new to Java, but with a rather complicated question.

We are looking at reading some bytes coming in from an Arduino. The Arduino sends bytes in the form:

 Serial.print(Voltage1);
 Serial.print(voltage2);


Since these voltages are numbers of the format "1.62", two digits after the decimal point, the Arduino sends 8 bytes, 4 for each voltage.

Previously in a MATLAB test we managed that by making the inputbuffer=8, and then splitting the bytes by doing something of the sort A=buffer(1:4) B=buffer(5:8), and as such we could plot or read the signals from the Arduino.

Is there a way to achieve this in Java? At the moment we are creating an input stream, and we tried to limit that to a buffer of the correct size, but we do not get anything even close to the expected. Most of the time our input from inputstream.read() gives us negatives, but not even something that we can understand or work with.

I hope this is well explained, and I really wish someone knows how to deal with this problem.
The standard way of doing this is to use delimiters. Serial is a streaming protocol, you don't necessarily get data in fixed size chunks. Something suitable would be like:

&lt;1.23,4.56&gt;


Notice the delimiters "&lt;", "," and ">".

The receiving end ignores incoming data until it gets "&lt;". Then it reads until it gets a comma. Between those two are the first number. Then it reads again until it gets a ">". Between those are the second number. Now you validate that what you got are in fact numbers.

This allows you to easily expand in the future to larger numbers, and more decimal places, eg.

&lt;42.213,674.50326&gt;