hi folks,
I'm trying to steer my arduino from my pc. I send a serial call with java to the arduino xbee shield. there I read out something and send it back over the serial port. Everything is working fine and I get the right response. I have only a short delay for each call.
Now my problem:
After 9 calls I get my first big delay with an amount of 5-8 seconds. Then I have some fast responses and then again some long delays.
What could be the reason for this big delays? Has anyone an idea?
I first thought this is because of the xbee sleepmode but X-CTU says the sleepmode is inactive.
here my arduino code:
(an example call would be '!8121')
void loop()
{
int input[4];
memset(input, '\0', 4);
int in = '\n';
while(in != '!')
{
in = Serial.read(); // Wait for the start of the message
}
while(Serial.available() < 4)
{
// Wait until we receive 4 characters
;
}
for(int i=0; i < 4; i++)
{
input[i] = Serial.read();
}
handleMessage...
Serial.print(actionId, BYTE);
Serial.print(value, BYTE);
Serial.println();
}
here my java code:
protected synchronized void write(String out)
{
OutputStream outstream = handler.getSerialOutputStream();
String serialMessage = out+"\r\n";
try {
outstream.write(serialMessage.getBytes());
outstream.flush();
outstream = null;
} catch (IOException e) {
e.printStackTrace();
}
}
protected synchronized void readSerial()
{
InputStream inStream = handler.getSerialInputStream();
try
{
int availableBytes = inStream.available();
if(availableBytes > 0)
{
// Read the serial port
byte[] readBuffer = new byte[availableBytes];
inStream.read(readBuffer);
// Print it out
//log.info("read out --> " + new String(readBuffer));
}
}
catch (IOException e)
{
log.info(e.getMessage());
}
}
thanks in advance