port.write(frameCount);
This is writing the frame count out as a string - NOT A SINGLE CHARACTER.
The frameCount keeps incrementing so after a while it get's higher then 255/256 which is the maximum character value if i'm correct.
if (Serial.available()) {
Serial.println(Serial.read());
}
This is reading ONE CHARACTER and pretending that it is the COMPLETE frame count. It, obviously, is NOT.
i must have looked over that, thanks, good to know
I tryed the code you posted, thanks for the contribution!!
What does this line do?
inData[index] = '\0';
(that line is also in the if(index < 19) part, where it is not needed i believe).
Unfortunatly it's still not working:
My serial monitor output is:
Recived
Receivd: <>
Receied: <>
Recived <>
Red: <>
Receied: Received <>
Receive: <>
Rceived: >
ece <>
Receive: <>
R
Received: >
ved: <>
Recived>
Rceivd: >
ved: <>
and the processing console shows:
R<>
eive: <
RecReceiveived: < <>
Rece: <>
ived: <>
Reed: < >
>
Received>
Rved: <>
Receied: <
>
What do i need for bufferUntil (or nothing)?
port.bufferUntil('\n');
import processing.serial.*;
Serial port;
String inString;
void setup() {
frameRate(1);
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);
//port.bufferUntil('\n');
}
void draw() {
port.write("[");
port.write(frameCount);
port.write("]");
println(inString);
}
void serialEvent(Serial port) {
inString = port.readString();
}
Your boolean started was never set back to false so it could be removed.
I also removed the other boolean and ended up with this:
(afcorse still no frameCount cause i continued on something that didn't work).
char inData[20];
byte index;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == '[')
{
index = 0;
inData[index] = '\0';
}
else if(inChar == ']')
{
Serial.print("Received: <");
Serial.print(inData);
Serial.println(">");
break;
}
else
{
if(index < 19)
{
inData[index++] = inChar;
}
}
}
}