now that my starting-troubles are cleared, I have a more complex problem, and I hope you can help me...
I´m trying to draw a linegraph with data that comes trough a TCP socket stream.
the data is coming continuously at a speed of 100 samples per second. As the data comes trough TCP socket, the data is beeing "packaged", so I get a bounch of data about once per second (about 100 samples, but not exactly 100...)
I tried to write the data into an ArrayList (because the amount of bytes may vary), but this throws an error, so that I had to use a byteArray
I write the data like this:
public void readData(){
if (myClient.available() > 0) {
// Read in the bytes byteCount = myClient.readBytes(byteBuffer); myClient.clear();
in draw() I splitt the interesting data and convert it to int and then draw the vertices like this:
for( i = 0; i<numbers.length;i++){ vertex(i,200-numbers[i]); if (byteCount > 0 ) { { if ((byteBuffer[i]==36 ) && (byteBuffer[i+1]==18)) { j=unhex(hex(byteBuffer[i+2])+(hex(byteBuffer[i+3])));
numbers[numbers.length-1]=200-j/5;
} } }
}
every 1000 mills I call the funcition ReadData(), so the buffer is beeing filled again.
my problem is, I´m loosing data.
I found the BufferedInputReader, and I think it may be helpfull in my case, but I cannot find how to use it with TCP client.
I post the whole code of the sketch, may be you can give me some hints what I can do better...
At the moment the input is a rectangle at 1,1 Hz with 50% dutycycle, for the case anyone of you might try to run the sketch....
import processing.net.*; Client myClient; byte[] byteBuffer = new byte[503]; int[] numbers = new int[499];
int f =0; int i=0; int t=0; int j=0; int byteCount=0;
// Declare a global time tracking variable long timeSinceLastEvent; long DELAY_BETWEEN_EVENTS = 1000; // 1s